From 7fb04334279dc35b93e0ce470958dece0a68a75b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 16 Feb 2019 09:37:02 -0800 Subject: buf-alloc-size: new function. * buf.c (buf_alloc_size): New function. (buf_init): buf-alloc-size intrinsic registered. * buf.h (buf_alloc_size): Declared. * txr.1: Documented. --- buf.c | 8 ++++++++ buf.h | 1 + txr.1 | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/buf.c b/buf.c index a5d3abc6..14b89a2a 100644 --- a/buf.c +++ b/buf.c @@ -220,6 +220,13 @@ val length_buf(val buf) return b->len; } +val buf_alloc_size(val buf) +{ + val self = lit("buf-alloc-size"); + struct buf *b = buf_handle(buf, self); + return b->size; +} + mem_t *buf_get(val buf, val self) { struct buf *b = buf_handle(buf, self); @@ -943,6 +950,7 @@ void buf_init(void) reg_fun(intern(lit("buf-trim"), user_package), func_n1(buf_trim)); reg_fun(intern(lit("buf-set-length"), user_package), func_n3o(buf_set_length, 2)); reg_fun(intern(lit("length-buf"), user_package), func_n1(length_buf)); + reg_fun(intern(lit("buf-alloc-size"), user_package), func_n1(buf_alloc_size)); reg_fun(intern(lit("copy-buf"), user_package), func_n1(copy_buf)); #if HAVE_I8 diff --git a/buf.h b/buf.h index 18641cfb..60004112 100644 --- a/buf.h +++ b/buf.h @@ -34,6 +34,7 @@ val copy_buf(val buf); val buf_trim(val buf); val buf_set_length(val obj, val len, val init_val); val length_buf(val buf); +val buf_alloc_size(val buf); mem_t *buf_get(val buf, val self); void buf_fill(val buf, mem_t *src, val self); diff --git a/txr.1 b/txr.1 index 3922a757..5207606d 100644 --- a/txr.1 +++ b/txr.1 @@ -57356,6 +57356,15 @@ Note: the generic .code length function is also applicable to buffers. +.coNP Function @ buf-alloc-size +.synb +.mets (buf-alloc-size << buf ) +.syne +.desc +The +.code buf-alloc-size +function retrieves the allocation size of the buffer. + .coNP Function @ buf-trim .synb .mets (buf-trim << buf ) -- cgit v1.2.3