New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] Remove some compiler hoops to jump through for EBCDIC #15683
Comments
From @petdanceCreated by @petdanceThis patch simplifies two bits of code that I came across while The first, in Perl_validate_proto, removes unnecessary variable The second, in S_scan_const, rearranges some code and #ifdefs so that This diff may be easier to understand if it's viewed as two side-by-side Perl Info
|
From @petdancetoke-ebcdic.patchdiff --git a/toke.c b/toke.c
index cab34b9..b2d9209 100644
--- a/toke.c
+++ b/toke.c
@@ -1568,7 +1568,7 @@ bool
Perl_validate_proto(pTHX_ SV *name, SV *proto, bool warn)
{
STRLEN len, origlen;
- char *p = proto ? SvPV(proto, len) : NULL;
+ char *p;
bool bad_proto = FALSE;
bool in_brackets = FALSE;
bool after_slash = FALSE;
@@ -1583,6 +1583,7 @@ Perl_validate_proto(pTHX_ SV *name, SV *proto, bool warn)
if (!proto)
return TRUE;
+ p = SvPV(proto, len);
origlen = len;
for (; len--; p++) {
if (!isSPACE(*p)) {
@@ -2954,10 +2955,7 @@ S_scan_const(pTHX_ char *start)
IV range_max; /* last character in range */
STRLEN save_offset;
STRLEN grow;
-#ifndef EBCDIC /* Not meaningful except in EBCDIC, so initialize to false */
- const bool convert_unicode = FALSE;
- const IV real_range_max = 0;
-#else
+#ifdef EBCDIC
bool convert_unicode;
IV real_range_max = 0;
#endif
@@ -3002,12 +3000,14 @@ S_scan_const(pTHX_ char *start)
#endif
if (range_min > range_max) {
+#ifdef EBCDIC
if (convert_unicode) {
/* Need to convert back to native for meaningful
* messages for this platform */
range_min = UNI_TO_NATIVE(range_min);
range_max = UNI_TO_NATIVE(range_max);
}
+#endif
/* Use the characters themselves for the error message if
* ASCII printables; otherwise some visible representation
@@ -3017,6 +3017,7 @@ S_scan_const(pTHX_ char *start)
"Invalid range \"%c-%c\" in transliteration operator",
(char)range_min, (char)range_max);
}
+#ifdef EBCDIC
else if (convert_unicode) {
/* diag_listed_as: Invalid range "%s" in transliteration operator */
Perl_croak(aTHX_
@@ -3024,6 +3025,7 @@ S_scan_const(pTHX_ char *start)
" in transliteration operator",
range_min, range_max);
}
+#endif
else {
/* diag_listed_as: Invalid range "%s" in transliteration operator */
Perl_croak(aTHX_
@@ -3105,9 +3107,8 @@ S_scan_const(pTHX_ char *start)
* (min, max, and the hyphen) */
d = save_offset + SvGROW(sv, SvLEN(sv) + grow - 3);
- /* Here, we expand out the range. On ASCII platforms, the
- * compiler should optimize out the 'convert_unicode==TRUE'
- * portion of this */
+#ifdef EBCDIC
+ /* Here, we expand out the range. */
if (convert_unicode) {
IV i;
@@ -3126,7 +3127,10 @@ S_scan_const(pTHX_ char *start)
}
}
}
- else {
+ else
+#endif
+ /* Always gets run for ASCII, and sometimes for EBCDIC. */
+ {
IV i;
/* Here, no conversions are necessary, which means that the
@@ -3146,8 +3150,8 @@ S_scan_const(pTHX_ char *start)
}
}
- /* (Compilers should optimize this out for non-EBCDIC). If the
- * original range extended above 255, add in that portion */
+#ifdef EBCDIC
+ /* If the original range extended above 255, add in that portion. */
if (real_range_max) {
*d++ = (char) UTF8_TWO_BYTE_HI(0x100);
*d++ = (char) UTF8_TWO_BYTE_LO(0x100);
@@ -3156,6 +3160,7 @@ S_scan_const(pTHX_ char *start)
if (real_range_max > 0x100)
d = (char*)uvchr_to_utf8((U8*)d, real_range_max);
}
+#endif
range_done:
/* mark the range as done, and continue */
|
The RT System itself - Status changed from 'new' to 'open' |
@tonycoz - Status changed from 'open' to 'pending release' |
From @khwilliamsonOn 10/24/2016 10:45 PM, Andy Lester (via RT) wrote:
Given that this code was generating compiler warnings was the reason to But I do want to clarify that he reason I wrote it the way it was, was By coding it the way it was, I made it easier to read, and hence
|
From @petdance
That was my intent, too, to make it easier to follow for the programmer by encapsulating the EBCDIC-only variables within the ifdef blocks. |
From @arcAndy Lester via RT <perlbug-followup@perl.org> wrote:
(Apologies for the delay in this response; I meant to follow up on My own view is that the net consequence of this change is to make it #ifdef EBCDIC This sort of code interleaves conditionals written in two very I'm also aware that we have a lot of code with the sort of structure -- |
From @khwilliamsonOn 11/27/2016 11:41 AM, Aaron Crane wrote:
But, my understanding is that this patch silences compiler warnings that I've spent quite a bit of effort to try to eliminate EBCDIC vs ASCII |
From @petdance
Yes, that is correct. It was uncovered on my branch to enable clang's -Weverything. |
From @khwilliamsonThank you for filing this report. You have helped make Perl better. With the release today of Perl 5.26.0, this and 210 other issues have been Perl 5.26.0 may be downloaded via: If you find that the problem persists, feel free to reopen this ticket. |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#129961 (status was 'resolved')
Searchable as RT129961$
The text was updated successfully, but these errors were encountered: