[Python.NET] Updates to callconvutil.cs for .NET 2.0

Michael Eddington meddington at gmail.com
Fri Sep 16 02:22:02 CEST 2005


Anyone else out there started to mess with Python.NET on the 2.0
platform?  One of the first hurtles was the output from ildasm does
not always place the method name on the next line, causing
callconvutil to place the modopt in the wrong place.  I've added a
regex in to check for and split the method line if the function name
is found.

Currently getting lots of access violation exceptions.

mike

Replace ReadMethod with the following:

    public void ReadMethod(string line)
    {
        Regex findMethod = new
Regex(@"^(\s*.method\s.*\s)([^\s()]+\([^()]*(?:,|\)\s.*))$");

        ArrayList lines = new ArrayList();
        string mline = line;

        string data;
        string buff;

        while ((data = reader.ReadLine()) != null)
        {
            buff = data.Trim();
            if (buff.StartsWith(ccAttr))
            {
                // BUG: mline may have method name in it already which breaks
                //      things.  This is mostly seen in .NET 2.0.
                // Example:  .method public hidebysig static int32 
tp_descr_set(native int ds,
                if (findMethod.IsMatch(mline))
                {
                    // method name is on same line as .method.  Need to insert
                    // modOpt prior to method name.
                    Match match = findMethod.Match(mline);

                    writer.WriteLine(match.Groups[1].Value + " ");
                    writer.WriteLine(modOpt + " ");
                    writer.WriteLine(match.Groups[2].Value);
                }
                else
                {
                    writer.WriteLine(mline);
                    writer.WriteLine(modOpt);
                }

                WriteBuffer(lines);
                writer.WriteLine(data);
                return;
            }
            else if (buff.StartsWith("} // end of method"))
            {
                writer.WriteLine(mline);
                WriteBuffer(lines);
                writer.WriteLine(data);
                return;
            }
            lines.Add(data);
        }
    }


More information about the PythonDotNet mailing list