summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Skvortsov <sasha.skvortsov109@gmail.com>2023-04-08 15:05:58 -0400
committerAlexander Skvortsov <sasha.skvortsov109@gmail.com>2023-04-16 13:05:29 -0400
commit6be20f1c4c8a601f8ce738c15fef1dfff4242a17 (patch)
tree67ac1a307c0a6c6112fb3d013ac9b024daff1625
parent4f327608998bb9b86cb20d439f889276f07f8dbb (diff)
downloadocaml-6be20f1c4c8a601f8ce738c15fef1dfff4242a17.tar.gz
extern.c: raise OOM instead of passing null in `caml_output_*` entrypoints
Signed-off-by: Alexander Skvortsov <sasha.skvortsov109@gmail.com>
-rw-r--r--runtime/extern.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/runtime/extern.c b/runtime/extern.c
index 9d9746ecf3..9b648e7e02 100644
--- a/runtime/extern.c
+++ b/runtime/extern.c
@@ -120,7 +120,7 @@ struct caml_extern_state {
struct output_block * extern_output_block;
};
-static struct caml_extern_state* get_extern_state (void)
+static struct caml_extern_state* prepare_extern_state (void)
{
Caml_check_caml_state();
struct caml_extern_state* extern_state;
@@ -129,10 +129,7 @@ static struct caml_extern_state* get_extern_state (void)
return Caml_state->extern_state;
extern_state =
- caml_stat_alloc_noexc(sizeof(struct caml_extern_state));
- if (extern_state == NULL) {
- return NULL;
- }
+ caml_stat_alloc(sizeof(struct caml_extern_state));
extern_state->extern_flags = 0;
extern_state->obj_counter = 0;
@@ -146,6 +143,12 @@ static struct caml_extern_state* get_extern_state (void)
return extern_state;
}
+static struct caml_extern_state* get_extern_state (void)
+{
+ Caml_check_caml_state();
+ return Caml_state->extern_state;
+}
+
void caml_free_extern_state (void)
{
if (Caml_state->extern_state != NULL) {
@@ -1072,7 +1075,7 @@ void caml_output_val(struct channel *chan, value v, value flags)
char header[MAX_INTEXT_HEADER_SIZE];
int header_len;
struct output_block * blk, * nextblk;
- struct caml_extern_state* s = get_extern_state ();
+ struct caml_extern_state* s = prepare_extern_state ();
if (! caml_channel_binary_mode(chan))
caml_failwith("output_value: not a binary channel");
@@ -1110,7 +1113,7 @@ CAMLprim value caml_output_value_to_bytes(value v, value flags)
intnat data_len, ofs;
value res;
struct output_block * blk, * nextblk;
- struct caml_extern_state* s = get_extern_state ();
+ struct caml_extern_state* s = prepare_extern_state ();
init_extern_output(s);
data_len = extern_value(s, v, flags, header, &header_len);
@@ -1143,7 +1146,7 @@ CAMLexport intnat caml_output_value_to_block(value v, value flags,
char header[MAX_INTEXT_HEADER_SIZE];
int header_len;
intnat data_len;
- struct caml_extern_state* s = get_extern_state ();
+ struct caml_extern_state* s = prepare_extern_state ();
/* At this point we don't know the size of the header.
Guess that it is small, and fix up later if not. */
@@ -1180,7 +1183,7 @@ CAMLexport void caml_output_value_to_malloc(value v, value flags,
intnat data_len;
char * res;
struct output_block * blk, * nextblk;
- struct caml_extern_state* s = get_extern_state ();
+ struct caml_extern_state* s = prepare_extern_state ();
init_extern_output(s);
data_len = extern_value(s, v, flags, header, &header_len);
@@ -1340,7 +1343,7 @@ CAMLprim value caml_obj_reachable_words(value v)
struct extern_item * sp;
uintnat h = 0;
uintnat pos = 0;
- struct caml_extern_state *s = get_extern_state ();
+ struct caml_extern_state *s = prepare_extern_state ();
s->obj_counter = 0;
s->extern_flags = 0;