summaryrefslogtreecommitdiffstats
path: root/byterun/sys.c
diff options
context:
space:
mode:
Diffstat (limited to 'byterun/sys.c')
-rw-r--r--byterun/sys.c46
1 files changed, 37 insertions, 9 deletions
diff --git a/byterun/sys.c b/byterun/sys.c
index 8b2551a00..cd49dd920 100644
--- a/byterun/sys.c
+++ b/byterun/sys.c
@@ -48,6 +48,7 @@
#include "signals.h"
#include "stacks.h"
#include "sys.h"
+#include "gc_ctrl.h"
static char * error_message(void)
{
@@ -93,6 +94,17 @@ CAMLexport void caml_sys_io_error(value arg)
CAMLprim value caml_sys_exit(value retcode)
{
+ if ((caml_verb_gc & 0x400) != 0) {
+ /* cf caml_gc_counters */
+ double minwords = caml_stat_minor_words
+ + (double) Wsize_bsize (caml_young_end - caml_young_ptr);
+ double prowords = caml_stat_promoted_words;
+ double majwords = caml_stat_major_words + (double) caml_allocated_words;
+ double allocated_words =
+ minwords + majwords - prowords;
+ caml_gc_message(0x400, "## Total allocated words: %ld\n", (long)allocated_words);
+ }
+
#ifndef NATIVE_CODE
caml_debugger(PROGRAM_EXIT);
#endif
@@ -125,7 +137,7 @@ CAMLprim value caml_sys_open(value path, value vflags, value vperm)
int fd, flags, perm;
char * p;
- p = caml_stat_alloc_string(path);
+ p = caml_strdup(String_val(path));
flags = caml_convert_flag_list(vflags, sys_open_flags);
perm = Int_val(vperm);
/* open on a named FIFO can block (PR#1533) */
@@ -152,13 +164,21 @@ CAMLprim value caml_sys_close(value fd)
CAMLprim value caml_sys_file_exists(value name)
{
+#ifdef _WIN32
+ struct _stati64 st;
+#else
struct stat st;
+#endif
char * p;
int ret;
- p = caml_stat_alloc_string(name);
+ p = caml_strdup(String_val(name));
caml_enter_blocking_section();
+#ifdef _WIN32
+ ret = _stati64(p, &st);
+#else
ret = stat(p, &st);
+#endif
caml_leave_blocking_section();
caml_stat_free(p);
@@ -168,13 +188,21 @@ CAMLprim value caml_sys_file_exists(value name)
CAMLprim value caml_sys_is_directory(value name)
{
CAMLparam1(name);
+#ifdef _WIN32
+ struct _stati64 st;
+#else
struct stat st;
+#endif
char * p;
int ret;
- p = caml_stat_alloc_string(name);
+ p = caml_strdup(String_val(name));
caml_enter_blocking_section();
+#ifdef _WIN32
+ ret = _stati64(p, &st);
+#else
ret = stat(p, &st);
+#endif
caml_leave_blocking_section();
caml_stat_free(p);
@@ -191,7 +219,7 @@ CAMLprim value caml_sys_remove(value name)
CAMLparam1(name);
char * p;
int ret;
- p = caml_stat_alloc_string(name);
+ p = caml_strdup(String_val(name));
caml_enter_blocking_section();
ret = unlink(p);
caml_leave_blocking_section();
@@ -205,8 +233,8 @@ CAMLprim value caml_sys_rename(value oldname, value newname)
char * p_old;
char * p_new;
int ret;
- p_old = caml_stat_alloc_string(oldname);
- p_new = caml_stat_alloc_string(newname);
+ p_old = caml_strdup(String_val(oldname));
+ p_new = caml_strdup(String_val(newname));
caml_enter_blocking_section();
ret = rename(p_old, p_new);
caml_leave_blocking_section();
@@ -222,7 +250,7 @@ CAMLprim value caml_sys_chdir(value dirname)
CAMLparam1(dirname);
char * p;
int ret;
- p = caml_stat_alloc_string(dirname);
+ p = caml_strdup(String_val(dirname));
caml_enter_blocking_section();
ret = chdir(p);
caml_leave_blocking_section();
@@ -289,7 +317,7 @@ CAMLprim value caml_sys_system_command(value command)
int status, retcode;
char *buf;
- buf = caml_stat_alloc_string(command);
+ buf = caml_strdup(String_val(command));
caml_enter_blocking_section ();
status = system(buf);
caml_leave_blocking_section ();
@@ -430,7 +458,7 @@ CAMLprim value caml_sys_read_directory(value path)
int ret;
caml_ext_table_init(&tbl, 50);
- p = caml_stat_alloc_string(path);
+ p = caml_strdup(String_val(path));
caml_enter_blocking_section();
ret = caml_read_directory(p, &tbl);
caml_leave_blocking_section();