ruby-changes:67147
From: Nobuyoshi <ko1@a...>
Date: Sat, 14 Aug 2021 11:34:53 +0900 (JST)
Subject: [ruby-changes:67147] a9977ba2f9 (master): Constified addr2line.c
https://git.ruby-lang.org/ruby.git/commit/?id=a9977ba2f9 From a9977ba2f9863e3fb1b2346589ebbca67d80536c Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sat, 14 Aug 2021 10:08:19 +0900 Subject: Constified addr2line.c --- addr2line.c | 136 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/addr2line.c b/addr2line.c index 8ee4416..fed1a8d 100644 --- a/addr2line.c +++ b/addr2line.c @@ -192,12 +192,12 @@ struct debug_section_definition { https://github.com/ruby/ruby/blob/trunk/addr2line.c#L192 static char binary_filename[PATH_MAX + 1]; static unsigned long -uleb128(char **p) +uleb128(const char **p) { unsigned long r = 0; int s = 0; for (;;) { - unsigned char b = *(unsigned char *)(*p)++; + unsigned char b = (unsigned char)*(*p)++; if (b < 0x80) { r += (unsigned long)b << s; break; @@ -209,12 +209,12 @@ uleb128(char **p) https://github.com/ruby/ruby/blob/trunk/addr2line.c#L209 } static long -sleb128(char **p) +sleb128(const char **p) { long r = 0; int s = 0; for (;;) { - unsigned char b = *(unsigned char *)(*p)++; + unsigned char b = (unsigned char)*(*p)++; if (b < 0x80) { if (b & 0x40) { r -= (0x80 - b) << s; @@ -231,7 +231,7 @@ sleb128(char **p) https://github.com/ruby/ruby/blob/trunk/addr2line.c#L231 } static const char * -get_nth_dirname(unsigned long dir, char *p) +get_nth_dirname(unsigned long dir, const char *p) { if (!dir--) { return ""; @@ -249,11 +249,11 @@ get_nth_dirname(unsigned long dir, char *p) https://github.com/ruby/ruby/blob/trunk/addr2line.c#L249 } static void -fill_filename(int file, char *include_directories, char *filenames, line_info_t *line, obj_info_t *obj) +fill_filename(int file, const char *include_directories, const char *filenames, line_info_t *line, obj_info_t *obj) { int i; - char *p = filenames; - char *filename; + const char *p = filenames; + const char *filename; unsigned long dir; for (i = 1; i <= file; i++) { filename = p; @@ -280,7 +280,7 @@ fill_filename(int file, char *include_directories, char *filenames, line_info_t https://github.com/ruby/ruby/blob/trunk/addr2line.c#L280 static void fill_line(int num_traces, void **traces, uintptr_t addr, int file, int line, - char *include_directories, char *filenames, + const char *include_directories, const char *filenames, obj_info_t *obj, line_info_t *lines, int offset) { int i; @@ -374,7 +374,7 @@ parse_debug_line_header(const char **pp, struct LineNumberProgramHeader *header) https://github.com/ruby/ruby/blob/trunk/addr2line.c#L374 } static int -parse_debug_line_cu(int num_traces, void **traces, char **debug_line, +parse_debug_line_cu(int num_traces, void **traces, const char **debug_line, obj_info_t *obj, line_info_t *lines, int offset) { const char *p = (const char *)*debug_line; @@ -399,8 +399,8 @@ parse_debug_line_cu(int num_traces, void **traces, char **debug_line, https://github.com/ruby/ruby/blob/trunk/addr2line.c#L399 #define FILL_LINE() \ do { \ fill_line(num_traces, traces, addr, file, line, \ - (char *)header.include_directories, \ - (char *)header.filenames, \ + header.include_directories, \ + header.filenames, \ obj, lines, offset); \ /*basic_block = prologue_end = epilogue_begin = 0;*/ \ } while (0) @@ -413,19 +413,19 @@ parse_debug_line_cu(int num_traces, void **traces, char **debug_line, https://github.com/ruby/ruby/blob/trunk/addr2line.c#L413 FILL_LINE(); break; case DW_LNS_advance_pc: - a = uleb128((char **)&p) * header.minimum_instruction_length; + a = uleb128(&p) * header.minimum_instruction_length; addr += a; break; case DW_LNS_advance_line: { - long a = sleb128((char **)&p); + long a = sleb128(&p); line += a; break; } case DW_LNS_set_file: - file = (unsigned int)uleb128((char **)&p); + file = (unsigned int)uleb128(&p); break; case DW_LNS_set_column: - /*column = (unsigned int)*/(void)uleb128((char **)&p); + /*column = (unsigned int)*/(void)uleb128(&p); break; case DW_LNS_negate_stmt: is_stmt = !is_stmt; @@ -450,10 +450,10 @@ parse_debug_line_cu(int num_traces, void **traces, char **debug_line, https://github.com/ruby/ruby/blob/trunk/addr2line.c#L450 /* epilogue_begin = 1; */ break; case DW_LNS_set_isa: - /* isa = (unsigned int)*/(void)uleb128((char **)&p); + /* isa = (unsigned int)*/(void)uleb128(&p); break; case 0: - a = uleb128((char **)&p); + a = uleb128(&p); op = *p++; switch (op) { case DW_LNE_end_sequence: @@ -477,7 +477,7 @@ parse_debug_line_cu(int num_traces, void **traces, char **debug_line, https://github.com/ruby/ruby/blob/trunk/addr2line.c#L477 break; case DW_LNE_set_discriminator: /* TODO:currently ignore */ - uleb128((char **)&p); + uleb128(&p); break; default: kprintf("Unknown extended opcode: %d in %s\n", @@ -500,10 +500,10 @@ parse_debug_line_cu(int num_traces, void **traces, char **debug_line, https://github.com/ruby/ruby/blob/trunk/addr2line.c#L500 static int parse_debug_line(int num_traces, void **traces, - char *debug_line, unsigned long size, + const char *debug_line, unsigned long size, obj_info_t *obj, line_info_t *lines, int offset) { - char *debug_line_end = debug_line + size; + const char *debug_line_end = debug_line + size; while (debug_line < debug_line_end) { if (parse_debug_line_cu(num_traces, traces, &debug_line, obj, lines, offset)) return -1; @@ -833,21 +833,21 @@ enum { https://github.com/ruby/ruby/blob/trunk/addr2line.c#L833 # define ABBREV_TABLE_SIZE 256 typedef struct { obj_info_t *obj; - char *file; - char *current_cu; + const char *file; + const char *current_cu; uint64_t current_low_pc; - char *debug_line_cu_end; - char *debug_line_files; - char *debug_line_directories; - char *p; - char *cu_end; - char *pend; - char *q0; - char *q; + const char *debug_line_cu_end; + const char *debug_line_files; + const char *debug_line_directories; + const char *p; + const char *cu_end; + const char *pend; + const char *q0; + const char *q; int format; // 4 or 8 uint8_t address_size; int level; - char *abbrev_table[ABBREV_TABLE_SIZE]; + const char *abbrev_table[ABBREV_TABLE_SIZE]; } DebugInfoReader; typedef struct { @@ -858,7 +858,7 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/addr2line.c#L858 typedef struct { union { - char *ptr; + const char *ptr; uint64_t uint64; int64_t int64; } as; @@ -891,39 +891,39 @@ get_uint64(const uint8_t *p) https://github.com/ruby/ruby/blob/trunk/addr2line.c#L891 } static uint8_t -read_uint8(char **ptr) +read_uint8(const char **ptr) { - const unsigned char *p = (const unsigned char *)*ptr; - *ptr = (char *)(p + 1); - return *p; + const char *p = *ptr; + *ptr = (p + 1); + return (uint8_t)*p; } static uint16_t -read_uint16(char **ptr) +read_uint16(const char **ptr) { - const unsigned char *p = (const unsigned char *)*ptr; - *ptr = (char *)(p + 2); - return get_uint16(p); + const char *p = *ptr; + *ptr = (p + 2); + return get_uint16((const uint8_t *)p); } static uint32_t -read_uint24(char **ptr) +read_uint24(const char **ptr) { - const unsigned char *p = (const unsigned char *)*ptr; - *ptr = (char *)(p + 3); - return (*p << 16) | get_uint16(p+1); + const char *p = *ptr; + *ptr = (p + 3); + return ((uint8_t)*p << 16) | get_uint16((const uint8_t *)p+1); } static uint32_t -read_uint32(char **ptr) +read_uint32(const char **ptr) { - const unsigned char *p = (const unsigned char *)*ptr; - *ptr = (char *)(p + 4); - return get_uint32(p); + const char *p = *ptr; + *ptr = (p + 4); + return get_uint32((const uint8_t *)p); } static uint64_t -read_uint64(char **ptr) +read_uint64(const char **ptr) { const unsigned char *p = (const unsigned char *)*ptr; *ptr = (char *)(p + 8); @@ -931,7 +931,7 @@ read_uint64(char **ptr) https://github.com/ruby/ruby/blob/trunk/addr2line.c#L931 } static uintptr_t -read_uintptr(char **ptr) +read_uintptr(const char **ptr) { const unsigned char *p = (const unsigned char *)*ptr; *ptr = (char *)(p + SIZEOF_VOIDP); @@ -976,7 +976,7 @@ debug_info_reader_init(DebugInfoReader *reader, obj_info_t *obj) https://github.com/ruby/ruby/blob/trunk/addr2line.c#L976 } static void -di_skip_die_attributes(char **p) +di_skip_die_attributes(const char **p) { for (;;) { uint64_t at = uleb128(p); @@ -996,7 +996,7 @@ static void https://github.com/ruby/ruby/blob/trunk/addr2line.c#L996 di_read_debug_abbrev_cu(DebugInfoReader *reader) { uint64_t prev = 0; - char *p = reader->q0; + const char *p = reader->q0; for (;;) { uint64_t abbrev_number = uleb128(&p); if (abbrev_number <= prev) break; @@ -1042,7 +1042,7 @@ set_int_value(DebugInfoValue *v, int64_t n) https://github.com/ruby/ruby/blob/trunk/addr2line.c#L1042 } static void -set_cstr_value(DebugInfoValue *v, char *s) +set_cstr_value(DebugInfoValue *v, const char *s) { v->as.ptr = s; v->off = 0; @@ -1050,7 +1050,7 @@ set_cstr_value(DebugInfoValue *v, char *s) https://github.com/ruby/ruby/blob/trunk/addr2line.c#L1050 } static void -set_cstrp_value(DebugInfoValue *v, char *s, uint64_t off) +set_cstrp_value(DebugInfoValue *v, const char *s, uint64_t off) { v->as.ptr = s; v->off = off; @@ -1058,7 +1058,7 @@ set_cstrp_value(DebugInfoValue *v, char *s, uint64_t off) https://github.com/ruby/ruby/blob/trunk/addr2line.c#L1058 } static void -set_data_value(DebugI (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/