Esempio n. 1
0
        StoreTyped(PythonExceptions.BaseException exc)
        {
            IntPtr ptr = this.allocator.Alloc((uint)Marshal.SizeOf(typeof(PyObject)));

            CPyMarshal.WriteIntField(ptr, typeof(PyObject), "ob_refcnt", 1);
            object type_ = PythonCalls.Call(Builtin.type, new object[] { exc });

            CPyMarshal.WritePtrField(ptr, typeof(PyObject), "ob_type", this.Store(type_));
            this.map.Associate(ptr, exc);
            return(ptr);
        }
Esempio n. 2
0
        public void ic_destroy(string name, object arg0)
        {
            if (!this.mapper.Alive)
            {
                return;
            }

            this.mapper.EnsureGIL();
            IntPtr ptr0 = IntPtr.Zero; // scoping for catch

            try
            {
                ptr0 = this.mapper.Store(arg0);
                int refcnt = this.mapper.RefCount(ptr0);
                if (refcnt != 2)
                {
                    Console.WriteLine("unexpected refcount {0} when deleting object id {1} at {2}", refcnt, Builtin.id(arg0), ptr0.ToString("x"));
                }
                this.mapper.DecRef(ptr0);
                this.mapper.DecRef(ptr0);
                this.mapper.Unmap(ptr0);
                PythonExceptions.BaseException error = (PythonExceptions.BaseException) this.mapper.LastException;
                if (error != null)
                {
                    this.mapper.LastException = null;
                    throw error.clsException;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error disposing {1} object at {2}: {0}", e, name, ptr0.ToString("x"));
            }
            finally
            {
                this.mapper.ReleaseGIL();
            }
        }