From f757b6a3845d0f91110194bed0e7136dc4731e99 Mon Sep 17 00:00:00 2001 From: Vincent Balat Date: Sat, 11 May 2024 19:30:19 +0200 Subject: [PATCH] Static linking: Fail if Eliom_config.parse_config is called without config file --- src/lib/eliom_config.server.ml | 5 ++++- src/lib/server/eliommod.ml | 6 +++--- src/lib/server/eliommod.mli | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib/eliom_config.server.ml b/src/lib/eliom_config.server.ml index 2417a9e0c..059de8720 100644 --- a/src/lib/eliom_config.server.ml +++ b/src/lib/eliom_config.server.ml @@ -132,7 +132,10 @@ let get_config_info () = let get_config () = match Eliom_common.global_register_allowed () with - | Some _ -> !Eliommod.config + | Some _ -> ( + match !Eliommod.config with + | Some c -> c + | None -> failwith "No config file. Is it a statically linked executable?") | None -> raise (Eliom_common.Eliom_site_information_not_available diff --git a/src/lib/server/eliommod.ml b/src/lib/server/eliommod.ml index 0ddfa64da..f2317cdc5 100644 --- a/src/lib/server/eliommod.ml +++ b/src/lib/server/eliommod.ml @@ -723,7 +723,7 @@ let site_init_ref = ref [] (** Register function for evaluation at site initialisation *) let register_site_init e = site_init_ref := e :: !site_init_ref -let config = ref [] +let config = ref None (* None means no config file (static linking) *) let config_in_tag = ref "" (* the parent tag of the currently handled tag *) type module_to_load = Files of string list | Name of string @@ -739,10 +739,10 @@ let site_init firstmodule = let load_eliom_module _sitedata cmo_or_name parent_tag content = let preload () = - config := content; + config := Some content; config_in_tag := parent_tag in - let postload () = config := [] in + let postload () = config := Some [] in try match cmo_or_name with | Files cmo -> Ocsigen_loader.loadfiles preload postload true cmo diff --git a/src/lib/server/eliommod.mli b/src/lib/server/eliommod.mli index 4c6e0d046..2074431bc 100644 --- a/src/lib/server/eliommod.mli +++ b/src/lib/server/eliommod.mli @@ -140,7 +140,7 @@ val end_init : unit -> unit val handle_init_exn : exn -> string val site_init_ref : (unit -> unit) list ref val register_site_init : (unit -> unit) -> unit -val config : Xml_light_types.xml list ref +val config : Xml_light_types.xml list option ref val config_in_tag : string ref type module_to_load = Files of string list | Name of string