[svn:parrot] r44484 - in trunk: include/parrot src src/packfile

plobsing at svn.parrot.org plobsing at svn.parrot.org
Fri Feb 26 00:08:17 UTC 2010


Author: plobsing
Date: Fri Feb 26 00:08:16 2010
New Revision: 44484
URL: https://trac.parrot.org/parrot/changeset/44484

Log:
add PF_size_strlen() function to get the storage size of a string without having allocated the string

add assertion the ImageIOSize derived size is identical to ImageIO size

Modified:
   trunk/include/parrot/packfile.h
   trunk/include/parrot/pmc_freeze.h
   trunk/src/packfile.c
   trunk/src/packfile/pf_items.c
   trunk/src/pmc_freeze.c

Modified: trunk/include/parrot/packfile.h
==============================================================================
--- trunk/include/parrot/packfile.h	Thu Feb 25 23:59:54 2010	(r44483)
+++ trunk/include/parrot/packfile.h	Fri Feb 26 00:08:16 2010	(r44484)
@@ -1091,6 +1091,9 @@
 size_t PF_size_string(ARGIN(const STRING *s))
         __attribute__nonnull__(1);
 
+PARROT_PURE_FUNCTION
+size_t PF_size_strlen(const UINTVAL len);
+
 PARROT_WARN_UNUSED_RESULT
 PARROT_CANNOT_RETURN_NULL
 opcode_t* PF_store_cstring(ARGOUT(opcode_t *cursor), ARGIN(const char *s))
@@ -1148,6 +1151,7 @@
 #define ASSERT_ARGS_PF_size_opcode __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
 #define ASSERT_ARGS_PF_size_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(s))
+#define ASSERT_ARGS_PF_size_strlen __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
 #define ASSERT_ARGS_PF_store_cstring __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(cursor) \
     , PARROT_ASSERT_ARG(s))

Modified: trunk/include/parrot/pmc_freeze.h
==============================================================================
--- trunk/include/parrot/pmc_freeze.h	Thu Feb 25 23:59:54 2010	(r44483)
+++ trunk/include/parrot/pmc_freeze.h	Fri Feb 26 00:08:16 2010	(r44484)
@@ -121,7 +121,7 @@
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
-INTVAL Parrot_freeze_size(PARROT_INTERP, ARGIN(PMC *pmc))
+UINTVAL Parrot_freeze_size(PARROT_INTERP, ARGIN(PMC *pmc))
         __attribute__nonnull__(1)
         __attribute__nonnull__(2);
 

Modified: trunk/src/packfile.c
==============================================================================
--- trunk/src/packfile.c	Thu Feb 25 23:59:54 2010	(r44483)
+++ trunk/src/packfile.c	Fri Feb 26 00:08:16 2010	(r44484)
@@ -3915,9 +3915,7 @@
 
       case PFC_PMC:
         component = self->u.key; /* the pmc (Sub, ...) */
-
-        packed_size =
-            PF_size_string(STRINGNULL) + Parrot_freeze_size(interp, component) / sizeof (opcode_t);
+        packed_size = PF_size_strlen(Parrot_freeze_size(interp, component));
         break;
 
       default:

Modified: trunk/src/packfile/pf_items.c
==============================================================================
--- trunk/src/packfile/pf_items.c	Thu Feb 25 23:59:54 2010	(r44483)
+++ trunk/src/packfile/pf_items.c	Fri Feb 26 00:08:16 2010	(r44484)
@@ -1402,7 +1402,7 @@
 
 /*
 
-=item C<size_t PF_size_string(const STRING *s)>
+=item C<size_t PF_size_strlen(const STRING *s)>
 
 Reports stored size of C<STRING> in C<opcode_t> units.
 
@@ -1415,7 +1415,27 @@
 PF_size_string(ARGIN(const STRING *s))
 {
     ASSERT_ARGS(PF_size_string)
-    opcode_t padded_size = s->bufused;
+    /* TODO: don't break encapsulation on strings */
+    const UINTVAL len = s->bufused;
+    return PF_size_strlen(len);
+}
+
+/*
+
+=item C<size_t PF_size_string(const UINTVAL len)>
+
+Reports stored size of C<STRING> in C<opcode_t> units given its in-memory byte length.
+
+=cut
+
+*/
+
+PARROT_PURE_FUNCTION
+size_t
+PF_size_strlen(const UINTVAL len)
+{
+    ASSERT_ARGS(PF_size_strlen)
+    opcode_t padded_size = len;
 
     if (padded_size % sizeof (opcode_t)) {
         padded_size += sizeof (opcode_t) - (padded_size % sizeof (opcode_t));

Modified: trunk/src/pmc_freeze.c
==============================================================================
--- trunk/src/pmc_freeze.c	Thu Feb 25 23:59:54 2010	(r44483)
+++ trunk/src/pmc_freeze.c	Fri Feb 26 00:08:16 2010	(r44484)
@@ -61,7 +61,7 @@
 
 /*
 
-=item C<INTVAL Parrot_freeze_size(PARROT_INTERP, PMC *pmc)>
+=item C<UINTVAL Parrot_freeze_size(PARROT_INTERP, PMC *pmc)>
 
 Get the size of an image to be frozen without allocating a large buffer.
 
@@ -74,15 +74,25 @@
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
-INTVAL
+UINTVAL
 Parrot_freeze_size(PARROT_INTERP, ARGIN(PMC *pmc))
 {
     ASSERT_ARGS(Parrot_freeze_size)
-    PMC *result;
-    PMC *visitor = Parrot_pmc_new(interp, enum_class_ImageIOSize);
+    UINTVAL int_result;
+    PMC    *pmc_result;
+    PMC    *visitor = Parrot_pmc_new(interp, enum_class_ImageIOSize);
     VTABLE_set_pmc(interp, visitor, pmc);
-    result = VTABLE_get_pmc(interp, visitor);
-    return VTABLE_get_integer(interp, result);
+    pmc_result = VTABLE_get_pmc(interp, visitor);
+    int_result = VTABLE_get_integer(interp, pmc_result);
+
+    {
+        /* XXX remove once bug found */
+        STRING *image = Parrot_freeze(interp, pmc);
+        const UINTVAL check_result =image->bufused;
+        PARROT_ASSERT(check_result == int_result);
+    }
+
+    return int_result;
 }
 
 


More information about the parrot-commits mailing list