Skip to content

Commit

Permalink
Refine GC_calloc_typed_descr_s to support pointers larger than words
Browse files Browse the repository at this point in the history
Issue #627 (bdwgc).

* include/gc/gc_typed.h (GC_CALLOC_TYPED_DESCR_PTRS): New macro.
* include/gc/gc_typed.h (GC_CALLOC_TYPED_DESCR_WORDS): Add comment
(that the value is the number of both "normal" and "pointer-sized"
words).
* include/gc/gc_typed.h [!GC_BUILD] (GC_calloc_typed_descr_s.opaque_p):
New field.
* include/gc/gc_typed.h [!GC_BUILD] (GC_calloc_typed_descr_s.opaque):
Change elements count from GC_CALLOC_TYPED_DESCR_WORDS to
GC_CALLOC_TYPED_DESCR_WORDS-GC_CALLOC_TYPED_DESCR_PTRS.
* typd_mlc.c (GC_calloc_typed_descr_s): Move complex_d field upper to
be the first field.
* typd_mlc.c (GC_calloc_prepare_explicitly_typed): Update static assert
about size of GC_calloc_typed_descr_s to use both
GC_CALLOC_TYPED_DESCR_WORDS and GC_CALLOC_TYPED_DESCR_PTRS.
  • Loading branch information
ivmai committed Jul 28, 2024
1 parent 48da162 commit 433e2dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions include/gc/gc_typed.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,15 @@ GC_API GC_ATTR_MALLOC GC_ATTR_CALLOC_SIZE(1, 2) void * GC_CALL
/* bitmap of d multiplied by the size of a pointer. */
/* Returned object is cleared. */

#define GC_CALLOC_TYPED_DESCR_WORDS 8
#define GC_CALLOC_TYPED_DESCR_PTRS 1
#define GC_CALLOC_TYPED_DESCR_WORDS 8 /* includes space for pointers */

#ifdef GC_BUILD
struct GC_calloc_typed_descr_s;
#else
struct GC_calloc_typed_descr_s {
GC_word opaque[GC_CALLOC_TYPED_DESCR_WORDS];
GC_uintptr_t opaque_p[GC_CALLOC_TYPED_DESCR_PTRS];
GC_word opaque[GC_CALLOC_TYPED_DESCR_WORDS - GC_CALLOC_TYPED_DESCR_PTRS];
};
#endif

Expand Down
6 changes: 4 additions & 2 deletions typd_mlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@ STATIC int GC_make_array_descriptor(size_t nelements, size_t size,
}

struct GC_calloc_typed_descr_s {
complex_descriptor *complex_d; /* the first field, the only pointer */
struct LeafDescriptor leaf;
GC_descr simple_d;
complex_descriptor *complex_d;
word alloc_lb; /* size_t actually */
signed_word descr_type; /* int actually */
};
Expand All @@ -480,7 +480,9 @@ GC_API int GC_CALL GC_calloc_prepare_explicitly_typed(
size_t n, size_t lb, GC_descr d)
{
GC_STATIC_ASSERT(sizeof(struct GC_calloc_typed_descr_s)
== GC_CALLOC_TYPED_DESCR_WORDS * sizeof(word));
== GC_CALLOC_TYPED_DESCR_PTRS * sizeof(ptr_t)
+ (GC_CALLOC_TYPED_DESCR_WORDS - GC_CALLOC_TYPED_DESCR_PTRS)
* sizeof(word));
GC_ASSERT(GC_explicit_typing_initialized);
GC_ASSERT(sizeof(struct GC_calloc_typed_descr_s) == ctd_sz);
(void)ctd_sz; /* unused currently */
Expand Down

0 comments on commit 433e2dd

Please sign in to comment.