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

Re: FSFS/svn-rep-sharing-stats questions

From: Daniel Shahaf <d.s_at_daniel.shahaf.name>
Date: Tue, 13 Oct 2009 04:58:29 +0200 (Jerusalem Standard Time)

Branko Cibej wrote on Tue, 13 Oct 2009 at 04:39 +0200:
> Daniel Shahaf wrote:
> > Was trying to avoid malloc'ing an unsigned int. But, indeed, I can't
> > find a reference allowing the cast. So I have two options:
> >
> > * malloc an unsigned int
> >
> > * use pointer arithmetic:
> > def increment():
> > void *p = apr_hash_get();
> > apr_hash_set(p+1)
> > def extract_final_value():
> > void *p = apr_hash_get();
> > return (p - NULL)
> >
>
> Which is not strictly well-defined, either. :) void* doesn't have a
> size, so you can't do arithmetic with it (never mind GCC's extension).
>

First, we use sizeof(void *) in our code.

[[[
.../trunk/subversion% grep -R void . | grep sizeof | grep -v /.svn/text-base/
./bindings/swig/perl/libsvn_swig_perl/swigutil_pl.c: void **result = apr_palloc(pool, sizeof(void *));
./bindings/swig/perl/libsvn_swig_perl/swigutil_pl.c: void **result = apr_palloc(pool, sizeof(void *));
./bindings/swig/python/libsvn_swig_py/swigutil_py.c: temp = apr_array_make(pool, targlen, sizeof(void *));
./bindings/swig/ruby/libsvn_swig_ruby/swigutil_rb.c: result = apr_palloc(pool, sizeof(void *));
./bindings/swig/ruby/libsvn_swig_ruby/swigutil_rb.c: *handler_baton = apr_palloc(*handler_pool, sizeof(void *));
./libsvn_client/commit.c: batons = apr_array_make(pool, new_entries->nelts, sizeof(void *));
./libsvn_client/commit_util.c: apr_array_make(subpool, commit_items->nelts, sizeof(void*));
./libsvn_delta/path_driver.c: apr_array_header_t *db_stack = apr_array_make(pool, 4, sizeof(void *));
./libsvn_diff/diff_file.c: memcpy((void *) (argv + 1), args->elts, sizeof(char*) * args->nelts);
./libsvn_ra_svn/client.c: memcpy((void *) *argv, cmd_argv, n * sizeof(char *));
./mod_dav_svn/lock.c: (void)apr_xml_parser_geterror(xml_parser, errbuf, sizeof(errbuf));
]]]

Second, I haven't tried to compile that code, but I'd be surprised if it
doesn't work (unless, e.g., arrays of void* are also not allowed).

> > I'll go with the first option :)
> >
>
> However from a *practical* standpoint:
>
> * C99 defines the types intptr_t and uintptr_t which are integer
> types guaranteed to be large enough to store a void*'s value
> without data loss;
> * We don't use C99, but if you let configure find an appropriate
> integer type, or use ptrdiff_t, it'll work for all practical
> purposes since you control what goes in the hash.

apr_int64_t?

> * You could always do your counting with char* ...
>

I might go with that, then.

> -- Brane
>

Thanks,

Daniel

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2406907
Received on 2009-10-13 23:47:59 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.