Commits

Anonymous committed cc4e57b

fixes for break_subsequence

Comments (0)

Files changed (2)

        смещения, имеющихся в значениях loop_index *)
     let len = cur_ofs - first_ofs in
     let () = assert (len >= 0) in
-    let () = fdbg "bs: feed_first_chunk: %i .. %i (len = %i)"
-      first_ofs cur_ofs len in
+    let () = fdbg "bs: feed_first_chunk: %i .. %i (len = %i) (chunk len = %i)"
+      first_ofs cur_ofs len (S.length first_chunk) in
     if len = 0
     then IO.return it_proc
     else
           in
           match sq_it with
           [ IE_done sub_res ->
+             let () = fdbg "bs: loop_ofs: sq_it done" in
              (* - когда результат от it_subseq_step -- *)
              (*   - Кормить *)
              feed_first_chunk ~cur_ofs:ofs it_proc >>% fun it_proc ->
               "break_sequence: it_subseq_step should return None on error")
               Sl.empty
           | IE_cont None k_sub ->
+              let () = fdbg "bs: loop_ofs: sq_it cont" in
               (* - когда не ошибка, а "хочу ещё" от it_subseq_step -- *)
               (*   - Кормить *)
               feed_first_chunk ~cur_ofs:ofs it_proc >>% fun it_proc ->
+              let () = fdbg "substep/cont: head = %s at ofs %i"
+                (dbgstream (Chunk first_chunk)) ofs in
+              let qtail = Deque_stream.cons
+                0
+                (let c = S.drop ofs first_chunk in
+                 let c = S.copy c in
+                 Chunk c
+                )
+                qtail
+              in
               step1 k_sub it_proc qtail
           ]  (* match sq_it *)
       ]  (* match it_subseq_step option *)
 and step1 k_sub it_proc q =
   (* запрашиваем чанк *)
   ie_contM & fun s ->
+  let () = fdbg "step1: new chunk = %s" (dbgstream s) in
   let q = Deque_stream.snoc q 0 s in
   (* дать s в k_sub, посмотреть на результат *)
   k_sub s >>% fun (it_sub, sl_sub) ->
   match it_sub with
   [ IE_done r ->
+      let () = fdbg "step1: it_sub done, sl_sub = %s" (Sl.dbgsl sl_sub) in
       break_subsequence_ret
         (Deque_stream.cons_sl sl_sub Deque_stream.empty)
         ~sub_res_opt:(Some r)
         it_proc
 
   | IE_cont (Some _) _ ->
+       let () = fdbg "step1: it_sub error" in
        (* - если ошибка -- loop_index со следующего смещения в первом чанке
             очереди (может дать ofs=len) *)
        match Deque_stream.destr_head q with
                  it_proc
 
            | Chunk first_chunk ->
+               feed_proc it_proc
+                 (Chunk (S.sub first_chunk ~ofs:first_ofs ~len:1))
+               >>% fun it_proc ->
                loop_index first_chunk (first_ofs + 1) it_proc ~qtail
            ]
        ]
 
-  | IE_cont None k_sub -> step1 k_sub it_proc q
+  | IE_cont None k_sub ->
+      let () = fdbg "step1: it_sub cont" in
+      step1 k_sub it_proc q
   ]
 in
   ie_cont & fun s ->
            then cmp arr ~ofs:(ofs + 1) ~i:(i + 1)
            else `No
      in
-     let ret ofs_after =
+     let ret ~arr ofs_after =
        let () = fdbg "probe_string: len=%i, dropping %i"
          (S.length arr) ofs_after in
        ie_doneM () (Chunk (S.drop ofs_after arr))
      in
      let rec it_first_step arr ~ofs ~i
       : option (IO.m (iteratee char unit * sl char)) =
+       (* let () = fdbg "probe_string: it_first_step: ofs=%i i=%i" ofs i in *)
        match cmp arr ~ofs ~i with
-       [ `Yes ofs_after -> Some (ret ofs_after)
+       [ `Yes ofs_after -> Some (ret ~arr ofs_after)
        | `No -> None
        | `Maybe i ->
            let () = fdbg "probe: cont from first step" in
            Some (ie_contM & it_step ~i)
        ]
      and it_step ~i s =
+       (* let () = fdbg "probe_string: it_step: i=%i, stream=%s"
+            i (dbgstream s)
+       in *)
        match s with
        [ EOF eopt ->
            ie_errorMsl
              (Sl.one s)
        | Chunk arr ->
            match cmp arr ~ofs:0 ~i with
-           [ `Yes ofs_after -> ret ofs_after
+           [ `Yes ofs_after -> ret ~arr ofs_after
            | `Maybe i -> ie_contM (it_step ~i)
            | `No -> ie_errorMsl Not_found (Sl.one s)
            ]
 ;
 
 
-value test_forms () =
+value test_forms ~allsizes () =
   let test1 =
 ( "qwe\r\n-----------------------------7045176531256545735900303621\
 \r\nContent-Disposition: form-data; name=\"MAX_FILE_SIZE\"\r\n\r\n100000\r\n\
   in
     List.iter
       (fun (body, boundary, expected) ->
-         match IO.runIO
-         ((enum_string
-             body
-             (     (H.it_multipart boundary
-                      (fun headers ->
-                         let () = fdbg "getting part" in
-                         gather_to_string >>= fun part ->
-                         (* let () = fdbg "got part: %S" part in *)
-                         dump_after "part" >>= fun () ->
-                         return (headers, part)
-                      )
-                      (stream2list >>= fun lst ->
-                       dump_after "all parts" >>= fun () ->
-                       return lst
-                      )
-                   )
+         let run_size sz =
+           let () = fdbg "test_forms/run_size %i" sz in
+           match IO.runIO
+           ((enum_string ~chunk_size:sz
+               body
+               (     (H.it_multipart boundary
+                        (fun headers ->
+                           let () = fdbg "getting part" in
+                           gather_to_string >>= fun part ->
+                           let () = fdbg "got part (%i bytes): %S"
+                             (String.length part) part in
+                           dump_after "part" >>= fun () ->
+                           return (headers, part)
+                        )
+                        (stream2list >>= fun lst ->
+                         dump_after "all parts" >>= fun () ->
+                         return lst
+                        )
+                     )
+               )
+            ) >>% run
+           )
+           with
+           [ `Ok got ->
+               if expected <> got
+               then failwith "test failed"
+               else Printf.printf "test passed\n%!"
+           | `Error e ->
+               failwith
+                 (Printf.sprintf
+                    "forms: test failed with exception: %s" (msg e)
+                 )
+               where rec msg e =
+                 match e with
+                 [ Left (e, s) ->
+                     sprintf "%s (stream left: %S)"
+                       (msg e) s
+                 | H.Multipart_error s -> s
+                 | Iteratees_err_msg e -> msg e
+                 | e -> Printexc.to_string e
+                 ]
+           ]
+         in
+           if allsizes
+           then
+             ( for i = 1 to String.length body
+               do
+                 run_size i
+               done
              )
-          ) >>% run
-         )
-         with
-         [ `Ok got ->
-             if expected <> got
-             then failwith "test failed"
-             else Printf.printf "test passed\n%!"
-         | `Error e ->
-             Printf.eprintf "forms: test failed with exception: %s" (msg e)
-             where rec msg e =
-               match e with
-               [ Left (e, s) ->
-                   sprintf "%s (stream left: %S)"
-                     (msg e) s
-               | H.Multipart_error s -> s
-               | Iteratees_err_msg e -> msg e
-               | e -> Printexc.to_string e
-               ]
-         ]
+           else
+             run_size 617
       )
       [test1]
 ;
 
   ; test_base64decode ()
 
-  ; test_forms ()
+  ; test_forms ~allsizes:False ()
 
   ; test_js_unescape ()
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.