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

Re: svn commit: r39997 - trunk/tools/server-side

From: Branko Cibej <brane_at_xbc.nu>
Date: Wed, 14 Oct 2009 06:41:56 +0200

Daniel Shahaf wrote:
> David Glasser wrote on Tue, 13 Oct 2009 at 12:45 -0700:
>
>> On Oct 13, 2009 12:27 PM, "Daniel Shahaf" <tigris_at_danielsh.fastmail.net>
>> wrote:
>>
>>
>>> +struct key_t
>>> +{
>>> + svn_revnum_t revision;
>>> + apr_off_t offset;
>>> +};
>>> +
>>> +/* What we need to know about a rep. */
>>> +struct value_t
>>> +{
>>> + svn_checksum_t *sha1_checksum;
>>> + apr_uint64_t refcount;
>>> +};
>>>
> ...
>
>>> + apr_hash_set(records, key, sizeof(*key), value);
>>>
>> Is it legit to hash on a struct? Couldn't there be padding bytes?
>>
>
> While this doesn't answer the question, we have precedent in
> libsvn_fs_base/bdb/env.c:
>
> apr_hash_set(bdb_cache, &bdb->key, sizeof bdb->key, NULL);
>
> where bdb->key is the following struct:
>
> typedef struct
> {
> apr_dev_t device;
> apr_ino_t inode;
> } bdb_env_key_t;
>

... but notice that bdb_env_key_t is part of bdb_env_t which has a
constructor called create_env() that uses calloc() to allocate the
struct. Yes, there can be padding, and yes, using (apr_p)calloc to
allocate the struct avoids hashing random padding bits.

-- Brane

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2407402
Received on 2009-10-14 06:42:22 CEST

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.