You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Greg Stein <gs...@lyra.org> on 2000/12/14 01:23:49 UTC

Re: CVS update: subversion/subversion/libsvn_fs txn-table.c

Actually, isn't this a facet of all calls to svn_fs__*_to_dbt()? That you're
feeding data to the DBT for insertion, and that nothing will attempt to
change the DBT after that point?

IOW, why wouldn't this cast move inside of str_to_dbt and a "const" applied
to the str_to_dbt prototype?

Cheers,
-g

On Wed, Dec 13, 2000 at 07:02:51PM -0000, jimb@tigris.org wrote:
>   User: jimb    
>   Date: 00/12/13 11:02:51
> 
>   Modified:    subversion/libsvn_fs txn-table.c
>   Log:
>   * libsvn_fs/txn-table.c (put_txn, svn_fs__get_txn): Acknowledge the
>   loss of svn_txn's constness, at a point where it is clear this does no
>   harm.
>   
>   Revision  Changes    Path
>   1.4       +7 -2      subversion/subversion/libsvn_fs/txn-table.c
>   
>   Index: txn-table.c
>   ===================================================================
>   RCS file: /cvs/subversion/subversion/libsvn_fs/txn-table.c,v
>   retrieving revision 1.3
>   retrieving revision 1.4
>   diff -u -r1.3 -r1.4
>   --- txn-table.c	2000/12/13 18:52:41	1.3
>   +++ txn-table.c	2000/12/13 19:02:51	1.4
>   @@ -72,7 +72,9 @@
>    		   txn_skel);
>      svn_fs__prepend (svn_fs__str_atom ("transaction", pool), txn_skel);
>    
>   -  svn_fs__str_to_dbt (&key, svn_txn);
>   +  /* Only in the context of this function do we know that the DB call
>   +     will not attempt to modify svn_txn, so the cast belongs here.  */
>   +  svn_fs__str_to_dbt (&key, (char *) svn_txn);
>      svn_fs__skel_to_dbt (&value, txn_skel, pool);
>      SVN_ERR (DB_WRAP (fs, "storing transaction record",
>    		    fs->transactions->put (fs->transactions, trail->db_txn,
>   @@ -174,9 +176,12 @@
>      DBT key, value;
>      skel_t *transaction;
>    
>   +  /* Only in the context of this function do we know that the DB call
>   +     will not attempt to modify svn_txn, so the cast belongs here.  */
>   +  svn_fs__str_to_dbt (&key, (char *) svn_txn);
>      SVN_ERR (DB_WRAP (fs, "reading transaction",
>    		    fs->transactions->get (fs->transactions, trail->db_txn,
>   -					   svn_fs__str_to_dbt (&key, svn_txn),
>   +					   &key,
>    					   svn_fs__result_dbt (&value),
>    					   0)));
>      svn_fs__track_dbt (&value, trail->pool);
>   
>   
>   

-- 
Greg Stein, http://www.lyra.org/

Re: CVS update: subversion/subversion/libsvn_fs txn-table.c

Posted by Greg Stein <gs...@lyra.org>.
On Thu, Dec 14, 2000 at 10:46:52AM -0500, Jim Blandy wrote:
> 
> > Actually, isn't this a facet of all calls to svn_fs__*_to_dbt()? That you're
> > feeding data to the DBT for insertion, and that nothing will attempt to
> > change the DBT after that point?
> > 
> > IOW, why wouldn't this cast move inside of str_to_dbt and a "const" applied
> > to the str_to_dbt prototype?
> 
> BTW, I don't think it's helpful to apply to `const' to `skel_t'
> arguments.  A skel is a tree, not a single node or array of nodes.  So
> a `const skel_t *' argument doesn't mean "I won't modify this tree",
> which is what one really wants to say; it means "I won't modify the
> top skel of this tree, but I might munge any of the other skels it
> points to," which is useless.

1) It is still important as it conveys a semantic. Sure, the typing rules
   allow you to change the contents. This is similar to applying a const
   marker to an svn_string_t. But we *do* know the intent when we see the
   const.

2) I'd like to see the child skel points as const. This would definitely
   toss out the "well, I might modify the thing you pass me" aspect. I'm not
   sure how feasible this will be, but plan to take a look at the problem
   when the FS code begins to settle.


Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: CVS update: subversion/subversion/libsvn_fs txn-table.c

Posted by Jim Blandy <ji...@zwingli.cygnus.com>.
> Actually, isn't this a facet of all calls to svn_fs__*_to_dbt()? That you're
> feeding data to the DBT for insertion, and that nothing will attempt to
> change the DBT after that point?
> 
> IOW, why wouldn't this cast move inside of str_to_dbt and a "const" applied
> to the str_to_dbt prototype?

BTW, I don't think it's helpful to apply to `const' to `skel_t'
arguments.  A skel is a tree, not a single node or array of nodes.  So
a `const skel_t *' argument doesn't mean "I won't modify this tree",
which is what one really wants to say; it means "I won't modify the
top skel of this tree, but I might munge any of the other skels it
points to," which is useless.

Re: CVS update: subversion/subversion/libsvn_fs txn-table.c

Posted by Jim Blandy <ji...@zwingli.cygnus.com>.
> btw, I'm happy to be seeing more "const" appearing in your code. It
> definitely helps in understanding what is an "in" vs "out" (or in/out)
> parameter.

Yes, I'm trying to use it whenever I can.

The documentation aspect of `const' I really like.  But I'm
uncomfortable using it to suggest something other than what it really
means, according to C.  In a lot of the cases you constified (back in
mid-November?), the meaning you're trying to convey is somewhat
different from the actual implications of `const'.

I'd rather say exactly what I mean in comments than say odd things in
the code that hint at my real intent.

Re: CVS update: subversion/subversion/libsvn_fs txn-table.c

Posted by Jim Blandy <ji...@zwingli.cygnus.com>.
Greg Stein <gs...@lyra.org> writes:

> btw, I'm happy to be seeing more "const" appearing in your code. It
> definitely helps in understanding what is an "in" vs "out" (or in/out)
> parameter.

Oh, you're going to hate my last commit, then... :(

Re: CVS update: subversion/subversion/libsvn_fs txn-table.c

Posted by Greg Stein <gs...@lyra.org>.
On Thu, Dec 14, 2000 at 07:44:14AM -0500, Jim Blandy wrote:
> 
> > Actually, isn't this a facet of all calls to svn_fs__*_to_dbt()? That you're
> > feeding data to the DBT for insertion, and that nothing will attempt to
> > change the DBT after that point?
> > 
> > IOW, why wouldn't this cast move inside of str_to_dbt and a "const" applied
> > to the str_to_dbt prototype?
> 
> The other *_to_dbt calls actually copy their arguments, so making
> their arguments const is appropriate there.  str_to_dbt points to its
> argument, and we can't promise that the DB won't modify it (there are
> some calls that both read and write a DBT).  So the cast needs to be
> made by code which can be sure it's correct.

Gotcha. Cool.

btw, I'm happy to be seeing more "const" appearing in your code. It
definitely helps in understanding what is an "in" vs "out" (or in/out)
parameter.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: CVS update: subversion/subversion/libsvn_fs txn-table.c

Posted by Jim Blandy <ji...@zwingli.cygnus.com>.
> Actually, isn't this a facet of all calls to svn_fs__*_to_dbt()? That you're
> feeding data to the DBT for insertion, and that nothing will attempt to
> change the DBT after that point?
> 
> IOW, why wouldn't this cast move inside of str_to_dbt and a "const" applied
> to the str_to_dbt prototype?

The other *_to_dbt calls actually copy their arguments, so making
their arguments const is appropriate there.  str_to_dbt points to its
argument, and we can't promise that the DB won't modify it (there are
some calls that both read and write a DBT).  So the cast needs to be
made by code which can be sure it's correct.