Hi Eli,

> > AFAIU, that's because the MinGW build omits the Gnulib stdio module,
> > where the prototypes live.  We cannot use the stdio module as-is,
> > because it redefines stuff (such as fopen) we implement in Emacs in an
> > incompatible fashion.
> > 
> > Which means we need something to replace those parts of the Gnulib
> > stdio.h header, and do that in a header that will be included by Emacs
> > sources, because otherwise the redirections of fprintf and friends to
> > the gl_consolesafe_* versions will not be in effect, and the
> > stdio-consolesafe module is basically compiled, but never used...
> 
> Ping!  Bruno, could you please suggest a solution for the above?
> 
> OTOH, if you think this is something for us to solve (since we caused
> it by omitting the stdio module),

I thought it's something for you and Paul to solve, since it requires knowledge
of the .h files and of the code structure of Emacs (which I don't have).
Sorry, I could have communicated that better.

> I'm okay with solving it by placing
> the necessary glue on nt/inc/ms-w32.h, which is an Emacs specific
> header file used in the Windows builds.

In such a file, you could add the following function declarations:

#if !defined _UCRT
/* Workarounds against msvcrt bugs.  */
extern size_t gl_consolesafe_fwrite (const void *ptr, size_t size, size_t 
nmemb, FILE *fp)
# if __GNUC__ >= 4 || defined __clang__
     __attribute__ ((__nonnull__ (1, 4)))
# endif
     ;
# if defined __MINGW32__
extern int gl_consolesafe_fprintf (FILE *restrict fp, const char *restrict 
format, ...)
#  if __GNUC__ >= 5 && !defined __clang__
     __attribute__ ((__format__ (__printf__, 2, 3)))
#  endif
#  if __GNUC__ >= 4 || defined __clang__
     __attribute__ ((__nonnull__ (1, 2)))
#  endif
     ;
extern int gl_consolesafe_printf (const char *restrict format, ...)
#  if __GNUC__ >= 5 && !defined __clang__
     __attribute__ ((__format__ (__printf__, 1, 2)))
#  endif
#  if __GNUC__ >= 4 || defined __clang__
     __attribute__ ((__nonnull__ (1)))
#  endif
     ;
extern int gl_consolesafe_vfprintf (FILE *restrict fp, const char *restrict 
format, va_list args)
#  if __GNUC__ >= 5 && !defined __clang__
     __attribute__ ((__format__ (__printf__, 2, 0)))
#  endif
#  if __GNUC__ >= 4 || defined __clang__
     __attribute__ ((__nonnull__ (1, 2)))
#  endif
     ;
extern int gl_consolesafe_vprintf (const char *restrict format, va_list args)
#  if __GNUC__ >= 5 && !defined __clang__
     __attribute__ ((__format__ (__printf__, 1, 0)))
#  endif
#  if __GNUC__ >= 4 || defined __clang__
     __attribute__ ((__nonnull__ (1)))
#  endif
     ;
# endif
#endif

and somewhere also these redirects:

#define fwrite gl_consolesafe_fwrite
#define fprintf gl_consolesafe_fprintf
#define printf gl_consolesafe_printf
#define vfprintf gl_consolesafe_vfprintf
#define vprintf gl_consolesafe_vprintf

Bruno




Reply via email to