[Omake] Lm_channel question.

Aleksey Nogin anogin at hrl.com
Mon Jul 16 13:48:53 PDT 2007


Jason,

A comment in lm_channel.ml says that "In binary mode, the write_buffer 
is the same as the out_buffer." Is this supposed to be an invariant? If 
so, if was violated in certain cases - and the attached patch fixes it.

P.S. I came across this when trying to understand the sprintf problem, 
and I have no evidence that this change is needed for anything other 
than keeping the code more self-consistent.

-- 
Aleksey Nogin, Research Scientist
Advanced Technologies Department, Information & System Sciences Lab
HRL Laboratories, LLC, Malibu, CA
-------------- next part --------------
Index: src/libmojave-external/util/lm_channel.ml
===================================================================
--- src/libmojave-external/util/lm_channel.ml	(revision 11277)
+++ src/libmojave-external/util/lm_channel.ml	(working copy)
@@ -130,8 +130,8 @@
 
      (*
       * In text mode, the output is double-buffered because
-      * of line ending translation.  In binary mode, the write_buffer
-      * is the same as the out_buffer.
+      * of line ending translation.  
+      * INVARIANT: In binary mode, the write_buffer is the same as the out_buffer.
       *
       * write_pid is the pid of the output thread, or 0 if there is no output thread.
       * write_index is the amount of data that has been written to the file.
@@ -295,6 +295,7 @@
       }
 
 let of_fun read write =
+   let out_buffer = String.create buf_size in
    { channel_id     = 0;
      channel_fd     = None;
      channel_kind   = FileChannel;
@@ -315,12 +316,12 @@
 
      out_max      = 0;
      out_expand   = false;
-     out_buffer   = String.create buf_size;
+     out_buffer   = out_buffer;
 
      write_pid    = 0;
      write_index  = 0;
      write_max    = 0;
-     write_buffer = String.create buf_size;
+     write_buffer = out_buffer;
 
      read_fun     = read;
      write_fun    = write
@@ -365,6 +366,7 @@
    info.write_fun <- writer
 
 let create_loc_string_aux file line char =
+   let out_buffer = String.create buf_size in
    { channel_id     = 0;
      channel_fd     = None;
      channel_kind   = FileChannel;
@@ -385,12 +387,12 @@
 
      out_max      = 0;
      out_expand   = true;
-     out_buffer   = String.create buf_size;
+     out_buffer   = out_buffer;
 
      write_pid    = 0;
      write_index  = 0;
      write_max    = 0;
-     write_buffer = "";
+     write_buffer = out_buffer;
 
      read_fun     = null_reader;
      write_fun    = null_writer
@@ -564,10 +566,13 @@
          out_max    = max
        } = info
    in
-      if max = String.length buffer then
+      if max = String.length buffer then begin
          let buffer2 = String.create (max * 2) in
             String.blit buffer 0 buffer2 0 max;
-            info.out_buffer <- buffer2
+            info.out_buffer <- buffer2;
+            if info.channel_binary then
+               info.write_buffer <- buffer2;
+      end
 
 let to_string info =
    let { out_buffer = buffer;


More information about the OMake-Devel mailing list