@@ -4,17 +4,16 @@ import * as Sys from "./sys.js";
4
4
import * as List from "./list.js" ;
5
5
import * as $$Array from "./array.js" ;
6
6
import * as Block from "./block.js" ;
7
+ import * as Bytes from "./bytes.js" ;
7
8
import * as Curry from "./curry.js" ;
8
9
import * as Printf from "./printf.js" ;
9
10
import * as $$String from "./string.js" ;
10
- import * as Caml_io from "./caml_io.js" ;
11
11
import * as Hashtbl from "./hashtbl.js" ;
12
12
import * as Callback from "./callback.js" ;
13
13
import * as Caml_sys from "./caml_sys.js" ;
14
14
import * as Filename from "./filename.js" ;
15
15
import * as Printexc from "./printexc.js" ;
16
16
import * as Caml_array from "./caml_array.js" ;
17
- import * as Caml_bytes from "./caml_bytes.js" ;
18
17
import * as Pervasives from "./pervasives.js" ;
19
18
import * as Caml_format from "./caml_format.js" ;
20
19
import * as Caml_exceptions from "./caml_exceptions.js" ;
@@ -459,40 +458,34 @@ function execvpe(name, args, env) {
459
458
460
459
function read ( fd , buf , ofs , len ) {
461
460
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 ) ;
466
464
}
467
- return Caml_external_polyfill . resolve ( "unix_read" ) ( fd , buf , ofs , len ) ;
468
465
}
469
466
470
467
function write ( fd , buf , ofs , len ) {
471
468
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 ) ;
476
472
}
477
- return Caml_external_polyfill . resolve ( "unix_write" ) ( fd , buf , ofs , len ) ;
478
473
}
479
474
480
475
function single_write ( fd , buf , ofs , len ) {
481
476
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 ) ;
486
480
}
487
- return Caml_external_polyfill . resolve ( "unix_single_write" ) ( fd , buf , ofs , len ) ;
488
481
}
489
482
490
483
function 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 ) ;
492
485
}
493
486
494
487
function 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 ) ;
496
489
}
497
490
498
491
function map_file ( fd , posOpt , kind , layout , shared , dims ) {
@@ -557,50 +550,42 @@ function domain_of_sockaddr(param) {
557
550
558
551
function recv ( fd , buf , ofs , len , flags ) {
559
552
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 ) ;
564
556
}
565
- return Caml_external_polyfill . resolve ( "unix_recv" ) ( fd , buf , ofs , len , flags ) ;
566
557
}
567
558
568
559
function recvfrom ( fd , buf , ofs , len , flags ) {
569
560
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 ) ;
574
564
}
575
- return Caml_external_polyfill . resolve ( "unix_recvfrom" ) ( fd , buf , ofs , len , flags ) ;
576
565
}
577
566
578
567
function send ( fd , buf , ofs , len , flags ) {
579
568
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 ) ;
584
572
}
585
- return Caml_external_polyfill . resolve ( "unix_send" ) ( fd , buf , ofs , len , flags ) ;
586
573
}
587
574
588
575
function sendto ( fd , buf , ofs , len , flags , addr ) {
589
576
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 ) ;
594
580
}
595
- return Caml_external_polyfill . resolve ( "unix_sendto" ) ( fd , buf , ofs , len , flags , addr ) ;
596
581
}
597
582
598
583
function 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 ) ;
600
585
}
601
586
602
587
function 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 ) ;
604
589
}
605
590
606
591
function SO_get ( prim , prim$1 , prim$2 ) {
@@ -1025,7 +1010,7 @@ function open_process_in(cmd) {
1025
1010
open_proc ( cmd , undefined , /* Process_in */ Block . __ ( 1 , [ inchan ] ) , 0 , in_write , 2 ) ;
1026
1011
}
1027
1012
catch ( e ) {
1028
- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( inchan ) ;
1013
+ Pervasives . close_in ( inchan ) ;
1029
1014
Caml_external_polyfill . resolve ( "unix_close" ) ( in_write ) ;
1030
1015
throw e ;
1031
1016
}
@@ -1041,8 +1026,7 @@ function open_process_out(cmd) {
1041
1026
open_proc ( cmd , undefined , /* Process_out */ Block . __ ( 2 , [ outchan ] ) , out_read , 1 , 2 ) ;
1042
1027
}
1043
1028
catch ( e ) {
1044
- Caml_io . caml_ml_flush ( outchan ) ;
1045
- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( outchan ) ;
1029
+ Pervasives . close_out ( outchan ) ;
1046
1030
Caml_external_polyfill . resolve ( "unix_close" ) ( out_read ) ;
1047
1031
throw e ;
1048
1032
}
@@ -1166,15 +1150,14 @@ function find_proc_id(fun_name, proc) {
1166
1150
1167
1151
function close_process_in ( inchan ) {
1168
1152
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 ) ;
1170
1154
return waitpid_non_intr ( pid ) [ 1 ] ;
1171
1155
}
1172
1156
1173
1157
function close_process_out ( outchan ) {
1174
1158
var pid = find_proc_id ( "close_process_out" , /* Process_out */ Block . __ ( 2 , [ outchan ] ) ) ;
1175
1159
try {
1176
- Caml_io . caml_ml_flush ( outchan ) ;
1177
- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( outchan ) ;
1160
+ Pervasives . close_out ( outchan ) ;
1178
1161
}
1179
1162
catch ( raw_exn ) {
1180
1163
var exn = Caml_js_exceptions . internalToOCamlException ( raw_exn ) ;
@@ -1193,10 +1176,9 @@ function close_process(param) {
1193
1176
inchan ,
1194
1177
outchan
1195
1178
] ) ) ;
1196
- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( inchan ) ;
1179
+ Pervasives . close_in ( inchan ) ;
1197
1180
try {
1198
- Caml_io . caml_ml_flush ( outchan ) ;
1199
- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( outchan ) ;
1181
+ Pervasives . close_out ( outchan ) ;
1200
1182
}
1201
1183
catch ( raw_exn ) {
1202
1184
var exn = Caml_js_exceptions . internalToOCamlException ( raw_exn ) ;
@@ -1217,10 +1199,9 @@ function close_process_full(param) {
1217
1199
outchan ,
1218
1200
errchan
1219
1201
] ) ) ;
1220
- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( inchan ) ;
1202
+ Pervasives . close_in ( inchan ) ;
1221
1203
try {
1222
- Caml_io . caml_ml_flush ( outchan ) ;
1223
- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( outchan ) ;
1204
+ Pervasives . close_out ( outchan ) ;
1224
1205
}
1225
1206
catch ( raw_exn ) {
1226
1207
var exn = Caml_js_exceptions . internalToOCamlException ( raw_exn ) ;
@@ -1229,7 +1210,7 @@ function close_process_full(param) {
1229
1210
}
1230
1211
1231
1212
}
1232
- Caml_external_polyfill . resolve ( "caml_ml_close_channel" ) ( errchan ) ;
1213
+ Pervasives . close_in ( errchan ) ;
1233
1214
return waitpid_non_intr ( pid ) [ 1 ] ;
1234
1215
}
1235
1216
0 commit comments