[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: PATCH: Remove unnecessary type casts

From: Julian Foad <julianfoad_at_btopenworld.com>
Date: 2004-03-08 01:32:04 CET

Philip Martin wrote:
> Julian Foad <julianfoad@btopenworld.com> writes:
>
>>OK for me to commit this?
>>
>>The API change in it is only to a private API, which, as I
>>understand it, can be changed in any release. (If it were a public
>>API, it would be relevant that this is a loosening of the API, which
>>is source-compatible in one direction, though I'm not sure about
>>binary compatibility.)
>
>>Index: subversion/libsvn_fs/bdb/dbt.c
>>===================================================================
>>--- subversion/libsvn_fs/bdb/dbt.c (revision 8769)
>>+++ subversion/libsvn_fs/bdb/dbt.c (working copy)
>
>>@@ -147,7 +147,7 @@
>> /* Set DBT to the text of the null-terminated string STR. DBT will
>> refer to STR's storage. Return DBT. */
>> DBT *
>>-svn_fs__str_to_dbt (DBT *dbt, char *str)
>>+svn_fs__str_to_dbt (DBT *dbt, const char *str)
>> {
>> svn_fs__set_dbt (dbt, str, strlen (str));
>> return dbt;
[...]
> Is it a good idea? The str parameter ends up getting cast to
> non-const inside svn_fs__set_dbt, do all the places that retrieve it
> treat it as const?

I think it is a good idea. I have not checked the places that retrieve the ultimate data structure field, but I looked at the callers and callee of this function svn_fs__str_to_dbt. Most or all of its callers are passing a constant string, and its callee expects a constant string. This function in the middle is the odd one out.

The further type-munging that takes place inside the callee svn_fs__set_dbt is probably due to historical lack of "const" in the BDB data structure. The data field must be logically constant, else svn_fs__set_dbt would be wrong in accepting a pointer-to-const, and the callers of svn_fs__str_to_dbt would be wrong in supplying constant data.

Does that make sense?

- Julian

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Mar 8 01:31:21 2004

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.