OSDN Git Service

Resolve some strnlen() implementation issues.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Thu, 12 May 2016 12:51:37 +0000 (13:51 +0100)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Thu, 12 May 2016 12:51:37 +0000 (13:51 +0100)
mingwrt/ChangeLog
mingwrt/Makefile.in
mingwrt/include/string.h
mingwrt/mingwex/strnlen.s

index 7d9c574..d9b3edb 100644 (file)
@@ -1,3 +1,22 @@
+2016-05-12  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
+       Resolve some strnlen() implementation issues.
+
+       * mingwex/strnlen.s (__mingw_strnlen) [!NUL]: Correct termination
+       logic; should have used jnz, not jz, to skip endpoint adjustment on
+       scanning past a terminal NUL character code.
+
+       * include/string.h [_POSIX_C_SOURCE >= 200809L] (strnlen): Do not
+       #define it, as this breaks GCC compilation; use __CRT_ALIAS instead,
+       with __JMPSTUB__ referencing via "oldname" libraries.
+
+       * Makefile.in (jmpstub_awk_script, libimpl_awk_script): Adapt to
+       facilitate assignment of __JMPSTUB__ and __LIBIMPL__ references to
+       libraries other than libmingwex.a
+       (strnlen.jmpstub.$OBJEXT): Assign it to all "moldname" libraries prior
+       to libmoldname80.a, in addition to libcoldname.a, as specified by the
+       __JMPSTUB__ assignment within <string.h>
+
 2016-05-03  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        Enforce consistent specification of package version.
index 9da8d14..d5017f7 100644 (file)
@@ -376,6 +376,15 @@ $(foreach name,coldname $(all_moldname),lib$(name).a): lib%.a: %.def
 $(foreach name,coldname $(all_moldname),lib$(name).a): $(addsuffix .$(OBJEXT), \
   isascii iscsym iscsymf toascii)
 
+# Selected versions of the oldname libraries also provide a
+# convenient vehicle for delivery of stubs, emulating functions
+# which appear in later MSVCRT versions, and which we also wish
+# to support in conjunction with earlier versions.
+#
+$(foreach name,moldname $(addprefix moldname,70 71),lib$(name).a) \
+$(foreach name,moldname $(addprefix moldname,70 71),lib$(name)d.a): \
+  strnlen.jmpstub.$(OBJEXT)
+
 coldname.def: %.def: ${mingwrt_srcdir}/moldname.def.in
        $(CC) -C -E -P -D__FILENAME__=$@ -D__CRTDLL__ -xc-header $< > $@
 
@@ -545,8 +554,8 @@ jmpstub_awk_script = test -z "$1" || awk '\
     fmt = "\nlib%s.a: %s\n%s: jmpstub.sx\n\t$$(COMPILE.sx) %s -o $$@ $$^\n"; \
   } \
   /__JMPSTUB(__)? *[(].*FUNCTION/ { \
-    LIB = "mingwex"; \
     FUNCTION = gensub( ".*[ ,(:]FUNCTION *= *"symbol".*", "\\1", 1 ); \
+    LIB = match( $$0, ".*[ ,(:]LIB *= *"symbol, altlib ) ? altlib[1] : "mingwex"; \
     OBJNAME = gensub( "_*(.*)_*", "\\1", 1, FUNCTION )".jmpstub.$$(OBJEXT)"; \
     OBJNAME_CFLAGS = "-D FUNCTION="FUNCTION; \
     if( match( $$0, ".*[ ,(:]REMAPPED *= *"symbol, alias ) ) \
@@ -566,8 +575,8 @@ libimpl_awk_script = test -z "$1" || awk '\
     fmt = "\nlib%s.a: %s\n%s.libimpl: %s\n"; \
   } \
   /__LIBIMPL(__)? *[(].*FUNCTION/ { \
-    LIB = "mingwex"; \
     FUNCTION = gensub( ".*[ ,(:]FUNCTION *= *"symbol".*", "\\1", 1 ); \
+    LIB = match( $$0, ".*[ ,(:]LIB *= *"symbol, altlib ) ? altlib[1] : "mingwex"; \
     OBJNAME = gensub( "_*(.*)_*", "\\1", 1, FUNCTION )".libimpl.$$(OBJEXT)"; \
     printf fmt, LIB, OBJNAME, FUNCTION, FILENAME; \
   } \
index c617ca9..2e5940b 100644 (file)
@@ -168,15 +168,15 @@ _CRTIMP __cdecl __MINGW_NOTHROW  char *strnlen (const char *, size_t);
  * the GCC breakage noted above.  (Note that we implement strnlen() with
  * the alternative external name, __mingw_strnlen() in libmingwex.a, to
  * avoid possible link time collision with MSVCR80.DLL's implementation,
- * then map this to strnlen() via a preprocessor define, so that users
- * may use it conventionally, (including taking its address); this may
- * interfere with C++ namespace qualification, but since strnlen() is
- * not a standard C++ function, we do not anticipate any consequent
- * usage issues).
+ * then map this to strnlen() via a __CRT_ALIAS, with stubs designated
+ * for linking from within the appropriate oldname libraries.
  */
-#define strnlen  __mingw_strnlen
 extern size_t __mingw_strnlen (const char *, size_t);
 
+__JMPSTUB__(( LIB=coldname; FUNCTION=strnlen ))
+__CRT_ALIAS size_t strnlen (const char *__text, size_t __maxlen)
+{ return __mingw_strnlen (__text, __maxlen); }
+
 #endif /* _POSIX_C_SOURCE >= 200809L */
 
 #undef __STRING_H_SOURCED__
index e023a69..66d7b49 100644 (file)
@@ -80,8 +80,8 @@ ___mingw_strnlen:
        movl    %edx, %edi      /* using this as the scan pointer ... */
        repne   scasb           /* as required by this CPU scan */
        mov     %edi, %eax      /* note where we stopped ... */
-       jz      .L3             /* but if we found NUL, we've overrun ... */
-       decl    %eax            /* so we need to adjust one byte backward */
+       jnz     .L3             /* no NUL found; count is complete ... */
+       decl    %eax            /* NUL found and counted; discount it */
 .L3:
        sub     %edx, %eax      /* compute effective count to return */
 .L4: