ping.

On 10/15/2021 7:41 PM, Brad Smith wrote:
The following diff fixes namespace polution with C++ in the stdio.h
header.

I was looking into a build issue when trying to build another program
dependent on a new port I posted (spdlog). Peeking at one of it's
headers I noticed a workaround for OpenBSD that doesn't work anyway.

Fixing the stdio.h header, removing the workaround and it builds fine.

// OpenBSD doesn't compile with :: before the fileno(..)
#    if defined(__OpenBSD__)
     int fd = fileno(f);
#    else
     int fd = ::fileno(f);
#    endif

Fixing the stdio.h header also allows us to remove the only local
patch we have for libc++, which upstream is not willing to accept
as it is just working around the namespace polution which none of
the other OS's supported have.

diff --git a/libcxx/include/stdio.h b/libcxx/include/stdio.h
index f84122034891f..b57268c264162 100644
--- a/libcxx/include/stdio.h
+++ b/libcxx/include/stdio.h
@@ -113,6 +113,8 @@ void perror(const char* s);
  #undef clearerr
  #undef feof
  #undef ferror
+#undef putchar
+#undef getchar
#endif

https://svnweb.freebsd.org/base/head/include/stdio.h?r1=210957&r2=228875&diff_format=u
https://github.com/DragonFlyBSD/DragonFlyBSD/commit/513b6430389cd0d20fbc2e5aa62d9c5246729321
http://cvsweb.netbsd.org/bsdweb.cgi/src/include/stdio.h.diff?r1=1.86&r2=1.87&only_with_tag=MAIN

I had this run through a bulk ports build on i386 without any issues.

Index: stdio.h
===================================================================
RCS file: /home/cvs/src/include/stdio.h,v
retrieving revision 1.54
diff -u -p -u -p -r1.54 stdio.h
--- stdio.h     11 Sep 2020 17:56:41 -0000      1.54
+++ stdio.h     12 Oct 2021 03:35:08 -0000
@@ -395,13 +395,14 @@ static __inline int __sputc(int _c, FILE
                return (__swbuf(_c, _p));
  }
+extern int __isthreaded;
+
+#ifndef __cplusplus
  #define       __sfeof(p)      (((p)->_flags & __SEOF) != 0)
  #define       __sferror(p)    (((p)->_flags & __SERR) != 0)
  #define       __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
  #define       __sfileno(p)    ((p)->_file)
-extern int __isthreaded;
-
  #define feof(p)               (!__isthreaded ? __sfeof(p) : (feof)(p))
  #define ferror(p)     (!__isthreaded ? __sferror(p) : (ferror)(p))
  #define clearerr(p)   (!__isthreaded ? __sclearerr(p) : (clearerr)(p))
@@ -435,5 +436,6 @@ extern int __isthreaded;
  #define       putchar(x)      putc(x, stdout)
  #define getchar_unlocked()    getc_unlocked(stdin)
  #define putchar_unlocked(c)   putc_unlocked(c, stdout)
+#endif /* __cplusplus */
#endif /* _STDIO_H_ */


Reply via email to