public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix btowc and wctob in C++
Date: Mon, 27 Mar 2006 16:44:00 -0000	[thread overview]
Message-ID: <20060327164414.GB30252@sunsite.mff.cuni.cz> (raw)

Hi!

Doing:

#include <wchar.h>

void *p = (void *) btowc;

at -O1+ in C++ (or similarly if for whatever reason the inline isn't always
inlined) results in endless recursion:

        .section        .text.btowc,"axG",@progbits,btowc,comdat
        .align 2
        .p2align 4,,15
        .weak   btowc
        .type   btowc, @function
btowc:
        jmp     btowc
        .size   btowc, .-btowc

The optimization really relies on the GNU C extern inline behavior.
We use the same __*_alias trick in plenty of the _FORTIFY_SOURCE headers,
but none of them is used for C++ nor for non-GCC compilers.
__USE_EXTERN_INLINES implies GCC 2.7+, so we just need to check for C++.

2006-03-27  Jakub Jelinek  <jakub@redhat.com>

	* wcsmbs/wchar.h (btowc, wctob): Don't optimize in C++.

--- libc/wcsmbs/wchar.h.jj	2006-03-17 08:37:07.000000000 +0100
+++ libc/wcsmbs/wchar.h	2006-03-27 18:38:07.000000000 +0200
@@ -321,6 +321,7 @@ __END_NAMESPACE_C99
 #ifdef __USE_EXTERN_INLINES
 /* Define inline function as optimization.  */
 
+# ifndef __cplusplus
 /* We can use the BTOWC and WCTOB optimizations since we know that all
    locales must use ASCII encoding for the values in the ASCII range
    and because the wchar_t encoding is always ISO 10646.  */
@@ -335,6 +336,7 @@ extern __inline int
 __NTH (wctob (wint_t __wc))
 { return (__builtin_constant_p (__wc) && __wc >= L'\0' && __wc <= L'\x7f'
 	  ? (int) __wc : __wctob_alias (__wc)); }
+# endif
 
 extern __inline size_t
 __NTH (mbrlen (__const char *__restrict __s, size_t __n,


	Jakub

             reply	other threads:[~2006-03-27 16:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-27 16:44 Jakub Jelinek [this message]
2006-03-27 20:13 ` Ulrich Drepper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060327164414.GB30252@sunsite.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).