@@ -4,17 +4,16 @@ import * as Sys from "./sys.js";
44import * as List from "./list.js" ;
55import * as $$Array from "./array.js" ;
66import * as Block from "./block.js" ;
7+ import * as Bytes from "./bytes.js" ;
78import * as Curry from "./curry.js" ;
89import * as Printf from "./printf.js" ;
910import * as $$String from "./string.js" ;
10- import * as Caml_io from "./caml_io.js" ;
1111import * as Hashtbl from "./hashtbl.js" ;
1212import * as Callback from "./callback.js" ;
1313import * as Caml_sys from "./caml_sys.js" ;
1414import * as Filename from "./filename.js" ;
1515import * as Printexc from "./printexc.js" ;
1616import * as Caml_array from "./caml_array.js" ;
17- import * as Caml_bytes from "./caml_bytes.js" ;
1817import * as Pervasives from "./pervasives.js" ;
1918import * as Caml_format from "./caml_format.js" ;
2019import * as Caml_exceptions from "./caml_exceptions.js" ;
@@ -459,40 +458,34 @@ function execvpe(name, args, env) {
459458
460459function read ( fd , buf , ofs , len ) {
461460 if ( ofs < 0 || len < 0 || ofs > ( buf . length - len | 0 ) ) {
462- throw [
463- Caml_builtin_exceptions . invalid_argument ,
464- "Unix.read"
465- ] ;
461+ return Pervasives . invalid_arg ( "Unix.read" ) ;
462+ } else {
463+ return Caml_external_polyfill . resolve ( "unix_read" ) ( fd , buf , ofs , len ) ;
466464 }
467- return Caml_external_polyfill . resolve ( "unix_read" ) ( fd , buf , ofs , len ) ;
468465}
469466
470467function write ( fd , buf , ofs , len ) {
471468 if ( ofs < 0 || len < 0 || ofs > ( buf . length - len | 0 ) ) {
472- throw [
473- Caml_builtin_exceptions . invalid_argument ,
474- "Unix.write"
475- ] ;
469+ return Pervasives . invalid_arg ( "Unix.write" ) ;
470+ } else {
471+ return Caml_external_polyfill . resolve ( "unix_write" ) ( fd , buf , ofs , len ) ;
476472 }
477- return Caml_external_polyfill . resolve ( "unix_write" ) ( fd , buf , ofs , len ) ;
478473}
479474
480475function single_write ( fd , buf , ofs , len ) {
481476 if ( ofs < 0 || len < 0 || ofs > ( buf . length - len | 0 ) ) {
482- throw [
483- Caml_builtin_exceptions . invalid_argument ,
484- "Unix.single_write"
485- ] ;
477+ return Pervasives . invalid_arg ( "Unix.single_write" ) ;
478+ } else {
479+ return Caml_external_polyfill . resolve ( "unix_single_write" ) ( fd , buf , ofs , len ) ;
486480 }
487- return Caml_external_polyfill . resolve ( "unix_single_write" ) ( fd , buf , ofs , len ) ;
488481}
489482
490483function write_substring ( fd , buf , ofs , len ) {
491- return write ( fd , Caml_bytes . bytes_of_string ( buf ) , ofs , len ) ;
484+ return write ( fd , Bytes . unsafe_of_string ( buf ) , ofs , len ) ;
492485}
493486
494487function single_write_substring ( fd , buf , ofs , len ) {
495- return single_write ( fd , Caml_bytes . bytes_of_string ( buf ) , ofs , len ) ;
488+ return single_write ( fd , Bytes . unsafe_of_string ( buf ) , ofs , len ) ;
496489}
497490
498491function map_file ( fd , posOpt , kind , layout , shared , dims ) {
@@ -557,50 +550,42 @@ function domain_of_sockaddr(param) {
557550
558551function recv ( fd , buf , ofs , len , flags ) {
559552 if ( ofs < 0 || len < 0 || ofs > ( buf . length - len | 0 ) ) {
560- throw [
561- Caml_builtin_exceptions . invalid_argument ,
562- "Unix.recv"
563- ] ;
553+ return Pervasives . invalid_arg ( "Unix.recv" ) ;
554+ } else {
555+ return Caml_external_polyfill . resolve ( "unix_recv" ) ( fd , buf , ofs , len , flags ) ;
564556 }
565- return Caml_external_polyfill . resolve ( "unix_recv" ) ( fd , buf , ofs , len , flags ) ;
566557}
567558
568559function recvfrom ( fd , buf , ofs , len , flags ) {
569560 if ( ofs < 0 || len < 0 || ofs > ( buf . length - len | 0 ) ) {
570- throw [
571- Caml_builtin_exceptions . invalid_argument ,
572- "Unix.recvfrom"
573- ] ;
561+ return Pervasives . invalid_arg ( "Unix.recvfrom" ) ;
562+ } else {
563+ return Caml_external_polyfill . resolve ( "unix_recvfrom" ) ( fd , buf , ofs , len , flags ) ;
574564 }
575- return Caml_external_polyfill . resolve ( "unix_recvfrom" ) ( fd , buf , ofs , len , flags ) ;
576565}
577566
578567function send ( fd , buf , ofs , len , flags ) {
579568 if ( ofs < 0 || len < 0 || ofs > ( buf . length - len | 0 ) ) {
580- throw [
581- Caml_builtin_exceptions . invalid_argument ,
582- "Unix.send"
583- ] ;
569+ return Pervasives . invalid_arg ( "Unix.send" ) ;
570+ } else {
571+ return Caml_external_polyfill . resolve ( "unix_send" ) ( fd , buf , ofs , len , flags ) ;
584572 }
585- return Caml_external_polyfill . resolve ( "unix_send" ) ( fd , buf , ofs , len , flags ) ;
586573}
587574
588575function sendto ( fd , buf , ofs , len , flags , addr ) {
589576 if ( ofs < 0 || len < 0 || ofs > ( buf . length - len | 0 ) ) {
590- throw [
591- Caml_builtin_exceptions . invalid_argument ,
592- "Unix.sendto"
593- ] ;
577+ return Pervasives . invalid_arg ( "Unix.sendto" ) ;
578+ } else {
579+ return Caml_external_polyfill . resolve ( "unix_sendto" ) ( fd , buf , ofs , len , flags , addr ) ;
594580 }
595- return Caml_external_polyfill . resolve ( "unix_sendto" ) ( fd , buf , ofs , len , flags , addr ) ;
596581}
597582
598583function send_substring ( fd , buf , ofs , len , flags ) {
599- return send ( fd , Caml_bytes . bytes_of_string ( buf ) , ofs , len , flags ) ;
584+ return send ( fd , Bytes . unsafe_of_string ( buf ) , ofs , len , flags ) ;
600585}
601586
602587function sendto_substring ( fd , buf , ofs , len , flags , addr ) {
603- return sendto ( fd , Caml_bytes . bytes_of_string ( buf ) , ofs , len , flags , addr ) ;
588+ return sendto ( fd , Bytes . unsafe_of_string ( buf ) , ofs , len , flags , addr ) ;
604589}
605590
606591function SO_get ( prim , prim$1 , prim$2 ) {
@@ -1025,7 +1010,7 @@ function open_process_in(cmd) {
10251010 open_proc ( cmd , undefined , /* Process_in */ Block . __ ( 1 , [ inchan ] ) , 0 , in_write , 2 ) ;
10261011 }
10271012 catch ( e ) {
1028- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( inchan ) ;
1013+ Pervasives . close_in ( inchan ) ;
10291014 Caml_external_polyfill . resolve ( "unix_close" ) ( in_write ) ;
10301015 throw e ;
10311016 }
@@ -1041,8 +1026,7 @@ function open_process_out(cmd) {
10411026 open_proc ( cmd , undefined , /* Process_out */ Block . __ ( 2 , [ outchan ] ) , out_read , 1 , 2 ) ;
10421027 }
10431028 catch ( e ) {
1044- Caml_io . caml_ml_flush ( outchan ) ;
1045- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( outchan ) ;
1029+ Pervasives . close_out ( outchan ) ;
10461030 Caml_external_polyfill . resolve ( "unix_close" ) ( out_read ) ;
10471031 throw e ;
10481032 }
@@ -1166,15 +1150,14 @@ function find_proc_id(fun_name, proc) {
11661150
11671151function close_process_in ( inchan ) {
11681152 var pid = find_proc_id ( "close_process_in" , /* Process_in */ Block . __ ( 1 , [ inchan ] ) ) ;
1169- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( inchan ) ;
1153+ Pervasives . close_in ( inchan ) ;
11701154 return waitpid_non_intr ( pid ) [ 1 ] ;
11711155}
11721156
11731157function close_process_out ( outchan ) {
11741158 var pid = find_proc_id ( "close_process_out" , /* Process_out */ Block . __ ( 2 , [ outchan ] ) ) ;
11751159 try {
1176- Caml_io . caml_ml_flush ( outchan ) ;
1177- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( outchan ) ;
1160+ Pervasives . close_out ( outchan ) ;
11781161 }
11791162 catch ( raw_exn ) {
11801163 var exn = Caml_js_exceptions . internalToOCamlException ( raw_exn ) ;
@@ -1193,10 +1176,9 @@ function close_process(param) {
11931176 inchan ,
11941177 outchan
11951178 ] ) ) ;
1196- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( inchan ) ;
1179+ Pervasives . close_in ( inchan ) ;
11971180 try {
1198- Caml_io . caml_ml_flush ( outchan ) ;
1199- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( outchan ) ;
1181+ Pervasives . close_out ( outchan ) ;
12001182 }
12011183 catch ( raw_exn ) {
12021184 var exn = Caml_js_exceptions . internalToOCamlException ( raw_exn ) ;
@@ -1217,10 +1199,9 @@ function close_process_full(param) {
12171199 outchan ,
12181200 errchan
12191201 ] ) ) ;
1220- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( inchan ) ;
1202+ Pervasives . close_in ( inchan ) ;
12211203 try {
1222- Caml_io . caml_ml_flush ( outchan ) ;
1223- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( outchan ) ;
1204+ Pervasives . close_out ( outchan ) ;
12241205 }
12251206 catch ( raw_exn ) {
12261207 var exn = Caml_js_exceptions . internalToOCamlException ( raw_exn ) ;
@@ -1229,7 +1210,7 @@ function close_process_full(param) {
12291210 }
12301211
12311212 }
1232- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( errchan ) ;
1213+ Pervasives . close_in ( errchan ) ;
12331214 return waitpid_non_intr ( pid ) [ 1 ] ;
12341215}
12351216
0 commit comments