Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 3496d7ce2f698bb2e741cbf8d06537e23216facf Mon Sep 17 00:00:00 2001
- From: Gabriel Scherer <gabriel.scherer@gmail.com>
- Date: Mon, 30 Mar 2015 14:12:23 +0200
- Subject: [PATCH] PR#6824: fix buffer sharing on partial application of
- Format.asprintf
- TODO Changes
- ---
- stdlib/format.ml | 15 ++++++++++-----
- 1 file changed, 10 insertions(+), 5 deletions(-)
- diff --git a/stdlib/format.ml b/stdlib/format.ml
- index 5e206e1..1d196a5 100644
- --- a/stdlib/format.ml
- +++ b/stdlib/format.ml
- @@ -976,6 +976,12 @@ let flush_str_formatter () =
- s
- ;;
- +let flush_buf_formatter buf ppf =
- + pp_flush_queue ppf false;
- + let s = Buffer.contents buf in
- + Buffer.reset buf;
- + s
- +
- (**************************************************************
- Basic functions on the standard formatter
- @@ -1176,12 +1182,11 @@ let printf fmt = fprintf std_formatter fmt
- let eprintf fmt = fprintf err_formatter fmt
- let ksprintf k (Format (fmt, _)) =
- + let b = Buffer.create 512 in
- + let ppf = formatter_of_buffer b in
- let k' () acc =
- - let b = Buffer.create 512 in
- - let ppf = formatter_of_buffer b in
- strput_acc ppf acc;
- - pp_flush_queue ppf false;
- - k (Buffer.contents b) in
- + k (flush_buf_formatter b ppf) in
- make_printf k' () End_of_acc fmt
- let sprintf fmt =
- @@ -1194,7 +1199,7 @@ let asprintf (Format (fmt, _)) =
- = fun ppf acc ->
- output_acc ppf acc;
- pp_flush_queue ppf false;
- - Buffer.contents b in
- + flush_buf_formatter b ppf in
- make_printf k' ppf End_of_acc fmt
- (**************************************************************
- --
- 2.1.4
Add Comment
Please, Sign In to add comment