From 913bb7103c13f3cc38d314cf3c5c5bdf7453f395 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 19 Apr 2011 15:29:58 +0200 Subject: [PATCH] Fastbufs: More exceptions --- ucw/doc/fastbuf.txt | 1 + ucw/fastbuf.h | 12 ++++++------ ucw/fb-mmap.c | 2 +- ucw/ff-string.c | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ucw/doc/fastbuf.txt b/ucw/doc/fastbuf.txt index 1578e760..13590a5d 100644 --- a/ucw/doc/fastbuf.txt +++ b/ucw/doc/fastbuf.txt @@ -80,4 +80,5 @@ exceptions live in the `ucw.fb` subtree. The following exceptions are defined: `ucw.fb.read`:: Read error (e.g., the `read` syscall has failed or the stream is write-only) `ucw.fb.seek`:: Seek error (e.g., file not seekable, or a seek behind EOF) `ucw.fb.tmp`:: Creation of temporary file failed +`ucw.fb.toolong`:: Object (typically a line) is too long `ucw.fb.write`:: Write error (e.g., the `write` syscall has failed or the stream is read-only) diff --git a/ucw/fastbuf.h b/ucw/fastbuf.h index 99037524..aa6c4931 100644 --- a/ucw/fastbuf.h +++ b/ucw/fastbuf.h @@ -153,7 +153,7 @@ enum fb_flags { }; /** Tie a fastbuf to a resource in the current resource pool. Returns the pointer to the same fastbuf. **/ -struct fastbuf *fb_tie(struct fastbuf *b); +struct fastbuf *fb_tie(struct fastbuf *b); /* Tie fastbuf to a resource if there is an active pool */ /*** * === Fastbuf on files [[fbparam]] @@ -197,7 +197,7 @@ extern struct fb_params fbpar_def; /** The default `fb_params` **/ * Use @params to select the fastbuf back-end and its parameters or * pass NULL if you are fine with defaults. * - * Dies if the file does not exist. + * Raises `ucw.fb.open` if the file does not exist. **/ struct fastbuf *bopen_file(const char *name, int mode, struct fb_params *params); struct fastbuf *bopen_file_try(const char *name, int mode, struct fb_params *params); /** Like bopen_file(), but returns NULL on failure. **/ @@ -355,7 +355,7 @@ void fbbuf_init_read(struct fastbuf *f, byte *buffer, uns size, uns can_overwrit /** * Creates a write-only fastbuf which writes into a provided memory buffer. * The fastbuf structure is allocated by the caller and pointed to by @f. - * An attempt to write behind the end of the buffer dies. + * An attempt to write behind the end of the buffer causes the `ucw.fb.write` exception. * * Data are written directly into the buffer, so it is not necessary to call @bflush() * at any moment. @@ -578,7 +578,7 @@ static inline uns bread(struct fastbuf *f, void *b, uns l) /** * Reads exactly @l bytes of data into @b. * If at the end of file, it returns 0. - * If there are data, but less than @l, it dies. + * If there are data, but less than @l, it raises `ucw.fb.eof`. */ static inline uns breadb(struct fastbuf *f, void *b, uns l) { @@ -607,7 +607,7 @@ static inline void bwrite(struct fastbuf *f, const void *b, uns l) /** Writes bu /** * Reads a line into @b and strips trailing `\n`. * Returns pointer to the terminating 0 or NULL on `EOF`. - * Dies if the line is longer than @l. + * Raises `ucw.fb.toolong` if the line is longer than @l. **/ char *bgets(struct fastbuf *f, char *b, uns l); char *bgets0(struct fastbuf *f, char *b, uns l); /** The same as @bgets(), but for 0-terminated strings. **/ @@ -621,7 +621,7 @@ struct mempool; struct bb_t; /** * Read a string, strip the trailing `\n` and store it into growing buffer @b. - * Dies if the line is longer than @limit. + * Raises `ucw.fb.toolong` if the line is longer than @limit. **/ uns bgets_bb(struct fastbuf *f, struct bb_t *b, uns limit); /** diff --git a/ucw/fb-mmap.c b/ucw/fb-mmap.c index fa0f03e0..8f9f0bb2 100644 --- a/ucw/fb-mmap.c +++ b/ucw/fb-mmap.c @@ -182,7 +182,7 @@ bfmmopen_internal(int fd, const char *name, uns mode) F->fd = fd; F->file_extend = F->file_size = ucw_seek(fd, 0, SEEK_END); if (F->file_size < 0) - die("seek(%s): %m", name); + bthrow(f, "open", "fb-mmap: Cannot detect size of %s -- is it seekable?", name); if (mode & O_APPEND) f->pos = F->file_size; F->mode = mode; diff --git a/ucw/ff-string.c b/ucw/ff-string.c index 366092bf..e3cb33da 100644 --- a/ucw/ff-string.c +++ b/ucw/ff-string.c @@ -35,7 +35,7 @@ bgets(struct fastbuf *f, char *b, uns l) *b++ = v; } if (unlikely(cnt == l)) - die("%s: Line too long", f->name); + bthrow(f, "toolong", "%s: Line too long", f->name); l -= cnt; bdirect_read_commit(f, src); src_len = bdirect_read_prepare(f, &src); @@ -114,7 +114,7 @@ bgets_bb(struct fastbuf *f, struct bb_t *bb, uns limit) if (cnt == buf_len) { if (unlikely(len == limit)) - die("%s: Line too long", f->name); + bthrow(f, "toolong", "%s: Line too long", f->name); bb_do_grow(bb, len + 1); buf = bb->ptr + len; buf_len = MIN(bb->len, limit) - len; @@ -212,7 +212,7 @@ bgets0(struct fastbuf *f, char *b, uns l) b++; } if (unlikely(cnt == l)) - die("%s: Line too long", f->name); + bthrow(f, "toolong", "%s: Line too long", f->name); l -= cnt; bdirect_read_commit(f, src); src_len = bdirect_read_prepare(f, &src); -- 2.39.2