Beispiel #1
0
        IC_file_dealloc(IntPtr ptr)
        {
            if (this.FILEs.ContainsKey(ptr))
            {
                Unmanaged.fclose(this.FILEs[ptr]);
                this.FILEs.Remove(ptr);
            }
            IntPtr       _type   = CPyMarshal.ReadPtrField(ptr, typeof(PyObject), "ob_type");
            dgt_void_ptr freeDgt = (dgt_void_ptr)
                                   CPyMarshal.ReadFunctionPtrField(
                _type, typeof(PyTypeObject), "tp_free", typeof(dgt_void_ptr));

            freeDgt(ptr);
        }
Beispiel #2
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();
            }
        }