ExtendTuple() static private method

static private ExtendTuple ( IntPtr t ) : IntPtr
t System.IntPtr
return System.IntPtr
示例#1
0
        public ModuleObject(string name) : base()
        {
            moduleName = (name == String.Empty) ? "CLR" : name;
            cache      = new Hashtable();
            _namespace = name;

            dict = Runtime.PyDict_New();
            IntPtr pyname = Runtime.PyString_FromString(moduleName);

            Runtime.PyDict_SetItemString(dict, "__name__", pyname);
            Runtime.PyDict_SetItemString(dict, "__file__", Runtime.PyNone);
            Runtime.PyDict_SetItemString(dict, "__doc__", Runtime.PyNone);
            Runtime.Decref(pyname);

            Marshal.WriteIntPtr(this.pyHandle, ObjectOffset.ob_dict, dict);

            // This hackery is required in order to allow a plain Python to
            // import the managed runtime via the CLR bootstrapper module.
            // The standard Python machinery in control at the time of the
            // import requires the module to pass PyModule_Check. :(

            if (!hacked)
            {
                IntPtr type = this.tpHandle;
                IntPtr mro  = Marshal.ReadIntPtr(type, TypeOffset.tp_mro);
                IntPtr ext  = Runtime.ExtendTuple(mro, Runtime.PyModuleType);
                Marshal.WriteIntPtr(type, TypeOffset.tp_mro, ext);
                Runtime.Decref(mro);
                hacked = true;
            }
        }
示例#2
0
        public CLRModule() : base("clr")
        {
            _namespace = string.Empty;

            // This hackery is required in order to allow a plain Python to
            // import the managed runtime via the CLR bootstrapper module.
            // The standard Python machinery in control at the time of the
            // import requires the module to pass PyModule_Check. :(
            if (!hacked)
            {
                IntPtr type = tpHandle;
                IntPtr mro  = Marshal.ReadIntPtr(type, TypeOffset.tp_mro);
                IntPtr ext  = Runtime.ExtendTuple(mro, Runtime.PyModuleType);
                Marshal.WriteIntPtr(type, TypeOffset.tp_mro, ext);
                Runtime.XDecref(mro);
                hacked = true;
            }
        }