dotgnu-pnet-commits
[Top][All Lists]
Advanced

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

[Dotgnu-pnet-commits] CVS: pnet/engine engine.h,1.65,1.66 lib_reflect.c


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/engine engine.h,1.65,1.66 lib_reflect.c,1.29,1.30 lib_string.c,1.29,1.30
Date: Thu, 09 Jan 2003 19:44:14 -0500

Update of /cvsroot/dotgnu-pnet/pnet/engine
In directory subversions:/tmp/cvs-serv6737/engine

Modified Files:
        engine.h lib_reflect.c lib_string.c 
Log Message:


Fix alignment and endian-ness issues in "UnpackConstant".


Index: engine.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/engine.h,v
retrieving revision 1.65
retrieving revision 1.66
diff -C2 -r1.65 -r1.66
*** engine.h    30 Dec 2002 06:14:41 -0000      1.65
--- engine.h    10 Jan 2003 00:44:11 -0000      1.66
***************
*** 435,438 ****
--- 435,445 ----
  
  /*
+  * Intern a string from a field constant within an image.
+  * Returns NULL if an exception was thrown.
+  */
+ ILString *_ILStringInternFromConstant(ILExecThread *thread, void *data,
+                                                                         
unsigned long numChars);
+ 
+ /*
   * Convert a string into a buffer of characters for direct access.
   * This is faster than calling "ToCharArray()", but should only

Index: lib_reflect.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/lib_reflect.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -r1.29 -r1.30
*** lib_reflect.c       9 Jan 2003 10:10:39 -0000       1.29
--- lib_reflect.c       10 Jan 2003 00:44:11 -0000      1.30
***************
*** 1358,1409 ****
   */
  ILObject* UnpackConstant(ILExecThread *thread,ILConstant* constant,
!                                                       ILType *type)
  {
        unsigned long len;
        ILInt32 intValue;
-       ILUInt32 uintValue;
        ILInt64 longValue;
-       ILUInt64 ulongValue;
        ILFloat floatValue;
        ILDouble doubleValue;
!       const char* strValue;
        switch(ILConstantGetElemType(constant))
        {
                case IL_META_ELEMTYPE_BOOLEAN:
-               case IL_META_ELEMTYPE_CHAR:
                case IL_META_ELEMTYPE_I1:
-               case IL_META_ELEMTYPE_I2:       
-               case IL_META_ELEMTYPE_I4:
-                       intValue = 
*((ILInt32*)(ILConstantGetValue(constant,&(len))));
-                       return ILExecThreadBox(thread,type,&(intValue));
-                       break;
                case IL_META_ELEMTYPE_U1:
                case IL_META_ELEMTYPE_U2:
                case IL_META_ELEMTYPE_U4:
!                       uintValue = 
*((ILUInt32*)(ILConstantGetValue(constant,&(len))));
!                       return ILExecThreadBox(thread,type,&(uintValue));
!                       break;
                case IL_META_ELEMTYPE_I8:
-                       longValue = 
*((ILInt64*)(ILConstantGetValue(constant,&(len))));
-                       return ILExecThreadBox(thread,type,&(longValue));
-                       break;
                case IL_META_ELEMTYPE_U8:
!                       ulongValue = 
*((ILInt64*)(ILConstantGetValue(constant,&(len))));
!                       return ILExecThreadBox(thread,type,&(ulongValue));
!                       break;
                case IL_META_ELEMTYPE_R4:
!                       floatValue =  
*((ILFloat*)(ILConstantGetValue(constant,&(len))));
                        return ILExecThreadBox(thread,type,&(floatValue));
!                       break;
                case IL_META_ELEMTYPE_R8:       
!                       doubleValue =  
*((ILDouble*)(ILConstantGetValue(constant,&(len))));
                        return ILExecThreadBox(thread,type,&(doubleValue));
!                       break;
                case IL_META_ELEMTYPE_STRING:
!                       strValue = (const char *)(ILConstantGetValue(constant, 
&len));
!                       return 
(ILObject*)((System_String*)ILStringCreateLen(thread,
!                                                                       
strValue,len));
!               /* TODO : implement the object unpacking ? */
        }
        return 0;
  }
--- 1358,1428 ----
   */
  ILObject* UnpackConstant(ILExecThread *thread,ILConstant* constant,
!                                                ILType *type)
  {
        unsigned long len;
+       ILInt8 byteValue;
+       ILInt16 shortValue;
        ILInt32 intValue;
        ILInt64 longValue;
        ILFloat floatValue;
        ILDouble doubleValue;
!       unsigned char *ptr;
! 
!       ptr = (unsigned char *)(ILConstantGetValue(constant,&(len)));
!       if(!ptr)
!               return 0;
! 
        switch(ILConstantGetElemType(constant))
        {
                case IL_META_ELEMTYPE_BOOLEAN:
                case IL_META_ELEMTYPE_I1:
                case IL_META_ELEMTYPE_U1:
+                       if(len < 1)
+                               return 0;
+                       byteValue = *((ILInt8 *)ptr);
+                       return ILExecThreadBox(thread,type,&(byteValue));
+ 
+               case IL_META_ELEMTYPE_I2:       
                case IL_META_ELEMTYPE_U2:
+               case IL_META_ELEMTYPE_CHAR:
+                       if(len < 2)
+                               return 0;
+                       shortValue = IL_READ_INT16(ptr);
+                       return ILExecThreadBox(thread,type,&(shortValue));
+ 
+               case IL_META_ELEMTYPE_I4:
                case IL_META_ELEMTYPE_U4:
!                       if(len < 4)
!                               return 0;
!                       intValue = IL_READ_INT32(ptr);
!                       return ILExecThreadBox(thread,type,&(intValue));
! 
                case IL_META_ELEMTYPE_I8:
                case IL_META_ELEMTYPE_U8:
!                       if(len < 8)
!                               return 0;
!                       longValue = IL_READ_INT64(ptr);
!                       return ILExecThreadBox(thread,type,&(longValue));
! 
                case IL_META_ELEMTYPE_R4:
!                       if(len < 4)
!                               return 0;
!                       floatValue =  IL_READ_FLOAT(ptr);
                        return ILExecThreadBox(thread,type,&(floatValue));
! 
                case IL_META_ELEMTYPE_R8:       
!                       if(len < 8)
!                               return 0;
!                       doubleValue =  IL_READ_DOUBLE(ptr);
                        return ILExecThreadBox(thread,type,&(doubleValue));
! 
                case IL_META_ELEMTYPE_STRING:
!                       return (ILObject 
*)_ILStringInternFromConstant(thread,ptr,len / 2);
! 
!               default:
!                       /* Assume that the constant is the "null" object */
!                       break;
        }
+ 
        return 0;
  }
***************
*** 1438,1455 ****
        if(ILField_IsLiteral(field))
        {
!               constant=ILConstantGetFromOwner((ILProgramItem*)field);
!               if(!constant)return 0;
!               /*
!                * Note: this is to support some non-compliant code generated
!                * by Mono's compiler */
!               type=ILClassToType(ILField_Owner(field));
                if(ILTypeIsEnum(type))
                {
!                       return UnpackConstant(thread,constant,ILClassToType(
!                                                                       
ILField_Owner(field)));
                }
                else
                {
!                       return 
UnpackConstant(thread,constant,ILField_Type(field));
                }
        }
--- 1457,1479 ----
        if(ILField_IsLiteral(field))
        {
!               /* Get the constant value associated with the literal field */
!               constant = ILConstantGetFromOwner((ILProgramItem*)field);
!               if(!constant)
!               {
!                       return 0;
!               }
! 
!               /* If the class is "enum", then use the type of the class 
instead
!                  of the field.  This is needed because some Reflection.Emit
!                  implementations generate the constants using the underlying
!                  type instead of the class type */
!               type = ILClassToType(ILField_Owner(field));
                if(ILTypeIsEnum(type))
                {
!                       return UnpackConstant(thread, constant, type);
                }
                else
                {
!                       return UnpackConstant(thread, constant, 
ILField_Type(field));
                }
        }

Index: lib_string.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/lib_string.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -r1.29 -r1.30
*** lib_string.c        1 Jan 2003 18:05:57 -0000       1.29
--- lib_string.c        10 Jan 2003 00:44:11 -0000      1.30
***************
*** 1791,1799 ****
  }
  
! ILString *_ILStringInternFromImage(ILExecThread *thread, ILImage *image,
!                                                                  ILToken 
token)
  {
-       const char *str;
-       unsigned long len;
        unsigned long posn;
        System_String *newStr;
--- 1791,1797 ----
  }
  
! static ILString *InternFromBuffer(ILExecThread *thread,
!                                                                 const char 
*str, unsigned long len)
  {
        unsigned long posn;
        System_String *newStr;
***************
*** 1803,1814 ****
        ILUInt32 hash;
  
-       /* Get the string from the image's "#US" blob */
-       str = ILImageGetUserString(image, token & ~IL_META_TOKEN_MASK, &len);
-       if(!str)
-       {
-               /* Shouldn't happen, but intern an empty string anyway */
-               len = 0;
-       }
- 
        /* Allocate a new hash table, if required */
        table = (ILStrHash *)(thread->process->internHash);
--- 1801,1804 ----
***************
*** 1896,1899 ****
--- 1886,1913 ----
        /* Return the final string to the caller */
        return (ILString *)newStr;
+ }
+ 
+ ILString *_ILStringInternFromImage(ILExecThread *thread, ILImage *image,
+                                                                  ILToken 
token)
+ {
+       const char *str;
+       unsigned long len;
+ 
+       /* Get the string from the image's "#US" blob */
+       str = ILImageGetUserString(image, token & ~IL_META_TOKEN_MASK, &len);
+       if(!str)
+       {
+               /* Shouldn't happen, but intern an empty string anyway */
+               len = 0;
+       }
+ 
+       /* Internalize the string buffer */
+       return InternFromBuffer(thread, str, len);
+ }
+ 
+ ILString *_ILStringInternFromConstant(ILExecThread *thread, void *data,
+                                                                         
unsigned long numChars)
+ {
+       return InternFromBuffer(thread, (const char *)data, numChars);
  }
  





reply via email to

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