@@ -51,6 +51,17 @@ static void *getsym(void *handle, const char *module, const char *name){
51
51
return sym ;
52
52
}
53
53
54
+ static void * getsym_exn (void * handle , const char * module , const char * name ){
55
+ void * sym = getsym (handle , module , name );
56
+ if (sym == NULL ) {
57
+ value msg = caml_alloc_sprintf (
58
+ "Dynlink: failed to load module due to missing symbol %s%s" ,
59
+ module , name );
60
+ caml_invalid_argument_value (msg );
61
+ }
62
+ return sym ;
63
+ }
64
+
54
65
CAMLprim value caml_natdynlink_getmap (value unit )
55
66
{
56
67
return caml_input_value_from_block (caml_globals_map , INT_MAX );
@@ -98,40 +109,32 @@ CAMLprim value caml_natdynlink_run(value handle_v, value symbol) {
98
109
CAMLlocal1 (result );
99
110
void * sym ,* sym2 ;
100
111
void * handle = Handle_val (handle_v );
101
-
102
- #define optsym (n ) getsym(handle,unit,n)
103
- const char * unit ;
112
+ const char * unit = String_val (symbol );
104
113
void (* entrypoint )(void );
105
114
106
- unit = String_val (symbol );
107
-
108
- sym = optsym ("__gc_roots" );
115
+ sym = getsym_exn (handle , unit , "__gc_roots" );
109
116
/* [caml_register_dyn_global] can raise, so do it prior to registering
110
117
frametables etc. */
111
- if ( NULL != sym ) caml_register_dyn_global (sym );
118
+ caml_register_dyn_global (sym );
112
119
113
- sym = optsym ( "__frametable" );
114
- if ( NULL != sym ) caml_register_frametable (sym );
120
+ sym = getsym_exn ( handle , unit , "__frametable" );
121
+ caml_register_frametable (sym );
115
122
116
- sym = optsym ("__data_begin" );
117
- sym2 = optsym ("__data_end" );
118
- if (NULL != sym && NULL != sym2 )
119
- caml_page_table_add (In_static_data , sym , sym2 );
123
+ sym = getsym_exn (handle , unit , "__data_begin" );
124
+ sym2 = getsym_exn (handle , unit , "__data_end" );
125
+ caml_page_table_add (In_static_data , sym , sym2 );
120
126
121
- sym = optsym ("__code_begin" );
122
- sym2 = optsym ("__code_end" );
123
- if (NULL != sym && NULL != sym2 )
124
- caml_register_code_fragment ((char * ) sym , (char * ) sym2 ,
125
- DIGEST_LATER , NULL );
127
+ sym = getsym_exn (handle , unit , "__code_begin" );
128
+ sym2 = getsym_exn (handle , unit , "__code_end" );
129
+ caml_register_code_fragment ((char * ) sym , (char * ) sym2 ,
130
+ DIGEST_LATER , NULL );
126
131
127
132
if ( caml_natdynlink_hook != NULL ) caml_natdynlink_hook (handle ,unit );
128
133
129
- entrypoint = optsym ( "__entry" );
134
+ entrypoint = getsym ( handle , unit , "__entry" );
130
135
if (NULL != entrypoint ) result = caml_callback ((value )(& entrypoint ), 0 );
131
136
else result = Val_unit ;
132
137
133
- #undef optsym
134
-
135
138
CAMLreturn (result );
136
139
}
137
140
0 commit comments