Mercurial > hg > Game > Cerium
changeset 1782:7245548995a8 draft
refactoring in string_args
author | Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 26 Nov 2013 18:57:06 +0900 |
parents | a96cf4e50524 |
children | 803dfdd1c741 |
files | example/string_args/main.cc example/string_args/ppe/Exec.cc |
diffstat | 2 files changed, 8 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/example/string_args/main.cc Tue Nov 26 17:46:05 2013 +0900 +++ b/example/string_args/main.cc Tue Nov 26 18:57:06 2013 +0900 @@ -23,11 +23,11 @@ for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "-cpu") == 0) { - spe_num = atoi(argv[i+1]); + spe_num = atoi(argv[i+1]); i++; } else if (strcmp(argv[i], "-sw") == 0) { - search_word = argv[i+1]; + search_word = argv[i+1]; i++; } else if (strcmp(argv[i], "-t") == 0) { - task_num = atoi(argv[i+1]); + task_num = atoi(argv[i+1]); i++; } } @@ -58,18 +58,11 @@ int TMmain(TaskManager *manager, int argc, char *argv[]) { - char *search_word = 0; - int search_word_len = 0; - - search_word = init(argc,argv); - search_word_len = strlen((const char*)search_word); + const char *search_word = init(argc,argv); + int search_word_len = strlen(search_word); - if (search_word < 0) { - return -1; - } - char *sword = (char*)manager->allocate(sizeof(char)*search_word_len); - //strcpy(sword,(const char*)search_word); - memcpy(sword,(const char*)search_word,search_word_len); + char *sword = (char*)manager->allocate(search_word_len+1); + memcpy(sword,search_word,search_word_len); // to get correct alignment task_init(); run_start(manager, sword, search_word_len);
--- a/example/string_args/ppe/Exec.cc Tue Nov 26 17:46:05 2013 +0900 +++ b/example/string_args/ppe/Exec.cc Tue Nov 26 18:57:06 2013 +0900 @@ -18,7 +18,7 @@ static int run(SchedTask *s, void *rbuf, void *wbuf) { - char *search_word = (char *)s->get_input(rbuf,0); + const char *search_word = (char *)s->get_input(rbuf,0); long task_size = (long)s->get_param(0);