Fix MPR 7178. Prevent infinite loop in at_exit callbacks.#675
Fix MPR 7178. Prevent infinite loop in at_exit callbacks.#675dbuenzli wants to merge 1 commit intoocaml:trunkfrom
Conversation
|
Just a note about the use case/how I found about this. I have a library ( One mechanism to do this is to have an Here's the piece of code, I worked around by calling |
I know this is not really the topic of this PR, but running the main program as part of the |
In fact in my example I don't run
In this context I didn't want to prevent myself from being able to reuse the same file both as an executable and be able to compile it and link it in a larger program so that wouldn't work. |
stdlib/pervasives.ml
Outdated
| let at_exit f = | ||
| let g = !exit_function in | ||
| exit_function := (fun () -> f(); g()) | ||
| exit_function := (fun () -> try f() with Already_exiting -> (); g()) |
There was a problem hiding this comment.
Missing parentheses around the try handler.
f3d4c59 to
2c63cdf
Compare
|
The doc for [exit] should mention that the control flow can now return from the function (through an exception). Users need to be aware of that if they have any kind of catch-all exception handlers above the call to exit (e.g. a proper try-finally idiom that release some resource, or some generic exception logger). Did you explore alternative ways to prevent the infinite loop (e.g. forcing termination on the second nested call; or keeping a list of pending at_exit functions and continuing directly with the next one when one of them calls [exit])? And with ways to have at_exit hooks change the exit code directly without calling [exit]? (E.g. |
Didn't think about that. In my opinion this makes the fix unsuitable. I think I'll close this for now and think about a way that also allows to fix MPR7253 at the same time. |
|
What about using C's |
|
Along the lines of what Alain suggests I think we should rather do this:
|
align Bytes.unsafe_of_string / Bytes.unsafe_to_string to ocaml trunk
* Fix "make fmt" and "make check-fmt" for Cmm_helpers * Format Cmm_helpers
Co-authored-by: Sabine Schmaltz <sabine@tarides.com>
Original report.
From the OCaml Compiler Hacking session @ Citrix. Thanks for hosting. Note, this is done against the
4.03branch since I didn't manage to make trunk to compile (binaries fail withFatal error: unknown C primitive 'caml_alloc_float_array')