Exemple #1
0
        PyString_AsStringAndSize(IntPtr strPtr, IntPtr dataPtrPtr, IntPtr sizePtr)
        {
            try
            {
                if (CPyMarshal.ReadPtrField(strPtr, typeof(PyObject), "ob_type") != this.PyString_Type)
                {
                    throw PythonOps.TypeError("PyString_AsStringAndSize: not a string");
                }

                IntPtr dataPtr = CPyMarshal.GetField(strPtr, typeof(PyStringObject), "ob_sval");
                CPyMarshal.WritePtr(dataPtrPtr, dataPtr);

                int length = CPyMarshal.ReadIntField(strPtr, typeof(PyStringObject), "ob_size");
                if (sizePtr == IntPtr.Zero)
                {
                    for (int i = 0; i < length; ++i)
                    {
                        if (CPyMarshal.ReadByte(CPyMarshal.Offset(dataPtr, i)) == 0)
                        {
                            throw PythonOps.TypeError("PyString_AsStringAndSize: string contains embedded 0s, but sizePtr is null");
                        }
                    }
                }
                else
                {
                    CPyMarshal.WriteInt(sizePtr, length);
                }
                return(0);
            }
            catch (Exception e)
            {
                this.LastException = e;
                return(-1);
            }
        }
Exemple #2
0
        ReadFunctionPtrField(IntPtr addr, Type type, string field, Type dgtType)
        {
            IntPtr readAddr = CPyMarshal.GetField(addr, type, field);
            IntPtr funcPtr  = CPyMarshal.ReadPtr(readAddr);

            return(Marshal.GetDelegateForFunctionPointer(funcPtr, dgtType));
        }
Exemple #3
0
        ReadCStringField(IntPtr addr, Type type, string field)
        {
            IntPtr strPtrAddr = CPyMarshal.GetField(addr, type, field);
            IntPtr readAddr   = CPyMarshal.ReadPtr(strPtrAddr);

            if (readAddr != IntPtr.Zero)
            {
                return(Marshal.PtrToStringAnsi(readAddr));
            }
            return("");
        }
Exemple #4
0
        StoreTyped(Complex value)
        {
            IntPtr ptr = this.allocator.Alloc((uint)Marshal.SizeOf(typeof(PyComplexObject)));

            CPyMarshal.WriteIntField(ptr, typeof(PyComplexObject), "ob_refcnt", 1);
            CPyMarshal.WritePtrField(ptr, typeof(PyComplexObject), "ob_type", this.PyComplex_Type);
            IntPtr cpxptr = CPyMarshal.GetField(ptr, typeof(PyComplexObject), "cval");

            CPyMarshal.WriteDoubleField(cpxptr, typeof(Py_complex), "real", value.Real);
            CPyMarshal.WriteDoubleField(cpxptr, typeof(Py_complex), "imag", value.Imaginary);
            this.map.Associate(ptr, value);
            return(ptr);
        }
Exemple #5
0
        IC_str_getreadbuffer(IntPtr strPtr, int seg, IntPtr bufPtrPtr)
        {
            if (seg != 0)
            {
                this.LastException = PythonOps.SystemError("string buffers have only 1 segment");
                return(-1);
            }

            IntPtr bufPtr = CPyMarshal.GetField(strPtr, typeof(PyStringObject), "ob_sval");

            CPyMarshal.WritePtr(bufPtrPtr, bufPtr);

            return(this.PyString_Size(strPtr));
        }
Exemple #6
0
        ReadIntField(IntPtr addr, Type type, string field)
        {
            IntPtr readAddr = CPyMarshal.GetField(addr, type, field);

            return(CPyMarshal.ReadInt(readAddr));
        }
Exemple #7
0
        WriteIntField(IntPtr addr, Type type, string field, int data)
        {
            IntPtr writeAddr = CPyMarshal.GetField(addr, type, field);

            CPyMarshal.WriteInt(writeAddr, data);
        }
Exemple #8
0
        WriteFunctionPtrField(IntPtr addr, Type type, string field, Delegate dgt)
        {
            IntPtr writeAddr = CPyMarshal.GetField(addr, type, field);

            CPyMarshal.WritePtr(writeAddr, Marshal.GetFunctionPointerForDelegate(dgt));
        }
Exemple #9
0
        WriteDoubleField(IntPtr addr, Type type, string field, double data)
        {
            IntPtr writeAddr = CPyMarshal.GetField(addr, type, field);

            CPyMarshal.WriteDouble(writeAddr, data);
        }