Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Mar 2013 23:26:24 +0100
From:      Jilles Tjoelker <jilles@stack.nl>
To:        "Cherry G. Mathew" <cherry@FreeBSD.org>
Cc:        svn-src-projects@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r248199 - projects/amd64_xen_pv/sys/amd64/xen
Message-ID:  <20130313222624.GC61432@stack.nl>
In-Reply-To: <201303121233.r2CCXp7F075011@svn.freebsd.org>
References:  <201303121233.r2CCXp7F075011@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Mar 12, 2013 at 12:33:51PM +0000, Cherry G. Mathew wrote:
> Author: cherry
> Date: Tue Mar 12 12:33:50 2013
> New Revision: 248199
> URL: http://svnweb.freebsd.org/changeset/base/248199

> Log:
>   Modify the mmu_map_hold_va() to indicate if it had to allocate backing pages.
>   'const'ify memrchr() to reflect its level of access to datatypes.

>   Approved by: gibbs (implicit)

> Modified:
>   projects/amd64_xen_pv/sys/amd64/xen/mmu_map.c
>   projects/amd64_xen_pv/sys/amd64/xen/mmu_map.h

> Modified: projects/amd64_xen_pv/sys/amd64/xen/mmu_map.c
> ==============================================================================
> --- projects/amd64_xen_pv/sys/amd64/xen/mmu_map.c	Tue Mar 12 12:23:47 2013	(r248198)
> +++ projects/amd64_xen_pv/sys/amd64/xen/mmu_map.c	Tue Mar 12 12:33:50 2013	(r248199)
> [snip]
>  /*$FreeBSD: head/lib/libc/string/memrchr.c 178051 2008-04-10 00:12:44Z delphij $*/
> @@ -381,16 +388,19 @@ mmu_map_hold_va(struct pmap *pm, void *a
>   * Reverse memchr()
>   * Find the last occurrence of 'c' in the buffer 's' of size 'n'.
>   */
> -static void *
> +
> +static const void * memrchr(const void *, int, size_t);
> +
> +static const void *
>  memrchr(const void *s, int c, size_t n)
>  {
>  	const unsigned char *cp;
>  
>  	if (n != 0) {
> -		cp = (unsigned char *)s + n;
> +		cp = (const unsigned char *)s + n;
>  		do {
>  			if (*(--cp) == (unsigned char)c)
> -				return((void *)cp);
> +				return((const void *)cp);
>  		} while (--n != 0);
>  	}
>  	return(NULL);

Perhaps add a comment here why the definition has been tightened. The
real memrchr() can work on const and non-const strings but must cast
away const in its definition somehow and relies on the programmer to
keep the const when a const pointer was passed. This modified version
respects the limitations of const better and does not allow modifying a
non-const string through its result. If that is all you need, it reduces
warnings/ugliness.

-- 
Jilles Tjoelker



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130313222624.GC61432>