[commit: ghc] master: RtsFlags: Fix const warning (d585073)

git at git.haskell.org git at git.haskell.org
Sat Nov 21 16:15:39 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/d585073d582d82fae80781dc23176b1ef59527a9/ghc

>---------------------------------------------------------------

commit d585073d582d82fae80781dc23176b1ef59527a9
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Sat Nov 21 15:48:09 2015 +0100

    RtsFlags: Fix const warning
    
    Reviewers: austin
    
    Reviewed By: austin
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D1509


>---------------------------------------------------------------

d585073d582d82fae80781dc23176b1ef59527a9
 includes/rts/Flags.h | 14 +++++++-------
 rts/ProfHeap.c       |  4 ++--
 rts/ProfHeap.h       |  2 +-
 rts/RtsFlags.c       |  9 ++++++++-
 4 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/includes/rts/Flags.h b/includes/rts/Flags.h
index 878e0f1..9321b4d 100644
--- a/includes/rts/Flags.h
+++ b/includes/rts/Flags.h
@@ -131,13 +131,13 @@ typedef struct _PROFILING_FLAGS {
 
     nat                 ccsLength;
 
-    char*               modSelector;
-    char*               descrSelector;
-    char*               typeSelector;
-    char*               ccSelector;
-    char*               ccsSelector;
-    char*               retainerSelector;
-    char*               bioSelector;
+    const char*         modSelector;
+    const char*         descrSelector;
+    const char*         typeSelector;
+    const char*         ccSelector;
+    const char*         ccsSelector;
+    const char*         retainerSelector;
+    const char*         bioSelector;
 
 } PROFILING_FLAGS;
 
diff --git a/rts/ProfHeap.c b/rts/ProfHeap.c
index bfb8aaa..43bd7b4 100644
--- a/rts/ProfHeap.c
+++ b/rts/ProfHeap.c
@@ -549,9 +549,9 @@ fprint_ccs(FILE *fp, CostCentreStack *ccs, nat max_length)
 }
 
 rtsBool
-strMatchesSelector( char* str, char* sel )
+strMatchesSelector( const char* str, const char* sel )
 {
-   char* p;
+   const char* p;
    // debugBelch("str_matches_selector %s %s\n", str, sel);
    while (1) {
        // Compare str against wherever we've got to in sel.
diff --git a/rts/ProfHeap.h b/rts/ProfHeap.h
index b3bed90..e29a9f6 100644
--- a/rts/ProfHeap.h
+++ b/rts/ProfHeap.h
@@ -14,7 +14,7 @@
 void    heapCensus         (Time t);
 nat     initHeapProfiling  (void);
 void    endHeapProfiling   (void);
-rtsBool strMatchesSelector (char* str, char* sel);
+rtsBool strMatchesSelector (const char* str, const char* sel);
 
 #include "EndPrivate.h"
 
diff --git a/rts/RtsFlags.c b/rts/RtsFlags.c
index e305128..9457279 100644
--- a/rts/RtsFlags.c
+++ b/rts/RtsFlags.c
@@ -1531,9 +1531,15 @@ static void read_debug_flags(const char* arg)
 
 #ifdef PROFILING
 // Parse a "-h" flag, returning whether the parse resulted in an error.
-static rtsBool read_heap_profiling_flag(const char *arg)
+static rtsBool read_heap_profiling_flag(const char *arg_in)
 {
     // Already parsed "-h"
+
+    // For historical reasons the parser here mutates the arguments.
+    // However, for sanity we want to guarantee const-correctness and parsing
+    // really ought to be an immutable operation. To avoid rewriting the parser
+    // we just operate on a temporary copy of the argument.
+    char *arg = strdup(arg_in);
     rtsBool error = rtsFalse;
     switch (arg[2]) {
     case '\0':
@@ -1638,6 +1644,7 @@ static rtsBool read_heap_profiling_flag(const char *arg)
         error = rtsTrue;
     }
 
+    free(arg);
     return error;
 }
 #endif



More information about the ghc-commits mailing list