diff options
| author | bors <bors@rust-lang.org> | 2013-09-04 13:05:50 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-09-04 13:05:50 -0700 |
| commit | 60fba4d7d677ec098e6a43014132fe99f7547363 (patch) | |
| tree | 4d66a75328a72b86972dc9c0973e619fadc206c7 /src/rt | |
| parent | 45c3ca72bc19230f82775eb4228f1b3f178baade (diff) | |
| parent | e38739bb442263f1ef67b6c2415f932aa49e6646 (diff) | |
| download | rust-60fba4d7d677ec098e6a43014132fe99f7547363.tar.gz rust-60fba4d7d677ec098e6a43014132fe99f7547363.zip | |
auto merge of #8880 : fhahn/rust/issue_8703, r=brson
I've started working on #8703. RUST_LOG="::help" should work, I hope I'll be able to finish the rest this weekend.
Diffstat (limited to 'src/rt')
| -rw-r--r-- | src/rt/rust_crate_map.cpp | 38 | ||||
| -rw-r--r-- | src/rt/rust_crate_map.h | 14 | ||||
| -rw-r--r-- | src/rt/rust_log.cpp | 155 | ||||
| -rw-r--r-- | src/rt/rustrt.def.in | 4 |
4 files changed, 37 insertions, 174 deletions
diff --git a/src/rt/rust_crate_map.cpp b/src/rt/rust_crate_map.cpp index 7faae196000..e6206fd7bcb 100644 --- a/src/rt/rust_crate_map.cpp +++ b/src/rt/rust_crate_map.cpp @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -12,36 +12,52 @@ #include <set> void iter_module_map(const mod_entry* map, - void (*fn)(const mod_entry* entry, void *cookie), - void *cookie) { + void (*fn)(void* fptr, void* env, const mod_entry *entry), + void* fptr, + void* env + ) { for (const mod_entry* cur = map; cur->name; cur++) { - fn(cur, cookie); + fn(fptr, env, cur); } } void iter_crate_map(const cratemap* map, - void (*fn)(const mod_entry* map, void *cookie), - void *cookie, + void (*fn)(void* fptr, void* env, const mod_entry *entry), + void *fptr, + void *env, std::set<const cratemap*>& visited) { if (visited.find(map) == visited.end()) { // Mark this crate visited visited.insert(map); // First iterate this crate - iter_module_map(map->entries(), fn, cookie); + iter_module_map(map->entries(), fn, fptr, env); // Then recurse on linked crates for (cratemap::iterator i = map->begin(), e = map->end(); i != e; ++i) { - iter_crate_map(*i, fn, cookie, visited); + iter_crate_map(*i, fn, fptr, env, visited); } } } void iter_crate_map(const cratemap* map, - void (*fn)(const mod_entry* map, void *cookie), - void *cookie) { + void (*fn)(void* fptr, void* env, const mod_entry *entry), + void *fptr, + void *env + ) { std::set<const cratemap*> visited; - iter_crate_map(map, fn, cookie, visited); + iter_crate_map(map, fn, fptr, env, visited); } + +extern "C" CDECL void +rust_iter_crate_map(const cratemap* map, + void (*fn)(void* fptr, void* env, const mod_entry *entry), + void *fptr, + void *env + ) { + return iter_crate_map(map, fn, fptr, env); +} + + // // Local Variables: // mode: C++ diff --git a/src/rt/rust_crate_map.h b/src/rt/rust_crate_map.h index 80b969d6f6d..1bcb2aa8f7e 100644 --- a/src/rt/rust_crate_map.h +++ b/src/rt/rust_crate_map.h @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -16,7 +16,7 @@ struct mod_entry { const char* name; - uint32_t* state; + uint32_t* log_level; }; class cratemap; @@ -83,12 +83,14 @@ public: }; void iter_module_map(const mod_entry* map, - void (*fn)(const mod_entry* entry, void *cookie), - void *cookie); + void (*fn)(void* fptr, void* env, const mod_entry *entry), + void *fptr, + void *env); void iter_crate_map(const cratemap* map, - void (*fn)(const mod_entry* entry, void *cookie), - void *cookie); + void (*fn)(void* fptr, void* env, const mod_entry *entry), + void *fptr, + void *env); // // Local Variables: diff --git a/src/rt/rust_log.cpp b/src/rt/rust_log.cpp deleted file mode 100644 index 97c1135fe01..00000000000 --- a/src/rt/rust_log.cpp +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/* - * Logging infrastructure that aims to support multi-threading - */ - - -#include "rust_crate_map.h" -#include "util/array_list.h" -#include "rust_util.h" - -// Reading log directives and setting log level vars - -struct log_directive { - char* name; - size_t level; -}; - - -const uint32_t log_err = 1; -const uint32_t log_warn = 2; -const uint32_t log_info = 3; -const uint32_t log_debug = 4; - -const size_t max_log_directives = 255; -const size_t max_log_level = 255; -const size_t default_log_level = log_err; - -// This is a rather ugly parser for strings in the form -// "crate1,crate2.mod3,crate3.x=1". Log levels are 0-255, -// with the most likely ones being 0-3 (defined in std::). -size_t parse_logging_spec(char* spec, log_directive* dirs) { - size_t dir = 0; - while (dir < max_log_directives && *spec) { - char* start = spec; - char cur; - while (true) { - cur = *spec; - if (cur == ',' || cur == '=' || cur == '\0') { - if (start == spec) {spec++; break;} - if (*spec != '\0') { - *spec = '\0'; - spec++; - } - size_t level = max_log_level; - if (cur == '=' && *spec != '\0') { - level = *spec - '0'; - if (level > max_log_level) level = max_log_level; - if (*spec) ++spec; - } - dirs[dir].name = start; - dirs[dir++].level = level; - break; - } else { - spec++; - } - } - } - return dir; -} - -struct update_entry_args { - log_directive* dirs; - size_t n_dirs; - size_t *n_matches; -}; - -static void update_entry(const mod_entry* entry, void *cookie) { - update_entry_args *args = (update_entry_args *)cookie; - size_t level = default_log_level, longest_match = 0; - for (size_t d = 0; d < args->n_dirs; d++) { - if (strstr(entry->name, args->dirs[d].name) == entry->name && - strlen(args->dirs[d].name) > longest_match) { - longest_match = strlen(args->dirs[d].name); - level = args->dirs[d].level; - } - } - *entry->state = level; - if (longest_match > 0) { - (*args->n_matches)++; - } -} - -void update_crate_map(const cratemap* map, log_directive* dirs, - size_t n_dirs, size_t *n_matches) { - update_entry_args args = { dirs, n_dirs, n_matches }; - iter_crate_map(map, update_entry, &args); -} - -void print_mod_name(const mod_entry* mod, void *cooke) { - printf(" %s\n", mod->name); -} - -void print_crate_log_map(const cratemap* map) { - iter_crate_map(map, print_mod_name, NULL); -} - -void update_log_settings(void* crate_map, char* settings) { - char* buffer = NULL; - log_directive dirs[256]; - size_t n_dirs = 0; - - if (settings) { - - if (strcmp(settings, "::help") == 0 || - strcmp(settings, "?") == 0) { - printf("\nCrate log map:\n\n"); - print_crate_log_map((const cratemap*)crate_map); - printf("\n"); - exit(1); - } - - size_t buflen = strlen(settings) + 1; - buffer = (char*)malloc(buflen); - strncpy(buffer, settings, buflen); - n_dirs = parse_logging_spec(buffer, &dirs[0]); - } - - size_t n_matches = 0; - update_crate_map((const cratemap*)crate_map, &dirs[0], - n_dirs, &n_matches); - - if (n_matches < n_dirs) { - fprintf(stderr, "warning: got %lu RUST_LOG specs but only matched %lu of them.\n" - "You may have mistyped a RUST_LOG spec.\n" - "Use RUST_LOG=::help to see the list of crates and modules.\n", - (unsigned long)n_dirs, (unsigned long)n_matches); - } - - free(buffer); -} - -extern "C" CDECL void -rust_update_log_settings(void* crate_map, char* settings) { - update_log_settings(crate_map, settings); -} - -// -// Local Variables: -// mode: C++ -// fill-column: 78; -// indent-tabs-mode: nil -// c-basic-offset: 4 -// buffer-file-coding-system: utf-8-unix -// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; -// End: -// diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in index b668d394406..c1ba0524be9 100644 --- a/src/rt/rustrt.def.in +++ b/src/rt/rustrt.def.in @@ -182,7 +182,7 @@ rust_valgrind_stack_register rust_valgrind_stack_deregister rust_take_env_lock rust_drop_env_lock -rust_update_log_settings +rust_iter_crate_map rust_running_on_valgrind rust_get_num_cpus rust_get_global_args_ptr @@ -191,4 +191,4 @@ rust_drop_global_args_lock rust_take_change_dir_lock rust_drop_change_dir_lock rust_get_test_int -rust_get_task \ No newline at end of file +rust_get_task |
