[svn:parrot] r45288 - trunk/src/pmc

petdance at svn.parrot.org petdance at svn.parrot.org
Mon Mar 29 23:14:58 UTC 2010


Author: petdance
Date: Mon Mar 29 23:14:57 2010
New Revision: 45288
URL: https://trac.parrot.org/parrot/changeset/45288

Log:
more headerization and consting

Modified:
   trunk/src/pmc/orderedhash.pmc
   trunk/src/pmc/packfile.pmc

Modified: trunk/src/pmc/orderedhash.pmc
==============================================================================
--- trunk/src/pmc/orderedhash.pmc	Mon Mar 29 21:11:42 2010	(r45287)
+++ trunk/src/pmc/orderedhash.pmc	Mon Mar 29 23:14:57 2010	(r45288)
@@ -79,11 +79,66 @@
 
 /* HEADERIZER HFILE: none */
 /* HEADERIZER BEGIN: static */
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
+
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+static PMC* box_integer(PARROT_INTERP, INTVAL val)
+        __attribute__nonnull__(1);
+
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+static PMC* box_number(PARROT_INTERP, FLOATVAL val)
+        __attribute__nonnull__(1);
+
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+static PMC* box_string(PARROT_INTERP, ARGIN(STRING *str))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
+static void find_bounds(PARROT_INTERP,
+    ARGIN(PMC *pmc_hash),
+    ARGMOD(PMC **first),
+    ARGMOD(PMC **last))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        __attribute__nonnull__(3)
+        __attribute__nonnull__(4)
+        FUNC_MODIFIES(*first)
+        FUNC_MODIFIES(*last);
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CAN_RETURN_NULL
+static PMC* get_list_item(PARROT_INTERP, ARGIN(PMC *self), INTVAL idx)
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
+#define ASSERT_ARGS_box_integer __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_box_number __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_box_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(str))
+#define ASSERT_ARGS_find_bounds __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(pmc_hash) \
+    , PARROT_ASSERT_ARG(first) \
+    , PARROT_ASSERT_ARG(last))
+#define ASSERT_ARGS_get_list_item __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(self))
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: static */
 
 /* Get list_item by index */
+/* XXX Can this actually return NULL or not? */
+PARROT_WARN_UNUSED_RESULT
+PARROT_CAN_RETURN_NULL
 static PMC*
-get_list_item(PARROT_INTERP, ARGIN(PMC *self), INTVAL idx) {
+get_list_item(PARROT_INTERP, ARGIN(PMC *self), INTVAL idx)
+{
     const Parrot_OrderedHash_attributes * const attrs = PARROT_ORDEREDHASH(self);
     const INTVAL n = VTABLE_elements(interp, attrs->hash);
     INTVAL                         pos;
@@ -104,7 +159,8 @@
 /* Find first/last in cloned/thawed OrderedHash */
 /* Parameter C<pmc_hash> is Hash, not OrderedHash */
 static void
-find_bounds(PARROT_INTERP, PMC *pmc_hash, PMC **first, PMC **last) {
+find_bounds(PARROT_INTERP, ARGIN(PMC *pmc_hash), ARGMOD(PMC **first), ARGMOD(PMC **last))
+{
     PMC * const iter = VTABLE_get_iter(interp, pmc_hash);
 
     while (VTABLE_get_bool(interp, iter)) {
@@ -122,24 +178,33 @@
 }
 
 /* Helpers for boxing values */
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
 static PMC*
-box_string(PARROT_INTERP, STRING *str) {
+box_string(PARROT_INTERP, ARGIN(STRING *str))
+{
     PMC * const ret = Parrot_pmc_new(interp, Parrot_get_ctx_HLL_type(interp,
                 enum_class_String));
     VTABLE_set_string_native(interp, ret, str);
     return ret;
 }
 
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
 static PMC*
-box_integer(PARROT_INTERP, INTVAL val) {
+box_integer(PARROT_INTERP, INTVAL val)
+{
     PMC * const ret = Parrot_pmc_new(interp, Parrot_get_ctx_HLL_type(interp,
                 enum_class_Integer));
     VTABLE_set_integer_native(interp, ret, val);
     return ret;
 }
 
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
 static PMC*
-box_number(PARROT_INTERP, FLOATVAL val) {
+box_number(PARROT_INTERP, FLOATVAL val)
+{
     PMC * const ret = Parrot_pmc_new(interp, Parrot_get_ctx_HLL_type(interp,
                 enum_class_Float));
     VTABLE_set_number_native(interp, ret, val);

Modified: trunk/src/pmc/packfile.pmc
==============================================================================
--- trunk/src/pmc/packfile.pmc	Mon Mar 29 21:11:42 2010	(r45287)
+++ trunk/src/pmc/packfile.pmc	Mon Mar 29 23:14:57 2010	(r45288)
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2001-2008, Parrot Foundation.
+Copyright (C) 2001-2010, Parrot Foundation.
 $Id$
 
 =head1 NAME
@@ -23,14 +23,30 @@
 
 /* HEADERIZER HFILE: none */
 /* HEADERIZER BEGIN: static */
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
+
+static void copy_packfile_header(PARROT_INTERP,
+    ARGMOD(PMC *self),
+    ARGIN(PackFile *pf))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2)
+        __attribute__nonnull__(3)
+        FUNC_MODIFIES(*self);
+
+#define ASSERT_ARGS_copy_packfile_header __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(self) \
+    , PARROT_ASSERT_ARG(pf))
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: static */
 
 /*
 Copy attributes from PackFile* to Packfile PMC.
 */
 static void
-copy_packfile_header(PARROT_INTERP, PMC *self, PackFile *pf) {
-    Parrot_Packfile_attributes *attrs = PARROT_PACKFILE(self);
+copy_packfile_header(PARROT_INTERP, ARGMOD(PMC *self), ARGIN(PackFile *pf))
+{
+    Parrot_Packfile_attributes * const attrs = PARROT_PACKFILE(self);
 
     attrs->wordsize         = pf->header->wordsize;
     attrs->byteorder        = pf->header->byteorder;
@@ -70,7 +86,7 @@
 
 */
     VTABLE void init() {
-        Parrot_Packfile_attributes *attrs =
+        Parrot_Packfile_attributes * const attrs =
                 PMC_data_typed(SELF, Parrot_Packfile_attributes*);
         PackFile                   *pf;
 
@@ -97,7 +113,7 @@
 */
 
     VTABLE void mark() {
-        Parrot_Packfile_attributes * attrs = PARROT_PACKFILE(SELF);
+        Parrot_Packfile_attributes * const attrs = PARROT_PACKFILE(SELF);
 
         Parrot_gc_mark_STRING_alive(INTERP, attrs->uuid);
         Parrot_gc_mark_PMC_alive(INTERP, attrs->directory);
@@ -114,17 +130,15 @@
 
 */
     VTABLE STRING *get_string() {
-        Parrot_Packfile_attributes * attrs = PARROT_PACKFILE(SELF);
-        PackFile                   * pf =
+        Parrot_Packfile_attributes * const attrs = PARROT_PACKFILE(SELF);
+        PackFile                   * const pf =
                 (PackFile*)VTABLE_get_pointer(interp, attrs->directory);
 
-        opcode_t    length;
-        opcode_t    *ptr;
         STRING      *str;
 
         /* Calculate required memory */
-        length  = PackFile_pack_size(interp, pf) * sizeof (opcode_t);
-        ptr     = (opcode_t*)Parrot_gc_allocate_memory_chunk(INTERP, length);
+        const opcode_t length = PackFile_pack_size(interp, pf) * sizeof (opcode_t);
+        opcode_t * const ptr  = (opcode_t*)Parrot_gc_allocate_memory_chunk(INTERP, length);
 
         /* Copy related attributes to header */
         pf->header->major     = attrs->version_major;
@@ -154,11 +168,10 @@
 Implementation note: taken from the bottom end of Parrot_pbc_read().
 */
     VTABLE void set_string_native(STRING *str) {
-        PackFile        *pf = PackFile_new(interp, 0);
-        const opcode_t  *ptr =
-                (const opcode_t*)Parrot_string_cstring(interp, str);
-        int             length = Parrot_str_byte_length(interp, str);
-        Parrot_Packfile_attributes * attrs = PARROT_PACKFILE(SELF);
+        PackFile  * const pf  = PackFile_new(interp, 0);
+        opcode_t  * const ptr = (const opcode_t*)Parrot_string_cstring(interp, str);
+        const int length      = Parrot_str_byte_length(interp, str);
+        Parrot_Packfile_attributes * const attrs = PARROT_PACKFILE(SELF);
 
         if (!PackFile_unpack(interp, pf, ptr, length)) {
             PackFile_destroy(interp, pf);
@@ -214,7 +227,8 @@
 
 */
     VTABLE INTVAL get_integer_keyed_str(STRING *key) {
-        Parrot_Packfile_attributes *attrs = PARROT_PACKFILE(SELF);
+        Parrot_Packfile_attributes * const attrs = PARROT_PACKFILE(SELF);
+
         if (!Parrot_str_compare(interp, key, CONST_STRING(interp, "wordsize")))
             return attrs->wordsize;
         if (!Parrot_str_compare(interp, key, CONST_STRING(interp, "byteorder")))
@@ -317,7 +331,7 @@
 
 */
     VTABLE void set_integer_keyed_str(STRING *key, INTVAL value) {
-        Parrot_Packfile_attributes *attrs = PARROT_PACKFILE(SELF);
+        Parrot_Packfile_attributes * const attrs = PARROT_PACKFILE(SELF);
         if (!Parrot_str_compare(interp, key, CONST_STRING(interp, "version_major"))) {
             attrs->version_major = value;
             return;
@@ -410,7 +424,7 @@
 */
 
     METHOD pack() {
-        STRING * ret = SELF.get_string();
+        STRING * const ret = SELF.get_string();
         RETURN(STRING * ret);
     }
 
@@ -440,11 +454,9 @@
 
 */
     METHOD get_directory() {
-        PMC *dir = PARROT_PACKFILE(SELF)->directory;
+        PMC * const dir = PARROT_PACKFILE(SELF)->directory;
         RETURN(PMC *dir);
     }
-
-
 }
 /*
 


More information about the parrot-commits mailing list