New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
caml_invalid_argument can't be used with dynamically allocated strings #7423
Comments
Comment author: @xavierleroy I'm not convinced by the repro case (just declare "char error[50];") nor by the need in general. |
Comment author: @gasche Richard W. Jones mentioned that he could use a similar feature on the mailing-list: https://sympa.inria.fr/sympa/arc/caml-list/2016-12/msg00021.html
The stack-based solutions rely on guessing arbitrary size limits on the dynamic strings, which is often possibles but sometimes inconvenient/inelegant. |
Comment author: @mshinwell Moving discussion to here: #946 |
Introduce variants of the functions that do not immediately raise the exception, allowing for resource cleanup. This is used in this way in an ulterior commit to avod duplicating cleanup code. Another motivating example is given at ocaml#7423: > caml_invalid_argument(str) is no return and does not free it's argument. So calling it with a string constructed dynamically will mean it'll never get freed. This led at the time to the introduction of caml_invalid_argument_value and caml_failwith_value that accept an OCaml string as argument. The present commit gives a general solution that fits with the rest of the resource-safe API.
Introduce variants of the functions that do not immediately raise the exception, allowing for resource cleanup. This is used in this way in an ulterior commit to avod duplicating cleanup code. Another motivating example is given at ocaml#7423: > caml_invalid_argument(str) is no return and does not free it's argument. So calling it with a string constructed dynamically will mean it'll never get freed. This led at the time to the introduction of caml_invalid_argument_value and caml_failwith_value that accept an OCaml string as argument. The present commit gives a general solution that fits with the rest of the resource-safe API.
Introduce variants of the functions that do not immediately raise the exception, allowing for resource cleanup. This is used in this way in an ulterior commit to avod duplicating cleanup code. Another motivating example is given at ocaml#7423: > caml_invalid_argument(str) is no return and does not free it's argument. So calling it with a string constructed dynamically will mean it'll never get freed. This led at the time to the introduction of caml_invalid_argument_value and caml_failwith_value that accept an OCaml string as argument. The present commit gives a general solution that fits with the rest of the resource-safe API.
Introduce variants of the functions that do not immediately raise the exception, allowing for resource cleanup. This is used in this way in an ulterior commit to avod duplicating cleanup code. Another motivating example is given at ocaml#7423: > caml_invalid_argument(str) is no return and does not free it's argument. So calling it with a string constructed dynamically will mean it'll never get freed. This led at the time to the introduction of caml_invalid_argument_value and caml_failwith_value that accept an OCaml string as argument. The present commit gives a general solution that fits with the rest of the resource-safe API.
Introduce variants of the functions that do not immediately raise the exception, allowing for resource cleanup. This is a preliminary change used to fix the error handling during the spawning of domains. Another motivating example is given at ocaml#7423: > caml_invalid_argument(str) is no return and does not free it's argument. So calling it with a string constructed dynamically will mean it'll never get freed. This led at the time to the introduction of [caml_invalid_argument_value] and [caml_failwith_value] that accept an OCaml string as argument, as a way to work around the lack of control on resource management. But this is a more general problem, for which the present commit gives a general solution that fits with the rest of the resource-safe API.
Introduce variants of the functions that do not immediately raise the exception, allowing for resource cleanup. This is a preliminary change used to fix the error handling during the spawning of domains. Another motivating example is given at ocaml#7423: > caml_invalid_argument(str) is no return and does not free it's argument. So calling it with a string constructed dynamically will mean it'll never get freed. This led at the time to the introduction of [caml_invalid_argument_value] and [caml_failwith_value] that accept an OCaml string as argument, as a way to work around the lack of control on resource management. But this is a more general problem, for which the present commit gives a general solution in combination with Make_exception_result, Is_exception_result, Extract_exception...
Original bug ID: 7423
Reporter: @stijn-devriendt
Assigned to: @mshinwell
Status: closed (set by @mshinwell on 2016-12-27T09:18:35Z)
Resolution: duplicate
Priority: normal
Severity: feature
Platform: Linux
OS: Ubuntu
OS Version: 14.04
Version: 4.03.0
Category: runtime system and C interface
Monitored by: @gasche "Richard Jones"
Bug description
From https://sympa.inria.fr/sympa/arc/caml-list/2016-11/msg00106.html
caml_invalid_argument(str) is no return and does not free it's
argument. So calling it with a string constructed dynamically will mean it'll never get freed.
I could construct an ocaml string and pass that to caml_raise_with_arg,
but I don't seem to be able to get to the caml_exn_Invalid_argument from
c.
Reply from Gabriel Scherer:
It may make sense to have caml_{failwith,invalid_argument}_value
variants of the exception-raising functions that take a parameter, and
be implemented using caml_raise_with_arg(s) directly instead of
caml_raise_with_string. Could you open a mantis issue or submit a
github pull request to track the question and continue discussion?
Steps to reproduce
char* error = new char[50];
snprintf(error, 50, "error: %d", 50);
caml_invalid_argument(error)
allocated memory is lost here.
The text was updated successfully, but these errors were encountered: