[svn:parrot] r49472 - in trunk: include/parrot src

cotto at svn.parrot.org cotto at svn.parrot.org
Thu Oct 7 22:10:18 UTC 2010


Author: cotto
Date: Thu Oct  7 22:10:18 2010
New Revision: 49472
URL: https://trac.parrot.org/parrot/changeset/49472

Log:
[extend] add functions for string registering and unregistering for embedded users

Modified:
   trunk/include/parrot/extend.h
   trunk/src/extend.c

Modified: trunk/include/parrot/extend.h
==============================================================================
--- trunk/include/parrot/extend.h	Thu Oct  7 22:09:35 2010	(r49471)
+++ trunk/include/parrot/extend.h	Thu Oct  7 22:10:18 2010	(r49472)
@@ -151,6 +151,10 @@
         __attribute__nonnull__(1);
 
 PARROT_EXPORT
+void Parrot_register_string(PARROT_INTERP, Parrot_String s)
+        __attribute__nonnull__(1);
+
+PARROT_EXPORT
 void Parrot_set_intreg(PARROT_INTERP, Parrot_Int regnum, Parrot_Int value)
         __attribute__nonnull__(1);
 
@@ -181,6 +185,10 @@
         __attribute__nonnull__(1);
 
 PARROT_EXPORT
+void Parrot_unregister_string(PARROT_INTERP, Parrot_String s)
+        __attribute__nonnull__(1);
+
+PARROT_EXPORT
 int Parrot_vfprintf(PARROT_INTERP,
     ARGIN(Parrot_PMC pio),
     ARGIN(const char *s),
@@ -224,6 +232,8 @@
        PARROT_ASSERT_ARG(s))
 #define ASSERT_ARGS_Parrot_register_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_Parrot_register_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_set_intreg __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_set_numreg __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -238,6 +248,8 @@
     , PARROT_ASSERT_ARG(signature))
 #define ASSERT_ARGS_Parrot_unregister_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_Parrot_unregister_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_vfprintf __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(pio) \

Modified: trunk/src/extend.c
==============================================================================
--- trunk/src/extend.c	Thu Oct  7 22:09:35 2010	(r49471)
+++ trunk/src/extend.c	Thu Oct  7 22:10:18 2010	(r49472)
@@ -595,6 +595,49 @@
 
 /*
 
+=item C<void Parrot_register_string(PARROT_INTERP, Parrot_String s)>
+
+Add a reference of the string to the interpreter's GC registry. This prevents
+strings only known to extension from getting destroyed during GC runs.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+void
+Parrot_register_string(PARROT_INTERP, Parrot_String s)
+{
+    ASSERT_ARGS(Parrot_register_string)
+    PARROT_CALLIN_START(interp);
+    Parrot_str_gc_register(interp, s);
+    PARROT_CALLIN_END(interp);
+}
+
+/*
+
+=item C<void Parrot_unregister_string(PARROT_INTERP, Parrot_String s)>
+
+Remove a reference of the string from the interpreter's GC registry. If the
+reference count reaches zero, the string will be destroyed during the next GC
+run.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+void
+Parrot_unregister_string(PARROT_INTERP, Parrot_String s)
+{
+    ASSERT_ARGS(Parrot_unregister_string)
+    PARROT_CALLIN_START(interp);
+    Parrot_str_gc_unregister(interp, s);
+    PARROT_CALLIN_END(interp);
+}
+
+/*
+
 =item C<Parrot_PMC Parrot_sub_new_from_c_func(PARROT_INTERP, void (*func(void)),
 const char * signature)>
 


More information about the parrot-commits mailing list