diff options
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | lib.c | 7 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | txr.1 | 39 |
4 files changed, 46 insertions, 2 deletions
@@ -6888,6 +6888,7 @@ void eval_init(void) reg_fun(intern(lit("cptr-int"), user_package), func_n2o(cptr_int, 1)); reg_fun(intern(lit("cptr-obj"), user_package), func_n2o(cptr_obj, 1)); + reg_fun(intern(lit("cptr-buf"), user_package), func_n2o(cptr_buf, 1)); reg_fun(intern(lit("cptr-zap"), user_package), func_n1(cptr_zap)); reg_fun(intern(lit("cptr-free"), user_package), func_n1(cptr_free)); reg_fun(intern(lit("cptr-cast"), user_package), func_n2(cptr_cast)); @@ -7832,6 +7832,13 @@ val cptr_obj(val obj, val type_sym_in) return cptr_typed(coerce(mem_t *, obj), type_sym, 0); } +val cptr_buf(val buf, val type_sym_in) +{ + val type_sym = default_null_arg(type_sym_in); + mem_t *ptr = buf_get(buf, lit("cptr-buf")); + return cptr_typed(ptr, type_sym, 0); +} + val cptr_zap(val cptr) { (void) cptr_handle(cptr, nil, lit("cptr-zap")); @@ -1030,6 +1030,7 @@ val cptr_type(val cptr); val cptr_size_hint(val cptr, val size); val cptr_int(val n, val type_sym); val cptr_obj(val obj, val type_sym); +val cptr_buf(val buf, val type_sym); val cptr_zap(val cptr); val cptr_free(val cptr); val cptr_cast(val to_type, val cptr); @@ -49650,13 +49650,13 @@ This symbol becomes the object's type tag. The lifetime of the returned -.cptr +.code cptr object is independent from that of .metn object . If the lifetime of .meta object reaches its end before that of the -.code cptr , +.codn cptr , the pointer stored inside the .code cptr becomes invalid. @@ -49683,6 +49683,41 @@ type, then the expression reproduces .metn n . +.coNP Function @ cptr-buf +.synb +.mets (cptr-obj < buf <> [ type-symbol ]) +.syne +.desc +The +.code cptr-buf +returns a +.code cptr +object which holds a pointer to a buffer object's storage +area. The +.meta buf +argument must be of type +.codn buf . + +The +.meta type-symbol +argument should be a symbol. If omitted, it defaults to +.codn nil . +This symbol becomes the +.code cptr +object's type tag. + +The lifetime of the returned +.code cptr +object is independent from that of +.metn buf . +If the lifetime of +.meta buf +reaches its end before that of the +.codn cptr , +the pointer stored inside the +.code cptr +becomes invalid. + .coNP Function @ cptr-cast .synb .mets (cptr-cast < type-symbol << cptr ) |