Exemplo n.º 1
0
 // new in CPython 3.5
 public static void _remove_dead_weakref(CodeContext context, PythonDictionary dict, object key)
 {
     if (dict.TryGetValue(key, out var value))
     {
         if (value is @ref r)
         {
             if (r._target.Target is null)
             {
                 dict.Remove(key);
             }
         }
         else if (value is weakproxy wp)
         {
             if (wp._target.Target is null)
             {
                 dict.Remove(key);
             }
         }
         else if (value is weakcallableproxy wcp)
         {
             if (wcp._target.Target is null)
             {
                 dict.Remove(key);
             }
         }
     }
 }
Exemplo n.º 2
0
            // This exists for subtypes because we don't yet automap DeleteMember onto __delattr__
            public void __delattr__(string name) {
                if (name == "__dict__") Delete__dict__();

                if (_dict != null) {
                    _dict.Remove(name);
                }
            }
Exemplo n.º 3
0
        Dispose(bool disposing)
        {
            if (!this.alive)
            {
                return;
            }

            this.alive = false;
            while (this.exitfuncs.Count > 0)
            {
                this.exitfuncs.Pop()();
            }

            PythonDictionary modules = (PythonDictionary)this.python.SystemState.Get__dict__()["modules"];

            if (!modules.Contains("numpy"))
            {
                // TODO: FIXME?
                // I don't know what it is about numpy, but using it heavily
                // makes this step extremely flaky: that's, like, BSOD flaky.
                // OTOH, even attempting this operation is very optimistic
                // indeed, and it's only really here so that I can repeatedly
                // construct/destroy mappers -- without leaking *too* much --
                // during test runs. In the wild, all this will be reclaimed
                // by the operating system at process shutdown time anyway.
                this.map.MapOverBridgePtrs(new PtrFunc(this.DumpPtr));
            }

            this.allocator.FreeAll();
            foreach (IntPtr FILE in this.FILEs.Values)
            {
                Unmanaged.fclose(FILE);
            }

            if (this.stub != null)
            {
                PythonCalls.Call(this.removeSysHacks);
                modules.Remove("mmap");
                modules.Remove("posix");
                modules.Remove("_csv");
                if (modules.Contains("csv"))
                {
                    modules.Remove("csv");
                }

                this.importer.Dispose();
                this.stub.Dispose();
            }
        }
Exemplo n.º 4
0
        internal bool DeleteCustomMember(CodeContext context, string name)
        {
            if (name == "__class__")
            {
                throw PythonOps.TypeError("__class__ must be set to class");
            }
            if (name == "__dict__")
            {
                throw PythonOps.TypeError("__dict__ must be set to a dictionary");
            }

            object delFunc;

            if (_class.HasDelAttr && _class.TryLookupSlot("__delattr__", out delFunc))
            {
                PythonCalls.Call(context, _class.GetOldStyleDescriptor(context, delFunc, this, _class), name.ToString());
                return(true);
            }


            if (name == "__del__")
            {
                // removing finalizer
                if (HasFinalizer() && !_class.HasFinalizer)
                {
                    ClearFinalizer();
                }
            }

            if (!_dict.Remove(name))
            {
                throw PythonOps.AttributeError("{0} is not a valid attribute", name);
            }
            return(true);
        }
Exemplo n.º 5
0
            public void __delattr__([NotNull] string name)
            {
                if (name == "__dict__")
                {
                    Delete__dict__();
                }

                _dict?.Remove(name);
            }
Exemplo n.º 6
0
        public static object RemoveDictionaryValue(IPythonObject self, string name)
        {
            PythonDictionary dict = self.Dict;

            if (dict != null)
            {
                if (dict.Remove(name))
                {
                    return(null);
                }
            }

            throw PythonOps.AttributeErrorForMissingAttribute(self.PythonType, name);
        }
Exemplo n.º 7
0
            public bool DeleteCustomMember(string name)
            {
                if (name == "message")
                {
                    _message = null;
                    return(true);
                }

                if (_dict == null)
                {
                    return(false);
                }

                return(_dict.Remove(name));
            }
Exemplo n.º 8
0
            public bool DeleteMember(CodeContext /*!*/ context, string name)
            {
                switch (name)
                {
                case "__dict__":
                    Delete__dict__();
                    break;
                }

                if (_dict == null)
                {
                    return(false);
                }

                return(_dict.Remove(name));
            }
Exemplo n.º 9
0
 public static object pop(PythonDictionary self, object key, object defaultValue) {
     //??? perf won't match expected Python perf
     object ret;
     if (self.TryGetValueNoMissing(key, out ret)) {
         self.Remove(key);
         return ret;
     } else {
         return defaultValue;
     }
 }
Exemplo n.º 10
0
 public static object pop(PythonDictionary self, object key) {
     //??? perf won't match expected Python perf
     object ret;
     if (self.TryGetValueNoMissing(key, out ret)) {
         self.Remove(key);
         return ret;
     } else {
         throw PythonOps.KeyError(key);
     }
 }