Skip to content

Commit

Permalink
locale.c, sv.c: compound literals are C99, but not C++
Browse files Browse the repository at this point in the history
C++ has a similar feature, but it has a different syntax, both
as of C++20 do support designated struct initializers.
  • Loading branch information
tonycoz authored and Leont committed May 24, 2023
1 parent 3b4552b commit 25dc730
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
29 changes: 19 additions & 10 deletions locale.c
Expand Up @@ -5323,11 +5323,12 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
* the list. Normally the loop is executed just once. But if setting the
* locale fails, inside the loop we add fallback trials to the array and so
* will execute the loop multiple times */
trial_locales[0] = (trial_locales_struct) {
trial_locales_struct ts = {
.trial_locale = setlocale_init,
.fallback_desc = NULL,
.fallback_name = NULL,
};
trial_locales[0] = ts;
trial_locales_count = 1;

for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) {
Expand Down Expand Up @@ -5485,13 +5486,14 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
goto done_lc_all;
}
}
trial_locales[trial_locales_count++] = (trial_locales_struct) {
trial_locales_struct ts = {
.trial_locale = lc_all,
.fallback_desc = (strEQ(lc_all, "C")
? "the standard locale"
: "a fallback locale"),
.fallback_name = lc_all,
};
trial_locales[trial_locales_count++] = ts;
}
done_lc_all:

Expand All @@ -5501,13 +5503,14 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
goto done_lang;
}
}
trial_locales[trial_locales_count++] = (trial_locales_struct) {
trial_locales_struct ts = {
.trial_locale = lang,
.fallback_desc = (strEQ(lang, "C")
? "the standard locale"
: "a fallback locale"),
.fallback_name = lang,
};
trial_locales[trial_locales_count++] = ts;
}
done_lang:

Expand Down Expand Up @@ -5544,13 +5547,14 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
}
}

trial_locales[trial_locales_count++] = (trial_locales_struct) {
trial_locales_struct ts = {
.trial_locale = system_default_locale,
.fallback_desc = (strEQ(system_default_locale, "C")
? "the standard locale"
: "the system default locale"),
.fallback_name = system_default_locale,
};
trial_locales[trial_locales_count++] = ts;
}
done_system_default:

Expand All @@ -5561,12 +5565,17 @@ Perl_init_i18nl10n(pTHX_ int printwarn)
goto done_C;
}
}
trial_locales[trial_locales_count++] = (trial_locales_struct) {
.trial_locale = "C",
.fallback_desc = "the standard locale",
.fallback_name = "C",
};

{
/* new scope to avoid C++ complaining about
initialization being bypassed by goto.
*/
trial_locales_struct ts = {
.trial_locale = "C",
.fallback_desc = "the standard locale",
.fallback_name = "C",
};
trial_locales[trial_locales_count++] = ts;
}
done_C: ;
} /* end of first time through the loop */
} /* end of looping through the trial locales */
Expand Down
39 changes: 25 additions & 14 deletions sv.c
Expand Up @@ -1062,20 +1062,28 @@ Perl_sv_upgrade(pTHX_ SV *const sv, svtype new_type)
SvANY(sv) = new_body;
switch(new_type) {
case SVt_PVAV:
*((XPVAV*) SvANY(sv)) = (XPVAV) {
.xmg_stash = NULL, .xmg_u = {.xmg_magic = NULL},
.xav_fill = -1, .xav_max = -1, .xav_alloc = 0
{
XPVAV pvav = {
.xmg_stash = NULL,
.xmg_u = {.xmg_magic = NULL},
.xav_fill = -1, .xav_max = -1, .xav_alloc = 0
};
*((XPVAV*) SvANY(sv)) = pvav;
}

AvREAL_only(sv);
break;
case SVt_PVHV:
*((XPVHV*) SvANY(sv)) = (XPVHV) {
.xmg_stash = NULL, .xmg_u = {.xmg_magic = NULL},
.xhv_keys = 0,
/* start with PERL_HASH_DEFAULT_HvMAX+1 buckets: */
.xhv_max = PERL_HASH_DEFAULT_HvMAX
{
XPVHV pvhv = {
.xmg_stash = NULL,
.xmg_u = {.xmg_magic = NULL},
.xhv_keys = 0,
/* start with PERL_HASH_DEFAULT_HvMAX+1 buckets: */
.xhv_max = PERL_HASH_DEFAULT_HvMAX
};
*((XPVHV*) SvANY(sv)) = pvhv;
}

assert(!SvOK(sv));
SvOK_off(sv);
Expand All @@ -1084,12 +1092,15 @@ Perl_sv_upgrade(pTHX_ SV *const sv, svtype new_type)
#endif
break;
case SVt_PVOBJ:
*((XPVOBJ*) SvANY(sv)) = (XPVOBJ) {
.xmg_stash = NULL, .xmg_u = {.xmg_magic = NULL},
.xobject_maxfield = -1,
.xobject_iter_sv_at = 0,
.xobject_fields = NULL,
};
{
XPVOBJ pvo = {
.xmg_stash = NULL, .xmg_u = {.xmg_magic = NULL},
.xobject_maxfield = -1,
.xobject_iter_sv_at = 0,
.xobject_fields = NULL,
};
*((XPVOBJ*) SvANY(sv)) = pvo;
}
break;
default:
NOT_REACHED;
Expand Down

0 comments on commit 25dc730

Please sign in to comment.