[svn:parrot] r49471 - in trunk: include/parrot src/string

cotto at svn.parrot.org cotto at svn.parrot.org
Thu Oct 7 22:09:36 UTC 2010


Author: cotto
Date: Thu Oct  7 22:09:35 2010
New Revision: 49471
URL: https://trac.parrot.org/parrot/changeset/49471

Log:
[gc] add internal functions for string registering and unregistering

Modified:
   trunk/include/parrot/string_funcs.h
   trunk/src/string/api.c

Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h	Thu Oct  7 22:07:28 2010	(r49470)
+++ trunk/include/parrot/string_funcs.h	Thu Oct  7 22:09:35 2010	(r49471)
@@ -206,6 +206,16 @@
         __attribute__nonnull__(1);
 
 PARROT_EXPORT
+void Parrot_str_gc_register(PARROT_INTERP, ARGIN(STRING *s))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
+PARROT_EXPORT
+void Parrot_str_gc_unregister(PARROT_INTERP, ARGIN(STRING *s))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
+PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 INTVAL Parrot_str_indexed(PARROT_INTERP, ARGIN(const STRING *s), INTVAL idx)
         __attribute__nonnull__(1)
@@ -540,6 +550,12 @@
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_str_from_num __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_Parrot_str_gc_register __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(s))
+#define ASSERT_ARGS_Parrot_str_gc_unregister __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(s))
 #define ASSERT_ARGS_Parrot_str_indexed __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(s))

Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c	Thu Oct  7 22:07:28 2010	(r49470)
+++ trunk/src/string/api.c	Thu Oct  7 22:09:35 2010	(r49471)
@@ -3213,6 +3213,54 @@
     return Parrot_str_from_uint(interp, tc, (UHUGEINTVAL)num, base, is_neg);
 }
 
+/*
+  
+=back
+
+=head2 GC registry interface
+
+=over 4
+
+=item C<void Parrot_str_gc_register(PARROT_INTERP, STRING *s)>
+
+Registers the STRING from the interpreter's GC registry to prevent it from
+being collected.
+
+*/
+
+
+PARROT_EXPORT
+void
+Parrot_str_gc_register(PARROT_INTERP, ARGIN(STRING *s))
+{   
+    ASSERT_ARGS(Parrot_str_gc_register)
+    /* Better not trigger a GC run with a potentially unanchored PMC */
+    Parrot_block_GC_mark(interp);
+
+    PARROT_ASSERT(interp->gc_registry);
+
+    VTABLE_set_pmc_keyed_str(interp, interp->gc_registry, s, PMCNULL);
+    Parrot_unblock_GC_mark(interp);
+}
+
+/*
+  
+=item C<void Parrot_str_gc_unregister(PARROT_INTERP, STRING *s)>
+
+Unregisters the STRING from the interpreter's GC registry.
+
+*/
+
+PARROT_EXPORT
+void
+Parrot_str_gc_unregister(PARROT_INTERP, ARGIN(STRING *s))
+{
+    ASSERT_ARGS(Parrot_str_gc_unregister)
+    PARROT_ASSERT(interp->gc_registry);
+
+    VTABLE_delete_keyed_str(interp, interp->gc_registry, s);
+}
+
 
 /*
 


More information about the parrot-commits mailing list