From: Torbjorn SVENSSON <torbjorn.svensson@st.com>
To: Jeff Johnston <jjohnstn@redhat.com>
Cc: Newlib <newlib@sourceware.org>
Subject: RE: [PATCH 3/3] libc: Replace one letter member names in __tzrule_struct
Date: Fri, 2 Oct 2020 07:36:08 +0000 [thread overview]
Message-ID: <AM6PR10MB2197FED021BB7DD7FA57971181310@AM6PR10MB2197.EURPRD10.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <CAOox84vVzPbBGf3hU+JFRjsNm-RkmicLgBodVHOQM3ZYTnEVkw@mail.gmail.com>
Hello!
Thanks for the feedback Jeff.
Regarding the alternative to using "__" prefix for the members; would it be better to move line 105-123 from newlib/libc/include/time.h to newlib/libc/time/local.h, thus not exposing it in the API?
The lines in question are:
typedef struct __tzrule_struct
{
char ch;
int m;
int n;
int d;
int s;
time_t change;
long offset; /* Match type of _timezone. */
} __tzrule_type;
typedef struct __tzinfo_struct
{
int __tznorth;
int __tzyear;
__tzrule_type __tzrule[2];
} __tzinfo_type;
__tzinfo_type *__gettzinfo (void);
Would this change be easier to get accepted? If this approach is better, I guess the single letter member names can be kept too…
While I took another look at the change, I also noticed that the struct definition (not usage) is also present in these files:
newlib/libc/sys/linux/include/time.h
newlib/libc/sys/phoenix/include/time.h
I’m not sure in what situations those files are used and when the time.h file that I modified is used, but I guess they should be in sync regardless.
Thanks
Torbjörn
From: Jeff Johnston <jjohnstn@redhat.com>
Sent: den 2 oktober 2020 01:21
To: Torbjorn SVENSSON <torbjorn.svensson@st.com>
Cc: Newlib <newlib@sourceware.org>
Subject: Re: [PATCH 3/3] libc: Replace one letter member names in __tzrule_struct
Hello, while I fully agree there is an issue (the struct was due to my initial check-in in 2005 based on glibc), the change will break API and thus technically requires a major release bump of newlib. I would prefer to wait for something else
to require a major bump before making such a change. In such a case, I also believe that the patch should either use double-underscores for the field names (e.g. __month) or hide the struct from regular users of time.h.
-- Jeff J.
On Thu, Oct 1, 2020 at 10:19 AM Torbjörn SVENSSON via Newlib <mailto:newlib@sourceware.org> wrote:
As discussed in GCC bug 97088
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97088), parameters in
prototypes of library functions should use reserved names, or no name
at all.
This patch replaces 'm', 'n', 'd' and 's' members in
'struct __tzrule_struct' to avoid possible clashes with user code in
case someone uses before including Newlib's time.h (or uses some
other conflicting definition)
Signed-off-by: Torbjörn SVENSSON <mailto:torbjorn.svensson@st.com>
---
newlib/libc/include/time.h | 8 ++++----
newlib/libc/time/tzcalc_limits.c | 14 +++++++-------
newlib/libc/time/tzset_r.c | 22 +++++++++++-----------
3 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/newlib/libc/include/time.h b/newlib/libc/include/time.h
index 3031590b4..6a540537f 100644
--- a/newlib/libc/include/time.h
+++ b/newlib/libc/include/time.h
@@ -105,10 +105,10 @@ void _tzset_r (struct _reent *);
typedef struct __tzrule_struct
{
char ch;
- int m;
- int n;
- int d;
- int s;
+ int month; /* Month of year if ch=M */
+ int week; /* Week of month if ch=M */
+ int day; /* Day of week if ch=M, day of year if ch=J or ch=D */
+ int secs; /* Time of day in seconds */
time_t change;
long offset; /* Match type of _timezone. */
} __tzrule_type;
diff --git a/newlib/libc/time/tzcalc_limits.c b/newlib/libc/time/tzcalc_limits.c
index e0ea6549c..b2163ed3d 100644
--- a/newlib/libc/time/tzcalc_limits.c
+++ b/newlib/libc/time/tzcalc_limits.c
@@ -34,13 +34,13 @@ __tzcalc_limits (int year)
if (tz->__tzrule[i].ch == 'J')
{
/* The Julian day n (1 <= n <= 365). */
- days = year_days + tz->__tzrule[i].d +
- (isleap(year) && tz->__tzrule[i].d >= 60);
+ days = year_days + tz->__tzrule[i].day +
+ (isleap(year) && tz->__tzrule[i].day >= 60);
/* Convert to yday */
--days;
}
else if (tz->__tzrule[i].ch == 'D')
- days = year_days + tz->__tzrule[i].d;
+ days = year_days + tz->__tzrule[i].day;
else
{
const int yleap = isleap(year);
@@ -49,15 +49,15 @@ __tzcalc_limits (int year)
days = year_days;
- for (j = 1; j < tz->__tzrule[i].m; ++j)
+ for (j = 1; j < tz->__tzrule[i].month; ++j)
days += ip[j-1];
m_wday = (EPOCH_WDAY + days) % DAYSPERWEEK;
- wday_diff = tz->__tzrule[i].d - m_wday;
+ wday_diff = tz->__tzrule[i].day - m_wday;
if (wday_diff < 0)
wday_diff += DAYSPERWEEK;
- m_day = (tz->__tzrule[i].n - 1) * DAYSPERWEEK + wday_diff;
+ m_day = (tz->__tzrule[i].week - 1) * DAYSPERWEEK + wday_diff;
while (m_day >= ip[j-1])
m_day -= DAYSPERWEEK;
@@ -67,7 +67,7 @@ __tzcalc_limits (int year)
/* store the change-over time in GMT form by adding offset */
tz->__tzrule[i].change = days * SECSPERDAY +
- tz->__tzrule[i].s + tz->__tzrule[i].offset;
+ tz->__tzrule[i].secs + tz->__tzrule[i].offset;
}
tz->__tznorth = (tz->__tzrule[0].change < tz->__tzrule[1].change);
diff --git a/newlib/libc/time/tzset_r.c b/newlib/libc/time/tzset_r.c
index 9e0cf834b..7117b51e6 100644
--- a/newlib/libc/time/tzset_r.c
+++ b/newlib/libc/time/tzset_r.c
@@ -115,9 +115,9 @@ _tzset_unlocked_r (struct _reent *reent_ptr)
return;
tz->__tzrule[i].ch = 'M';
- tz->__tzrule[i].m = m;
- tz->__tzrule[i].n = w;
- tz->__tzrule[i].d = d;
+ tz->__tzrule[i].month = m;
+ tz->__tzrule[i].week = w;
+ tz->__tzrule[i].day = d;
tzenv += n;
}
@@ -142,22 +142,22 @@ _tzset_unlocked_r (struct _reent *reent_ptr)
if (i == 0)
{
tz->__tzrule[0].ch = 'M';
- tz->__tzrule[0].m = 3;
- tz->__tzrule[0].n = 2;
- tz->__tzrule[0].d = 0;
+ tz->__tzrule[0].month = 3;
+ tz->__tzrule[0].week = 2;
+ tz->__tzrule[0].day = 0;
}
else
{
tz->__tzrule[1].ch = 'M';
- tz->__tzrule[1].m = 11;
- tz->__tzrule[1].n = 1;
- tz->__tzrule[1].d = 0;
+ tz->__tzrule[1].month = 11;
+ tz->__tzrule[1].week = 1;
+ tz->__tzrule[1].day = 0;
}
}
else
{
tz->__tzrule[i].ch = ch;
- tz->__tzrule[i].d = d;
+ tz->__tzrule[i].day = d;
}
tzenv = end;
@@ -172,7 +172,7 @@ _tzset_unlocked_r (struct _reent *reent_ptr)
if (*tzenv == '/')
sscanf (tzenv, "/%hu%n:%hu%n:%hu%n", &hh, &n, &mm, &n, &ss, &n);
- tz->__tzrule[i].s = ss + SECSPERMIN * mm + SECSPERHOUR * hh;
+ tz->__tzrule[i].secs = ss + SECSPERMIN * mm + SECSPERHOUR * hh;
tzenv += n;
}
--
2.18.0
next prev parent reply other threads:[~2020-10-02 7:36 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-01 14:17 [PATCH 0/3] libc: Comply with the libstdc++ test case names.cc Torbjörn SVENSSON
2020-10-01 14:17 ` [PATCH 1/3] libc/include/inttypes.h: Remove parameter name Torbjörn SVENSSON
2020-10-01 23:22 ` Jeff Johnston
2020-10-02 6:52 ` Torbjorn SVENSSON
2020-10-02 6:53 ` nrupp
2020-10-02 21:01 ` Jeff Johnston
2020-10-01 14:17 ` [PATCH 2/3] libc/include/wchar.h: " Torbjörn SVENSSON
2020-10-01 23:24 ` Jeff Johnston
2020-10-02 6:53 ` Torbjorn SVENSSON
2020-10-02 21:02 ` Jeff Johnston
2020-10-01 14:17 ` [PATCH 3/3] libc: Replace one letter member names in __tzrule_struct Torbjörn SVENSSON
2020-10-01 23:21 ` Jeff Johnston
2020-10-02 7:36 ` Torbjorn SVENSSON [this message]
2020-10-02 21:04 ` Jeff Johnston
2020-10-05 12:50 ` [PATCH v2] libc/time: Move internal newlib tz-structs to local.h Torbjörn SVENSSON
2020-10-15 6:52 ` Torbjorn SVENSSON
2020-10-15 10:21 ` Corinna Vinschen
2020-10-15 16:47 ` Torbjorn SVENSSON
2020-10-15 17:09 ` Jeff Johnston
2020-10-15 17:15 ` Corinna Vinschen
2020-10-15 17:11 ` Corinna Vinschen
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=AM6PR10MB2197FED021BB7DD7FA57971181310@AM6PR10MB2197.EURPRD10.PROD.OUTLOOK.COM \
--to=torbjorn.svensson@st.com \
--cc=jjohnstn@redhat.com \
--cc=newlib@sourceware.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).