mirror of
				https://github.com/Ryujinx/Opentk.git
				synced 2025-11-04 11:54:52 +00:00 
			
		
		
		
	Do not reuse a single StreamReader for reading signatures. Avoids issues with XPathDocument closing the stream behind our backs.
This commit is contained in:
		
							parent
							
								
									e6bed64bd8
								
							
						
					
					
						commit
						355f5beb7b
					
				| 
						 | 
				
			
			@ -40,9 +40,9 @@ namespace Bind
 | 
			
		|||
    class EnumProcessor
 | 
			
		||||
    {
 | 
			
		||||
        const string Path = "/signatures/replace/enum[@name='{0}']";
 | 
			
		||||
        StreamReader Overrides { get; set; }
 | 
			
		||||
        string Overrides { get; set; }
 | 
			
		||||
 | 
			
		||||
        public EnumProcessor(StreamReader overrides)
 | 
			
		||||
        public EnumProcessor(string overrides)
 | 
			
		||||
        {
 | 
			
		||||
            if (overrides == null)
 | 
			
		||||
                throw new ArgumentNullException("overrides");
 | 
			
		||||
| 
						 | 
				
			
			@ -55,7 +55,6 @@ namespace Bind
 | 
			
		|||
            var nav = new XPathDocument(Overrides).CreateNavigator();
 | 
			
		||||
            enums = ProcessNames(enums, nav);
 | 
			
		||||
            enums = ProcessConstants(enums, nav);
 | 
			
		||||
            Overrides.BaseStream.Seek(0, SeekOrigin.Begin);
 | 
			
		||||
            return enums;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,9 +46,9 @@ namespace Bind
 | 
			
		|||
            new Regex("(ib|[tdrey]s|[eE]n[vd]|bled|Flag|Tess|Status|Pixels|Instanced|Indexed|Varyings|Boolean|IDs)", RegexOptions.Compiled | RegexOptions.RightToLeft);
 | 
			
		||||
        static readonly Regex EndingsAddV = new Regex("^0", RegexOptions.Compiled);
 | 
			
		||||
 | 
			
		||||
        StreamReader Overrides { get; set; }
 | 
			
		||||
        string Overrides { get; set; }
 | 
			
		||||
 | 
			
		||||
        public FuncProcessor(StreamReader overrides)
 | 
			
		||||
        public FuncProcessor(string overrides)
 | 
			
		||||
        {
 | 
			
		||||
            if (overrides == null)
 | 
			
		||||
                throw new ArgumentNullException("overrides");
 | 
			
		||||
| 
						 | 
				
			
			@ -72,7 +72,6 @@ namespace Bind
 | 
			
		|||
            wrappers = CreateCLSCompliantWrappers(wrappers, enums);
 | 
			
		||||
            Console.WriteLine("Removing non-CLS compliant duplicates.");
 | 
			
		||||
 | 
			
		||||
            Overrides.BaseStream.Seek(0, SeekOrigin.Begin);
 | 
			
		||||
            return MarkCLSCompliance(wrappers);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -70,27 +70,17 @@ namespace Bind.GL2
 | 
			
		|||
 | 
			
		||||
        public virtual void Process()
 | 
			
		||||
        {
 | 
			
		||||
            using (var overrides = new StreamReader(Path.Combine(Settings.InputPath, Settings.OverridesFile)))
 | 
			
		||||
            {
 | 
			
		||||
                using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, glTypemap))
 | 
			
		||||
                    Type.GLTypes = SpecReader.ReadTypeMap(sr);
 | 
			
		||||
                using (StreamReader sr = Utilities.OpenSpecFile(Settings.InputPath, csTypemap))
 | 
			
		||||
                    Type.CSTypes = SpecReader.ReadCSTypeMap(sr);
 | 
			
		||||
                using (var sr = new StreamReader(Path.Combine(Settings.InputPath, enumSpec)))
 | 
			
		||||
                {
 | 
			
		||||
                    Enums = SpecReader.ReadEnums(sr);
 | 
			
		||||
            string overrides = Path.Combine(Settings.InputPath, Settings.OverridesFile);
 | 
			
		||||
            Type.GLTypes = SpecReader.ReadTypeMap(Path.Combine(Settings.InputPath, glTypemap));
 | 
			
		||||
            Type.CSTypes = SpecReader.ReadCSTypeMap(Path.Combine(Settings.InputPath, csTypemap));
 | 
			
		||||
            Enums = SpecReader.ReadEnums(Path.Combine(Settings.InputPath, enumSpec));
 | 
			
		||||
            Utilities.Merge(Enums, SpecReader.ReadEnums(overrides));
 | 
			
		||||
                }
 | 
			
		||||
                using (var sr = new StreamReader(Path.Combine(Settings.InputPath, glSpec)))
 | 
			
		||||
                {
 | 
			
		||||
                    Delegates = SpecReader.ReadDelegates(sr);
 | 
			
		||||
            Delegates = SpecReader.ReadDelegates(Path.Combine(Settings.InputPath, glSpec));
 | 
			
		||||
            Utilities.Merge(Delegates, SpecReader.ReadDelegates(overrides));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            Enums = new EnumProcessor(overrides).Process(Enums);
 | 
			
		||||
            Wrappers = new FuncProcessor(overrides).Process(Delegates, Enums);
 | 
			
		||||
        }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,9 +12,9 @@ namespace Bind
 | 
			
		|||
{
 | 
			
		||||
    interface ISpecReader
 | 
			
		||||
    {
 | 
			
		||||
        DelegateCollection ReadDelegates(StreamReader specFile);
 | 
			
		||||
        EnumCollection ReadEnums(StreamReader specFile);
 | 
			
		||||
        Dictionary<string, string> ReadTypeMap(StreamReader specFile);
 | 
			
		||||
        Dictionary<string, string> ReadCSTypeMap(StreamReader specFile);
 | 
			
		||||
        DelegateCollection ReadDelegates(string file);
 | 
			
		||||
        EnumCollection ReadEnums(string file);
 | 
			
		||||
        Dictionary<string, string> ReadTypeMap(string file);
 | 
			
		||||
        Dictionary<string, string> ReadCSTypeMap(string file);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -102,25 +102,26 @@ namespace Bind
 | 
			
		|||
 | 
			
		||||
        #region ISpecReader Members
 | 
			
		||||
 | 
			
		||||
        public DelegateCollection ReadDelegates(StreamReader specFile)
 | 
			
		||||
        public DelegateCollection ReadDelegates(string file)
 | 
			
		||||
        {
 | 
			
		||||
            XPathDocument specs = new XPathDocument(specFile);
 | 
			
		||||
            var specs = new XPathDocument(file);
 | 
			
		||||
            var delegates = ReadDelegates(specs.CreateNavigator().SelectSingleNode("/signatures/add"));
 | 
			
		||||
            specFile.BaseStream.Seek(0, SeekOrigin.Begin);
 | 
			
		||||
            return delegates;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Dictionary<string, string> ReadTypeMap(StreamReader specFile)
 | 
			
		||||
        public Dictionary<string, string> ReadTypeMap(string file)
 | 
			
		||||
        {
 | 
			
		||||
            using (var sr = new StreamReader(file))
 | 
			
		||||
            {
 | 
			
		||||
                Console.WriteLine("Reading opengl types.");
 | 
			
		||||
                Dictionary<string, string> GLTypes = new Dictionary<string, string>();
 | 
			
		||||
 | 
			
		||||
            if (specFile == null)
 | 
			
		||||
                if (sr == null)
 | 
			
		||||
                    return GLTypes;
 | 
			
		||||
 | 
			
		||||
                do
 | 
			
		||||
                {
 | 
			
		||||
                string line = specFile.ReadLine();
 | 
			
		||||
                    string line = sr.ReadLine();
 | 
			
		||||
 | 
			
		||||
                    if (String.IsNullOrEmpty(line) || line.StartsWith("#"))
 | 
			
		||||
                        continue;
 | 
			
		||||
| 
						 | 
				
			
			@ -166,19 +167,22 @@ namespace Bind
 | 
			
		|||
                        GLTypes.Add(words[0], words[1]);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            while (!specFile.EndOfStream);
 | 
			
		||||
                while (!sr.EndOfStream);
 | 
			
		||||
 | 
			
		||||
                return GLTypes;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Dictionary<string, string> ReadCSTypeMap(StreamReader specFile)
 | 
			
		||||
        public Dictionary<string, string> ReadCSTypeMap(string file)
 | 
			
		||||
        {
 | 
			
		||||
            using (var sr = new StreamReader(file))
 | 
			
		||||
            {
 | 
			
		||||
                Dictionary<string, string> CSTypes = new Dictionary<string, string>();
 | 
			
		||||
                Console.WriteLine("Reading C# types.");
 | 
			
		||||
 | 
			
		||||
            while (!specFile.EndOfStream)
 | 
			
		||||
                while (!sr.EndOfStream)
 | 
			
		||||
                {
 | 
			
		||||
                string line = specFile.ReadLine();
 | 
			
		||||
                    string line = sr.ReadLine();
 | 
			
		||||
                    if (String.IsNullOrEmpty(line) || line.StartsWith("#"))
 | 
			
		||||
                        continue;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -194,23 +198,22 @@ namespace Bind
 | 
			
		|||
 | 
			
		||||
                return CSTypes;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public EnumCollection ReadEnums(StreamReader specFile)
 | 
			
		||||
        public EnumCollection ReadEnums(string file)
 | 
			
		||||
        {
 | 
			
		||||
            // First, read all enum definitions from spec and override file.
 | 
			
		||||
            // Afterwards, read all token/enum overrides from overrides file.
 | 
			
		||||
            // Every single enum is merged into
 | 
			
		||||
 | 
			
		||||
            EnumCollection enums = new EnumCollection();
 | 
			
		||||
            XPathDocument specs = new XPathDocument(specFile);
 | 
			
		||||
 | 
			
		||||
            var specs = new XPathDocument(file);
 | 
			
		||||
            foreach (XPathNavigator nav in specs.CreateNavigator().Select("/signatures/add"))
 | 
			
		||||
            {
 | 
			
		||||
                var new_enums = ReadEnums(nav);
 | 
			
		||||
                Utilities.Merge(enums, new_enums);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            specFile.BaseStream.Seek(0, SeekOrigin.Begin);
 | 
			
		||||
            return enums;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue