12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788open!Core_kernelopen!ImportmoduleScheduler=Async_unix.Async_unix_private.Raw_schedulerletscheduler=Scheduler.t()moduleArity=structtype'callbackt=|Arity1:('a1->'r)t|Arity2:('a1->'a2->'r)t[@@derivingsexp_of]endopenAritytype'callbackt={arity:'callbackArity.t;name:string}[@@derivingsexp_of]letreport_exn_when_calling_callback=letout_of_memory_message="Ecaml received Out_of_memory"inletout_of_memory_value=out_of_memory_message|>Value.of_utf8_bytesinfunction|Out_of_memory->(tryValue.Private.message_zero_allocout_of_memory_valuewith|_->eprintf"%s"out_of_memory_message)|exn->letsexp=[%message"Ecaml callback handling raised"(exn:Exn.t)]in(tryValue.message_ssexpwith|_->eprint_ssexp);;letregister(typecallback)(t:callbackt)~(f:callback)~should_run_holding_async_lock=letwith_lockf=ifScheduler.am_holding_lockschedulerthenf()elseScheduler.with_lockschedulerfinletcallback:callback=matcht.aritywith|Arity1->funa1->(tryifnotshould_run_holding_async_lockthenfa1elsewith_lock(fun()->fa1)with|exn->report_exn_when_calling_callbackexn;raiseexn)|Arity2->funa1a2->(tryifnotshould_run_holding_async_lockthenfa1a2elsewith_lock(fun()->fa1a2)with|exn->report_exn_when_calling_callbackexn;raiseexn)inCaml.Callback.registert.namecallback;;letdispatch_function={arity=Arity2;name="dispatch_function"}letend_of_module_initialization={arity=Arity1;name="end_of_module_initialization"};;(** [no_active_env] is used when the C code detects that OCaml is attempting to call an
Emacs function but there is no active env. It prints a message that includes an
OCaml backtrace, which may be useful in debugging. *)let()=register{arity=Arity1;name="no_active_env"}~f:(fun()->eprint_s[%message"Ecaml called with no active env"~backtrace:(Backtrace.get():Backtrace.t)])~should_run_holding_async_lock:true;;letfree_embedded_caml_values={arity=Arity1;name="free_embedded_caml_values"}letinitialize_module=()