ActualiseArbitraryObject(IntPtr ptr) { IntPtr typePtr = CPyMarshal.ReadPtrField(ptr, typeof(PyObject), "ob_type"); PythonType type_ = (PythonType)this.Retrieve(typePtr); object[] args = new object[] {}; if (Builtin.issubclass(this.scratchContext, type_, TypeCache.Int32)) { args = new object[] { CPyMarshal.ReadIntField(ptr, typeof(PyIntObject), "ob_ival") }; } if (Builtin.issubclass(this.scratchContext, type_, TypeCache.Double)) { args = new object[] { CPyMarshal.ReadDoubleField(ptr, typeof(PyFloatObject), "ob_fval") }; } if (Builtin.issubclass(this.scratchContext, type_, TypeCache.String)) { args = new object[] { this.ReadPyString(ptr) }; } if (Builtin.issubclass(this.scratchContext, type_, TypeCache.PythonType)) { string name = CPyMarshal.ReadCStringField(ptr, typeof(PyTypeObject), "tp_name"); PythonTuple tp_bases = this.ExtractBases(typePtr); args = new object[] { name, tp_bases, new PythonDictionary() }; } object obj = PythonCalls.Call(this.classStubs[typePtr], args); Builtin.setattr(this.scratchContext, obj, "__class__", type_); this.StoreBridge(ptr, obj); this.IncRef(ptr); GC.KeepAlive(obj); // TODO: please test me, if you can work out how to }
ActualiseFloat(IntPtr fptr) { double value = CPyMarshal.ReadDoubleField(fptr, typeof(PyFloatObject), "ob_fval"); this.map.Associate(fptr, value); }