Пример #1
0
        Register_PyString_Type(IntPtr address)
        {
            // not quite trivial to autogenerate
            CPyMarshal.Zero(address, Marshal.SizeOf(typeof(PyTypeObject)));
            CPyMarshal.WriteIntField(address, typeof(PyTypeObject), "ob_refcnt", 1);
            CPyMarshal.WriteIntField(address, typeof(PyTypeObject), "tp_basicsize", Marshal.SizeOf(typeof(PyStringObject)) - 1);
            CPyMarshal.WriteIntField(address, typeof(PyTypeObject), "tp_itemsize", 1);
            CPyMarshal.WriteCStringField(address, typeof(PyTypeObject), "tp_name", "str");
            CPyMarshal.WritePtrField(address, typeof(PyTypeObject), "tp_str", this.GetFuncPtr("IC_PyString_Str"));
            CPyMarshal.WritePtrField(address, typeof(PyTypeObject), "tp_repr", this.GetFuncPtr("PyObject_Repr"));

            uint   sqSize = (uint)Marshal.SizeOf(typeof(PySequenceMethods));
            IntPtr sqPtr  = this.allocator.Alloc(sqSize);

            CPyMarshal.Zero(sqPtr, sqSize);
            CPyMarshal.WritePtrField(sqPtr, typeof(PySequenceMethods), "sq_concat", this.GetFuncPtr("IC_PyString_Concat_Core"));
            CPyMarshal.WritePtrField(address, typeof(PyTypeObject), "tp_as_sequence", sqPtr);

            uint   bfSize = (uint)Marshal.SizeOf(typeof(PyBufferProcs));
            IntPtr bfPtr  = this.allocator.Alloc(bfSize);

            CPyMarshal.Zero(bfPtr, bfSize);
            CPyMarshal.WritePtrField(bfPtr, typeof(PyBufferProcs), "bf_getreadbuffer", this.GetFuncPtr("IC_str_getreadbuffer"));
            CPyMarshal.WritePtrField(bfPtr, typeof(PyBufferProcs), "bf_getwritebuffer", this.GetFuncPtr("IC_str_getwritebuffer"));
            CPyMarshal.WritePtrField(bfPtr, typeof(PyBufferProcs), "bf_getsegcount", this.GetFuncPtr("IC_str_getsegcount"));
            CPyMarshal.WritePtrField(bfPtr, typeof(PyBufferProcs), "bf_getcharbuffer", this.GetFuncPtr("IC_str_getreadbuffer"));
            CPyMarshal.WritePtrField(address, typeof(PyTypeObject), "tp_as_buffer", bfPtr);

            CPyMarshal.WriteIntField(address, typeof(PyTypeObject), "tp_flags", (Int32)Py_TPFLAGS.HAVE_GETCHARBUFFER);

            this.map.Associate(address, TypeCache.String);
        }
Пример #2
0
 Register_PyFile_Type(IntPtr address)
 {
     // not worth autogenerating
     // we're using the cpy file type by default, with methods patched in C
     // to redirect into C# when ipy files turn up
     CPyMarshal.WriteIntField(address, typeof(PyTypeObject), "ob_refcnt", 1);
     CPyMarshal.WriteCStringField(address, typeof(PyTypeObject), "tp_name", "file");
     this.map.Associate(address, TypeCache.PythonFile);
 }
Пример #3
0
 Register_PyBool_Type(IntPtr address)
 {
     // not quite trivial to autogenerate
     CPyMarshal.Zero(address, Marshal.SizeOf(typeof(PyTypeObject)));
     CPyMarshal.WriteIntField(address, typeof(PyTypeObject), "ob_refcnt", 1);
     CPyMarshal.WritePtrField(address, typeof(PyTypeObject), "tp_base", this.PyInt_Type);
     CPyMarshal.WriteCStringField(address, typeof(PyTypeObject), "tp_name", "bool");
     this.map.Associate(address, TypeCache.Boolean);
 }
Пример #4
0
        Register_PyEllipsis_Type(IntPtr address)
        {
            // not quite trivial to autogenerate
            // (but surely there's a better way to get the Ellipsis object...)
            CPyMarshal.Zero(address, Marshal.SizeOf(typeof(PyTypeObject)));
            CPyMarshal.WriteIntField(address, typeof(PyTypeObject), "ob_refcnt", 1);
            CPyMarshal.WriteCStringField(address, typeof(PyTypeObject), "tp_name", "ellipsis");
            object ellipsisType = PythonCalls.Call(Builtin.type, new object[] { PythonOps.Ellipsis });

            this.map.Associate(address, ellipsisType);
        }