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

Re: svn commit: r999507 - in /subversion/trunk/subversion: svnrdump/dump_editor.c tests/cmdline/svnrdump_tests.py

From: Daniel Shahaf <d.s_at_daniel.shahaf.name>
Date: Wed, 22 Sep 2010 22:09:07 +0200

Ramkumar Ramachandra wrote on Thu, Sep 23, 2010 at 01:12:52 +0530:
> Daniel Shahaf writes:
> > Choosing path=NULL to represent "the root" seems odd to me (that's not
> > how we usually represent it), but that's for another day.
>
> I think I'm using "" to represent the root somewhere, but I'll have to
> check this. I'll figure something out during the cleanup.
>

I see.

> > > True. However, abspath is a `char *` with no memory allocated to it: I
> > > want whatever its value is to be allocated in `pool` since it's passed
> > > around.
> >
> > I think you've got your pointers confused. Can you drop the pstrdup(),
> > see that nothing breaks, and then we can discuss why nothing broke?
>
> Hehe, I wouldn't be surprised if this is the case -- I've been working
> with APR pools day and night now :p
>
> Okay, I'll drop this during the cleanup. Do explain this to me though :)

abspath is a pointer, lives on the stack, and is passed by value (like
any old int) in function calls. What you allocate from the pool is the
value it points to --- i.e., the two bytes of "/".

However, literal string constants are static strings --- they are loaded
into memory from the binary image (ever tried 'strings /usr/bin/svn'?)
and stay there until that is unloaded --- while pool-allocated strings
allocated on the heap, and stays there until the pool is cleared.
The other difference is that literal strings are not writable (they are
const char *) while pool-allocate strings are mutable (non-const char *).

So, the only reasons you'd have to duplicate a static string is if the
static string lives in a library which you know you'll unload[1] or if
you need a non-const char * for some reason. In your case, 'abspath' is
a const char *, so neither of these cases applies.

Okay?

Daniel
(waiting to hear from you that dropping the strdup() causes a segfault)

[1] Thanks, dev@ archives.
Received on 2010-09-22 22:13:40 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.