[MLton-devel] Patch to FreeBSD GC init code and general comments to C code

jlouis@diku.dk jlouis@diku.dk
Sun, 22 Sep 2002 23:18:26 +0200


After reading a bit down over the code, I think this is much more pure
in the garbage collector. I have provided a patch at the bottom. The
patch removes a need for sysctl and awk in at least one place. The swap
information isnt present in sysctl on FreeBSD though, so no luck there
yet. Furthermore, reading the kvm_getswapinfo() directly requires mlton
to be setgid(kmem). And that is not acceptable.

Second shouldnt we hoist all #includes to the top of the files, instead
of spreading them out all over the file? My experience tells me we are
going to get bitten by it if we dont.

Third the ensure-gmp target in mlton/runtime/Makefile will cause a lot
of trouble. On FreeBSD at least, libgmp is part of the base system and
should be linked in unless someone actually deletes it. I dont think
there is any need for the check (on FreeBSD). If we really need them, we
should consider using automake, autoconf and other programs that can
check it.  The task of converting to those GNU tools is time consuming
though.

Index: gc.c
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/gc.c,v
retrieving revision 1.95
diff -u -r1.95 gc.c
--- gc.c	19 Sep 2002 18:49:22 -0000	1.95
+++ gc.c	22 Sep 2002 21:06:56 -0000
@@ -13,6 +13,7 @@
 #include <string.h>
 #if (defined (__FreeBSD__))
 #include <sys/types.h>
+#include <sys/sysctl.h>
 #endif
 #include <sys/mman.h>
 #include <sys/resource.h>
@@ -2862,22 +2863,18 @@
 }
 
 /* returns total amount of memory available */
-static int 
-get_total_mem() 
+static int
+get_total_mem()
 {
-        static char buffer[256];
-        FILE *file;
-
-        file = popen("/sbin/sysctl hw.physmem | awk '{ print $2; }'\n", "r");
-        if (file == NULL) 
-                diee ("sysctl failed");
-
+	int i, mem, len;
 
-        fgets(buffer, 255, file);
+	len = sizeof(int);
+	i = sysctlbyname("hw.physmem", &mem, &len, NULL, 0);
 
-        pclose(file);
+	if (i == -1)
+		diee("sysctl failed");
 
-        return atoi(buffer);
+	return mem;
 }
 
 static void setMemInfo (GC_state s) {

-- 
Jesper
 Algorithms has to be seen to be believed - D. E. Knuth


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel