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

Re: Subversion generic streams

From: Jim Blandy <jimb_at_zwingli.cygnus.com>
Date: 2000-12-12 16:27:42 CET

Is it possible to design a decent generic stream system that is very
low on bureaucracy?

I agree that generic streams are graceful and fun. The reason I
originally suggested svn_fs_read_fn instead of something broader is
that my experience doing generic streams in Guile was that they were
clumsy to construct. You had to write a lot of code to capture even
the simplest idea. My thought was that an svn_fs_read_fn should be a
quick thing to throw together.

Some dead code from the fs, just for discussion:

    /* The type for a string contents baton. */
    struct read_string {
      svn_string_t *contents;
      apr_size_t offset;
    };

    /* A read-like function for reading from a string content baton. */
    static svn_error_t *
    read_string_fn (void *baton,
                    char *buffer,
                    apr_size_t *len,
                    apr_pool_t *pool)
    {
      struct read_string *rs = baton;
      int remaining = rs->contents->len - rs->offset;

      /* How many bytes are we actually going to deliver? */
      int provide = (*len > remaining ? remaining : *len);

      memcpy (buffer, rs->contents->data + rs->offset, provide);
      *len = provide;
      return 0;
    }

    ...

      struct read_string *rs;

      rs = NEW (pool, struct read_string);
      rs->contents = some string;
      rs->offset = 0;

      *contents_p = read_string_fn;
      *contents_baton_p = rs;

With generic streams, you'd have an additional structure here
containing function pointers and a baton. Or maybe you'd put the
function pointers in some constant initialized structure.
Received on Sat Oct 21 14:36:16 2006

This is an archived mail posted to the Subversion Dev mailing list.