summaryrefslogtreecommitdiff
path: root/typd_mlc.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-06-06 20:01:41 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-06-07 14:08:30 +0300
commitaabfaeb28ccbc3016aa17d0934b0affb721286cf (patch)
treef596a1f6c0807c13df602e07cbbd9da321153f14 /typd_mlc.c
parent0c44b469646fb07cf82a62deed6a7ee693112c8f (diff)
downloadbdwgc-aabfaeb28ccbc3016aa17d0934b0affb721286cf.tar.gz
Specify that internal allocations failure is unlikely
(refactoring) * finalize.c [!GC_NO_FINALIZATION] (GC_register_disappearing_link_inner): Assume failure of allocation (resulting in NULL or GC_oom_fn call) is unlikely. * malloc.c [DBG_HDRS_ALL || GC_GCJ_SUPPORT || !GC_NO_FINALIZATION] (GC_generic_malloc_inner_ignore_off_page): Likewise. * malloc.c (GC_generic_malloc): Likewise. * malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER] (calloc, strdup, strndup): Likewise. * mallocx.c (GC_realloc, GC_memalign, GC_strdup, GC_strndup): Likewise. * mallocx.c [GC_REQUIRE_WCSDUP] (GC_wcsdup): Likewise. * specific.c [USE_CUSTOM_SPECIFIC] (GC_setspecific): Likewise. * typd_mlc.c (GC_make_sequence_descriptor, GC_make_descriptor): Likewise. * malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER] (calloc): Expect that lb and n are not greater than GC_SQRT_SIZE_MAX. * typd_mlc.c (GC_calloc_explicitly_typed): Likewise. * typd_mlc.c (GC_add_ext_descriptor): Assume that resizing of GC_ext_descriptors[] is rare. * typd_mlc.c (GC_calloc_explicitly_typed): Do not call GC_make_array_descriptor() if n * lb > GC_SIZE_MAX. * malloc.c [REDIRECT_MALLOC && !REDIRECT_MALLOC_IN_HEADER && !strndup] (strndup): Expect that len is not greater than size. * mallocx.c (GC_strndup): Likewise. * typd_mlc.c (GC_make_sequence_descriptor): Reformat code.
Diffstat (limited to 'typd_mlc.c')
-rw-r--r--typd_mlc.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/typd_mlc.c b/typd_mlc.c
index 193bde39..9c84e432 100644
--- a/typd_mlc.c
+++ b/typd_mlc.c
@@ -107,7 +107,7 @@ STATIC signed_word GC_add_ext_descriptor(const word * bm, word nbits)
DCL_LOCK_STATE;
LOCK();
- while (GC_avail_descr + nwords >= GC_ed_size) {
+ while (EXPECT(GC_avail_descr + nwords >= GC_ed_size, FALSE)) {
typed_ext_descr_t *newExtD;
size_t new_size;
word ed_size = GC_ed_size;
@@ -293,17 +293,17 @@ GC_make_sequence_descriptor(complex_descriptor *first,
struct SequenceDescriptor * result =
(struct SequenceDescriptor *)
GC_malloc(sizeof(struct SequenceDescriptor));
+
+ if (EXPECT(NULL == result, FALSE)) return NULL;
+
/* Can't result in overly conservative marking, since tags are */
- /* very small integers. Probably faster than maintaining type */
- /* info. */
- if (result != 0) {
- result -> sd_tag = SEQUENCE_TAG;
- result -> sd_first = first;
- result -> sd_second = second;
- GC_dirty(result);
- REACHABLE_AFTER_DIRTY(first);
- REACHABLE_AFTER_DIRTY(second);
- }
+ /* very small integers. Probably faster than maintaining type info. */
+ result -> sd_tag = SEQUENCE_TAG;
+ result -> sd_first = first;
+ result -> sd_second = second;
+ GC_dirty(result);
+ REACHABLE_AFTER_DIRTY(first);
+ REACHABLE_AFTER_DIRTY(second);
return (complex_descriptor *)result;
}
@@ -560,9 +560,11 @@ GC_API GC_descr GC_CALL GC_make_descriptor(const GC_word * bm, size_t len)
result |= GC_DS_BITMAP;
} else {
signed_word index = GC_add_ext_descriptor(bm, (word)last_set_bit + 1);
- if (index == -1) return WORDS_TO_BYTES(last_set_bit+1) | GC_DS_LENGTH;
- /* Out of memory: use conservative */
- /* approximation. */
+
+ if (EXPECT(index == -1, FALSE)) {
+ /* Out of memory: use a conservative approximation. */
+ return WORDS_TO_BYTES(last_set_bit + 1) | GC_DS_LENGTH;
+ }
result = GC_MAKE_PROC(GC_typed_mark_proc_index, (word)index);
}
return result;
@@ -644,11 +646,12 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_calloc_explicitly_typed(size_t n,
struct LeafDescriptor leaf;
GC_ASSERT(GC_explicit_typing_initialized);
- descr_type = GC_make_array_descriptor((word)n, (word)lb, d, &simple_descr,
- &complex_descr, &leaf);
- if ((lb | n) > GC_SQRT_SIZE_MAX /* fast initial check */
+ if (EXPECT((lb | n) > GC_SQRT_SIZE_MAX, FALSE) /* fast initial check */
&& lb > 0 && n > GC_SIZE_MAX / lb)
return (*GC_get_oom_fn())(GC_SIZE_MAX); /* n*lb overflow */
+
+ descr_type = GC_make_array_descriptor((word)n, (word)lb, d, &simple_descr,
+ &complex_descr, &leaf);
lb *= n;
switch(descr_type) {
case NO_MEM: