crt: Move the msvcrt snprintf/vsnprintf aliases into separate object files

This avoids duplicate definitions, if something refers to e.g.
__ms_vsnprintf, while the inline vsnprintf also has been instantiated
in C++ mode. (In C++ mode, the inline vsnprintf function isn't marked
static.)

This should fix https://github.com/msys2/MINGW-packages/issues/6271.

Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
Martin Storsjö 2020-03-15 23:16:45 +02:00
parent 7c03b11bf1
commit b46a25b433
5 changed files with 48 additions and 27 deletions

View File

@ -170,7 +170,9 @@ src_msvcrt_common=\
misc/wcrtomb.c \ misc/wcrtomb.c \
stdio/acrt_iob_func.c \ stdio/acrt_iob_func.c \
stdio/snprintf.c \ stdio/snprintf.c \
stdio/snprintf_alias.c \
stdio/vsnprintf.c \ stdio/vsnprintf.c \
stdio/vsnprintf_alias.c \
math/frexp.c math/frexp.c
src_msvcrt=\ src_msvcrt=\

View File

@ -3,19 +3,8 @@
* This file is part of the mingw-w64 runtime package. * This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package. * No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/ */
#include <_mingw.h>
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h> #include <stdio.h>
/* Intentionally not including stdio.h, as it unconditionally defines the
* snprintf inline, and it can't be renamed with "#define snprintf othername"
* either, as stdio.h contains "#undef snprintf". */
_CRTIMP int __cdecl _vscprintf(const char * __restrict__ _Format,va_list _ArgList);
_CRTIMP int __cdecl _vsnprintf(char * __restrict__ _Dest,size_t _Count,const char * __restrict__ _Format,va_list _Args);
int __cdecl __ms_snprintf(char* buffer, size_t n, const char *format, ...);
int __cdecl __ms_snprintf(char* buffer, size_t n, const char *format, ...) int __cdecl __ms_snprintf(char* buffer, size_t n, const char *format, ...)
{ {
@ -47,5 +36,3 @@ int __cdecl __ms_snprintf(char* buffer, size_t n, const char *format, ...)
va_end(argptr); va_end(argptr);
return retval; return retval;
} }
int __attribute__ ((alias ("__ms_snprintf"))) __cdecl snprintf(char*, size_t, const char *, ...);

View File

@ -0,0 +1,25 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <stdarg.h>
#include <stddef.h>
/* Intentionally not including stdio.h, as it unconditionally defines the
* snprintf inline, and it can't be renamed with "#define snprintf othername"
* either, as stdio.h contains "#undef snprintf". */
int __cdecl __ms_vsnprintf(char *buffer, size_t n, const char *format, va_list arg);
int __cdecl snprintf(char *buffer, size_t n, const char *format, ...)
{
int retval;
va_list argptr;
va_start(argptr, format);
retval = __ms_vsnprintf(buffer, n, format, argptr);
va_end(argptr);
return retval;
}

View File

@ -4,18 +4,8 @@
* No warranty is given; refer to the file DISCLAIMER.PD within this package. * No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/ */
#define __CRT__NO_INLINE #define __CRT__NO_INLINE
#include <_mingw.h>
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h> #include <stdio.h>
/* Intentionally not including stdio.h, as it unconditionally defines the
* vsnprintf inline, and it can't be renamed with "#define vsnprintf othername"
* either, as stdio.h contains "#undef vsnprintf". */
_CRTIMP int __cdecl _vscprintf(const char * __restrict__ _Format,va_list _ArgList);
_CRTIMP int __cdecl _vsnprintf(char * __restrict__ _Dest,size_t _Count,const char * __restrict__ _Format,va_list _Args);
int __cdecl __ms_vsnprintf (char *s,size_t n,const char *format,va_list arg);
int __cdecl __ms_vsnprintf (char *s,size_t n,const char *format,va_list arg) int __cdecl __ms_vsnprintf (char *s,size_t n,const char *format,va_list arg)
{ {
@ -39,5 +29,3 @@ int __cdecl __ms_vsnprintf (char *s,size_t n,const char *format,va_list arg)
return retval; return retval;
} }
int __attribute__ ((alias ("__ms_vsnprintf"))) __cdecl vsnprintf(char*, size_t, const char *, va_list);

View File

@ -0,0 +1,19 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <stdarg.h>
#include <stddef.h>
/* Intentionally not including stdio.h, as it unconditionally defines the
* vsnprintf inline, and it can't be renamed with "#define vsnprintf othername"
* either, as stdio.h contains "#undef vsnprintf". */
int __cdecl __ms_vsnprintf(char *buffer, size_t n, const char *format, va_list arg);
int __cdecl vsnprintf(char *buffer, size_t n, const char *format, va_list arg)
{
return __ms_vsnprintf(buffer, n, format, arg);
}