This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix tokenize function.


On Sat, Jun 13, 2009 at 05:13, Przemyslaw
Pawelczyk<przemyslaw@pawelczyk.it> wrote:
> Previous implementation was error-prone, because allowed returning empty
> tokens (mimiced strsep()), which is fine if there is a NULL semantic.
> Unfortunately SystemTap doesn't provide it in scripts and has only blank
> string (""), therefore testing against it was misleading.
> The solution is to return only non-empty tokens (mimic strtok()).

testsuite/systemtap.string/tokenize.exp turned out to be bogus,
because (for previous implementation of tokenize) blank textstr4
enabled further tokenization of textstr3, that should be already done.
In second version of the patch I'll fix also the test case. Simplified
example:

stap -e 'global s[2]; probe begin { s[1] = "before,,after"; s[2] = "";
foreach (i in s) { println(i); tok = tokenize(s[i], ","); while (tok
!= "") { println(tok); tok = tokenize("", ","); }}; exit(); }'

Result from previous implementation:
1
before
2
after

Result from my implementation:
1
before
after
2

> It was also unsafe, because NUL-termination wasn't guaranteed in the
> passed string, but this is crucial for proper strsep() working.

I unknowingly lied here, sorry. I'll remove that part in the second version.

Regards.

-- 
Przemysław Pawełczyk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]