From: Keith M. <no...@so...> - 2017-12-18 11:47:18
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Repository: mingw-org-wsl". The branch, 5.1-trunk has been updated via 8ea0d1ac0c1df465382dc525294b2725757f0628 (commit) from 9808774164e87c6c8534479377191e59e4d1d24c (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://sf.net/p/mingw/mingw-org-wsl/ci/8ea0d1ac0c1df465382dc525294b2725757f0628/ commit 8ea0d1ac0c1df465382dc525294b2725757f0628 Author: Keith Marshall <ke...@us...> Date: Mon Dec 18 11:45:49 2017 +0000 Support strtok() re-entrancy, per request [#2342]. diff --git a/mingwrt/ChangeLog b/mingwrt/ChangeLog index a628995..2f6fb6b 100644 --- a/mingwrt/ChangeLog +++ b/mingwrt/ChangeLog @@ -1,3 +1,19 @@ +2017-12-18 Keith Marshall <ke...@us...> + + Support strtok() re-entrancy, per request [#2342]. + + * mingwex/strtok_r.c: New file; it implements... + (strtok_r): ...this function, per POSIX.1-1995 specification. + * Makefile.in (libmingwex.a): Add reference; make it depend on... + (strtok_r.$OBJEXT): ...this. + + * include/string.h: Declare corresponding runtime API. + [_POSIX_C_SOURCE >= 199506L] (strtok_r): Add function prototype. + [__MSVCRT_VERSION__ >= __MSVCR80_DLL] (strtok_s): Likewise; this is + the Microsoft equivalent function, first introduced in this non-free + MSVC runtime library; subsequently available in MSVCRT.DLL since... + [_WIN32_WINNT >= _WIN32_WINNT_VISTA]: ...this release, likewise. + 2017-12-16 Keith Marshall <ke...@us...> Implement autotest module for POSIX clock API functions. @@ -12,14 +28,16 @@ * include/time.h [_POSIX_C_SOURCE >= 199309L] (clockid_t): New structured data type; define it opaquely, and... (CLOCK_REALTIME, CLOCK_MONOTONIC): ...declare these extern instances. - [_POSIX_C_SOURCE >= 200809L] (gettimeofday): Mark it "deprecated". - [_POSIX_C_SOURCE >= 199309L] (clock_getres, clock_gettime) - (clock_settime): New functions; declare prototypes. + (clock_getres, clock_gettime, clock_settime): New functions; declare + prototypes. * mingwex/clockapi.h mingwex/clockapi.c mingwex/clockres.c * mingwex/clockset.c mingwex/clocktime.c: New files; they implement the preceding clock instances, and associated API functions. + * include/sys/time.h [_POSIX_C_SOURCE >= 200809L] (gettimeofday): + Mark it as "deprecated". + 2017-12-14 Keith Marshall <ke...@us...> Add support for POSIX.1 "obsolescence" warnings. diff --git a/mingwrt/Makefile.in b/mingwrt/Makefile.in index 024918a..1b8f081 100644 --- a/mingwrt/Makefile.in +++ b/mingwrt/Makefile.in @@ -452,7 +452,7 @@ libmingwex.a: $(addsuffix .$(OBJEXT), clockapi clockres clockset clocktime) libmingwex.a: $(addsuffix .$(OBJEXT), mkstemp mkdtemp cryptnam setenv) libmingwex.a: $(addsuffix .$(OBJEXT), tdelete tfind tsearch twalk) -libmingwex.a: $(addsuffix .$(OBJEXT), dirent wdirent dlfcn strerror_r) +libmingwex.a: $(addsuffix .$(OBJEXT), dirent wdirent dlfcn strerror_r strtok_r) libmingwex.a: $(addsuffix .$(OBJEXT), getdelim gettimeofday) vpath %.s ${mingwrt_srcdir}/mingwex diff --git a/mingwrt/include/string.h b/mingwrt/include/string.h index 288aedc..c982a30 100644 --- a/mingwrt/include/string.h +++ b/mingwrt/include/string.h @@ -199,6 +199,17 @@ __CRT_ALIAS size_t strnlen (const char *__text, size_t __maxlen) #endif /* MSVCRT.DLL || pre-MSVCR80.DLL */ #endif /* _POSIX_C_SOURCE >= 200809L */ +#if _POSIX_C_SOURCE >= 199506L /* SUSv2 */ +/* SUSv2 added a re-entrant variant of strtok(), which maintains state + * using a user supplied reference pointer, rather than the internal + * reference used by strtok() itself, thus making it both thread-safe, + * and suitable for interleaved use on multiple strings, even within a + * single thread context, (which isn't possible with strtok() itself, + * even with Microsoft's intrinsically thread-safe implementation). + */ +extern char *strtok_r +(char *__restrict__, const char *__restrict__, char **__restrict__); + #if _POSIX_C_SOURCE >= 200112L /* POSIX.1-2001 added a re-entrant variant of strerror(), which stores * the message text in a user supplied buffer, rather than in (possibly @@ -210,7 +221,9 @@ __CRT_ALIAS size_t strnlen (const char *__text, size_t __maxlen) * copies of strerror()'s message text. */ extern int strerror_r (int, char *, size_t); -#endif + +#endif /* POSIX.1-2001 */ +#endif /* SUSv2 */ #if __MSVCRT_VERSION__>=__MSVCR80_DLL || _WIN32_WINNT >= _WIN32_WINNT_VISTA /* MSVCR80.DLL introduced a safer, (erroneously so called "more secure"), @@ -219,6 +232,13 @@ extern int strerror_r (int, char *, size_t); */ _CRTIMP __cdecl __MINGW_NOTHROW int strerror_s (char *, size_t, int); +/* Also introduced in MSVCR80.DLL, and retrofitted to MSVCRT.DLL from the + * release of Windows-Vista, strtok_s() is a direct analogue for POSIX.1's + * strtok_r() function; (contrary to Microsoft's description, it is neither + * a "more secure", nor even a "safer" version of strtok() itself). + */ +_CRTIMP __cdecl __MINGW_NOTHROW char *strtok_s (char *, const char *, char **); + #elif _POSIX_C_SOURCE >= 200112L /* For the benefit of pre-Vista MSVCRT.DLL users, we provide an approximate * emulation of strerror_s(), in terms of inline referral to POSIX.1-2001's diff --git a/mingwrt/mingwex/strtok_r.c b/mingwrt/mingwex/strtok_r.c new file mode 100644 index 0000000..87eebea --- /dev/null +++ b/mingwrt/mingwex/strtok_r.c @@ -0,0 +1,75 @@ +/* + * strtok_r.c + * + * Implementation of "re-entrant" version of ISO-C strtok() function. + * + * $Id$ + * + * Written by Keith Marshall <kei...@us...> + * Copyright (C) 2017, MinGW.org Project. + * + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +#include <string.h> + +char *strtok_r +(char *__restrict__ s, const char *__restrict__ sep, char **__restrict__ state) +{ + /* "Re-entrant" version of ISO-C strtok() function; maintains state + * via caller provided pointer variable, to avoid interference between + * concurrent invocations on distinct source strings. Requires initial + * call with non-NULL "s", to retrieve the first token and initialize + * "state", followed by repeated calls with "s" == NULL, to retrieve + * subsequent tokens. + */ + if( s == NULL ) + /* Non-initialization call; retrieve previously saved state. + */ + s = *state; + + /* Step over any leading separator characters, at the beginning of "s"; + * check that this didn't take us all the way to the terminating NUL... + */ + if( *(s += strspn (s, sep)) == '\0' ) + { + /* ...or if it did, initialize/reset "state", to indicate that there + * are no (more) tokens to retrieve; return NULL token, to indicate + * that there are none available. + */ + *state = s; + return NULL; + } + /* Locate the first separator charactor, if any, following the current + * token; reset "state" to mark its position, then, ensuring that we + * never advance beyond the terminal NUL of "s"... + */ + if( *(*state = s + strcspn (s, sep)) != '\0' ) + /* ...when an actual separator has been identified, replace it with + * NUL, to terminate the token, and advance "state" to the point at + * which scanning for any potential "next" token should resume. + */ + *(*state)++ = '\0'; + + return s; +} + +/* $RCSfile$: end of file */ ----------------------------------------------------------------------- Summary of changes: mingwrt/ChangeLog | 24 +++++++++++++-- mingwrt/Makefile.in | 2 +- mingwrt/include/string.h | 22 +++++++++++++- mingwrt/mingwex/strtok_r.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 mingwrt/mingwex/strtok_r.c hooks/post-receive -- Repository: mingw-org-wsl |