Closed Bug 106372 Opened 24 years ago Closed 24 years ago

Need PR_strtok_r()

Categories

(NSPR :: NSPR, enhancement, P1)

enhancement

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: roland.mainz, Assigned: roland.mainz)

References

Details

Attachments

(1 file, 1 obsolete file)

We _urgendly_ need a NSPR version of strtok_r(). Some code already uses strtok_r() and strtok(). But the first one is not available on all platforms we support (per cls) and the 2nd one (strtok()) should be avoided in multithreaded apps. as it is not thread-safe on all platforms. Patch in bug 100069 has a version of strtok_r(). Just grab it and rename it to PR_strtok_r() ... :-)
Severity: critical → enhancement
Status: NEW → ASSIGNED
I just found out today that xpcom/ds/nsCRT.cpp has a supposedly threadsafe version of strtok. You might want to try it.
1. |strtok()| does not help because I use strtok_r() in a "nested way" (|for|-loop using strtok_r() which calls function which itself uses strtok_r()). |strtok()| won't help... see [3] 2. The function sits in XPCOM, not in NSPR. I think it would be very usefull to have POSIX-like |strtok_r()| in NSPR (use own if OS does not provide one - but use the OS version if present). 3. It looks that xpcom/ds/nsCRT.cpp#nsCRT::strtok() is a completly different beast than POSIX strtok_r() (just looking at comments like "Unlike regular strtok, the first argument cannot be null." and "too many delimiters"... ewww... ;-( ).
Blocks: 84947, 100069
Stealing this from wtc...
Assignee: wtc → Roland.Mainz
Status: ASSIGNED → NEW
Patch follows in a few mins ...
Status: NEW → ASSIGNED
This should be added to mozilla/nsprpub/lib/libc. The function should use the PL_ prefix, that is, it should be renamed PL_strtok_r(). If PL_strtok_r calls strtok_r where strtok_r is present, PL_strtok_r may need to have the same signature as strtok_r (in parcular, with respect to the use of const) for the best performance. char *strtok_r(char *s, const char *sep, char **lasts);
Attached patch Patch for 2001-10-20-08-trunk (obsolete) — Splinter Review
> This should be added to mozilla/nsprpub/lib/libc. > The function should use the PL_ prefix, that is, > it should be renamed PL_strtok_r(). Done, see patch. > If PL_strtok_r calls strtok_r where strtok_r is > present, PL_strtok_r may need to have the same > signature as strtok_r (in parcular, with respect > to the use of const) for the best performance I would prefer a simple |#define PL_foobar(arg1, arg2) foobar(arg1, arg2)| to save the function call overhead (for example I _hate_ X.org code which wastes a lot of time in such wrapper code). However, the whole "use native function if OS has it" can be done in a later step... ---- Requesting r=/sr= ...
Keywords: patch, review
cc'ing a potential nspr reviewer.
cc'ing some potential nspr reviewers.
Attachment #55285 - Attachment is obsolete: true
Attachment #55285 - Flags: needs-work+
Roland, I edited your patch to indent by four spaces, avoid the goto statement, and use for loops. I also added comments in plstr.h to document the new function and added a test case for PL_strtok_r.
Comment on attachment 55868 [details] [diff] [review] Roland Mainz's patch, edited, added comments and a test. Thanks for the new patch... :-) r=Roland.Mainz@informatik.med.uni-giessen.de
Attachment #55868 - Flags: review+
wtc: Wanna check this in for me, please ? I do not have CVS checkin permission ....
Roland, I will try to do that later today. This bug won't be marked fixed until I find someone to help me add the new file to the Mac project file.
I checked in my patch (with minor editing) on the tip of NSPRPUB_PRE_4_2_CLIENT_BRANCH of NSPR. Simon, could you please add mozilla/nsprpub/lib/libc/src/strtok.c to NSPR's Mac project file on the NSPRPUB_PRE_4_2_CLIENT_BRANCH?
Priority: -- → P1
Target Milestone: --- → 4.2
Sorry, I meant to say I checked in my patch (with minor editing) on the tip and the NSPRPUB_PRE_4_2_CLIENT_BRANCH of NSPR. ^^^
Done. So I should do the mac project on the NSPR tip too?
Simon Fraser wrote: > So I should do the mac project on the NSPR tip too? Yes, please. I did not dare to ask because I could copy the file to the NSPR tip and check it in. Thanks! :-)
Mac project fixed on the NSPR tip.
Marked the bug fixed.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Filed bug 109177 as a follow-up to kill the |strtok()|-clones from the tree and replace them all with |PL_strtok_r()| ...
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: