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

Raja R Harinath rharinath at novell.com
Fri Oct 28 06:53:04 EDT 2005


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