svn commit: r248199 - projects/amd64_xen_pv/sys/amd64/xen
Jilles Tjoelker
jilles at stack.nl
Wed Mar 13 22:26:26 UTC 2013
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
More information about the svn-src-projects
mailing list