[uim-commit] r2897 - branches/r5rs/sigscheme
yamaken at freedesktop.org
yamaken at freedesktop.org
Thu Jan 12 22:40:27 PST 2006
Author: yamaken
Date: 2006-01-12 22:40:24 -0800 (Thu, 12 Jan 2006)
New Revision: 2897
Modified:
branches/r5rs/sigscheme/alloc.c
branches/r5rs/sigscheme/config.h
branches/r5rs/sigscheme/sigschemeinternal.h
Log:
* sigscheme/config.h
- (SCM_LBUF_F_STRING, SCM_LBUF_F_SYMBOL): Follow the changes
* sigscheme/sigschemeinternal.h
- (struct ScmLBuf): Rename members
- (struct ScmLBuf_void_): New type
- (LBUF_BUF, LBUF_SIZE, LBUF_INIT_SIZE, LBUF_EXT_CNT): Follow the
renamings
- (LBUF_INIT, LBUF_FREE, LBUF_ALLOC, LBUF_REALLOC, LBUF_EXTEND):
Reform to wrapper to its function version
- (LBUF_F_LINEAR, LBUF_F_EXPONENTIAL): Removed
- (scm_lbuf_init, scm_lbuf_free, scm_lbuf_alloc, scm_lbuf_realloc,
scm_lbuf_extend, scm_lbuf_f_linear, scm_lbuf_f_exponential): New
function decl
* sigscheme/alloc.c
- (scm_lbuf_init, scm_lbuf_free, scm_lbuf_alloc, scm_lbuf_extend,
scm_lbuf_f_linear, scm_lbuf_f_exponential): New function inherited
the code from its macro version
- (scm_lbuf_realloc):
* Ditto
* Fix shrinking case
Modified: branches/r5rs/sigscheme/alloc.c
===================================================================
--- branches/r5rs/sigscheme/alloc.c 2006-01-12 19:46:11 UTC (rev 2896)
+++ branches/r5rs/sigscheme/alloc.c 2006-01-13 06:40:24 UTC (rev 2897)
@@ -128,3 +128,70 @@
return p;
}
+
+/*=======================================
+ Extendable Local Buffer
+=======================================*/
+void
+scm_lbuf_init(struct ScmLBuf_void_ *lbuf, void *init_buf, size_t init_size)
+{
+ lbuf->buf = lbuf->init_buf = init_buf;
+ lbuf->size = lbuf->init_size = init_size;
+ lbuf->extended_cnt = 0;
+}
+
+void
+scm_lbuf_free(struct ScmLBuf_void_ *lbuf)
+{
+ if (lbuf->buf != lbuf->init_buf)
+ free(lbuf->buf);
+}
+
+void
+scm_lbuf_alloc(struct ScmLBuf_void_ *lbuf, size_t size)
+{
+ lbuf->buf = scm_malloc(size);
+ lbuf->size = size;
+}
+
+void
+scm_lbuf_realloc(struct ScmLBuf_void_ *lbuf, size_t size)
+{
+ if (lbuf->buf == lbuf->init_buf) {
+ if (size < lbuf->size)
+ lbuf->size = size;
+ lbuf->buf = memcpy(scm_malloc(size), lbuf->buf, lbuf->size);
+ } else {
+ lbuf->buf = scm_realloc(lbuf->buf, size);
+ }
+ lbuf->size = size;
+}
+
+void
+scm_lbuf_extend(struct ScmLBuf_void_ *lbuf,
+ size_t (*f)(struct ScmLBuf_void_ *), size_t least_size)
+{
+ size_t new_size;
+
+ if (lbuf->size < least_size) {
+ new_size = (*f)(lbuf);
+ if (new_size < lbuf->size)
+ ERR("local buffer exceeded");
+ if (new_size < least_size)
+ new_size = least_size;
+ scm_lbuf_realloc(lbuf, new_size);
+ lbuf->extended_cnt++;
+ }
+}
+
+size_t
+scm_lbuf_f_linear(struct ScmLBuf_void_ *lbuf)
+{
+ return (lbuf->size + lbuf->init_size);
+}
+
+size_t
+scm_lbuf_f_exponential(struct ScmLBuf_void_ *lbuf)
+{
+ return (lbuf->size << 1);
+}
Modified: branches/r5rs/sigscheme/config.h
===================================================================
--- branches/r5rs/sigscheme/config.h 2006-01-12 19:46:11 UTC (rev 2896)
+++ branches/r5rs/sigscheme/config.h 2006-01-13 06:40:24 UTC (rev 2897)
@@ -95,8 +95,8 @@
#define SCM_INITIAL_SYMBOL_BUF_SIZE 64
/* token buffer size extender function */
-#define SCM_LBUF_F_STRING LBUF_F_LINEAR
-#define SCM_LBUF_F_SYMBOL LBUF_F_LINEAR
+#define SCM_LBUF_F_STRING scm_lbuf_f_linear
+#define SCM_LBUF_F_SYMBOL scm_lbuf_f_linear
/*===========================================================================
Debugging
Modified: branches/r5rs/sigscheme/sigschemeinternal.h
===================================================================
--- branches/r5rs/sigscheme/sigschemeinternal.h 2006-01-12 19:46:11 UTC (rev 2896)
+++ branches/r5rs/sigscheme/sigschemeinternal.h 2006-01-13 06:40:24 UTC (rev 2897)
@@ -403,72 +403,53 @@
/* don't touch inside directly */
#define ScmLBuf(T) \
struct ScmLBuf_##T##_ { \
- T *_buf; \
- size_t _size; \
- T *_init_buf; \
- size_t _init_size; \
- int _extended_cnt; \
+ T *buf; \
+ size_t size; \
+ T *init_buf; \
+ size_t init_size; \
+ int extended_cnt; \
}
+ScmLBuf(void);
+
/* lvalue access is permitted */
-#define LBUF_BUF(lbuf) ((lbuf)._buf)
+#define LBUF_BUF(lbuf) ((lbuf).buf)
/* lvalue access is not permitted */
#define LBUF_END(lbuf) (&LBUF_BUF(lbuf)[LBUF_SIZE(lbuf)])
-#define LBUF_SIZE(lbuf) ((lbuf)._size)
-#define LBUF_INIT_SIZE(lbuf) ((lbuf)._init_size)
-#define LBUF_EXT_CNT(lbuf) ((lbuf)._extended_cnt)
+#define LBUF_SIZE(lbuf) ((lbuf).size)
+#define LBUF_INIT_SIZE(lbuf) ((lbuf).init_size)
+#define LBUF_EXT_CNT(lbuf) ((lbuf).extended_cnt)
#define LBUF_INIT(lbuf, init_buf, init_size) \
- do { \
- (lbuf)._buf = (lbuf)._init_buf = init_buf; \
- (lbuf)._size = (lbuf)._init_size = init_size; \
- (lbuf)._extended_cnt = 0; \
- } while (/* CONSTCOND */ 0)
+ scm_lbuf_init((struct ScmLBuf_void_ *)&(lbuf), (init_buf), (init_size))
#define LBUF_FREE(lbuf) \
- do { \
- if ((lbuf)._buf != (lbuf)._init_buf) \
- free((lbuf)._buf); \
- } while (/* CONSTCOND */ 0)
+ scm_lbuf_free((struct ScmLBuf_void_ *)&(lbuf))
#define LBUF_ALLOC(lbuf, size) \
- do { \
- (lbuf)._buf = scm_malloc(size); \
- (lbuf)._size = (size); \
- } while (/* CONSTCOND */ 0)
+ scm_lbuf_alloc((struct ScmLBuf_void_ *)&(lbuf), (size))
#define LBUF_REALLOC(lbuf, size) \
- do { \
- if ((lbuf)._buf == (lbuf)._init_buf) { \
- (lbuf)._buf = memcpy(scm_malloc(size), LBUF_BUF(lbuf), LBUF_SIZE(lbuf)); \
- } else { \
- (lbuf)._buf = scm_realloc((lbuf)._buf, (size)); \
- } \
- (lbuf)._size = (size); \
- } while (/* CONSTCOND */ 0)
+ scm_lbuf_realloc((struct ScmLBuf_void_ *)&(lbuf), (size))
-#define LBUF_EXTEND(lbuf, f, min_size) \
- do { \
- size_t new_size; \
- \
- if (LBUF_SIZE(lbuf) < (min_size)) { \
- new_size = f(lbuf); \
- if (new_size < LBUF_SIZE(lbuf)) \
- ERR("local buffer exceeded"); \
- if (new_size < (size_t)min_size) \
- new_size = (size_t)min_size; \
- LBUF_REALLOC((lbuf), new_size); \
- (lbuf)._extended_cnt++; \
- } \
- } while (/* CONSTCOND */ 0)
+#define LBUF_EXTEND(lbuf, f, least_size) \
+ scm_lbuf_extend((struct ScmLBuf_void_ *)&(lbuf), (f), (least_size))
+void scm_lbuf_init(struct ScmLBuf_void_ *lbuf,
+ void *init_buf, size_t init_size);
+void scm_lbuf_free(struct ScmLBuf_void_ *lbuf);
+void scm_lbuf_alloc(struct ScmLBuf_void_ *lbuf, size_t size);
+void scm_lbuf_realloc(struct ScmLBuf_void_ *lbuf, size_t size);
+void scm_lbuf_extend(struct ScmLBuf_void_ *lbuf,
+ size_t (*f)(struct ScmLBuf_void_ *), size_t least_size);
+
/*
* extended size functions:
* define your own version if more optimized version is needed
*/
-#define LBUF_F_LINEAR(lbuf) (LBUF_SIZE(lbuf) + LBUF_INIT_SIZE(lbuf))
-#define LBUF_F_EXPONENTIAL(lbuf) (LBUF_SIZE(lbuf) << 1)
+size_t scm_lbuf_f_linear(struct ScmLBuf_void_ *lbuf);
+size_t scm_lbuf_f_exponential(struct ScmLBuf_void_ *lbuf);
/*=======================================
Function Declarations
More information about the uim-commit
mailing list