Message ID | 1441625652-5233-2-git-send-email-thomas.wood@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Mon, Sep 07, 2015 at 12:34:12PM +0100, Thomas Wood wrote: > Signed-off-by: Thomas Wood <thomas.wood@intel.com> > --- > tests/gem_pwrite_snooped.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/tests/gem_pwrite_snooped.c b/tests/gem_pwrite_snooped.c > index d3f6223..29142c3 100644 > --- a/tests/gem_pwrite_snooped.c > +++ b/tests/gem_pwrite_snooped.c > @@ -76,14 +76,14 @@ static void blit(drm_intel_bo *dst, drm_intel_bo *src, > intel_batchbuffer_free(batch); > } > > -static void *memchr_inv(const void *s, int c, size_t n) > +static void const *memchr_inv(const void *s, int c, size_t n) const void * is the usual way to write that > { > const unsigned char *us = s; > unsigned char uc = c; > > while (n--) { > if (*us != uc) > - return (void *) us; > + return (void const *) us; No need for the cast if you make it return const void *. > us++; > } > > -- > 1.9.1 > > _______________________________________________ > Intel-gfx mailing list > Intel-gfx@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/intel-gfx
On Mon, Sep 07, 2015 at 12:34:12PM +0100, Thomas Wood wrote: > Signed-off-by: Thomas Wood <thomas.wood@intel.com> > --- > tests/gem_pwrite_snooped.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/tests/gem_pwrite_snooped.c b/tests/gem_pwrite_snooped.c > index d3f6223..29142c3 100644 > --- a/tests/gem_pwrite_snooped.c > +++ b/tests/gem_pwrite_snooped.c > @@ -76,14 +76,14 @@ static void blit(drm_intel_bo *dst, drm_intel_bo *src, > intel_batchbuffer_free(batch); > } > > -static void *memchr_inv(const void *s, int c, size_t n) > +static void const *memchr_inv(const void *s, int c, size_t n) Oh, and I'll just note that I wrote it the way I did orignally so that it matches memchr(). But I suppose matching memchr() exactly is not all that important. > { > const unsigned char *us = s; > unsigned char uc = c; > > while (n--) { > if (*us != uc) > - return (void *) us; > + return (void const *) us; > us++; > } > > -- > 1.9.1 > > _______________________________________________ > Intel-gfx mailing list > Intel-gfx@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/intel-gfx
On 7 September 2015 at 13:53, Ville Syrjälä <ville.syrjala@linux.intel.com> wrote: > On Mon, Sep 07, 2015 at 12:34:12PM +0100, Thomas Wood wrote: >> Signed-off-by: Thomas Wood <thomas.wood@intel.com> >> --- >> tests/gem_pwrite_snooped.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/tests/gem_pwrite_snooped.c b/tests/gem_pwrite_snooped.c >> index d3f6223..29142c3 100644 >> --- a/tests/gem_pwrite_snooped.c >> +++ b/tests/gem_pwrite_snooped.c >> @@ -76,14 +76,14 @@ static void blit(drm_intel_bo *dst, drm_intel_bo *src, >> intel_batchbuffer_free(batch); >> } >> >> -static void *memchr_inv(const void *s, int c, size_t n) >> +static void const *memchr_inv(const void *s, int c, size_t n) > > Oh, and I'll just note that I wrote it the way I did orignally so that > it matches memchr(). But I suppose matching memchr() exactly is not all > that important. It may actually be more useful to remove const from the function parameter rather than add it to the return type. Other than adding or removing the const annotations, there doesn't seem to be any other way of avoiding the warning from -Wcast-qual in this case. > >> { >> const unsigned char *us = s; >> unsigned char uc = c; >> >> while (n--) { >> if (*us != uc) >> - return (void *) us; >> + return (void const *) us; >> us++; >> } >> >> -- >> 1.9.1 >> >> _______________________________________________ >> Intel-gfx mailing list >> Intel-gfx@lists.freedesktop.org >> http://lists.freedesktop.org/mailman/listinfo/intel-gfx > > -- > Ville Syrjälä > Intel OTC
On Mon, Sep 07, 2015 at 03:49:58PM +0100, Thomas Wood wrote: > On 7 September 2015 at 13:53, Ville Syrjälä > <ville.syrjala@linux.intel.com> wrote: > > On Mon, Sep 07, 2015 at 12:34:12PM +0100, Thomas Wood wrote: > >> Signed-off-by: Thomas Wood <thomas.wood@intel.com> > >> --- > >> tests/gem_pwrite_snooped.c | 4 ++-- > >> 1 file changed, 2 insertions(+), 2 deletions(-) > >> > >> diff --git a/tests/gem_pwrite_snooped.c b/tests/gem_pwrite_snooped.c > >> index d3f6223..29142c3 100644 > >> --- a/tests/gem_pwrite_snooped.c > >> +++ b/tests/gem_pwrite_snooped.c > >> @@ -76,14 +76,14 @@ static void blit(drm_intel_bo *dst, drm_intel_bo *src, > >> intel_batchbuffer_free(batch); > >> } > >> > >> -static void *memchr_inv(const void *s, int c, size_t n) > >> +static void const *memchr_inv(const void *s, int c, size_t n) > > > > Oh, and I'll just note that I wrote it the way I did orignally so that > > it matches memchr(). But I suppose matching memchr() exactly is not all > > that important. > > It may actually be more useful to remove const from the function > parameter rather than add it to the return type. The function doesn't change the data, so passing in const definitely makes sense. I guess it could also use __attribute__((pure)) > Other than adding or > removing the const annotations, there doesn't seem to be any other way > of avoiding the warning from -Wcast-qual in this case. Would be nice if we could have const and non-const versions of the function, so that the constness of the returned type depends on what gets passed in. But this is C and not C++ so we can't have that. And even in C++ you would then have to make the function argument to non-const as well, which loses the information that it doesn't change the data. > > > > > >> { > >> const unsigned char *us = s; > >> unsigned char uc = c; > >> > >> while (n--) { > >> if (*us != uc) > >> - return (void *) us; > >> + return (void const *) us; > >> us++; > >> } > >> > >> -- > >> 1.9.1 > >> > >> _______________________________________________ > >> Intel-gfx mailing list > >> Intel-gfx@lists.freedesktop.org > >> http://lists.freedesktop.org/mailman/listinfo/intel-gfx > > > > -- > > Ville Syrjälä > > Intel OTC
diff --git a/tests/gem_pwrite_snooped.c b/tests/gem_pwrite_snooped.c index d3f6223..29142c3 100644 --- a/tests/gem_pwrite_snooped.c +++ b/tests/gem_pwrite_snooped.c @@ -76,14 +76,14 @@ static void blit(drm_intel_bo *dst, drm_intel_bo *src, intel_batchbuffer_free(batch); } -static void *memchr_inv(const void *s, int c, size_t n) +static void const *memchr_inv(const void *s, int c, size_t n) { const unsigned char *us = s; unsigned char uc = c; while (n--) { if (*us != uc) - return (void *) us; + return (void const *) us; us++; }
Signed-off-by: Thomas Wood <thomas.wood@intel.com> --- tests/gem_pwrite_snooped.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)