[svn:parrot] r40818 - in trunk: include/parrot src src/gc
NotFound at svn.parrot.org
NotFound at svn.parrot.org
Wed Aug 26 11:31:42 UTC 2009
Author: NotFound
Date: Wed Aug 26 11:31:41 2009
New Revision: 40818
URL: https://trac.parrot.org/parrot/changeset/40818
Log:
[core] centralize PMC destruction in one function
Modified:
trunk/include/parrot/pmc.h
trunk/src/gc/mark_sweep.c
trunk/src/pmc.c
Modified: trunk/include/parrot/pmc.h
==============================================================================
--- trunk/include/parrot/pmc.h Wed Aug 26 10:13:44 2009 (r40817)
+++ trunk/include/parrot/pmc.h Wed Aug 26 11:31:41 2009 (r40818)
@@ -54,6 +54,11 @@
__attribute__nonnull__(1);
PARROT_EXPORT
+void Parrot_pmc_destroy(PARROT_INTERP, ARGIN(PMC *pmc))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_EXPORT
INTVAL PMC_is_null(SHIM_INTERP, ARGIN_NULLOK(const PMC *pmc));
PARROT_EXPORT
@@ -149,6 +154,9 @@
|| PARROT_ASSERT_ARG(pmc)
#define ASSERT_ARGS_Parrot_create_mro __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
+#define ASSERT_ARGS_Parrot_pmc_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(pmc)
#define ASSERT_ARGS_PMC_is_null __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
#define ASSERT_ARGS_pmc_new __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
Modified: trunk/src/gc/mark_sweep.c
==============================================================================
--- trunk/src/gc/mark_sweep.c Wed Aug 26 10:13:44 2009 (r40817)
+++ trunk/src/gc/mark_sweep.c Wed Aug 26 11:31:41 2009 (r40818)
@@ -778,28 +778,7 @@
if (PObj_needs_early_gc_TEST(p))
--arena_base->num_early_gc_PMCs;
- if (PObj_active_destroy_TEST(p))
- VTABLE_destroy(interp, pmc);
-
- if (PMC_data(pmc) && pmc->vtable->attr_size) {
-#if GC_USE_FIXED_SIZE_ALLOCATOR
- Parrot_gc_free_pmc_attributes(interp, pmc, pmc->vtable->attr_size);
-#else
- mem_sys_free(PMC_data(pmc));
- PMC_data(pmc) = NULL;
-#endif
- }
- else {
- PMC_data(pmc) = NULL;
- }
-
-
-#ifndef NDEBUG
-
- pmc->vtable = (VTABLE *)0xdeadbeef;
-
-#endif
-
+ Parrot_pmc_destroy(interp, pmc);
}
Modified: trunk/src/pmc.c
==============================================================================
--- trunk/src/pmc.c Wed Aug 26 10:13:44 2009 (r40817)
+++ trunk/src/pmc.c Wed Aug 26 11:31:41 2009 (r40818)
@@ -91,6 +91,54 @@
/*
+=item C<void Parrot_pmc_destroy(PARROT_INTERP, PMC *pmc)>
+
+Destroy a PMC. Call his destroy vtable function if needed, and deallocate
+his attributes if they are automatically allocated.
+
+For internal usage of the PMC handling functions and garbage collection
+subsystem.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+void
+Parrot_pmc_destroy(PARROT_INTERP, ARGIN(PMC *pmc))
+{
+ ASSERT_ARGS(Parrot_pmc_destroy)
+
+ if (PObj_active_destroy_TEST(pmc)) {
+ VTABLE_destroy(interp, pmc);
+ /* Prevent repeated calls. */
+ PObj_active_destroy_CLEAR(pmc);
+ }
+
+ if (pmc->vtable->attr_size) {
+ if (PMC_data(pmc)) {
+#if GC_USE_FIXED_SIZE_ALLOCATOR
+ Parrot_gc_free_pmc_attributes(interp, pmc, pmc->vtable->attr_size);
+#else
+ mem_sys_free(PMC_data(pmc));
+ PMC_data(pmc) = NULL;
+#endif
+ }
+ }
+ else {
+ PMC_data(pmc) = NULL;
+ }
+
+#ifndef NDEBUG
+
+ pmc->vtable = (VTABLE *)0xdeadbeef;
+
+#endif
+
+}
+
+/*
+
=item C<PMC * pmc_new(PARROT_INTERP, INTVAL base_type)>
Creates a new PMC of type C<base_type> (which is an index into the list of PMC
@@ -218,17 +266,8 @@
/* Singleton/const PMCs/types are not eligible */
check_pmc_reuse_flags(interp, pmc->vtable->flags, new_vtable->flags);
- /* Does the old PMC need any resources freed? */
- if (PObj_active_destroy_TEST(pmc))
- VTABLE_destroy(interp, pmc);
-
- if (PMC_data(pmc) && pmc->vtable->attr_size) {
-#if GC_USE_FIXED_SIZE_ALLOCATOR
- Parrot_gc_free_pmc_attributes(interp, pmc, pmc->vtable->attr_size);
-#else
- mem_sys_free(PMC_data(pmc));
-#endif
- }
+ /* Free the old PMC resources. */
+ Parrot_pmc_destroy(interp, pmc);
PObj_flags_SETTO(pmc, PObj_is_PMC_FLAG | new_flags);
@@ -280,15 +319,23 @@
/* Singleton/const PMCs/types are not eligible */
check_pmc_reuse_flags(interp, pmc->vtable->flags, new_vtable->flags);
- /* Does the old PMC need any resources freed? */
- if (PObj_active_destroy_TEST(pmc))
- VTABLE_destroy(interp, pmc);
+ Parrot_pmc_destroy(interp, pmc);
PObj_flags_SETTO(pmc, PObj_is_PMC_FLAG | new_flags);
/* Set the right vtable */
pmc->vtable = new_vtable;
+ if (new_vtable->attr_size) {
+#if GC_USE_FIXED_SIZE_ALLOCATOR
+ Parrot_gc_allocate_pmc_attributes(interp, pmc, new_vtable->attr_size);
+#else
+ PMC_data(pmc) = mem_sys_allocate_zeroed(new_vtable->attr_size);
+#endif
+}
+ else
+ PMC_data(pmc) = NULL;
+
return pmc;
}
More information about the parrot-commits
mailing list