-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 15.10.2013 19:14, LRN wrote:
> On 15.10.2013 16:34, LRN wrote:
>> Testcase is attached. Some invocations of stpcpy work, some don't.
> 
> expand_builtin_stpcpy() from gcc/builtins.c sheds some light on this
> (when return value is ignored, stpcpy() is replaced with strcpy()).
> After reading a diff between the asm output (at jon_y's suggestion) i
> concluded that builtin stpcpy is not a full implementation. It's there
> only to optimize for cases where second argument is known at compile
> time. When that is not the case, it just calls system stpcpy. Which
> isn't available :(
> 
> Here are patches that add stpcpy() to mingw-w64.
> 
Changed the patches in the way it was suggested on the IRC, used
__mingw_printf() as a template for inlining.


- -- 
O< ascii ribbon - stop html email! - www.asciiribbon.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (MingW32)

iQEcBAEBAgAGBQJSXlnyAAoJEOs4Jb6SI2Cw7BIIAM1+l3vunkXgkZVp2E2mO0N8
iaQO/m76ftYsMNpEC2qCGY3ri6zYAAGpASzgt/zn2mhkZkMgGifow07zRIm1aeIs
O8LPpK/Oq4YU8RywBHwXJ4CPW0uHnsTCJv8juujqEUd+LcOSNcr4X3cQRSA+0hWM
iIdC1HcWQPGx4RnumjjJD+grlk2uWUqXepYs3nfOlkzijNgNOH0CHvTmB9TEf1ld
6+XYOKFJh5iQdrFzOeqOpetG1aglekj7i0svPStVQauLKFGtHwlO8wLrpjiy7iiX
akKeW880xkk0x/pmVQKWz6j568sp/96QF8onOUF0+XSz4PoIK+jgJ0FkUFnQkJU=
=/BN7
-----END PGP SIGNATURE-----
From eedb12b2124339e9e494a3d24bebd9a8ebde681f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?=
 =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= <[email protected]>
Date: Tue, 15 Oct 2013 13:21:25 +0000
Subject: [PATCH 1/2] Add stpcpy() implementation

---
 mingw-w64-crt/Makefile.am   |  2 +-
 mingw-w64-crt/misc/stpcpy.c | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100755 mingw-w64-crt/misc/stpcpy.c

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index a2f89a6..fe634c7 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -233,7 +233,7 @@ src_libmingwex=\
   misc/wcsnlen.c         misc/wcstof.c                misc/wcstoimax.c         
   misc/wcstold.c             misc/wcstoumax.c      \
   misc/wctob.c           misc/wctrans.c               misc/wctype.c            
   misc/wdirent.c             misc/winbs_uint64.c   \
   misc/winbs_ulong.c     misc/winbs_ushort.c          misc/wmemchr.c           
   misc/wmemcmp.c             misc/wmemcpy.c        \
-  misc/wmemmove.c        misc/wmempcpy.c              misc/wmemset.c           
   misc/purecall.c \
+  misc/wmemmove.c        misc/wmempcpy.c              misc/wmemset.c           
   misc/purecall.c            misc/stpcpy.c         \
   \
   stdio/mingw_pformat.h    \
   stdio/vfscanf2.S         stdio/vfwscanf2.S         stdio/vscanf2.S          
stdio/vsscanf2.S          stdio/vswscanf2.S \
diff --git a/mingw-w64-crt/misc/stpcpy.c b/mingw-w64-crt/misc/stpcpy.c
new file mode 100755
index 0000000..509341f
--- /dev/null
+++ b/mingw-w64-crt/misc/stpcpy.c
@@ -0,0 +1,11 @@
+#define __CRT__NO_INLINE
+
+#include <string.h>
+
+char * __cdecl __mingw_stpcpy (char * __restrict__ _Dest,const char * 
__restrict__ _Source)
+{
+  for (; *_Source; _Source++, _Dest++)
+    *_Dest = *_Source;
+  *_Dest = '\0';
+  return _Dest;
+}
-- 
1.8.4

From 982326bf10d44f40477af904db890120dd48f615 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?=
 =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= <[email protected]>
Date: Tue, 15 Oct 2013 13:21:36 +0000
Subject: [PATCH 2/2] Add stpcpy() prototype

---
 mingw-w64-headers/crt/string.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mingw-w64-headers/crt/string.h b/mingw-w64-headers/crt/string.h
index 972bd54..9bb04c2 100644
--- a/mingw-w64-headers/crt/string.h
+++ b/mingw-w64-headers/crt/string.h
@@ -49,6 +49,12 @@ extern "C" {
   char * __cdecl _strset(char *_Str,int _Val) 
__MINGW_ATTRIB_DEPRECATED_SEC_WARN;
   char * __cdecl _strset_l(char *_Str,int _Val,_locale_t _Locale) 
__MINGW_ATTRIB_DEPRECATED_SEC_WARN;
   char * __cdecl strcpy(char * __restrict__ _Dest,const char * __restrict__ 
_Source);
+  char * __cdecl __mingw_stpcpy(char * __restrict__ _Dest,const char * 
__restrict__ _Source) __MINGW_NOTHROW;
+#if (defined (_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700) || \
+    (defined (_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L) || \
+    (defined (_GNU_SOURCE))
+  __mingw_ovr char *stpcpy(char * __restrict__ _Dest,const char * __restrict__ 
_Source) { return __mingw_stpcpy(_Dest, _Source); }
+#endif
   char * __cdecl strcat(char * __restrict__ _Dest,const char * __restrict__ 
_Source);
   int __cdecl strcmp(const char *_Str1,const char *_Str2);
   size_t __cdecl strlen(const char *_Str);
-- 
1.8.4

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to