[Mono-dev] [PATCH] Friend access for class members

Carlos Alberto Cortez calberto.cortez at gmail.com
Fri Oct 28 07:00:42 EDT 2005


Hey,

I applied your suggestion and also removed some redundant comparations
in the same place (for family, famor and famand). Also I've applied the
changes to access friend internal classes. 

Finally, more tests are added, so I'm attaching them.

Carlos.

BTW, the tests are running just fine.


El vie, 28-10-2005 a las 16:23 +0530, Raja R Harinath escribió:
> Hi,
> 
> Carlos Alberto Cortez <calberto.cortez at gmail.com> writes:
> 
> > The attached patch implements friend access for class members (methods,
> > properties, fields). 
> >
> > I'm not including the type-check section, since that part will be
> > modified (next merge to gmcs) and I'm waiting for that to happen.
> > However, that change should be small (I will send the patch).
> 
> I have completed the merge of the relevant parts.  Please post an
> updated patch.
> 
> Meanwhile, I have some comments:
> 
> [snip]
> > @@ -2646,25 +2726,38 @@
> >  				MethodBase mb = (MethodBase) m;
> >  				MethodAttributes ma = mb.Attributes & MethodAttributes.MemberAccessMask;
> >  
> > +				if (ma == MethodAttributes.Public)
> > +					return true;
> 
> Ok.
> 
> >  				if (ma == MethodAttributes.Private)
> >  					return private_ok ||
> >  						IsPrivateAccessible (invocation_type, m.DeclaringType) ||
> >  						IsNestedChildOf (invocation_type, m.DeclaringType);
> >  
> > -				if (invocation_assembly == mb.DeclaringType.Assembly) {
> > +				if (invocation_assembly == mb.DeclaringType.Assembly)
> >  					if (ma == MethodAttributes.Assembly || ma == MethodAttributes.FamORAssem)
> >  						return true;
> > -				} else {
> > -					if (ma == MethodAttributes.Assembly || ma == MethodAttributes.FamANDAssem)
> > -						return false;
> 
> I would retain the old code, and change the check to:
> 
>   if (invocation_assembly == mb.DeclaringType.Assembly ||
>       TypeManager.InternalsVisibleTo (invocation_assembly, mb.DeclaringType.Assembly)) 
> 
> > +					
> > +				if (ma == MethodAttributes.Family ||
> > +				    ma == MethodAttributes.FamANDAssem ||
> > +				    ma == MethodAttributes.FamORAssem) {
> > +					if (!CheckValidFamilyAccess (mb.IsStatic, m)) {
> > +						if (ma == MethodAttributes.Family || ma == MethodAttributes.FamANDAssem)
> > +							return false;
> > +					} else {
> > +						// We are valid
> > +						if (ma == MethodAttributes.Family || ma == MethodAttributes.FamORAssem)
> > +							return true;
> > +						
> > +						// Check for FamANDAssem
> > +						if (invocation_assembly == mb.DeclaringType.Assembly)
> > +							return true;
> > +					}
> >  				}
> > -				if (ma == MethodAttributes.Family ||
> > -				    ma == MethodAttributes.FamANDAssem ||
> > -				    ma == MethodAttributes.FamORAssem)
> > -					return CheckValidFamilyAccess (mb.IsStatic, m);
> 
> I don't like this too much.  I'd much rather keep the old code.
> 
> - Hari




More information about the Mono-devel-list mailing list