[svn:parrot] r44397 - in branches/boehm_gc_2: include/parrot src/gc

bacek at svn.parrot.org bacek at svn.parrot.org
Tue Feb 23 19:47:58 UTC 2010


Author: bacek
Date: Tue Feb 23 19:47:58 2010
New Revision: 44397
URL: https://trac.parrot.org/parrot/changeset/44397

Log:
Expose strdup via GC Subsystem

Modified:
   branches/boehm_gc_2/include/parrot/gc_api.h
   branches/boehm_gc_2/src/gc/api.c
   branches/boehm_gc_2/src/gc/gc_boehm.c
   branches/boehm_gc_2/src/gc/gc_ms.c
   branches/boehm_gc_2/src/gc/gc_private.h

Modified: branches/boehm_gc_2/include/parrot/gc_api.h
==============================================================================
--- branches/boehm_gc_2/include/parrot/gc_api.h	Tue Feb 23 19:47:31 2010	(r44396)
+++ branches/boehm_gc_2/include/parrot/gc_api.h	Tue Feb 23 19:47:58 2010	(r44397)
@@ -316,6 +316,10 @@
         __attribute__nonnull__(2)
         FUNC_MODIFIES(*str);
 
+char* Parrot_gc_strdup(PARROT_INTERP, ARGIN(const char * const str))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
 PARROT_CANNOT_RETURN_NULL
 STRING * Parrot_gc_sys_name(PARROT_INTERP)
         __attribute__nonnull__(1);
@@ -458,6 +462,9 @@
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(str))
+#define ASSERT_ARGS_Parrot_gc_strdup __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(str))
 #define ASSERT_ARGS_Parrot_gc_sys_name __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_gc_total_copied __attribute__unused__ int _ASSERT_ARGS_CHECK = (\

Modified: branches/boehm_gc_2/src/gc/api.c
==============================================================================
--- branches/boehm_gc_2/src/gc/api.c	Tue Feb 23 19:47:31 2010	(r44396)
+++ branches/boehm_gc_2/src/gc/api.c	Tue Feb 23 19:47:58 2010	(r44397)
@@ -313,6 +313,7 @@
     PARROT_ASSERT(interp->gc_sys->allocate_memory_chunk_with_interior_pointers);
     PARROT_ASSERT(interp->gc_sys->reallocate_memory_chunk_with_interior_pointers);
     PARROT_ASSERT(interp->gc_sys->free_memory_chunk);
+    PARROT_ASSERT(interp->gc_sys->gc_strdup);
 
     PARROT_ASSERT(interp->gc_sys->get_gc_info);
 }
@@ -761,6 +762,21 @@
             data, newsize, oldsize);
 }
 
+/*
+
+=item C<char* Parrot_gc_strdup(PARROT_INTERP, const char * const str)>
+
+Strdup using GC Subsystem.
+
+=cut
+
+*/
+char*
+Parrot_gc_strdup(PARROT_INTERP, ARGIN(const char * const str))
+{
+    ASSERT_ARGS(Parrot_gc_strdup)
+    return interp->gc_sys->gc_strdup(interp, str);
+}
 
 /*
 

Modified: branches/boehm_gc_2/src/gc/gc_boehm.c
==============================================================================
--- branches/boehm_gc_2/src/gc/gc_boehm.c	Tue Feb 23 19:47:31 2010	(r44396)
+++ branches/boehm_gc_2/src/gc/gc_boehm.c	Tue Feb 23 19:47:58 2010	(r44397)
@@ -135,6 +135,9 @@
     size_t size)
         __attribute__nonnull__(1);
 
+static char* gc_boehm_strdup(PARROT_INTERP, const char * const str)
+        __attribute__nonnull__(1);
+
 static void gc_boehm_unblock_mark(PARROT_INTERP)
         __attribute__nonnull__(1);
 
@@ -202,6 +205,8 @@
 #define ASSERT_ARGS_gc_boehm_reallocate_string_storage \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_gc_boehm_strdup __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_gc_boehm_unblock_mark __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
@@ -510,6 +515,13 @@
         GC_FREE(data);
 }
 
+static char*
+gc_boehm_strdup(PARROT_INTERP, const char * const str)
+{
+    ASSERT_ARGS(gc_boehm_strdup)
+    return GC_STRDUP(str);
+}
+
 /*
 
 =item C<static size_t gc_boehm_get_gc_info(PARROT_INTERP, Interpinfo_enum what)>
@@ -652,6 +664,7 @@
     gc_sys->reallocate_memory_chunk_with_interior_pointers
                 = gc_boehm_reallocate_memory_chunk_zeroed;
     gc_sys->free_memory_chunk       = gc_boehm_free_memory_chunk;
+    gc_sys->gc_strdup               = gc_boehm_strdup;
 
     gc_sys->block_mark      = gc_boehm_block_mark;
     gc_sys->unblock_mark    = gc_boehm_unblock_mark;

Modified: branches/boehm_gc_2/src/gc/gc_ms.c
==============================================================================
--- branches/boehm_gc_2/src/gc/gc_ms.c	Tue Feb 23 19:47:31 2010	(r44396)
+++ branches/boehm_gc_2/src/gc/gc_ms.c	Tue Feb 23 19:47:58 2010	(r44397)
@@ -391,6 +391,7 @@
     interp->gc_sys->reallocate_memory_chunk_with_interior_pointers
                 = gc_ms_reallocate_memory_chunk_zeroed;
     interp->gc_sys->free_memory_chunk       = gc_ms_free_memory_chunk;
+    interp->gc_sys->gc_strdup               = gc_ms_strdup;
 
     interp->gc_sys->block_mark      = gc_ms_block_GC_mark;
     interp->gc_sys->unblock_mark    = gc_ms_unblock_GC_mark;
@@ -1186,6 +1187,32 @@
         free(data);
 }
 
+/*
+
+=item C<char * gc_ms_strdup(PARROT_INTERP, const char * const src)>
+
+Copy a C string to a new block of memory allocated with mem_sys_allocate,
+that can be later deallocated with mem_sys_free.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+PARROT_MALLOC
+PARROT_CANNOT_RETURN_NULL
+char *
+gc_ms_strdup(PARROT_INTERP, ARGIN(const char * const src))
+{
+    ASSERT_ARGS(gc_ms_strdup)
+
+    const size_t l = strlen(src);
+    char * const result = (char *)gc_ms_allocate_memory_chunk(interp, l + 1);
+    memcpy(result, src, l);
+    result[l] = '\0';
+    return result;
+}
+
 
 /*
 

Modified: branches/boehm_gc_2/src/gc/gc_private.h
==============================================================================
--- branches/boehm_gc_2/src/gc/gc_private.h	Tue Feb 23 19:47:31 2010	(r44396)
+++ branches/boehm_gc_2/src/gc/gc_private.h	Tue Feb 23 19:47:58 2010	(r44397)
@@ -142,6 +142,8 @@
             size_t oldsize, size_t newsize);
     void (*free_memory_chunk)(PARROT_INTERP, void *data);
 
+    char* (*gc_strdup)(PARROT_INTERP, const char * const str);
+
     void (*block_mark)(PARROT_INTERP);
     void (*unblock_mark)(PARROT_INTERP);
     unsigned int (*is_blocked_mark)(PARROT_INTERP);
@@ -598,6 +600,13 @@
 /* HEADERIZER BEGIN: src/gc/gc_ms.c */
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 
+PARROT_EXPORT
+PARROT_MALLOC
+PARROT_CANNOT_RETURN_NULL
+char * gc_ms_strdup(PARROT_INTERP, ARGIN(const char * const src))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
 PARROT_CANNOT_RETURN_NULL
 void * gc_ms_allocate_fixed_size_storage(PARROT_INTERP, size_t size)
         __attribute__nonnull__(1);
@@ -638,6 +647,9 @@
 void Parrot_gc_ms_init(PARROT_INTERP)
         __attribute__nonnull__(1);
 
+#define ASSERT_ARGS_gc_ms_strdup __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(src))
 #define ASSERT_ARGS_gc_ms_allocate_fixed_size_storage \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))


More information about the parrot-commits mailing list