Guest User

Untitled

a guest
Feb 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. From 3496d7ce2f698bb2e741cbf8d06537e23216facf Mon Sep 17 00:00:00 2001
  2. From: Gabriel Scherer <gabriel.scherer@gmail.com>
  3. Date: Mon, 30 Mar 2015 14:12:23 +0200
  4. Subject: [PATCH] PR#6824: fix buffer sharing on partial application of
  5. Format.asprintf
  6.  
  7. TODO Changes
  8. ---
  9. stdlib/format.ml | 15 ++++++++++-----
  10. 1 file changed, 10 insertions(+), 5 deletions(-)
  11.  
  12. diff --git a/stdlib/format.ml b/stdlib/format.ml
  13. index 5e206e1..1d196a5 100644
  14. --- a/stdlib/format.ml
  15. +++ b/stdlib/format.ml
  16. @@ -976,6 +976,12 @@ let flush_str_formatter () =
  17. s
  18. ;;
  19.  
  20. +let flush_buf_formatter buf ppf =
  21. + pp_flush_queue ppf false;
  22. + let s = Buffer.contents buf in
  23. + Buffer.reset buf;
  24. + s
  25. +
  26. (**************************************************************
  27.  
  28. Basic functions on the standard formatter
  29. @@ -1176,12 +1182,11 @@ let printf fmt = fprintf std_formatter fmt
  30. let eprintf fmt = fprintf err_formatter fmt
  31.  
  32. let ksprintf k (Format (fmt, _)) =
  33. + let b = Buffer.create 512 in
  34. + let ppf = formatter_of_buffer b in
  35. let k' () acc =
  36. - let b = Buffer.create 512 in
  37. - let ppf = formatter_of_buffer b in
  38. strput_acc ppf acc;
  39. - pp_flush_queue ppf false;
  40. - k (Buffer.contents b) in
  41. + k (flush_buf_formatter b ppf) in
  42. make_printf k' () End_of_acc fmt
  43.  
  44. let sprintf fmt =
  45. @@ -1194,7 +1199,7 @@ let asprintf (Format (fmt, _)) =
  46. = fun ppf acc ->
  47. output_acc ppf acc;
  48. pp_flush_queue ppf false;
  49. - Buffer.contents b in
  50. + flush_buf_formatter b ppf in
  51. make_printf k' ppf End_of_acc fmt
  52.  
  53. (**************************************************************
  54. --
  55. 2.1.4
Add Comment
Please, Sign In to add comment