public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Felipe Magno de Almeida <felipe.m.almeida@gmail.com>
Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: Fix compilation errors with libstdc++v3 for AVR target and allow --enable-libstdcxx
Date: Tue, 10 Jan 2017 14:16:00 -0000	[thread overview]
Message-ID: <20170110141611.GL13348@redhat.com> (raw)
In-Reply-To: <CADfx-VRcaMXjyZ27xHvgP==zpMw=SUzu=KhAC91cs3i7p74qUA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 703 bytes --]

On 23/12/16 13:18 -0200, Felipe Magno de Almeida wrote:
>On Fri, Dec 16, 2016 at 10:45 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
>> On 15/12/16 21:41 -0300, Felipe Magno de Almeida wrote:
>>>
>>> Good point. Do you want me to update the patch with __men or go your way
>>> with the wrapper?
>
>Hello Jonathan,
>
>> I think my wrapper's too ugly :-)
>
>:)
>
>> So please follow the same approach as for tm_mon (pass __mem to the
>> function, the copy it to tm_mon if there was no error). That adds a
>> write and a branch for every extracted field, which I hope shouldn't
>> have too much impact.
>
>Please find it attached.

This has now been committed to trunk (with whitespace fixes) - thanks.


[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 4944 bytes --]

commit 1cf9a4be2647a9bb54e763b74fb09d5a21706bd6
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jan 10 12:43:29 2017 +0000

    Use temporary int objects to access struct tm members
    
    Call _M_extract_* functions family through temporary int objects, so
    it doesn't convert from lvalue to rvalue through a temporary in AVR
    because of the incompatible types used in AVR-Libc.
    
    This fixes compilation errors with AVR-Libc while compiling libstdc++
    for AVR target.
    
    2017-01-10  Felipe Magno de Almeida <felipe@expertisesolutions.com.br>
    
    	* include/bits/locale_facets_nonio.tcc
    	(time_get::_M_extract_via_format): Avoid compilation errors with
    	non-standard struct tm.

diff --git a/libstdc++-v3/include/bits/locale_facets_nonio.tcc b/libstdc++-v3/include/bits/locale_facets_nonio.tcc
index 2fcf234..a449c41 100644
--- a/libstdc++-v3/include/bits/locale_facets_nonio.tcc
+++ b/libstdc++-v3/include/bits/locale_facets_nonio.tcc
@@ -659,30 +659,38 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
 		  // Abbreviated weekday name [tm_wday]
 		  const char_type*  __days1[7];
 		  __tp._M_days_abbreviated(__days1);
-		  __beg = _M_extract_name(__beg, __end, __tm->tm_wday, __days1,
+		  __beg = _M_extract_name(__beg, __end, __mem, __days1,
 					  7, __io, __tmperr);
+		  if (!__tmperr)
+		    __tm->tm_wday = __mem;
 		  break;
 		case 'A':
 		  // Weekday name [tm_wday].
 		  const char_type*  __days2[7];
 		  __tp._M_days(__days2);
-		  __beg = _M_extract_name(__beg, __end, __tm->tm_wday, __days2,
+		  __beg = _M_extract_name(__beg, __end, __mem, __days2,
 					  7, __io, __tmperr);
+		  if (!__tmperr)
+		    __tm->tm_wday = __mem;
 		  break;
 		case 'h':
 		case 'b':
 		  // Abbreviated month name [tm_mon]
 		  const char_type*  __months1[12];
 		  __tp._M_months_abbreviated(__months1);
-		  __beg = _M_extract_name(__beg, __end, __tm->tm_mon, 
+		  __beg = _M_extract_name(__beg, __end, __mem,
 					  __months1, 12, __io, __tmperr);
+		  if (!__tmperr)
+		    __tm->tm_mon = __mem;
 		  break;
 		case 'B':
 		  // Month name [tm_mon].
 		  const char_type*  __months2[12];
 		  __tp._M_months(__months2);
-		  __beg = _M_extract_name(__beg, __end, __tm->tm_mon, 
+		  __beg = _M_extract_name(__beg, __end, __mem,
 					  __months2, 12, __io, __tmperr);
+		  if (!__tmperr)
+		    __tm->tm_mon = __mem;
 		  break;
 		case 'c':
 		  // Default time and date representation.
@@ -693,18 +701,22 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
 		  break;
 		case 'd':
 		  // Day [01, 31]. [tm_mday]
-		  __beg = _M_extract_num(__beg, __end, __tm->tm_mday, 1, 31, 2,
+		  __beg = _M_extract_num(__beg, __end, __mem, 1, 31, 2,
 					 __io, __tmperr);
+		  if (!__tmperr)
+		    __tm->tm_mday = __mem;
 		  break;
 		case 'e':
 		  // Day [1, 31], with single digits preceded by
 		  // space. [tm_mday]
 		  if (__ctype.is(ctype_base::space, *__beg))
-		    __beg = _M_extract_num(++__beg, __end, __tm->tm_mday, 1, 9,
+		    __beg = _M_extract_num(++__beg, __end, __mem, 1, 9,
 					   1, __io, __tmperr);
 		  else
-		    __beg = _M_extract_num(__beg, __end, __tm->tm_mday, 10, 31,
+		    __beg = _M_extract_num(__beg, __end, __mem, 10, 31,
 					   2, __io, __tmperr);
+		  if (!__tmperr)
+		    __tm->tm_mday = __mem;
 		  break;
 		case 'D':
 		  // Equivalent to %m/%d/%y.[tm_mon, tm_mday, tm_year]
@@ -715,13 +727,17 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
 		  break;
 		case 'H':
 		  // Hour [00, 23]. [tm_hour]
-		  __beg = _M_extract_num(__beg, __end, __tm->tm_hour, 0, 23, 2,
+		  __beg = _M_extract_num(__beg, __end, __mem, 0, 23, 2,
 					 __io, __tmperr);
+		  if (!__tmperr)
+		    __tm->tm_hour = __mem;
 		  break;
 		case 'I':
 		  // Hour [01, 12]. [tm_hour]
-		  __beg = _M_extract_num(__beg, __end, __tm->tm_hour, 1, 12, 2,
+		  __beg = _M_extract_num(__beg, __end, __mem, 1, 12, 2,
 					 __io, __tmperr);
+		  if (!__tmperr)
+		    __tm->tm_hour = __mem;
 		  break;
 		case 'm':
 		  // Month [01, 12]. [tm_mon]
@@ -732,8 +748,10 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
 		  break;
 		case 'M':
 		  // Minute [00, 59]. [tm_min]
-		  __beg = _M_extract_num(__beg, __end, __tm->tm_min, 0, 59, 2,
+		  __beg = _M_extract_num(__beg, __end, __mem, 0, 59, 2,
 					 __io, __tmperr);
+		  if (!__tmperr)
+		    __tm->tm_min = __mem;
 		  break;
 		case 'n':
 		  if (__ctype.narrow(*__beg, 0) == '\n')
@@ -752,11 +770,13 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
 		  // Seconds. [tm_sec]
 		  // [00, 60] in C99 (one leap-second), [00, 61] in C89.
 #if _GLIBCXX_USE_C99
-		  __beg = _M_extract_num(__beg, __end, __tm->tm_sec, 0, 60, 2,
+		  __beg = _M_extract_num(__beg, __end, __mem, 0, 60, 2,
 #else
-		  __beg = _M_extract_num(__beg, __end, __tm->tm_sec, 0, 61, 2,
+		  __beg = _M_extract_num(__beg, __end, __mem, 0, 61, 2,
 #endif
 					 __io, __tmperr);
+		  if (!__tmperr)
+		  __tm->tm_sec = __mem;
 		  break;
 		case 't':
 		  if (__ctype.narrow(*__beg, 0) == '\t')

      reply	other threads:[~2017-01-10 14:16 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-16  5:10 Felipe Magno de Almeida
2016-09-16  5:53 ` Marc Glisse
2016-09-16  6:19   ` Felipe Magno de Almeida
2016-09-16  7:01     ` Felipe Magno de Almeida
2016-11-10 15:40       ` Felipe Magno de Almeida
2016-11-10 15:52         ` Felipe Magno de Almeida
2016-12-06 15:08           ` Jonathan Wakely
2016-12-06 17:59           ` Jonathan Wakely
2023-09-29 14:07             ` Jonathan Wakely
2023-09-29 14:30               ` Jonathan Wakely
2016-12-06 18:11           ` Jonathan Wakely
2016-11-12  3:19         ` Jonathan Wakely
2016-12-06 18:45     ` Jonathan Wakely
2016-12-14 21:43       ` Felipe Magno de Almeida
2016-12-15 11:34         ` Jonathan Wakely
     [not found]           ` <CADfx-VRosQDhU0uOQhknAzcbhVyrdnQ9n=9NmGVmPkP9n+NqGg@mail.gmail.com>
2016-12-16 12:51             ` Jonathan Wakely
2016-12-23 16:09               ` Felipe Magno de Almeida
2017-01-10 14:16                 ` Jonathan Wakely [this message]

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=20170110141611.GL13348@redhat.com \
    --to=jwakely@redhat.com \
    --cc=felipe.m.almeida@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /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).