mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-18 21:29:18 +02:00
Allow optional collection of opaque pointers
This commit is contained in:
parent
236c7e84f4
commit
479e880b30
4 changed files with 20 additions and 2 deletions
|
@ -1,5 +1,11 @@
|
|||
# Changelog
|
||||
|
||||
## 0.16 - TBD
|
||||
|
||||
Features
|
||||
|
||||
- Updated the C API to optionally allow the GC to free memory pointed to by an Opaque object.
|
||||
|
||||
## 0.15 - February 26, 2020
|
||||
|
||||
Features
|
||||
|
|
6
gc.c
6
gc.c
|
@ -534,6 +534,11 @@ static size_t gc_convert_heap_page_to_free_list(gc_heap *h, gc_thread_data *thd)
|
|||
fprintf(stderr, "mp_clear from sweep\n");
|
||||
#endif
|
||||
mp_clear(&(((bignum_type *)p)->bn));
|
||||
} else if (type_of(p) == c_opaque_tag && opaque_collect_ptr(p)) {
|
||||
#if GC_DEBUG_VERBOSE
|
||||
fprintf(stderr, "free opaque pointer %p from sweep\n", opaque_ptr(p));
|
||||
#endif
|
||||
free( opaque_ptr(p) );
|
||||
}
|
||||
|
||||
// Free block
|
||||
|
@ -956,6 +961,7 @@ char *gc_copy_obj(object dest, char *obj, gc_thread_data * thd)
|
|||
mark(hp) = thd->gc_alloc_color;
|
||||
immutable(hp) = immutable(obj);
|
||||
type_of(hp) = c_opaque_tag;
|
||||
hp->collect_ptr = ((c_opaque_type *) obj)->collect_ptr;
|
||||
hp->ptr = ((c_opaque_type *) obj)->ptr;
|
||||
return (char *)hp;
|
||||
}
|
||||
|
|
|
@ -692,7 +692,9 @@ typedef cvar_type *cvar;
|
|||
typedef struct {
|
||||
gc_header_type hdr;
|
||||
tag_type tag;
|
||||
/** This pointer can be anything, GC will not collect it */
|
||||
unsigned char collect_ptr;
|
||||
/** This pointer can be anything, GC will not collect it
|
||||
unless collect_ptr is set */
|
||||
void *ptr;
|
||||
} c_opaque_type;
|
||||
typedef c_opaque_type *c_opaque;
|
||||
|
@ -704,11 +706,15 @@ typedef c_opaque_type *c_opaque;
|
|||
var.hdr.grayed = 0; \
|
||||
var.hdr.immutable = 0; \
|
||||
var.tag = c_opaque_tag; \
|
||||
var.collect_ptr = 0; \
|
||||
var.ptr = p;
|
||||
|
||||
/** Access the Opaque's pointer */
|
||||
#define opaque_ptr(x) (((c_opaque)x)->ptr)
|
||||
|
||||
/** Access the Opaque's "collect pointer" field */
|
||||
#define opaque_collect_ptr(x) (((c_opaque)x)->collect_ptr)
|
||||
|
||||
/**
|
||||
* @brief The mutex thread synchronization type
|
||||
*
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*version-banner*
|
||||
*c-file-header-comment*)
|
||||
(begin
|
||||
(define *version-number* "0.15")
|
||||
(define *version-number* "0.16")
|
||||
(define *version-name* "")
|
||||
(define *version* (string-append *version-number* " " *version-name* ""))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue