git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [WIP PATCH 1/7] Add skeleton RA svnclient

From
DSDaniel Shahaf <d.s@daniel.shahaf.name>
Date
Jun 25, 2010, 11:30 UTC
Message-ID
<alpine.561.2.00.1006251412170.2144@daniel2.local>
In-Reply-To
<AANLkTimirObq-HBrB4rQdAprN8mfd92rfFKSegJKwMsc@mail.gmail.com>
Ramkumar Ramachandra wrote on Fri, 25 Jun 2010 at 14:07 -0000:
Show 21 quoted lines
> Daniel Shahaf wrote:
> > Jonathan Nieder wrote on Fri, 25 Jun 2010 at 03:14 -0000:
> >> What is a baton?
> >>
> >
> > The context object for a callback.
> >
> > You call:
> >
> >    some_function(your_callback_function, your_baton)
> >
> > which then calls:
> >
> >    your_callback_function(your_baton, other_arguments)
> 
> In general, I've found that batons are void * objects in which you can
> stuff anything you like and pass around from function to function:
> I've abused them quite heavily in my code by stuffing all kinds of
> things into them: see fb->eb->* in my current code for an example of
> this.
> 
We do that too sometimes:

% pwd $trunk_wc/subversion/libsvn_client/ % grep -- "->eb->" *.c | head commit_util.c: return (*db->eb->real_editor->add_file)(path, db->real_baton, commit_util.c: return (*db->eb->real_editor->delete_entry)(path, revision, commit_util.c: return (*db->eb->real_editor->open_file)(path, db->real_baton, commit_util.c: return (*fb->eb->real_editor->close_file)(fb->real_baton, commit_util.c: return (*fb->eb->real_editor->change_file_prop)(fb->real_baton, commit_util.c: return (*fb->eb->real_editor->apply_textdelta)(fb->real_baton, ...

Show 23 quoted lines
> >> [...]
> >> > +  void *wrapped_edit_baton;
> >> [...]
> >> > +  void *edit_baton;
> >> > +  void *wrapped_dir_baton;
> >> [...]
> >> > +  void *edit_baton;
> >> > +  void *wrapped_file_baton;
> >>
> >> Are these opaque types necessary?
> >>
> >
> > The convention in Subversion's code is to convert the void * to
> > a concrete_baton_t * only inside the callback.  If you wish to declare
> > these, e.g., as
> >
> >    debug_editor_baton_t *wrapped_baton;
> >
> > You can probably do that too.
> 
> The function prototypes in libsvn contain void * parameters
> corresponding to batons, so I'd have to typecast explicitly to avoid
> any warnings.

By the way, a common pitfall is to mis-treat the void *baton argument as the wrong type of baton. That is, code of the form

    f(void *baton) {
        foo_baton_t *fb = baton;
    }
instead of
    f(void *baton) {
        bar_baton_t *bb = baton;
    }
Show 5 quoted lines
> I think Jonathan's also referring to the absence of the
> "struct" keyword everywhere, as that is against Git policy.
> Unfortunately, everything is typedef'ed in libsvn, and we cannot do
> much about that.
> 
Usually we do
    typedef struct svn_error_t svn_error_t;
so you can add the 'struct' back if you want.
Show 20 quoted lines
> >> What does this do?  Is SVN_ERR for debugging?
> >
> > That's how we implement exception throwing in C.  SVN_ERR means "if this
> > returned a non-NULL svn_error_t *, then return that error to our
> > caller".
> >
> > The other pattern does
> >
> >    svn_error_t *err = svn_stream_printf();
> >
> > and then inspects err and err->apr_err to decide whether to ignore the
> > error or return it (possibly wrapped).
> 
> >> Where does the output go?
> >>
> >
> > SVN_ERR does not print anything.  It may return(), though.
> 
> Embarrassingly enough, write_indent does exactly what it says it does:
> It writes some spaces (or indent) to eb->out
To represent nesting.
> Note however, that even with all this error handling, the most common
> type of error I get by far is the segfault: I'll make an effort to
> document the pitfalls.
> 

Note there are several kinds of errors that can cause a segfault. (@Ram, you've encountered some of them already, I know.)

Show 11 quoted lines
> >> I take it these are callbacks?  Is there overview documentation for
> >> them somewhere?
> >>
> >
> > svn_delta_editor_t in
> > http://svn.apache.org/repos/asf/subversion/trunk/subversion/include/svn_delta.h
> 
> Yes, they are callbacks that are fired automatically by the editor. In
> svn_delta.h, look at struct svn_delta_editor_t (and the corresponding
> doxygen-style comments).
> 

The compiled doxygen docs are available on <http://subversion.apache.org/docs/#api>. Personally I always just read the header file directly (with :set filetype=c.doxygen).

Previous: Ramkumar RamachandraNext: Jonathan Nieder
Message 6 of 18 in “[GSoC update] git-remote-svn: Week 8”
  1. Ramkumar RamachandraJun 23, 2010
  2. 1/7 Add skeleton RA svnclientRamkumar Ramachandra, Jun 23, 2010
  3. Jonathan NiederJun 25, 2010
  4. Daniel ShahafJun 25, 2010
  5. Ramkumar RamachandraJun 25, 2010
  6. Daniel ShahafJun 25, 2010
  7. OT: typesafe callbacks in C (Re: [WIP PATCH 1/7] Add skeleton RA svnclient)Jonathan Nieder, Jun 25, 2010
  8. Jonathan NiederJun 25, 2010
  9. Jonathan NiederJun 25, 2010
  10. 2/7 Add stripped dump editorRamkumar Ramachandra, Jun 23, 2010
  11. 3/7 Import dump_node to dump what changed and cleanup whitespaceRamkumar Ramachandra, Jun 23, 2010
  12. Ramkumar RamachandraJun 23, 2010
  13. 4/7 Replace deprecated svn_path_joinRamkumar Ramachandra, Jun 23, 2010
  14. 5/7 Trigger dump_node in change_dir_propRamkumar Ramachandra, Jun 23, 2010
  15. 6/7 Add file_baton and trigger dump_node in change_file_propRamkumar Ramachandra, Jun 23, 2010
  16. 7/7 Dump the text deltaRamkumar Ramachandra, Jun 23, 2010
  17. Ramkumar RamachandraJun 23, 2010
  18. Jonathan NiederJun 25, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.