const-correctness in interface

Bug #447237 reported by Fred Richards
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
libmemcached
Fix Released
Undecided
Trond Norbye

Bug Description

All the function declarations that contain this:

    (... const char **keys, size_t *key_length, ...)

should be:

    (... const char * const *keys, const size_t *key_length, ...)

(and the man pages fixed). The way the interfaces are declared in 0.33, this, e.g:

    char **keys /* to be alloc'd and filled in */;
    size_t *len /* same */;

    rc = memcached_mget(stptr, keys, len, count);

results in the following error from GCC 4.x: "invalid conversion from 'char**' to 'const char**'". Legacy code that was written to the API prior to the introduction of the const qualifiers (< 0.21?) therefore does not build with the newer API (and newer GCC). An explicit (const char **) cast of the keys argument is required, as is done throughout the libmemcached code with calls to memcached_key_test().

You can grep for 'const char \*\*' to find all the places that need the added const qualifiers. WIth the correct const qualifiers the explicit casts on the memcached_key_test() argument that will no longer be necessary.

The changes do not alter the regression test results.

Related branches

Revision history for this message
Monty Taylor (mordred) wrote : Re: [Bug 447237] [NEW] const-correctness in interface

I'm all for any const correctness fixes.

Fred Richards wrote:
> Public bug reported:
>
> All the function declarations that contain this:
>
> (... const char **keys, size_t *key_length, ...)
>
> should be:
>
> (... const char * const *keys, const size_t *key_length, ...)
>
> (and the man pages fixed). The way the interfaces are declared in 0.33,
> this, e.g:
>
> char **keys /* to be alloc'd and filled in */;
> size_t *len /* same */;
>
> rc = memcached_mget(stptr, keys, len, count);
>
> results in the following error from GCC 4.x: "invalid conversion from
> 'char**' to 'const char**'". Legacy code that was written to the API
> prior to the introduction of the const qualifiers (< 0.21?) therefore
> does not build with the newer API (and newer GCC). An explicit (const
> char **) cast of the keys argument is required, as is done throughout
> the libmemcached code with calls to memcached_key_test().
>
> You can grep for 'const char \*\*' to find all the places that need the
> added const qualifiers. WIth the correct const qualifiers the explicit
> casts on the memcached_key_test() argument that will no longer be
> necessary.
>
> The changes do not alter the regression test results.
>
> ** Affects: libmemcached
> Importance: Undecided
> Status: New
>

Revision history for this message
Trond Norbye (trond-norbye) wrote :

Sounds good, but let's wait for the next release

Changed in libmemcached:
assignee: nobody → Trond Norbye (trond-norbye)
status: New → Confirmed
Brian Aker (brianaker)
Changed in libmemcached:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.