Move function from sgen to gc so boehm can use it too.
authorRodrigo Kumpera <kumpera@gmail.com>
Fri, 5 Nov 2010 13:26:08 +0000 (11:26 -0200)
committerRodrigo Kumpera <kumpera@gmail.com>
Wed, 10 Nov 2010 19:35:48 +0000 (17:35 -0200)
* sgen-gc.c (mono_sgen_parse_environment_string_extract_number):
Move this function to gc.c and rename.

mono/metadata/gc-internal.h
mono/metadata/gc.c
mono/metadata/sgen-gc.c
mono/metadata/sgen-marksweep.c

index 52001ba24f3d4f77371d63bf42e5ce2fdc93b103..84d1d216d6be8d366a588a4c1756372d643ba15c 100644 (file)
@@ -300,5 +300,7 @@ void mono_gc_register_mach_exception_thread (pthread_t thread) MONO_INTERNAL;
 pthread_t mono_gc_get_mach_exception_thread (void) MONO_INTERNAL;
 #endif
 
+gboolean mono_gc_parse_environment_string_extract_number (const char *str, glong *out) MONO_INTERNAL;
+
 #endif /* __MONO_METADATA_GC_INTERNAL_H__ */
 
index 9d708638957e00180dcca64b4b40f6d33cfc8e3d..2e992f30b706f2633756188459916167aa9a70f0 100644 (file)
@@ -10,6 +10,7 @@
 #include <config.h>
 #include <glib.h>
 #include <string.h>
+#include <errno.h>
 
 #include <mono/metadata/gc-internal.h>
 #include <mono/metadata/mono-gc.h>
@@ -1221,3 +1222,55 @@ mono_gc_get_mach_exception_thread (void)
        return mach_exception_thread;
 }
 #endif
+
+/**
+ * mono_gc_parse_environment_string_extract_number:
+ *
+ * @str: points to the first digit of the number
+ * @out: pointer to the variable that will receive the value
+ *
+ * Tries to extract a number from the passed string, taking in to account m, k
+ * and g suffixes
+ *
+ * Returns true if passing was successful
+ */
+gboolean
+mono_gc_parse_environment_string_extract_number (const char *str, glong *out)
+{
+       char *endptr;
+       int len = strlen (str), shift = 0;
+       glong val;
+       gboolean is_suffix = FALSE;
+       char suffix;
+
+       switch (str [len - 1]) {
+               case 'g':
+               case 'G':
+                       shift += 10;
+               case 'm':
+               case 'M':
+                       shift += 10;
+               case 'k':
+               case 'K':
+                       shift += 10;
+                       is_suffix = TRUE;
+                       suffix = str [len - 1];
+                       break;
+       }
+
+       errno = 0;
+       val = strtol (str, &endptr, 10);
+
+       if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
+                       || (errno != 0 && val == 0) || (endptr == str))
+               return FALSE;
+
+       if (is_suffix) {
+               if (*(endptr + 1)) /* Invalid string. */
+                       return FALSE;
+               val <<= shift;
+       }
+
+       *out = val;
+       return TRUE;
+}
index 1e2271175fae95c9a71ac6bb14dcaac97ed2ed2f..fed1dae919fa3825c3b55e9d54bfbe006a6dc8b4 100644 (file)
@@ -6500,49 +6500,6 @@ mono_gc_is_gc_thread (void)
        return result;
 }
 
-/* Tries to extract a number from the passed string, taking in to account m, k
- * and g suffixes */
-gboolean
-mono_sgen_parse_environment_string_extract_number (const char *str, glong *out)
-{
-       char *endptr;
-       int len = strlen (str), shift = 0;
-       glong val;
-       gboolean is_suffix = FALSE;
-       char suffix;
-
-       switch (str [len - 1]) {
-               case 'g':
-               case 'G':
-                       shift += 10;
-               case 'm':
-               case 'M':
-                       shift += 10;
-               case 'k':
-               case 'K':
-                       shift += 10;
-                       is_suffix = TRUE;
-                       suffix = str [len - 1];
-                       break;
-       }
-
-       errno = 0;
-       val = strtol (str, &endptr, 10);
-
-       if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
-                       || (errno != 0 && val == 0) || (endptr == str))
-               return FALSE;
-
-       if (is_suffix) {
-               if (*(endptr + 1)) /* Invalid string. */
-                       return FALSE;
-               val <<= shift;
-       }
-
-       *out = val;
-       return TRUE;
-}
-
 void
 mono_gc_base_init (void)
 {
@@ -6644,7 +6601,7 @@ mono_gc_base_init (void)
                        if (g_str_has_prefix (opt, "nursery-size=")) {
                                long val;
                                opt = strchr (opt, '=') + 1;
-                               if (*opt && mono_sgen_parse_environment_string_extract_number (opt, &val)) {
+                               if (*opt && mono_gc_parse_environment_string_extract_number (opt, &val)) {
                                        default_nursery_size = val;
 #ifdef SGEN_ALIGN_NURSERY
                                        if ((val & (val - 1))) {
index a774679268351a408cec46802a91b9d7001198a4..ae141a3b620abcb3b70a90526c183d04b6e6680f 100644 (file)
@@ -37,7 +37,7 @@
 #include "metadata/sgen-gc.h"
 #include "metadata/sgen-protocol.h"
 #include "metadata/sgen-cardtable.h"
-
+#include "metadata/gc-internal.h"
 
 #define DEBUG(l,x)
 
@@ -1349,7 +1349,7 @@ major_handle_gc_param (const char *opt)
        if (g_str_has_prefix (opt, "major-heap-size=")) {
                const char *arg = strchr (opt, '=') + 1;
                glong size;
-               if (!mono_sgen_parse_environment_string_extract_number (arg, &size))
+               if (!mono_gc_parse_environment_string_extract_number (arg, &size))
                        return FALSE;
                ms_heap_num_blocks = (size + MS_BLOCK_SIZE - 1) / MS_BLOCK_SIZE;
                g_assert (ms_heap_num_blocks > 0);