Skip to content

Commit

Permalink
Static linking: Allow accessing sitedata outside module loading phase
Browse files Browse the repository at this point in the history
but during initialisation
  • Loading branch information
balat committed May 9, 2024
1 parent 6209715 commit 1d4dc0e
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 25 deletions.
9 changes: 1 addition & 8 deletions src/lib/eliom_common.server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -687,23 +687,16 @@ let verify_all_registered sitedata =
| l1, l2 ->
raise (Eliom_there_are_unregistered_services (sitedata.site_dir, l1, l2))

let during_eliom_module_loading, begin_load_eliom_module, end_load_eliom_module =
let during_eliom_module_loading_ = ref false in
( (fun () -> !during_eliom_module_loading_)
, (fun () -> during_eliom_module_loading_ := true)
, fun () -> during_eliom_module_loading_ := false )

let global_register_allowed () =
if Ocsigen_extensions.during_initialisation ()
&& during_eliom_module_loading ()
then Some get_current_sitedata
else None

let get_site_data () =
match get_sp_option () with
| Some sp -> sp.sp_sitedata
| None ->
if during_eliom_module_loading ()
if Ocsigen_extensions.during_initialisation ()
then get_current_sitedata ()
else failwith "get_site_data"

Expand Down
3 changes: 0 additions & 3 deletions src/lib/eliom_common.server.mli
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,6 @@ val add_unregistered_na : sitedata -> na_key_serv -> unit
val remove_unregistered : sitedata -> Url.path -> unit
val remove_unregistered_na : sitedata -> na_key_serv -> unit
val verify_all_registered : sitedata -> unit
val during_eliom_module_loading : unit -> bool
val begin_load_eliom_module : unit -> unit
val end_load_eliom_module : unit -> unit
val global_register_allowed : unit -> (unit -> sitedata) option

val get_site_data : unit -> sitedata
Expand Down
2 changes: 0 additions & 2 deletions src/lib/eliom_registration.server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1345,5 +1345,3 @@ let instruction ?xhr_links ?data_timeout ?service_timeout ?persistent_timeout
(`Site (Ocsigen_server.Site.repr site))
"" [];
Eliommod_pagegen.gen None sitedata

let end_init = Eliom_common.end_load_eliom_module
2 changes: 0 additions & 2 deletions src/lib/eliom_registration.server.mli
Original file line number Diff line number Diff line change
Expand Up @@ -519,5 +519,3 @@ val instruction :
-> ?eliommodule_names:string list
-> unit
-> Ocsigen_server.Site.instruction

val end_init : unit -> unit
3 changes: 2 additions & 1 deletion src/lib/eliom_syntax.server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ let get_global_data, modify_global_data =
in
let is_site_available () =
(* Matches valid states for Eliom_common.get_site_data *)
Eliom_common.(get_sp_option () <> None || during_eliom_module_loading ())
Eliom_common.(
get_sp_option () <> None || Ocsigen_extensions.during_initialisation ())
in
let get () =
if is_site_available ()
Expand Down
12 changes: 3 additions & 9 deletions src/lib/server/eliommod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -725,24 +725,18 @@ let config_in_tag = ref "" (* the parent tag of the currently handled tag *)
let site_init firstmodule =
if !firstmodule
then (
Eliom_common.begin_load_eliom_module ();
(* I want to be able to define global client values during that phase: *)
Eliom_syntax.set_global true;
List.iter (fun f -> f ()) !site_init_ref;
Eliom_syntax.set_global false;
firstmodule := false;
Eliom_common.end_load_eliom_module ())
firstmodule := false)

let load_eliom_module _sitedata cmo_or_name parent_tag content =
let preload () =
config := content;
config_in_tag := parent_tag;
Eliom_common.begin_load_eliom_module ()
in
let postload () =
Eliom_common.end_load_eliom_module ();
config := []
config_in_tag := parent_tag
in
let postload () = config := [] in
try
match cmo_or_name with
| `Files cmo -> Ocsigen_loader.loadfiles preload postload true cmo
Expand Down

0 comments on commit 1d4dc0e

Please sign in to comment.