From 2b20f0abd43c10b27de24ccce1e52476ea4b2c27 Mon Sep 17 00:00:00 2001 From: skimo Date: Sat, 22 Jul 2000 10:20:31 +0000 Subject: [PATCH] pass thread specific data do db --- common/db.c | 19 +++++++++++++++---- common/exf.h | 4 +--- common/log.c | 54 +++++++++++++++++++++++++++--------------------------- common/screen.c | 4 +++- common/screen.h | 8 +++++++- 5 files changed, 53 insertions(+), 36 deletions(-) diff --git a/common/db.c b/common/db.c index 76f488f3..815ca758 100644 --- a/common/db.c +++ b/common/db.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: db.c,v 10.31 2000/07/21 22:09:28 skimo Exp $ (Berkeley) $Date: 2000/07/21 22:09:28 $"; +static const char sccsid[] = "$Id: db.c,v 10.32 2000/07/22 10:20:31 skimo Exp $ (Berkeley) $Date: 2000/07/22 10:20:31 $"; #endif /* not lint */ #include @@ -94,6 +94,8 @@ db_get(sp, lno, flags, pp, lenp) CHAR_T *wp; size_t wlen; size_t nlen; + char *bp; + size_t blen; /* * The underlying recno stuff handles zero by returning NULL, but @@ -156,16 +158,21 @@ db_get(sp, lno, flags, pp, lenp) nocache: nlen = 1024; -retry: + GET_SPACE_GOTO(sp, bp, blen, nlen); + if (0) { +retry: ADD_SPACE_GOTO(sp, bp, blen, nlen); + } + /* BINC_GOTO(sp, (char *)ep->c_lp, ep->c_blen, nlen); + */ /* Get the line from the underlying database. */ memset(&key, 0, sizeof(key)); key.data = &lno; key.size = sizeof(lno); memset(&data, 0, sizeof(data)); - data.data = ep->c_lp; - data.ulen = ep->c_blen; + data.data = bp; + data.ulen = blen; data.flags = DB_DBT_USERMEM; switch (ep->db->get(ep->db, NULL, &key, &data, 0)) { case ENOMEM: @@ -181,6 +188,8 @@ err3: if (lenp != NULL) *lenp = 0; if (pp != NULL) *pp = NULL; + if (bp != NULL) + FREE_SPACE(sp, bp, blen); return (1); case 0: ; @@ -201,6 +210,8 @@ err3: if (lenp != NULL) *lenp = wlen; if (pp != NULL) *pp = ep->c_lp; + if (bp != NULL) + FREE_SPACE(sp, bp, blen); return (0); } diff --git a/common/exf.h b/common/exf.h index 03604c66..95a22869 100644 --- a/common/exf.h +++ b/common/exf.h @@ -6,7 +6,7 @@ * * See the LICENSE file for redistribution information. * - * $Id: exf.h,v 10.12 2000/07/15 20:26:34 skimo Exp $ (Berkeley) $Date: 2000/07/15 20:26:34 $ + * $Id: exf.h,v 10.13 2000/07/22 10:20:31 skimo Exp $ (Berkeley) $Date: 2000/07/22 10:20:31 $ */ /* Undo direction. */ /* @@ -29,8 +29,6 @@ struct _exf { db_recno_t c_nlines; /* Cached lines in the file. */ DB *log; /* Log db structure. */ - char *l_lp; /* Log buffer. */ - size_t l_len; /* Log buffer length. */ db_recno_t l_high; /* Log last + 1 record number. */ db_recno_t l_cur; /* Log current record number. */ MARK l_cursor; /* Log cursor position. */ diff --git a/common/log.c b/common/log.c index dfd0a502..609ba238 100644 --- a/common/log.c +++ b/common/log.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: log.c,v 10.15 2000/07/21 22:09:28 skimo Exp $ (Berkeley) $Date: 2000/07/21 22:09:28 $"; +static const char sccsid[] = "$Id: log.c,v 10.16 2000/07/22 10:20:31 skimo Exp $ (Berkeley) $Date: 2000/07/22 10:20:31 $"; #endif /* not lint */ #include @@ -94,8 +94,8 @@ log_init(sp, ep) * buffers because the global ones are almost by definition * going to be in use when the log runs. */ - ep->l_lp = NULL; - ep->l_len = 0; + sp->wp->l_lp = NULL; + sp->wp->l_len = 0; ep->l_cursor.lno = 1; /* XXX Any valid recno. */ ep->l_cursor.cno = 0; ep->l_high = ep->l_cur = 1; @@ -130,11 +130,11 @@ log_end(sp, ep) (void)(ep->log->close)(ep->log,DB_NOSYNC); ep->log = NULL; } - if (ep->l_lp != NULL) { - free(ep->l_lp); - ep->l_lp = NULL; + if (sp->wp->l_lp != NULL) { + free(sp->wp->l_lp); + sp->wp->l_lp = NULL; } - ep->l_len = 0; + sp->wp->l_len = 0; ep->l_cursor.lno = 1; /* XXX Any valid recno. */ ep->l_cursor.cno = 0; ep->l_high = ep->l_cur = 1; @@ -184,15 +184,15 @@ log_cursor1(sp, type) EXF *ep; ep = sp->ep; - BINC_RET(sp, ep->l_lp, ep->l_len, sizeof(u_char) + sizeof(MARK)); - ep->l_lp[0] = type; - memmove(ep->l_lp + sizeof(u_char), &ep->l_cursor, sizeof(MARK)); + BINC_RET(sp, sp->wp->l_lp, sp->wp->l_len, sizeof(u_char) + sizeof(MARK)); + sp->wp->l_lp[0] = type; + memmove(sp->wp->l_lp + sizeof(u_char), &ep->l_cursor, sizeof(MARK)); memset(&key, 0, sizeof(key)); key.data = &ep->l_cur; key.size = sizeof(db_recno_t); memset(&data, 0, sizeof(data)); - data.data = ep->l_lp; + data.data = sp->wp->l_lp; data.size = sizeof(u_char) + sizeof(MARK); if (ep->log->put(ep->log, NULL, &key, &data, 0) == -1) LOG_ERR; @@ -264,17 +264,17 @@ log_line(sp, lno, action) if (db_get(sp, lno, DBG_FATAL, &lp, &len)) return (1); BINC_RET(sp, - ep->l_lp, ep->l_len, + sp->wp->l_lp, sp->wp->l_len, len * sizeof(CHAR_T) + sizeof(u_char) + sizeof(db_recno_t)); - ep->l_lp[0] = action; - memmove(ep->l_lp + sizeof(u_char), &lno, sizeof(db_recno_t)); - MEMMOVEW(ep->l_lp + sizeof(u_char) + sizeof(db_recno_t), lp, len); + sp->wp->l_lp[0] = action; + memmove(sp->wp->l_lp + sizeof(u_char), &lno, sizeof(db_recno_t)); + MEMMOVEW(sp->wp->l_lp + sizeof(u_char) + sizeof(db_recno_t), lp, len); memset(&key, 0, sizeof(key)); key.data = &ep->l_cur; key.size = sizeof(db_recno_t); memset(&data, 0, sizeof(data)); - data.data = ep->l_lp; + data.data = sp->wp->l_lp; data.size = len * sizeof(CHAR_T) + sizeof(u_char) + sizeof(db_recno_t); if (ep->log->put(ep->log, NULL, &key, &data, 0) == -1) @@ -338,16 +338,16 @@ log_mark(sp, lmp) ep->l_cursor.lno = OOBLNO; } - BINC_RET(sp, ep->l_lp, - ep->l_len, sizeof(u_char) + sizeof(LMARK)); - ep->l_lp[0] = LOG_MARK; - memmove(ep->l_lp + sizeof(u_char), lmp, sizeof(LMARK)); + BINC_RET(sp, sp->wp->l_lp, + sp->wp->l_len, sizeof(u_char) + sizeof(LMARK)); + sp->wp->l_lp[0] = LOG_MARK; + memmove(sp->wp->l_lp + sizeof(u_char), lmp, sizeof(LMARK)); memset(&key, 0, sizeof(key)); key.data = &ep->l_cur; key.size = sizeof(db_recno_t); memset(&data, 0, sizeof(data)); - data.data = ep->l_lp; + data.data = sp->wp->l_lp; data.size = sizeof(u_char) + sizeof(LMARK); if (ep->log->put(ep->log, NULL, &key, &data, 0) == -1) LOG_ERR; @@ -376,14 +376,14 @@ vi_log_get(SCR *sp, db_recno_t *lnop, size_t *size) nlen = 1024; retry: - BINC_RET(sp, ep->l_lp, ep->l_len, nlen); + BINC_RET(sp, sp->wp->l_lp, sp->wp->l_len, nlen); memset(&key, 0, sizeof(key)); key.data = lnop; /* Initialize db request. */ key.size = sizeof(db_recno_t); memset(&data, 0, sizeof(data)); - data.data = ep->l_lp; - data.ulen = ep->l_len; + data.data = sp->wp->l_lp; + data.ulen = sp->wp->l_len; data.flags = DB_DBT_USERMEM; switch (ep->log->get(ep->log, NULL, &key, &data, 0)) { case ENOMEM: @@ -437,7 +437,7 @@ log_backward(sp, rp) #if defined(DEBUG) && 0 log_trace(sp, "log_backward", ep->l_cur, data.data); #endif - switch (*(p = (u_char *)ep->l_lp)) { + switch (*(p = (u_char *)sp->wp->l_lp)) { case LOG_CURSOR_INIT: if (didop) { memmove(rp, p + sizeof(u_char), sizeof(MARK)); @@ -541,7 +541,7 @@ log_setline(sp) #if defined(DEBUG) && 0 log_trace(sp, "log_setline", ep->l_cur, data.data); #endif - switch (*(p = (u_char *)ep->l_lp)) { + switch (*(p = (u_char *)sp->wp->l_lp)) { case LOG_CURSOR_INIT: memmove(&m, p + sizeof(u_char), sizeof(MARK)); if (m.lno != sp->lno || ep->l_cur == 1) { @@ -629,7 +629,7 @@ log_forward(sp, rp) #if defined(DEBUG) && 0 log_trace(sp, "log_forward", ep->l_cur, data.data); #endif - switch (*(p = (u_char *)ep->l_lp)) { + switch (*(p = (u_char *)sp->wp->l_lp)) { case LOG_CURSOR_END: if (didop) { ++ep->l_cur; diff --git a/common/screen.c b/common/screen.c index c030a608..dfa78566 100644 --- a/common/screen.c +++ b/common/screen.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: screen.c,v 10.19 2000/07/19 20:31:58 skimo Exp $ (Berkeley) $Date: 2000/07/19 20:31:58 $"; +static const char sccsid[] = "$Id: screen.c,v 10.20 2000/07/22 10:20:31 skimo Exp $ (Berkeley) $Date: 2000/07/22 10:20:31 $"; #endif /* not lint */ #include @@ -69,6 +69,8 @@ screen_init(gp, orig, spp) if (orig == NULL) { sp->searchdir = NOTSET; } else { + sp->wp = orig->wp; + /* Alternate file name. */ if (orig->alt_name != NULL && (sp->alt_name = strdup(orig->alt_name)) == NULL) diff --git a/common/screen.h b/common/screen.h index daab9868..4dac525f 100644 --- a/common/screen.h +++ b/common/screen.h @@ -6,7 +6,7 @@ * * See the LICENSE file for redistribution information. * - * $Id: screen.h,v 10.36 2000/07/15 20:26:34 skimo Exp $ (Berkeley) $Date: 2000/07/15 20:26:34 $ + * $Id: screen.h,v 10.37 2000/07/22 10:20:31 skimo Exp $ (Berkeley) $Date: 2000/07/22 10:20:31 $ */ /* @@ -55,6 +55,12 @@ struct _win { char *tmp_bp; /* Temporary buffer. */ size_t tmp_blen; /* Temporary buffer size. */ + char *l_lp; /* Log buffer. */ + size_t l_len; /* Log buffer length. */ + + char *conv_bp; + size_t conv_blen; + /* Flags. */ #define W_TMP_INUSE 0x0001 /* Temporary buffer in use. */ u_int32_t flags; -- 2.11.4.GIT