Mercurial > hg > Applications > Grep
view regexParser/cerium/ppe/Exec.cc @ 275:8879eb8c64a8
remove segmentation fault
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 30 Jan 2016 19:06:41 +0900 |
parents | 5aa9d01926f1 |
children | 99d635926ef3 |
line wrap: on
line source
#include <stdio.h> #include <string.h> #include "Exec.h" #include "Func.h" #include "regexParser.h" #include "threadedSearch.h" #include "FileMapReduce.h" /* これは必須 */ SchedDefineTask1(Exec,blockedGrep); static TSValue stateNothing(TSValue tsv) { return tsv; } static TSValue stateSkip(TSValue tsv) { tsv.buff.matchBegin = tsv.buff.buffptr; return tsv; } static TSValue stateMatch(TSValue tsv) { ResultPtr r = NEW(Result); r->begin = tsv.buff.matchBegin; r->end = tsv.buff.buffptr; *tsv.resultEnd = r; r->next = NULL; tsv.resultEnd = &r->next; tsv.current = tsv.tg->stateList->tState; tsv.buff.buffptr--; tsv = stateSkip(tsv); return tsv; } TSValue blockSearch(TransitionGeneratorPtr tg,Buffer buff) { TSValue tsv; tsv.buff = buff; tsv.tg = tg; tsv.result = NULL; tsv.resultEnd = &tsv.result; tsv.current = tg->anyState->tState; tsv.current->stateSkip = stateSkip; tsv.current->stateContinue = stateNothing; tsv.tg->stateSkip = stateSkip; tsv.tg->stateMatch = stateMatch; tsv.tg->stateNothing = stateNothing; unsigned char *end = buff.buffend; buff.buffend = buff.buff+1; tSearch(tsv); tsv.blockBegin = tsv.current; buff.buffend = end; tSearch(tsv); tsv.blockEnd = tsv.current; if (tsv.blockEnd->state->bitState.bitContainer != 1) { ResultPtr r = NEW(Result); r->begin = tsv.buff.matchBegin; r->end = NULL; *tsv.resultEnd = r; r->next = NULL; tsv.resultEnd = &r->next; } return tsv; } static int blockedGrep(SchedTask *s, void *rbuf, void *wbuf) { long task_spwaned = (long)s->get_param(0); long division_size = (long)s->get_param(1); long length = (long)s->get_param(2); long out_size = (long)s->get_param(3); MapReduce *w = (MapReduce*)s->get_param(4); long allocation = task_spwaned + (long)s->x; unsigned char* i_data; unsigned long * o_data; if (division_size) { i_data = (unsigned char*)s->get_input(rbuf,0) + allocation*division_size; o_data = (unsigned long *)s->get_output(wbuf,1) + allocation*out_size; } else { i_data = (unsigned char*)s->get_input(0); o_data = (unsigned long *)s->get_output(0); } TransitionGeneratorPtr tg = (TransitionGeneratorPtr)w->global; Buffer buff; buff.buff = buff.buffptr = buff.matchBegin = i_data; buff.buffend = buff.buff + length; TSValue tsv = blockSearch(tg,buff); o_data[0] = (unsigned long)tsv.result; o_data[1] = (unsigned long)tsv.blockBegin->state; o_data[2] = (unsigned long)tsv.blockEnd->state; return 0; }