dotgnu-pnet
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pnet-developers] [bugs #11998] Problems with casting arrays, isinst, a


From: Marcus Urban
Subject: [Pnet-developers] [bugs #11998] Problems with casting arrays, isinst, and the as operator
Date: Wed, 16 Feb 2005 07:23:05 +0000
User-agent: Mozilla/5.0 (compatible; Konqueror/3.3; Linux 2.4.21-144-athlon; X11; i686; en_US) KHTML/3.3.92 (like Gecko)

URL:
  <http://savannah.gnu.org/bugs/?func=detailitem&item_id=11998>

                 Summary: Problems with casting arrays, isinst, and the as
operator
                 Project: DotGNU Portable.NET
            Submitted by: mathpup
            Submitted on: Wed 02/16/2005 at 07:23
                Category: None
                Severity: 5 - Average
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open

    _______________________________________________________

Details:

There is something wrong with the with the C# "as" and "is" operators, which
seem to be compiled into CIL "isinst" instructions.

The following sequence prints "False" on Pnet but true on MS:

        Array x = new string[1];
        object[] y = x as object[];
        Console.WriteLine(y == null );

I was trying to debug this myself, but I do not think that I have enough
knowledge of the runtime engine internals. Also, I do not quite understand
the correspondence between CVM instructions and similarly-named CIL
instructions. I looked around to cvm_ptr.c and found this:

VMCASE(COP_ISINST):
{
        /* Determine if the object on the stack top is an
           instance of a particular class */
        classInfo = CVM_ARG_PTR(ILClass *);
        if(stacktop[-1].ptrValue != 0 &&
           !ILClassInheritsFrom(GetObjectClass(stacktop[-1].ptrValue), 
classInfo))
        {
                stacktop[-1].ptrValue = 0;
        }
        MODIFY_PC_AND_STACK(CVM_LEN_PTR, 0);
}

However, according to the CIL spec, ISINST is supposed to attempt casting
from source-type to result-type, and replace the top element of the stack
with the result (if casting is successful) or null (if casting fails). I do
not quite understand what it going on here because it seems as though the
COP_ISINST case should look more like COP_CASTCLASS case.

I'm very confused about all this, but I think that someone more familiar with
the runtime could fix it easily.






    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Wed 02/16/2005 at 07:23  Name: array-cast.cs  Size: 165B   By: mathpup
Test case
<http://savannah.gnu.org/bugs/download.php?item_id=11998&item_file_id=2202>

    _______________________________________________________

This item URL is:

  <http://savannah.gnu.org/bugs/?func=detailitem&item_id=11998>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]