Ejemplo n.º 1
0
        IC_PyFile_AsFile(IntPtr pyFilePtr)
        {
            try
            {
                if (this.FILEs.ContainsKey(pyFilePtr))
                {
                    return(this.FILEs[pyFilePtr]);
                }

                PythonFile pyFile = (PythonFile)this.Retrieve(pyFilePtr);

                this.PrintToStdErr("Warning: creating unmanaged FILE* from managed stream. Please use ironclad.open with this extension.");
                int    fd   = this.ConvertPyFileToDescriptor(pyFile);
                IntPtr FILE = IntPtr.Zero;
                if (InappropriateReflection.StreamFromPythonFile(pyFile).CanWrite)
                {
                    FILE = Unmanaged._fdopen(fd, "w");
                }
                else
                {
                    FILE = Unmanaged._fdopen(fd, "r");
                }
                this.FILEs[pyFilePtr] = FILE;
                return(FILE);
            }
            catch (Exception e)
            {
                this.LastException = e;
                return(IntPtr.Zero);
            }
        }
Ejemplo n.º 2
0
        ConvertPyFileToDescriptor(PythonFile pyFile)
        {
            FileStream stream     = InappropriateReflection.StreamFromPythonFile(pyFile);
            SafeHandle safeHandle = stream.SafeFileHandle;
            IntPtr     handle     = safeHandle.DangerousGetHandle();

            return(Unmanaged._open_osfhandle(handle, 0));
        }