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

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

[Dotgnu-pnet-commits] CVS: pnet/image lib_attrs.c,1.8,1.9 link.c,1.21,1.


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/image lib_attrs.c,1.8,1.9 link.c,1.21,1.22 member.c,1.23,1.24 meta_build.c,1.24,1.25 meta_writer.c,1.11,1.12 program.h,1.16,1.17
Date: Tue, 06 May 2003 05:53:23 -0400

Update of /cvsroot/dotgnu-pnet/pnet/image
In directory subversions:/tmp/cvs-serv17226/image

Modified Files:
        lib_attrs.c link.c member.c meta_build.c meta_writer.c 
        program.h 
Log Message:


Implement PInvoke lookups for fields so that global variables
within shared objects can be accessed.


Index: lib_attrs.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/lib_attrs.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** lib_attrs.c 25 Apr 2003 02:59:28 -0000      1.8
--- lib_attrs.c 6 May 2003 09:53:21 -0000       1.9
***************
*** 82,85 ****
--- 82,86 ----
  {
        ILMethod *method;
+       ILField *field;
        const char *name;
        int nameLen;
***************
*** 97,103 ****
        int result;
  
!       /* We must use this on a method */
        method = ILProgramItemToMethod(item);
!       if(!method)
        {
                return 0;
--- 98,114 ----
        int result;
  
!       /* According to the ECMA spec, we must use this on a method.
!          We have added an extension to also support PInvoke'ed fields.
!          The metadata supports PInvoke information on fields, and it
!          is necessary for importing variables from shared objects */
        method = ILProgramItemToMethod(item);
!       field = ILProgramItemToField(item);
!       if(!method && !field)
!       {
!               return 0;
!       }
! 
!       /* If it is a field, then it must be static and non-literal */
!       if(field && (!ILField_IsStatic(field) || ILField_IsLiteral(field)))
        {
                return 0;
***************
*** 224,234 ****
                return -1;
        }
!       result = (ILPInvokeCreate(method, 0, attrs, module, aliasName) != 0);
!       if(result)
        {
!               /* Mark the method with the "pinvokeimpl" flag */
!               ILMemberSetAttrs((ILMember *)method,
!                                                IL_META_METHODDEF_PINVOKE_IMPL,
!                                                
IL_META_METHODDEF_PINVOKE_IMPL);
        }
        ILFree(dllName);
--- 235,260 ----
                return -1;
        }
!       if(method)
!       {
!               result = (ILPInvokeCreate(method, 0, attrs, module, aliasName) 
!= 0);
!               if(result)
!               {
!                       /* Mark the method with the "pinvokeimpl" flag */
!                       ILMemberSetAttrs((ILMember *)method,
!                                                        
IL_META_METHODDEF_PINVOKE_IMPL,
!                                                        
IL_META_METHODDEF_PINVOKE_IMPL);
!               }
!       }
!       else
        {
!               result = (ILPInvokeFieldCreate
!                                               (field, 0, attrs, module, 
aliasName) != 0);
!               if(result)
!               {
!                       /* Mark the field with the "pinvokeimpl" flag */
!                       ILMemberSetAttrs((ILMember *)field,
!                                                        
IL_META_FIELDDEF_PINVOKE_IMPL,
!                                                        
IL_META_FIELDDEF_PINVOKE_IMPL);
!               }
        }
        ILFree(dllName);

Index: link.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/link.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -r1.21 -r1.22
*** link.c      3 May 2003 00:06:50 -0000       1.21
--- link.c      6 May 2003 09:53:21 -0000       1.22
***************
*** 932,940 ****
  
        /* Does the name need to be remapped for this platform? */
!       namelen = SearchForDllMap(&(pinvoke->method->member.programItem),
                                                          name, &remapName);
        if(namelen == -1)
        {
!               namelen = 
SearchForDllMap(&(pinvoke->method->member.owner->programItem),
                                                                  name, 
&remapName);
                if(namelen == -1)
--- 932,940 ----
  
        /* Does the name need to be remapped for this platform? */
!       namelen = SearchForDllMap(&(pinvoke->memberInfo->programItem),
                                                          name, &remapName);
        if(namelen == -1)
        {
!               namelen = 
SearchForDllMap(&(pinvoke->memberInfo->owner->programItem),
                                                                  name, 
&remapName);
                if(namelen == -1)

Index: member.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/member.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -r1.23 -r1.24
*** member.c    18 Apr 2003 09:15:53 -0000      1.23
--- member.c    6 May 2003 09:53:21 -0000       1.24
***************
*** 1238,1242 ****
  
        /* Initialize the other PInvoke fields */
!       pinvoke->method = method;
        pinvoke->module = module;
        if(aliasName && aliasName[0] != '\0')
--- 1238,1242 ----
  
        /* Initialize the other PInvoke fields */
!       pinvoke->memberInfo = (ILMember *)method;
        pinvoke->module = module;
        if(aliasName && aliasName[0] != '\0')
***************
*** 1257,1263 ****
  }
  
  ILMethod *ILPInvokeGetMethod(ILPInvoke *pinvoke)
  {
!       return pinvoke->method;
  }
  
--- 1257,1276 ----
  }
  
+ ILPInvoke *ILPInvokeFieldCreate(ILField *field, ILToken token,
+                                                       ILUInt32 attributes, 
ILModule *module,
+                                                       const char *aliasName)
+ {
+       return ILPInvokeCreate((ILMethod *)field, token, attributes,
+                                                  module, aliasName);
+ }
+ 
  ILMethod *ILPInvokeGetMethod(ILPInvoke *pinvoke)
  {
!       return ILProgramItemToMethod(ILToProgramItem(pinvoke->memberInfo));
! }
! 
! ILField *ILPInvokeGetField(ILPInvoke *pinvoke)
! {
!       return ILProgramItemToField(ILToProgramItem(pinvoke->memberInfo));
  }
  
***************
*** 1278,1282 ****
        {
                if(member->kind == IL_META_MEMBERKIND_PINVOKE &&
!                  ((ILPInvoke *)member)->method == method)
                {
                        return ((ILPInvoke *)member);
--- 1291,1295 ----
        {
                if(member->kind == IL_META_MEMBERKIND_PINVOKE &&
!                  ((ILPInvoke *)member)->memberInfo == (ILMember *)method)
                {
                        return ((ILPInvoke *)member);
***************
*** 1285,1288 ****
--- 1298,1306 ----
        }
        return 0;
+ }
+ 
+ ILPInvoke *ILPInvokeFindField(ILField *field)
+ {
+       return ILPInvokeFind((ILMethod *)field);
  }
  

Index: meta_build.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/meta_build.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -r1.24 -r1.25
*** meta_build.c        28 Feb 2003 06:21:49 -0000      1.24
--- meta_build.c        6 May 2003 09:53:21 -0000       1.25
***************
*** 1301,1321 ****
  {
        ILMethod *method;
        ILModule *module;
        ILPInvoke *pinvoke;
  
!       /* An early version supported PInvoke for fields.  That is now obsolete 
*/
        if((values[IL_OFFSET_IMPLMAP_METHOD] & IL_META_TOKEN_MASK)
!                               != IL_META_TOKEN_METHOD_DEF)
        {
!               META_VAL_ERROR("pinvoke must be applied to a method");
                return IL_LOADERR_BAD_META;
        }
  
!       /* Validate that the method is really PInvoke */
!       method = ILMethod_FromToken(image, values[IL_OFFSET_IMPLMAP_METHOD]);
!       if(!method || !ILMethod_HasPInvokeImpl(method))
        {
!               META_VAL_ERROR("pinvoke token applied to a non-pinvoke method");
!               return IL_LOADERR_BAD_META;
        }
  
--- 1301,1340 ----
  {
        ILMethod *method;
+       ILField *field;
        ILModule *module;
        ILPInvoke *pinvoke;
  
!       /* An early version supported PInvoke for fields.  That is now obsolete,
!          but we have revived it so that variables can be imported from DLL's 
*/
        if((values[IL_OFFSET_IMPLMAP_METHOD] & IL_META_TOKEN_MASK)
!                               != IL_META_TOKEN_METHOD_DEF &&
!          (values[IL_OFFSET_IMPLMAP_METHOD] & IL_META_TOKEN_MASK)
!                               != IL_META_TOKEN_FIELD_DEF)
        {
!               META_VAL_ERROR("pinvoke must be applied to a method or field");
                return IL_LOADERR_BAD_META;
        }
  
!       /* Validate that the method or field is really PInvoke */
!       if((values[IL_OFFSET_IMPLMAP_METHOD] & IL_META_TOKEN_MASK)
!                               == IL_META_TOKEN_METHOD_DEF)
        {
!               method = ILMethod_FromToken(image, 
values[IL_OFFSET_IMPLMAP_METHOD]);
!               if(!method || !ILMethod_HasPInvokeImpl(method))
!               {
!                       META_VAL_ERROR("pinvoke token applied to a non-pinvoke 
method");
!                       return IL_LOADERR_BAD_META;
!               }
!               field = 0;
!       }
!       else
!       {
!               field = ILField_FromToken(image, 
values[IL_OFFSET_IMPLMAP_METHOD]);
!               if(!field || !ILField_HasPInvokeImpl(field))
!               {
!                       META_VAL_ERROR("pinvoke token applied to a non-pinvoke 
field");
!                       return IL_LOADERR_BAD_META;
!               }
!               method = 0;
        }
  
***************
*** 1329,1336 ****
  
        /* Create the PInvoke record */
!       pinvoke = ILPInvokeCreate(method, token,
!                                                         
values[IL_OFFSET_IMPLMAP_ATTRS], module,
!                                                         ILImageGetString
!                                                                       (image, 
values[IL_OFFSET_IMPLMAP_ALIAS]));
        if(!pinvoke)
        {
--- 1348,1365 ----
  
        /* Create the PInvoke record */
!       if(method)
!       {
!               pinvoke = ILPInvokeCreate
!                               (method, token,
!                                values[IL_OFFSET_IMPLMAP_ATTRS], module,
!                                ILImageGetString(image, 
values[IL_OFFSET_IMPLMAP_ALIAS]));
!       }
!       else
!       {
!               pinvoke = ILPInvokeFieldCreate
!                               (field, token,
!                                values[IL_OFFSET_IMPLMAP_ATTRS], module,
!                                ILImageGetString(image, 
values[IL_OFFSET_IMPLMAP_ALIAS]));
!       }
        if(!pinvoke)
        {

Index: meta_writer.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/meta_writer.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** meta_writer.c       28 Feb 2003 11:35:03 -0000      1.11
--- meta_writer.c       6 May 2003 09:53:21 -0000       1.12
***************
*** 538,542 ****
        values[IL_OFFSET_IMPLMAP_ATTRS] = pinvoke->member.attributes;
        values[IL_OFFSET_IMPLMAP_METHOD] =
!                       pinvoke->method->member.programItem.token;
        values[IL_OFFSET_IMPLMAP_ALIAS] =
                        GetPersistString(image, pinvoke->aliasName);
--- 538,542 ----
        values[IL_OFFSET_IMPLMAP_ATTRS] = pinvoke->member.attributes;
        values[IL_OFFSET_IMPLMAP_METHOD] =
!                       pinvoke->memberInfo->programItem.token;
        values[IL_OFFSET_IMPLMAP_ALIAS] =
                        GetPersistString(image, pinvoke->aliasName);
***************
*** 1232,1238 ****
  static int Sort_ImplMap(ILPInvoke **pinvoke1, ILPInvoke **pinvoke2)
  {
!       ILToken token1 = (*pinvoke1)->method->member.programItem.token;
!       ILToken token2 = (*pinvoke2)->method->member.programItem.token;
!       if(token1 < token2)
        {
                return -1;
--- 1232,1253 ----
  static int Sort_ImplMap(ILPInvoke **pinvoke1, ILPInvoke **pinvoke2)
  {
!       ILToken token1 = (*pinvoke1)->memberInfo->programItem.token;
!       ILToken token2 = (*pinvoke2)->memberInfo->programItem.token;
!       ILToken tokenNum1 = (token1 & ~IL_META_TOKEN_MASK);
!       ILToken tokenNum2 = (token2 & ~IL_META_TOKEN_MASK);
! 
!       /* Compare the bottom parts of the token first, because
!          the table must be sorted on its encoded value, not
!          on the original value.  Encoded values put the token
!          type in the low order bits */
!       if(tokenNum1 < tokenNum2)
!       {
!               return -1;
!       }
!       else if(tokenNum1 > tokenNum2)
!       {
!               return 1;
!       }
!       else if(token1 < token2)
        {
                return -1;

Index: program.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/program.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -r1.16 -r1.17
*** program.h   28 Feb 2003 04:57:47 -0000      1.16
--- program.h   6 May 2003 09:53:21 -0000       1.17
***************
*** 396,400 ****
  {
        ILMember                member;                         /* Common 
member fields */
!       ILMethod           *method;                             /* Method 
PInvoke applies to */
        ILModule           *module;                             /* Module 
function is imported from */
        const char         *aliasName;                  /* Alias for the 
function */
--- 396,400 ----
  {
        ILMember                member;                         /* Common 
member fields */
!       ILMember           *memberInfo;                 /* Member PInvoke 
applies to */
        ILModule           *module;                             /* Module 
function is imported from */
        const char         *aliasName;                  /* Alias for the 
function */





reply via email to

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