diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-04-06 00:57:24 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-04-06 00:57:24 -0700 |
commit | c5acd13409cca8f95b7a921efc12ad8833713ffe (patch) | |
tree | ef9779d7283bf68f3531e2dc0402f18cdfd267be | |
parent | 064d4cd974f5e54cb310838eb25e36a6bf83d24d (diff) | |
download | txr-c5acd13409cca8f95b7a921efc12ad8833713ffe.tar.gz txr-c5acd13409cca8f95b7a921efc12ad8833713ffe.tar.bz2 txr-c5acd13409cca8f95b7a921efc12ad8833713ffe.zip |
New function: cptr-size-hint.
* eval.c (eval_init): Register cptr-size-hint intrinsic.
* lib.c (cptr_size_hint): New function.
* lib.h (cptr_size_hint): Declared.
* txr.1: Documented.
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | lib.c | 7 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | txr.1 | 20 |
4 files changed, 29 insertions, 0 deletions
@@ -6872,6 +6872,7 @@ void eval_init(void) reg_fun(intern(lit("int-cptr"), user_package), func_n1(int_cptr)); reg_fun(intern(lit("cptrp"), user_package), func_n1(cptrp)); reg_fun(intern(lit("cptr-type"), user_package), func_n1(cptr_type)); + reg_fun(intern(lit("cptr-size-hint"), user_package), func_n2(cptr_size_hint)); reg_varl(intern(lit("cptr-null"), user_package), cptr(0)); reg_fun(intern(lit("rt-defvarl"), system_package), func_n1(rt_defvarl)); @@ -7723,6 +7723,13 @@ val cptr_type(val cptr) return cptr->co.cls; } +val cptr_size_hint(val cptr, val size) +{ + (void) cptr; + malloc_bytes += c_unum(size); + return nil; +} + val cptr_int(val n, val type_sym_in) { val type_sym = default_null_arg(type_sym_in); @@ -1020,6 +1020,7 @@ val cptr(mem_t *ptr); val cptr_typed(mem_t *handle, val type_sym, struct cobj_ops *ops); val cptrp(val obj); 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_zap(val cptr); @@ -59882,6 +59882,26 @@ The expression .code "(cptr-int 0)" also produces a null pointer on all platforms where \*(TX is found. +.coNP Function @ cptr-size-hint +.synb +.mets (cptr-size-hint < cptr << bytes ) +.syne +.desc +The +.code cptr-size-hint +function indicates to the garbage collector that the given +.meta cptr +object is associated with +.meta bytes +of foreign memory that are otherwise invisible to the garbage collector. + +Note: this function should be used if the foreign memory is indirectly +managed by the +.meta cptr +object in cooperation with the garbage collector. Specifically, +.meta cptr +should have a finalizer registered against it which will liberate the +foreign memory. .SH* FOREIGN FUNCTION INTERFACE |