[svn:parrot] r44208 - in branches/sys_mem_reduce: include/parrot src/gc src/string src/string/encoding

bacek at svn.parrot.org bacek at svn.parrot.org
Fri Feb 19 22:45:04 UTC 2010


Author: bacek
Date: Fri Feb 19 22:45:03 2010
New Revision: 44208
URL: https://trac.parrot.org/parrot/changeset/44208

Log:
Switch charsets and encodings to use GC allocations

Modified:
   branches/sys_mem_reduce/include/parrot/charset.h
   branches/sys_mem_reduce/include/parrot/encoding.h
   branches/sys_mem_reduce/src/gc/api.c
   branches/sys_mem_reduce/src/string/charset.c
   branches/sys_mem_reduce/src/string/encoding.c
   branches/sys_mem_reduce/src/string/encoding/utf16.c
   branches/sys_mem_reduce/src/string/encoding/utf8.c

Modified: branches/sys_mem_reduce/include/parrot/charset.h
==============================================================================
--- branches/sys_mem_reduce/include/parrot/charset.h	Fri Feb 19 22:44:35 2010	(r44207)
+++ branches/sys_mem_reduce/include/parrot/charset.h	Fri Feb 19 22:45:03 2010	(r44208)
@@ -101,7 +101,8 @@
         __attribute__nonnull__(2);
 
 PARROT_EXPORT
-void Parrot_charsets_encodings_deinit(SHIM_INTERP);
+void Parrot_charsets_encodings_deinit(PARROT_INTERP)
+        __attribute__nonnull__(1);
 
 PARROT_EXPORT
 void Parrot_charsets_encodings_init(PARROT_INTERP)
@@ -149,20 +150,23 @@
 PARROT_EXPORT
 PARROT_CAN_RETURN_NULL
 PARROT_MALLOC
-CHARSET * Parrot_new_charset(SHIM_INTERP);
+CHARSET * Parrot_new_charset(PARROT_INTERP)
+        __attribute__nonnull__(1);
 
 PARROT_EXPORT
-INTVAL Parrot_register_charset(SHIM_INTERP,
+INTVAL Parrot_register_charset(PARROT_INTERP,
     ARGIN(const char *charsetname),
     ARGIN(CHARSET *charset))
+        __attribute__nonnull__(1)
         __attribute__nonnull__(2)
         __attribute__nonnull__(3);
 
 PARROT_EXPORT
-void Parrot_register_charset_converter(SHIM_INTERP,
+void Parrot_register_charset_converter(PARROT_INTERP,
     ARGIN(const CHARSET *lhs),
     ARGIN(CHARSET *rhs),
     ARGIN(charset_converter_t func))
+        __attribute__nonnull__(1)
         __attribute__nonnull__(2)
         __attribute__nonnull__(3)
         __attribute__nonnull__(4);
@@ -175,7 +179,8 @@
 #define ASSERT_ARGS_Parrot_charset_number_of_str __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(src))
 #define ASSERT_ARGS_Parrot_charsets_encodings_deinit \
-     __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+     __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_charsets_encodings_init \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
@@ -191,13 +196,16 @@
     , PARROT_ASSERT_ARG(charsetname))
 #define ASSERT_ARGS_Parrot_make_default_charset __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(charset))
-#define ASSERT_ARGS_Parrot_new_charset __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_Parrot_new_charset __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_register_charset __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(charsetname) \
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(charsetname) \
     , PARROT_ASSERT_ARG(charset))
 #define ASSERT_ARGS_Parrot_register_charset_converter \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(lhs) \
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(lhs) \
     , PARROT_ASSERT_ARG(rhs) \
     , PARROT_ASSERT_ARG(func))
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */

Modified: branches/sys_mem_reduce/include/parrot/encoding.h
==============================================================================
--- branches/sys_mem_reduce/include/parrot/encoding.h	Fri Feb 19 22:44:35 2010	(r44207)
+++ branches/sys_mem_reduce/include/parrot/encoding.h	Fri Feb 19 22:45:03 2010	(r44208)
@@ -153,7 +153,9 @@
         __attribute__nonnull__(2)
         __attribute__nonnull__(3);
 
-void parrot_deinit_encodings(void);
+void parrot_deinit_encodings(PARROT_INTERP)
+        __attribute__nonnull__(1);
+
 void Parrot_str_internal_register_encoding_names(PARROT_INTERP)
         __attribute__nonnull__(1);
 
@@ -183,7 +185,8 @@
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(encodingname) \
     , PARROT_ASSERT_ARG(encoding))
-#define ASSERT_ARGS_parrot_deinit_encodings __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_parrot_deinit_encodings __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_str_internal_register_encoding_names \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))

Modified: branches/sys_mem_reduce/src/gc/api.c
==============================================================================
--- branches/sys_mem_reduce/src/gc/api.c	Fri Feb 19 22:44:35 2010	(r44207)
+++ branches/sys_mem_reduce/src/gc/api.c	Fri Feb 19 22:45:03 2010	(r44208)
@@ -293,7 +293,7 @@
     if (interp->gc_sys->finalize_gc_system)
         interp->gc_sys->finalize_gc_system(interp);
 
-    mem_sys_free(interp->gc_sys);
+    mem_internal_free(interp->gc_sys);
     interp->gc_sys = NULL;
 }
 
@@ -665,7 +665,7 @@
 
 =item C<void *
 Parrot_gc_reallocate_memory_chunk_with_interior_pointers(PARROT_INTERP, void
-*data, size_t newsize, size_t oldsize)>
+*data, size_t oldsize, size_t newsize)>
 
 TODO Write docu.
 

Modified: branches/sys_mem_reduce/src/string/charset.c
==============================================================================
--- branches/sys_mem_reduce/src/string/charset.c	Fri Feb 19 22:44:35 2010	(r44207)
+++ branches/sys_mem_reduce/src/string/charset.c	Fri Feb 19 22:45:03 2010	(r44208)
@@ -64,11 +64,12 @@
 static void Parrot_str_internal_register_charset_names(PARROT_INTERP)
         __attribute__nonnull__(1);
 
-static INTVAL register_charset(
+static INTVAL register_charset(PARROT_INTERP,
     ARGIN(const char *charsetname),
     ARGIN(CHARSET *charset))
         __attribute__nonnull__(1)
-        __attribute__nonnull__(2);
+        __attribute__nonnull__(2)
+        __attribute__nonnull__(3);
 
 static void register_static_converters(PARROT_INTERP)
         __attribute__nonnull__(1);
@@ -77,7 +78,8 @@
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_register_charset __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(charsetname) \
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(charsetname) \
     , PARROT_ASSERT_ARG(charset))
 #define ASSERT_ARGS_register_static_converters __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
@@ -98,10 +100,10 @@
 PARROT_CAN_RETURN_NULL
 PARROT_MALLOC
 CHARSET *
-Parrot_new_charset(SHIM_INTERP)
+Parrot_new_charset(PARROT_INTERP)
 {
     ASSERT_ARGS(Parrot_new_charset)
-    return mem_allocate_typed(CHARSET);
+    return mem_gc_allocate_zeroed_typed(interp, CHARSET);
 }
 
 /*
@@ -117,7 +119,7 @@
 
 PARROT_EXPORT
 void
-Parrot_charsets_encodings_deinit(SHIM_INTERP)
+Parrot_charsets_encodings_deinit(PARROT_INTERP)
 {
     ASSERT_ARGS(Parrot_charsets_encodings_deinit)
     int i;
@@ -125,13 +127,13 @@
 
     for (i = 0; i < n; ++i) {
         if (all_charsets->set[i].n_converters)
-            mem_sys_free(all_charsets->set[i].to_converters);
-        mem_sys_free(all_charsets->set[i].charset);
+            mem_gc_free(interp, all_charsets->set[i].to_converters);
+        mem_gc_free(interp, all_charsets->set[i].charset);
     }
-    mem_sys_free(all_charsets->set);
-    mem_sys_free(all_charsets);
+    mem_gc_free(interp, all_charsets->set);
+    mem_gc_free(interp, all_charsets);
     all_charsets = NULL;
-    parrot_deinit_encodings();
+    parrot_deinit_encodings(interp);
 }
 
 /*
@@ -311,8 +313,8 @@
 
 /*
 
-=item C<static INTVAL register_charset(const char *charsetname, CHARSET
-*charset)>
+=item C<static INTVAL register_charset(PARROT_INTERP, const char *charsetname,
+CHARSET *charset)>
 
 Adds a new charset C<charset> with name <charsetname> to the list of
 all charsets. Returns 0 and does nothing if a charset with that name
@@ -323,7 +325,8 @@
 */
 
 static INTVAL
-register_charset(ARGIN(const char *charsetname), ARGIN(CHARSET *charset))
+register_charset(PARROT_INTERP, ARGIN(const char *charsetname),
+        ARGIN(CHARSET *charset))
 {
     ASSERT_ARGS(register_charset)
     int i;
@@ -339,10 +342,10 @@
      * loading of charsets from inside threads
      */
     if (!n)
-        all_charsets->set = mem_allocate_typed(One_charset);
+        all_charsets->set = mem_gc_allocate_zeroed_typed(interp, One_charset);
     else
-        all_charsets->set = (One_charset *)mem_sys_realloc(all_charsets->set,
-                (n + 1) * sizeof (One_charset));
+        all_charsets->set = mem_gc_realloc_n_typed_zeroed(interp,
+                all_charsets->set, n + 1, n, One_charset);
 
     all_charsets->n_charsets++;
     all_charsets->set[n].charset      = charset;
@@ -429,29 +432,29 @@
 
 PARROT_EXPORT
 INTVAL
-Parrot_register_charset(SHIM_INTERP, ARGIN(const char *charsetname),
+Parrot_register_charset(PARROT_INTERP, ARGIN(const char *charsetname),
         ARGIN(CHARSET *charset))
 {
     ASSERT_ARGS(Parrot_register_charset)
     if (!all_charsets) {
-        all_charsets             = mem_allocate_typed(All_charsets);
+        all_charsets             = mem_gc_allocate_zeroed_typed(interp, All_charsets);
         all_charsets->set        = NULL;
         all_charsets->n_charsets = 0;
     }
 
     if (STREQ("binary", charsetname)) {
         Parrot_binary_charset_ptr = charset;
-        return register_charset(charsetname, charset);
+        return register_charset(interp, charsetname, charset);
     }
 
     if (STREQ("iso-8859-1", charsetname)) {
         Parrot_iso_8859_1_charset_ptr = charset;
-        return register_charset(charsetname, charset);
+        return register_charset(interp, charsetname, charset);
     }
 
     if (STREQ("unicode", charsetname)) {
         Parrot_unicode_charset_ptr = charset;
-        return register_charset(charsetname, charset);
+        return register_charset(interp, charsetname, charset);
     }
 
     if (STREQ("ascii", charsetname)) {
@@ -459,7 +462,7 @@
             Parrot_default_charset_ptr = charset;
 
         Parrot_ascii_charset_ptr = charset;
-        return register_charset(charsetname, charset);
+        return register_charset(interp, charsetname, charset);
     }
 
     return 0;
@@ -594,7 +597,7 @@
 
 PARROT_EXPORT
 void
-Parrot_register_charset_converter(SHIM_INTERP,
+Parrot_register_charset_converter(PARROT_INTERP,
         ARGIN(const CHARSET *lhs), ARGIN(CHARSET *rhs),
         ARGIN(charset_converter_t func))
 {
@@ -608,11 +611,11 @@
             const int nc = left->n_converters++;
 
             if (nc) {
-                left->to_converters = (To_converter *)mem_sys_realloc(
-                        left->to_converters, sizeof (To_converter) * (nc + 1));
+                left->to_converters = mem_gc_realloc_n_typed_zeroed(interp,
+                        left->to_converters, nc + 1, nc, To_converter);
             }
             else
-                left->to_converters = (To_converter *)mem_sys_allocate(sizeof (To_converter));
+                left->to_converters = mem_gc_allocate_zeroed_typed(interp, To_converter);
             left->to_converters[nc].to = rhs;
             left->to_converters[nc].func = func;
         }

Modified: branches/sys_mem_reduce/src/string/encoding.c
==============================================================================
--- branches/sys_mem_reduce/src/string/encoding.c	Fri Feb 19 22:44:35 2010	(r44207)
+++ branches/sys_mem_reduce/src/string/encoding.c	Fri Feb 19 22:45:03 2010	(r44208)
@@ -56,7 +56,7 @@
 
 /*
 
-=item C<void parrot_deinit_encodings(void)>
+=item C<void parrot_deinit_encodings(PARROT_INTERP)>
 
 Deinitialize encodings and free all memory used by them.
 
@@ -65,17 +65,17 @@
 */
 
 void
-parrot_deinit_encodings(void)
+parrot_deinit_encodings(PARROT_INTERP)
 {
     ASSERT_ARGS(parrot_deinit_encodings)
     const int n = all_encodings->n_encodings;
     int i;
 
     for (i = 0; i < n; ++i) {
-        mem_sys_free(all_encodings->enc[i].encoding);
+        mem_gc_free(interp, all_encodings->enc[i].encoding);
     }
-    mem_sys_free(all_encodings->enc);
-    mem_sys_free(all_encodings);
+    mem_gc_free(interp, all_encodings->enc);
+    mem_gc_free(interp, all_encodings);
     all_encodings = NULL;
 }
 
@@ -298,7 +298,7 @@
 */
 
 static INTVAL
-register_encoding(SHIM_INTERP, ARGIN(const char *encodingname),
+register_encoding(PARROT_INTERP, ARGIN(const char *encodingname),
         ARGIN(ENCODING *encoding))
 {
     ASSERT_ARGS(register_encoding)
@@ -315,10 +315,10 @@
      * loading of encodings from inside threads
      */
     if (!n)
-        all_encodings->enc = mem_allocate_typed(One_encoding);
+        all_encodings->enc = mem_gc_allocate_zeroed_typed(interp, One_encoding);
     else
-        all_encodings->enc = (One_encoding*)mem_sys_realloc(all_encodings->enc,
-                (n + 1) * sizeof (One_encoding));
+        all_encodings->enc = mem_gc_realloc_n_typed_zeroed(interp,
+                all_encodings->enc, n + 1, n, One_encoding);
     all_encodings->n_encodings++;
     all_encodings->enc[n].encoding = encoding;
 

Modified: branches/sys_mem_reduce/src/string/encoding/utf16.c
==============================================================================
--- branches/sys_mem_reduce/src/string/encoding/utf16.c	Fri Feb 19 22:44:35 2010	(r44207)
+++ branches/sys_mem_reduce/src/string/encoding/utf16.c	Fri Feb 19 22:45:03 2010	(r44208)
@@ -298,7 +298,7 @@
 #if PARROT_HAS_ICU
     if (in_place) {
         /* need intermediate memory */
-        p = (UChar *)mem_sys_allocate(src_len * sizeof (UChar));
+        p = mem_gc_allocate_n_typed(interp, src_len, UChar);
     }
     else {
         Parrot_gc_reallocate_string_storage(interp, dest, sizeof (UChar) * src_len);
@@ -319,7 +319,7 @@
              * have to resize - required len in UChars is in dest_len
              */
             if (in_place)
-                p = (UChar *)mem_sys_realloc(p, dest_len * sizeof (UChar));
+                p = mem_gc_realloc_n_typed(interp, p, dest_len, UChar);
             else {
                 result->bufused = dest_len * sizeof (UChar);
                 Parrot_gc_reallocate_string_storage(interp, dest,
@@ -335,7 +335,7 @@
     if (in_place) {
         Parrot_gc_reallocate_string_storage(interp, src, src->bufused);
         memcpy(src->strstart, p, src->bufused);
-        mem_sys_free(p);
+        mem_gc_free(interp, p);
     }
     result->charset  = Parrot_unicode_charset_ptr;
     result->encoding = Parrot_utf16_encoding_ptr;

Modified: branches/sys_mem_reduce/src/string/encoding/utf8.c
==============================================================================
--- branches/sys_mem_reduce/src/string/encoding/utf8.c	Fri Feb 19 22:44:35 2010	(r44207)
+++ branches/sys_mem_reduce/src/string/encoding/utf8.c	Fri Feb 19 22:45:03 2010	(r44208)
@@ -608,7 +608,7 @@
 
     if (in_place) {
         /* need intermediate memory */
-        p = (unsigned char *)mem_sys_allocate(src_len);
+        p = mem_gc_allocate_n_typed(interp, src_len, unsigned char);
     }
     else {
         Parrot_gc_reallocate_string_storage(interp, dest, src_len);
@@ -631,7 +631,7 @@
                     need = 16;
                 dest_len += need;
                 if (in_place)
-                    p = (unsigned char *)mem_sys_realloc(p, dest_len);
+                    p = mem_gc_realloc_n_typed(interp, p, dest_len, unsigned char);
                 else {
                     result->bufused = dest_pos;
                     Parrot_gc_reallocate_string_storage(interp, dest, dest_len);
@@ -648,7 +648,7 @@
     if (in_place) {
         Parrot_gc_reallocate_string_storage(interp, src, src->bufused);
         memcpy(src->strstart, p, src->bufused);
-        mem_sys_free(p);
+        mem_gc_free(interp, p);
     }
     return result;
 }


More information about the parrot-commits mailing list