Index: gnu/usr.bin/perl/.lgtm.yml =================================================================== RCS file: gnu/usr.bin/perl/.lgtm.yml diff -N gnu/usr.bin/perl/.lgtm.yml --- gnu/usr.bin/perl/.lgtm.yml 30 Dec 2019 02:10:02 -0000 1.1.1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,15 +0,0 @@ -extraction: - cpp: - configure: - command: - - "./Configure -des -Dusedevel" - index: - build_command: - - "make" -path_classifiers: - generated: - - charclass_invlists.h - # These files are incorrectly classified as generated. Work around - # this pending a fix on LGTM.com. - - exclude: perl.c - - exclude: op.c Index: gnu/usr.bin/perl/AUTHORS =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/AUTHORS,v diff -u -p -a -u -p -r1.12 AUTHORS --- gnu/usr.bin/perl/AUTHORS 14 May 2024 19:38:53 -0000 1.12 +++ gnu/usr.bin/perl/AUTHORS 22 Jan 2025 00:37:41 -0000 @@ -28,7 +28,7 @@ Aaron J. Mackey Aaron Trevena -Abe Timmerman +Abe Timmerman Abhijit Menon-Sen Abigail Abir Viqar @@ -72,6 +72,7 @@ Alexander Foken Alexander Gernler Alexander Gough Alexander Hartmaier +Alexander Kanavin Alexander Klimov Alexander Nikolov Alexander Smishlajev @@ -90,6 +91,7 @@ Allen Smith Ambrose Kofi Laing Ammon Riley +Amory Meltzer Ananth Kesari Anatoly Vorobey Anders Johnson @@ -100,6 +102,7 @@ Andreas König Andreas Schwab Andreas Voegele +Andrei Horodniceanu Andrei Yelistratov Andrej Borsenkow Andrew Bettison @@ -159,6 +162,7 @@ Bart Van Assche Bas van Sisseren Beau Cox +Beckett Normington Ben Carter Ben Cornett Ben Hengst @@ -229,6 +233,7 @@ Bruce Barnett Bruce J. Keeler Bruce P. Schuck +Bruno Meneguele Bryan Stenson Bud Huff Byron Brummer @@ -318,6 +323,7 @@ Damon Atkins Dan Boorstein Dan Brook +Dan Church Dan Collins Dan Dascalescu Dan Dedrick @@ -460,6 +466,7 @@ Eric Melville Eric Promislow Erich Rickheit Erik +Erik Huelsmann Eryq Etienne Grossman Eugen Konkov @@ -509,6 +516,7 @@ Gerard Goossen Gerd Knops Gerrit P. Haase +Gianni Ceccarelli Gideon Israel Dsouza Giles Lean Giovanni Tataranni @@ -528,6 +536,7 @@ Grant McLean Greg Chapman Greg Earle +Greg Kennedy Greg Kuperberg Greg Matheson Greg Seibert @@ -537,6 +546,7 @@ gregor herrmann Guenter Schmidt Guido Flohr +guoguangwu Guruprasad S Gurusamy Sarathy Gustaf Neumann @@ -576,6 +586,7 @@ Hugo van der Sanden Huw Rogers Håkon Hægland +iabyn Iain Truskett Ian Goodacre Ian Maloney @@ -920,8 +931,10 @@ Marty Lucich Martyn Pearce Marvin Humphrey +Masahiro Honma Masahiro KAJIURA Mashrab Kuvatov +Mathias Kende Mathias Koerber Mathieu Arnold Mats Peterson @@ -1050,6 +1063,7 @@ Olivier Mengué Olli Savia Ollivier Robert +OpossumPetya Osvaldo Villalon Owain G. Ainsworth Owen Taylor @@ -1158,6 +1172,7 @@ Randy Stauner Raul Dias +Raul E Rangel Raymund Will Redvers Davies Reini Urban @@ -1433,6 +1448,7 @@ Wayne Scott Wilfredo Sánchez William J. Middleton +William Lyu William Mann William Middleton William R Ward @@ -1443,6 +1459,7 @@ Wilson P. Snyder II Winfried König Wolfgang Laun Wolfram Humann +x-yuri Xavier Noria YAMASHINA Hio Yaroslav Kuzmin @@ -1462,5 +1479,6 @@ Zbynek Vyskovsky Zsbán Ambrus Ævar Arnfjörð Bjarmason +Дилян Палаузов Михаил Козачков 小鸡 <345865759@163.com> Index: gnu/usr.bin/perl/Configure =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Configure,v diff -u -p -a -u -p -r1.56 Configure --- gnu/usr.bin/perl/Configure 14 May 2024 19:39:39 -0000 1.56 +++ gnu/usr.bin/perl/Configure 22 Jan 2025 00:37:41 -0000 @@ -707,7 +707,6 @@ d_nexttoward='' d_nice='' d_nl_langinfo='' d_nl_langinfo_l='' -d_thread_safe_nl_langinfo_l='' d_off64_t='' d_open3='' d_fpathconf='' @@ -954,6 +953,11 @@ d_wcsxfrm='' d_wctomb='' d_writev='' default_inc_excludes_dot='' +d_perl_lc_all_category_positions_init='' +d_perl_lc_all_separator='' +d_perl_lc_all_uses_name_value_pairs='' +perl_lc_all_category_positions_init='' +perl_lc_all_separator='' dlext='' bin_ELF='' cccdlflags='' @@ -2608,6 +2612,11 @@ for file in $loclist; do *) echo "I don't know where '$file' is, and my life depends on it." >&4 echo "Go find a public domain implementation or fix your PATH setting!" >&4 + + test -f /etc/debian_version && echo "Run \"apt install build-essential\" to install make and friends" >&4 + test -f /etc/SUSE-brand && echo "Run \"zypper install 'pattern:devel_C_C++'\" to install make and friends" >&4 + test -f /etc/redhat-release && echo "Run \"yum groupinstall 'Development Tools'\" to install make and friends" >&4 + test -f /etc/fedora-release && echo "Run \"dnf group install 'Development Tools'\" to install make and friends" >&4 exit 1 ;; esac @@ -10994,7 +11003,6 @@ set atoll d_atoll eval $inlibc : See if a file contains compiler warnings -: See if a file contains compiler warnings case "$osname" in 'aix') cat >compiler_warning <try.c < -#endif -#include -#$i_langinfo I_LANGINFO -#ifdef I_LANGINFO -# include -#endif -#$i_pthread I_PTHREAD -#ifdef I_PTHREAD -# include -#endif -#$i_locale I_LOCALE -#ifdef I_LOCALE -# include -#endif - -void * -thread_start(void * arg) -{ - nl_langinfo(RADIXCHAR); -} - -int main() { - char * main_buffer; - char save_main_buffer[1000]; - pthread_t subthread; - pthread_attr_t attr; - - main_buffer = nl_langinfo_l(CODESET, newlocale(LC_ALL_MASK, "C", 0)); - - /* If too large for our generous allowance, just assume we don't have - * it. */ - if (strlen(main_buffer) >= sizeof(save_main_buffer)) { - exit(1); - } - - strcpy(save_main_buffer, main_buffer); - - if (pthread_attr_init(&attr) != 0) { - exit(1); - } - - if (pthread_create(&subthread, &attr, thread_start, NULL) != 0) { - exit(1); - } - - if (pthread_join(subthread, NULL) != 0) { - exit(1); - } - - exit(! (strcmp(main_buffer, save_main_buffer) == 0)); -} -EOCP -case "$usethreads" in - define) - set try - if eval $compile; then - echo "Your system has nl_langinfo_l()..." >&4 - d_nl_langinfo_l="$define" - echo "$d_nl_langinfo_l" >&4 - if $run ./try; then - echo "and it is thread-safe (just as I'd hoped)." >&4 - d_thread_safe_nl_langinfo_l="$define" - echo "$d_thread_safe_nl_langinfo_l" >&4 - else - echo "but it isn't thread-safe." >&4 - fi - else - echo "your system does not have nl_langinfo_l()" >&4 - fi - ;; - *) echo "Since threads aren't selected, we won't bother looking for nl_langinfo_l()" >&4 -esac -if test X"$d_nl_langinfo_l" = X; then - d_nl_langinfo_l="$undef" -fi -if test X"$d_thread_safe_nl_langinfo_l" = X; then - d_thread_safe_nl_langinfo_l="$undef" -fi -$rm_try +set nl_langinfo_l d_nl_langinfo_l +eval $inlibc : Look for non 'int'-sized bitfields case "$d_non_int_bitfields" in @@ -17403,156 +17322,701 @@ fi set pause d_pause eval $inlibc -: see if pipe2 exists -set pipe2 d_pipe2 -eval $inlibc +: see if locale.h is available +set locale.h i_locale +eval $inhdr -: see if poll exists -set poll d_poll -eval $inlibc +: see if this system has wctype.h +set wctype.h i_wctype +eval $inhdr -: see if prctl exists -set prctl d_prctl +: see if towupper exists +set towupper d_towupper eval $inlibc -: see if prctl supports PR_SET_NAME -d_prctl_set_name=$undef -case $d_prctl in - $define) - $cat >try.c < -#endif -#include +: check for setlocale function and behavior +case "$d_setlocale" in +'') +$cat >&4 <try.c < +#include +#$i_locale I_LOCALE +#ifdef I_LOCALE +# include +#endif +#$i_wctype I_WCTYPE +#ifdef I_WCTYPE +# include +#endif -: see if readlink exists -set readlink d_readlink -eval $inlibc +int main() { + const char * invalid_name = "\a"; /* This is really invalid! */ + int accepts_any_locale_name = 0; + int has_C_UTF8 = 0; + unsigned char bad_setlocale = 255; -: Check if there is a /proc symlink to the abs path of -: the executing program. We will honor hints of d_procselfexe=$undef -: or procselfexe being non-empty, otherwise will try to determine both -: if we have readlink. -: AmigaOS will attempt to mount proc: aka /proc, if /proc/... is -: referenced, and AmigaOS does not have a proc filesystem anyway. -echo " " -val="$undef" -if $test "X$d_procselfexe" = Xundef; then - procselfexe='' -elif $test "X$procselfexe" != X -a "X$procselfexe" != 'X '; then - val="$define" -elif $test "X$d_readlink" = Xdefine; then - : NetBSD first as /proc/self is a symlink to /proc/curproc, - : and it feels more tidy to avoid an extra level of symlink - set NetBSD /proc/curproc/exe Linux /proc/self/exe FreeBSD /proc/curproc/file Solaris /proc/self/path/a.out - while test $# -gt 0; do - type=$1; try=$2 - shift; shift - if $issymlink $try; then - $ls -l $try > reflect - if $contains /`basename $ls` reflect >/dev/null 2>&1; then - echo "You have $type-like $try." - procselfexe='"'$try'"' - val="$define" - : This will break out of the loop - set X; shift - fi - fi - done -fi -$rm -f reflect -set d_procselfexe -eval $setvar + /* If LC_CTYPE isn't defined the compilation will fail, and locales will be + * disabled. It's hard to imagine an instance where meaningful locale + * handling could be done without LC_CTYPE */ + const char * name = setlocale(LC_CTYPE, "C"); -: backward compatibility for d_hvfork -if test X$d_hvfork != X; then - d_vfork="$d_hvfork" - d_hvfork='' -fi -: see if there is a vfork -val='' -set vfork val -eval $inlibc + if (name == NULL || strcmp(name, "C") != 0) { + exit(bad_setlocale); + } -d_pseudofork=$undef + name = setlocale(LC_CTYPE, invalid_name); + if (name != NULL) { -: Ok, but do we want to use it. vfork is reportedly unreliable in -: perl on Solaris 2.x, and probably elsewhere. -case "$val" in -$define) - echo " " - case "$usevfork" in - false) dflt='n';; - *) dflt='y';; - esac - cat <<'EOM' + /* Let it pass if it accepts the name but gives back one of the C + * locales */ + if (strcmp(name, "C") != 0 && strcmp(name, "C.UTF-8") != 0) { + accepts_any_locale_name = 1; + } + } -Perl can only use a vfork() that doesn't suffer from strict -restrictions on calling functions or modifying global data in -the child. For example, glibc-2.1 contains such a vfork() -that is unsuitable. If your system provides a proper fork() -call, chances are that you do NOT want perl to use vfork(). + name = setlocale(LC_CTYPE, "C.UTF-8"); + if (name != NULL) { + unsigned char y_with_diaeresis = ('A' == 193) ? 0xDF : 0xFF; -EOM - rp="Do you still want to use vfork()?" - . ./myread - case "$ans" in - y|Y) ;; - *) - echo "Ok, we won't use vfork()." - val="$undef" - ;; - esac - ;; -esac -set d_vfork -eval $setvar -case "$d_vfork" in -$define) usevfork='true';; -*) usevfork='false';; -esac +#$d_towupper HAS_TOWUPPER +#ifdef HAS_TOWUPPER -: see whether the pthread_atfork exists -$cat >try.c < -#include -int main() { -#ifdef PTHREAD_ATFORK - pthread_atfork(NULL,NULL,NULL); -#endif -} -EOP + /* We assume that if the machine doesn't have the C99 towupper, it + * doesn't have C.UTF-8, even if we successfully changed locales to + * include it. This seems safer even on platforms that didn't accept + * the really invalid name */ -: see if pthread_atfork exists -set try -DPTHREAD_ATFORK -if eval $compile; then - val="$define" -else - val="$undef" -fi -case "$usethreads" in -$define) - case "$val" in - $define) echo 'pthread_atfork found.' >&4 ;; - *) echo 'pthread_atfork NOT found.' >&4 ;; - esac -esac -set d_pthread_atfork -eval $setvar + if (towupper(y_with_diaeresis) == 0x178) { + has_C_UTF8 = 1; + } + +#endif + + } + + exit( 0 /* (separator - min_separator) << 3 + | uses_name_value_pair_names << 2 + */ + | has_C_UTF8 << 1 + | accepts_any_locale_name); + +} +EOCP +val= +set d_setlocale +eval $setvar +case $d_setlocale in + $undef) d_setlocale_accepts_any_locale_name="$undef" + d_has_C_UTF8="false" + ;; + *) set try + if eval $compile; then + echo "Your system has setlocale()..." >&4 + $run ./try + case $? in + 0) echo "and it seems sane; you don't have a C.UTF-8 locale" >&4 + d_setlocale="$define" + d_setlocale_accepts_any_locale_name="$undef" + d_has_C_UTF8="false" + ;; + 1) echo "and it seems sane, but accepts any locale name as valid" >&4 + d_setlocale="$define" + d_setlocale_accepts_any_locale_name="$define" + d_has_C_UTF8="false" + ;; + 2) echo "and it seems sane; you have a C.UTF-8 locale" >&4 + d_setlocale="$define" + d_setlocale_accepts_any_locale_name="$undef" + d_has_C_UTF8="true" + ;; + 3) echo "and it seems sane, but accepts any locale name as valid" >&4 + d_setlocale="$define" + d_setlocale_accepts_any_locale_name="$define" + d_has_C_UTF8="true" + ;; + *) echo "but it doesn't seem to work, so we won't use it." >&4 + d_setlocale="$undef" + d_setlocale_accepts_any_locale_name="$undef" + d_has_C_UTF8="false" + ;; + esac + else + echo "your system does not have setlocale()" >&4 + d_setlocale="$undef" + d_setlocale_accepts_any_locale_name="$undef" + d_has_C_UTF8="false" + fi +esac +$rm_try +;; +*) val="$d_setlocale" + set d_setlocale + eval $setvar + case "$d_setlocale" in + $undef) echo "There may be other ways to set the locale on your system, so we need to ask:" >&4 + ;; + esac + rp="Does your system have the C.UTF-8 locale?" + dflt=n + . ./myread + case "$ans" in + [Yy]*) d_has_C_UTF8="true" + c_utf8_locale=" or C.UTF-8" + ;; + *) d_has_C_UTF8="false" + c_utf8_locale="" + ;; + esac + case "$d_setlocale" in + $define) + rp="When you set your locale to something besides C$c_utf8_locale, does it actually do so? (Answer no if it just pretends to set it)" >&4 + dflt=n + . ./myread + case "$ans" in + true|[Yy]*) + d_setlocale_accepts_any_locale_name="$define" + ;; + *) d_setlocale_accepts_any_locale_name="$undef" + ;; + esac + ;; + *) d_setlocale_accepts_any_locale_name="$undef" + ;; + esac +esac + +: Check the syntax of LC_ALL when categories are set to different locales +echo " " +$echo "Checking the syntax of LC_ALL when categories are set to different locales..." >&4 + +case $d_setlocale in + $define) +$rm -f try try.* +$cat >try.c <<'EOF' +#include +#include +#include +#include +#include + +#ifndef LC_ALL + +int +main (const int argc, const char ** argv) +{ +} + +#else +# define C_ARRAY_LENGTH(a) (sizeof(a)/sizeof((a)[0])) +# define strEQ(s1,s2) (strcmp(s1,s2) == 0) +# define strNE(s1,s2) (strcmp(s1,s2) != 0) +# define Copy(s,d,n,t) (void)memcpy((char*)(d),(const char*)(s), (n) * sizeof(t)) +# define memEQ(s1,s2,l) (memcmp(((const void *) (s1)), ((const void *) (s2)), l) == 0) +# define memNE(s1,s2,l) (! memEQ(s1,s2,l)) + +int +main (const int argc, const char ** argv) +{ + + int debug = 0; + + /* All categories Perl knows about on any system. If any are missing, this + * won't work for that system, and they must be added here and in perl.h, + * locale.c */ + const int categories[] = { + +# ifdef LC_CTYPE + LC_CTYPE, +# endif +# ifdef LC_NUMERIC + LC_NUMERIC, +# endif +# ifdef LC_COLLATE + LC_COLLATE, +# endif +# ifdef LC_TIME + LC_TIME, +# endif +# ifdef LC_MESSAGES + LC_MESSAGES, +# endif +# ifdef LC_MONETARY + LC_MONETARY, +# endif +# ifdef LC_ADDRESS + LC_ADDRESS, +# endif +# ifdef LC_IDENTIFICATION + LC_IDENTIFICATION, +# endif +# ifdef LC_MEASUREMENT + LC_MEASUREMENT, +# endif +# ifdef LC_PAPER + LC_PAPER, +# endif +# ifdef LC_TELEPHONE + LC_TELEPHONE, +# endif +# ifdef LC_NAME + LC_NAME, +# endif +# ifdef LC_SYNTAX + LC_SYNTAX, +# endif +# ifdef LC_TOD + LC_TOD +# endif + + }; + + const char * category_names[] = { + +# ifdef LC_CTYPE + "LC_CTYPE", +# endif +# ifdef LC_NUMERIC + "LC_NUMERIC", +# endif +# ifdef LC_COLLATE + "LC_COLLATE", +# endif +# ifdef LC_TIME + "LC_TIME", +# endif +# ifdef LC_MESSAGES + "LC_MESSAGES", +# endif +# ifdef LC_MONETARY + "LC_MONETARY", +# endif +# ifdef LC_ADDRESS + "LC_ADDRESS", +# endif +# ifdef LC_IDENTIFICATION + "LC_IDENTIFICATION", +# endif +# ifdef LC_MEASUREMENT + "LC_MEASUREMENT", +# endif +# ifdef LC_PAPER + "LC_PAPER", +# endif +# ifdef LC_TELEPHONE + "LC_TELEPHONE", +# endif +# ifdef LC_NAME + "LC_NAME", +# endif +# ifdef LC_SYNTAX + "LC_SYNTAX", +# endif +# ifdef LC_TOD + "LC_TOD" +# endif + + }; + + char alternate[1024] = { '\0' } ; + + /* This is a list of locales that are likely to be found on any machine + * (Windows and non-Windows) */ + const char * candidates[] = { + "POSIX", + "C.UTF-8", + "en_US", + "en_US.UTF-8", + "American", + "English" + }; + char separator[1024]; + size_t separator_len = 0; + unsigned int distincts_count = 0; + + /* We look through the candidates for one which returns the same non-C + * locale for every category */ + for (unsigned int i = 0; i < C_ARRAY_LENGTH(candidates); i++) { + const char * candidate = candidates[i]; + distincts_count = 0; + alternate[0] = '\0'; + + for (unsigned int j = 0; j < C_ARRAY_LENGTH(categories); j++) { + const int category = categories[j]; + const char * locale_name = setlocale(category, candidate); + + if (locale_name == NULL) { /* Not on this system */ + break; + } + + if (debug) fprintf(stderr, + "i=%d,j=%d;" + " Return of setlocale(%d=%s, '%s') is '%s'\n", + i, j, + category, category_names[j], + candidate, locale_name); + + /* If the candidate is indistinguishable from C, break to try the + * next candidate */ + if (strEQ(locale_name, "C")) { + break; + } + + /* Save the name the first time through, and on subsequent ones */ + /* make sure the name is the same as before, so the code below can + * be assured of finding it when searching */ + if (j == 0) { + strncpy(alternate, locale_name, sizeof(alternate)); + } + else if (strNE(alternate, locale_name)) { + break; + } + + distincts_count++; + } + + /* Done with this candidate. If every category returned the same non-C + * name, this candidate works. It not, loop to try the next candidate + * */ + if (distincts_count == C_ARRAY_LENGTH(categories)) { + break; + } + } + + /* Here, either found a suitable candidate, or exhausted the possibilities. + * In the latter case, give up */ + if (distincts_count < C_ARRAY_LENGTH(categories)) { + fprintf(stderr, "Couldn't find a locale distinguishable from C\n"); + return 1; + } + + /* An example syntax, from cygwin, is: + * LC_COLLATE/LC_CTYPE/LC_MONETARY/LC_NUMERIC/LC_TIME/LC_MESSAGES + * The locales for a given category are always in the same position, + * indicated above, with a slash separating them */ + + int map_LC_ALL_position_to_category[C_ARRAY_LENGTH(categories)]; + + /* Initialize */ + for (unsigned int i = 0; i < C_ARRAY_LENGTH(categories); i++) { + map_LC_ALL_position_to_category[i] = INT_MAX; + } + + const char * lc_all = NULL; + + /* We need to find the category that goes in each position */ + for (unsigned int i = 0; i < C_ARRAY_LENGTH(categories); i++) { + + /* First set everything to 'C' */ + if (! setlocale(LC_ALL, "C")) { + fprintf(stderr, "Failed to set LC_ALL to C\n"); + return 1; + } + + /* Then set this category to the alternate */ + if (! setlocale(categories[i], alternate)) { + fprintf(stderr, "Failed to set %d to to '%s'\n", + categories[i], alternate); + return 1; + } + + /* Then find what the system says LC_ALL looks like with just this one + * category not set to 'C' */ + lc_all = setlocale(LC_ALL, NULL); + if (! lc_all) { + fprintf(stderr, "Failed to retrieve LC_ALL\n"); + return 1; + } + + if (debug) fprintf(stderr, "LC_ALL is '%s'\n", lc_all); + + /* Assume is name=value pairs if the result contains both an equals and + * a semi-colon. */ + if (strchr(lc_all, '=') && strchr(lc_all, ';')) { + fprintf(stdout, "\"=;\"\n\n"); + return 0; + } + + /* Here isn't name=value pairs. Find the position of the alternate */ + const char * alt_pos = strstr(lc_all, alternate); + if (! alt_pos) { + fprintf(stderr, "Couldn't find '%s' in '%s'\n", alternate, lc_all); + return 1; + } + + /* Parse the LC_ALL string from the beginning up to where the alternate + * locale is */ + const char * s = lc_all; + int count = 0; + while (s < alt_pos) { + + /* Count the 'C' locales before the non-C one. (Note the letter + * 'C' can only occur as the entire 'C' locale, since all of them + * are that locale before 'alt_pos') */ + const char * next_C = (const char *) memchr(s, 'C', alt_pos - s); + if (next_C) { + count++; + s = next_C + 1; + continue; + } + + /* Here, there is no 'C' between 's' and the alternate locale, so + * 'count' gives the total number of occurrences of 'C' in that + * span. If count is 0, this is the first category in an LC_ALL + * string, and we know its position, but not the separator. */ + if (count == 0) { + break; + } + + /* When 'count' isn't 0, 's' points to one past the previous 'C'. + * The separator starts here, ending just before the non-C locale. + */ + + const char * new_sep = s; + unsigned int new_sep_len = alt_pos - s; + + /* If we don't already have a separator saved, save this as it */ + if (separator_len == 0) { + separator_len = new_sep_len; + Copy(s, separator, separator_len, char); + separator[separator_len] = '\0'; + } + else { /* Otherwise make sure it's the same string as previously + * calculated */ + if ( new_sep_len != separator_len + || memNE(separator, new_sep, separator_len)) + { + fprintf(stderr, "Unexpectedly got distinct separators" + " '%s' vs '%s\n", separator, new_sep); + return 1; + } + } + + /* Here, we have found the position of category[i] in LC_ALL. */ + break; + + } /* End of loop parsing the LC_ALL string */ + + if (map_LC_ALL_position_to_category[count] != INT_MAX) { + fprintf(stderr, "Categories %d and %d both appear to occupy" + " position %d in LC_ALL; there is something" + " wrong with the calculation\n", + categories[count], categories[i], + count); + return 1; + } + + /* Save the position of this category */ + map_LC_ALL_position_to_category[count] = categories[i]; + + } /* End of loop through all the categories */ + + fprintf(stdout, "\"%s\"\n{", separator); + for (unsigned int i = 0; i < C_ARRAY_LENGTH(categories) - 1; i++) { + fprintf(stdout, " %d,", map_LC_ALL_position_to_category[i]); + } + fprintf(stdout, " %d }\n", map_LC_ALL_position_to_category[ + C_ARRAY_LENGTH(categories) - 1]); + return 0; + +} + +#endif +EOF +set try +if eval $compile_ok; then + output=`$run ./try 2>/dev/null` + separator=`echo "$output" | $sed 1q` + case $separator in + "\"=;\"") + d_perl_lc_all_uses_name_value_pairs="$define" + d_perl_lc_all_separator="$undef" + perl_lc_all_separator= + d_perl_lc_all_category_positions_init="$undef" + perl_lc_all_category_positions_init= + ;; + "") d_perl_lc_all_uses_name_value_pairs="$undef" + d_perl_lc_all_separator="$undef" + perl_lc_all_separator= + d_perl_lc_all_category_positions_init="$undef" + perl_lc_all_category_positions_init= + ;; + *) d_perl_lc_all_uses_name_value_pairs="$undef" + d_perl_lc_all_separator="$define" + perl_lc_all_separator="$separator" + d_perl_lc_all_category_positions_init="$define" + perl_lc_all_category_positions_init=`echo "$output" | sed -n 2p` + ;; + esac +else + $echo "Failed to compile lc_all probe" >&4 +fi +$rm -f try try.* +;; +*) d_perl_lc_all_separator="$undef" + perl_lc_all_separator= + d_perl_lc_all_category_positions_init="$undef" + perl_lc_all_category_positions_init= + + # No setlocale(), but using this default allows our code to compile + # and run without having to have a bunch more #ifdef's + d_perl_lc_all_uses_name_value_pairs="$define" +;; +esac + +: see if pipe2 exists +set pipe2 d_pipe2 +eval $inlibc + +: see if poll exists +set poll d_poll +eval $inlibc + +: see if prctl exists +set prctl d_prctl +eval $inlibc + +: see if prctl supports PR_SET_NAME +d_prctl_set_name=$undef +case $d_prctl in + $define) + $cat >try.c < +#endif +#include + +int main (int argc, char *argv[]) +{ + return (prctl (PR_SET_NAME, "Test")); + } /* main */ +EOM + set try + if eval $compile_ok && $run ./try; then + echo "Your prctl (PR_SET_NAME, ...) works" + d_prctl_set_name=$define + fi + $rm_try + ;; + esac + +: see if readlink exists +set readlink d_readlink +eval $inlibc + +: Check if there is a /proc symlink to the abs path of +: the executing program. We will honor hints of d_procselfexe=$undef +: or procselfexe being non-empty, otherwise will try to determine both +: if we have readlink. +: AmigaOS will attempt to mount proc: aka /proc, if /proc/... is +: referenced, and AmigaOS does not have a proc filesystem anyway. +echo " " +val="$undef" +if $test "X$d_procselfexe" = Xundef; then + procselfexe='' +elif $test "X$procselfexe" != X -a "X$procselfexe" != 'X '; then + val="$define" +elif $test "X$d_readlink" = Xdefine; then + : NetBSD first as /proc/self is a symlink to /proc/curproc, + : and it feels more tidy to avoid an extra level of symlink + set NetBSD /proc/curproc/exe Linux /proc/self/exe FreeBSD /proc/curproc/file Solaris /proc/self/path/a.out + while test $# -gt 0; do + type=$1; try=$2 + shift; shift + if $issymlink $try; then + $ls -l $try > reflect + if $contains /`basename $ls` reflect >/dev/null 2>&1; then + echo "You have $type-like $try." + procselfexe='"'$try'"' + val="$define" + : This will break out of the loop + set X; shift + fi + fi + done +fi +$rm -f reflect +set d_procselfexe +eval $setvar + +: backward compatibility for d_hvfork +if test X$d_hvfork != X; then + d_vfork="$d_hvfork" + d_hvfork='' +fi +: see if there is a vfork +val='' +set vfork val +eval $inlibc + +d_pseudofork=$undef + +: Ok, but do we want to use it. vfork is reportedly unreliable in +: perl on Solaris 2.x, and probably elsewhere. +case "$val" in +$define) + echo " " + case "$usevfork" in + false) dflt='n';; + *) dflt='y';; + esac + cat <<'EOM' + +Perl can only use a vfork() that doesn't suffer from strict +restrictions on calling functions or modifying global data in +the child. For example, glibc-2.1 contains such a vfork() +that is unsuitable. If your system provides a proper fork() +call, chances are that you do NOT want perl to use vfork(). + +EOM + rp="Do you still want to use vfork()?" + . ./myread + case "$ans" in + y|Y) ;; + *) + echo "Ok, we won't use vfork()." + val="$undef" + ;; + esac + ;; +esac +set d_vfork +eval $setvar +case "$d_vfork" in +$define) usevfork='true';; +*) usevfork='false';; +esac + +: see whether the pthread_atfork exists +$cat >try.c < +#include +int main() { +#ifdef PTHREAD_ATFORK + pthread_atfork(NULL,NULL,NULL); +#endif +} +EOP + +: see if pthread_atfork exists +set try -DPTHREAD_ATFORK +if eval $compile; then + val="$define" +else + val="$undef" +fi +case "$usethreads" in +$define) + case "$val" in + $define) echo 'pthread_atfork found.' >&4 ;; + *) echo 'pthread_atfork NOT found.' >&4 ;; + esac +esac +set d_pthread_atfork +eval $setvar : see if pthread_attr_setscope exists set pthread_attr_setscope d_pthread_attr_setscope @@ -18238,230 +18702,6 @@ eval $inlibc set setlinebuf d_setlinebuf eval $inlibc -: see if this system has wctype.h -set wctype.h i_wctype -eval $inhdr - -: see if towupper exists -set towupper d_towupper -eval $inlibc - -: check for setlocale function and behavior -case "$d_setlocale" in -'') -$cat >&4 <try.c < -#include -#$i_locale I_LOCALE -#ifdef I_LOCALE -# include -#endif -#$i_wctype I_WCTYPE -#ifdef I_WCTYPE -# include -#endif - -int main() { - const char * invalid_name = "\a"; /* This is really invalid! */ - int accepts_any_locale_name = 0; - int has_C_UTF8 = 0; - unsigned char bad_setlocale = 255; - - /* If LC_CTYPE isn't defined the compilation will fail, and locales will be - * disabled. It's hard to imagine an instance where meaningful locale - * handling could be done without LC_CTYPE */ - const char * name = setlocale(LC_CTYPE, "C"); - - if (name == NULL || strcmp(name, "C") != 0) { - exit(bad_setlocale); - } - - name = setlocale(LC_CTYPE, invalid_name); - if (name != NULL) { - - /* Let it pass if it accepts the name but gives back one of the C - * locales */ - if (strcmp(name, "C") != 0 && strcmp(name, "C.UTF-8") != 0) { - accepts_any_locale_name = 1; - } - } - - name = setlocale(LC_CTYPE, "C.UTF-8"); - if (name != NULL) { - unsigned char y_with_diaeresis = ('A' == 193) ? 0xDF : 0xFF; - -#$d_towupper HAS_TOWUPPER -#ifdef HAS_TOWUPPER - - /* We assume that if the machine doesn't have the C99 towupper, it - * doesn't have C.UTF-8, even if we successfully changed locales to - * include it. This seems safer even on platforms that didn't accept - * the really invalid name */ - - if (towupper(y_with_diaeresis) == 0x178) { - has_C_UTF8 = 1; - } - -#endif - - } - -#if 0 - - /* Currently unused code to determine if LC_ALL with disparate values uses - * category = value pairs or positional, and to determine the separator - * between the categories. We could add code so that if the separator were - * > '9', we subtract 10; similarly for 'Z' and 'z', and then just about - * every possible ASCII separator would fit in the 5 bits available in the - * exit code. This would not be true in EBCDIC. And then if LC_ALL is - * positional, we probably would want to know the order of the categories. - * Using a file between the C program and the shell script would really be - * require to do that */ -#ifdef LC_ALL - - unsigned char min_separator = ' ' - 1; - unsigned char separator = min_separator; - int uses_name_value_pair_names = 0; - - name = setlocale(LC_ALL, "C"); - if (name == NULL || strcmp(name, "C") != 0) { - exit(bad_setlocale); - } - - if (has_C_UTF8) { - char * pos; - - name = setlocale(LC_CTYPE, "C.UTF-8"); - if (name == NULL) { - exit(bad_setlocale); - } - name = setlocale(LC_ALL, NULL); - if (name == NULL) { - exit(bad_setlocale); - } - - pos = strstr(name, "LC_CTYPE" "=C.UTF-8"); - if (pos != NULL) { - uses_name_value_pair_names = 1; - if (pos == name) { - separator = name[sizeof("LC_CTYPE=C.UTF-8") - 1]; - } - else { - separator = *(pos - 1); - } - } - else { - pos = strstr(name, "C.UTF-8"); - if (pos == NULL) { - /* bad */ - } - else if (pos == name) { - separator = name[sizeof("C.UTF-8") - 1]; - } - else { - separator = *(pos - 1); - } - } - } - -#endif -#endif - - exit( 0 /* (separator - min_separator) << 3 - | uses_name_value_pair_names << 2 - */ - | has_C_UTF8 << 1 - | accepts_any_locale_name); - -} -EOCP -val= -set d_setlocale -eval $setvar -case $d_setlocale in - $undef) d_setlocale_accepts_any_locale_name="$undef" - d_has_C_UTF8="false" - ;; - *) set try - if eval $compile; then - echo "Your system has setlocale()..." >&4 - $run ./try - case $? in - 0) echo "and it seems sane; you don't have a C.UTF-8 locale" >&4 - d_setlocale="$define" - d_setlocale_accepts_any_locale_name="$undef" - d_has_C_UTF8="false" - ;; - 1) echo "and it seems sane, but accepts any locale name as valid" >&4 - d_setlocale="$define" - d_setlocale_accepts_any_locale_name="$define" - d_has_C_UTF8="false" - ;; - 2) echo "and it seems sane; you have a C.UTF-8 locale" >&4 - d_setlocale="$define" - d_setlocale_accepts_any_locale_name="$undef" - d_has_C_UTF8="true" - ;; - 3) echo "and it seems sane, but accepts any locale name as valid" >&4 - d_setlocale="$define" - d_setlocale_accepts_any_locale_name="$define" - d_has_C_UTF8="true" - ;; - *) echo "but it doesn't seem to work, so we won't use it." >&4 - d_setlocale="$undef" - d_setlocale_accepts_any_locale_name="$undef" - d_has_C_UTF8="false" - ;; - esac - else - echo "your system does not have setlocale()" >&4 - d_setlocale="$undef" - d_setlocale_accepts_any_locale_name="$undef" - d_has_C_UTF8="false" - fi -esac -$rm_try -;; -*) val="$d_setlocale" - set d_setlocale - eval $setvar - case "$d_setlocale" in - $undef) echo "There may be other ways to set the locale on your system, so we need to ask:" >&4 - ;; - esac - rp="Does your system have the C.UTF-8 locale?" - dflt=n - . ./myread - case "$ans" in - [Yy]*) d_has_C_UTF8="true" - c_utf8_locale=" or C.UTF-8" - ;; - *) d_has_C_UTF8="false" - c_utf8_locale="" - ;; - esac - case "$d_setlocale" in - $define) - rp="When you set your locale to something besides C$c_utf8_locale, does it do so, or just pretend to?" >&4 - dflt=n - . ./myread - case "$ans" in - true|[Yy]*) - d_setlocale_accepts_any_locale_name="$undef" - ;; - *) d_setlocale_accepts_any_locale_name="$define" - ;; - esac - ;; - *) d_setlocale_accepts_any_locale_name="$undef" - ;; - esac -esac - : see if setlocale_r exists set setlocale_r d_setlocale_r eval $inlibc @@ -21281,8 +21521,8 @@ int main() { STDIO_STREAM_ARRAY[i]._flag) fflush(&STDIO_STREAM_ARRAY[i]); } - } # endif + } #endif _exit(42); } @@ -21693,13 +21933,13 @@ EOCP fi fi -if $test X"$sPRId64" = X -a X"$quadtype" != X; then - $cat >try.c <try.c <<'EOCP' #include #include int main() { - $quadtype q = 12345678901; - printf("%Ld\n", q); + long long q = 12345678901LL; /* AIX cc requires the LL suffix. */ + printf("%lld\n", q); } EOCP set try @@ -21707,21 +21947,21 @@ EOCP yyy=`$run ./try` case "$yyy" in 12345678901) - sPRId64='"Ld"'; sPRIi64='"Li"'; sPRIu64='"Lu"'; - sPRIo64='"Lo"'; sPRIx64='"Lx"'; sPRIXU64='"LX"'; - echo "We will use %Ld." + sPRId64='"lld"'; sPRIi64='"lli"'; sPRIu64='"llu"'; + sPRIo64='"llo"'; sPRIx64='"llx"'; sPRIXU64='"llX"'; + echo "We will use the %lld style." ;; esac fi fi -if $test X"$sPRId64" = X -a X"$quadtype" = X"long long"; then - $cat >try.c <<'EOCP' +if $test X"$sPRId64" = X -a X"$quadtype" != X; then + $cat >try.c < #include int main() { - long long q = 12345678901LL; /* AIX cc requires the LL suffix. */ - printf("%lld\n", q); + $quadtype q = 12345678901; + printf("%qd\n", q); } EOCP set try @@ -21729,9 +21969,9 @@ EOCP yyy=`$run ./try` case "$yyy" in 12345678901) - sPRId64='"lld"'; sPRIi64='"lli"'; sPRIu64='"llu"'; - sPRIo64='"llo"'; sPRIx64='"llx"'; sPRIXU64='"llX"'; - echo "We will use the %lld style." + sPRId64='"qd"'; sPRIi64='"qi"'; sPRIu64='"qu"'; + sPRIo64='"qo"'; sPRIx64='"qx"'; sPRIXU64='"qX"'; + echo "We will use %qd." ;; esac fi @@ -21743,7 +21983,7 @@ if $test X"$sPRId64" = X -a X"$quadtype" #include int main() { $quadtype q = 12345678901; - printf("%qd\n", q); + printf("%Ld\n", q); } EOCP set try @@ -21751,9 +21991,9 @@ EOCP yyy=`$run ./try` case "$yyy" in 12345678901) - sPRId64='"qd"'; sPRIi64='"qi"'; sPRIu64='"qu"'; - sPRIo64='"qo"'; sPRIx64='"qx"'; sPRIXU64='"qX"'; - echo "We will use %qd." + sPRId64='"Ld"'; sPRIi64='"Li"'; sPRIu64='"Lu"'; + sPRIo64='"Lo"'; sPRIx64='"Lx"'; sPRIXU64='"LX"'; + echo "We will use %Ld." ;; esac fi @@ -23825,7 +24065,7 @@ else mv ccsym1.raw ccsym.raw fi -$awk '/\=/ { print $0; next } +$awk '/=/ { print $0; next } { print $0"=1" }' ccsym.raw >ccsym.list $comm -13 Cppsym.true ccsym.list >ccsym.own $comm -12 Cppsym.true ccsym.list >ccsym.com @@ -25039,6 +25279,9 @@ d_open3='$d_open3' d_openat='$d_openat' d_pathconf='$d_pathconf' d_pause='$d_pause' +d_perl_lc_all_category_positions_init='$d_perl_lc_all_category_positions_init' +d_perl_lc_all_separator='$d_perl_lc_all_separator' +d_perl_lc_all_uses_name_value_pairs='$d_perl_lc_all_uses_name_value_pairs' d_perl_otherlibdirs='$d_perl_otherlibdirs' d_phostname='$d_phostname' d_pipe2='$d_pipe2' @@ -25212,7 +25455,6 @@ d_telldir='$d_telldir' d_telldirproto='$d_telldirproto' d_tgamma='$d_tgamma' d_thread_local='$d_thread_local' -d_thread_safe_nl_langinfo_l='$d_thread_safe_nl_langinfo_l' d_time='$d_time' d_timegm='$d_timegm' d_times='$d_times' @@ -25587,6 +25829,8 @@ patchlevel='$patchlevel' path_sep='$path_sep' perl5='$perl5' perl='$perl' +perl_lc_all_category_positions_init='$perl_lc_all_category_positions_init' +perl_lc_all_separator='$perl_lc_all_separator' perl_patchlevel='$perl_patchlevel' perl_static_inline='$perl_static_inline' perl_thread_local='$perl_thread_local' Index: gnu/usr.bin/perl/INSTALL =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/INSTALL,v diff -u -p -a -u -p -r1.31 INSTALL --- gnu/usr.bin/perl/INSTALL 14 May 2024 19:38:53 -0000 1.31 +++ gnu/usr.bin/perl/INSTALL 22 Jan 2025 00:37:42 -0000 @@ -92,10 +92,10 @@ to F for more detaile =head3 Compatibility with earlier versions -B This version is not binary compatible with earlier versions -of Perl. If you have built extensions (i.e. modules that include C code) -using an earlier version of Perl, you will need to rebuild and reinstall -those extensions. +B This version is not binary compatible with versions of Perl +earlier than 5.40.0. If you have built extensions (i.e. modules that +include C code) using an earlier version of Perl, you will need to +rebuild and reinstall those extensions. Pure perl modules without XS or C code should continue to work fine without reinstallation. See the discussion below on @@ -318,6 +318,7 @@ enable this, run sh Configure -Dusethreads The default is to compile without thread support. +C<-Duseithreads> is currently synonymous with C<-Dusethreads>. Perl used to have two different internal threads implementations. The current model (available internally since 5.6, and as a user-level module @@ -750,7 +751,7 @@ The directories set up by Configure fall =item Directories for the perl distribution -By default, Configure will use the following directories for 5.38.2. +By default, Configure will use the following directories for 5.40.1. $version is the full perl version number, including subversion, e.g. 5.12.3, and $archname is a string like sun4-sunos, determined by Configure. The full definitions of all Configure @@ -2580,8 +2581,8 @@ L Perl modules having binary parts (meaning that a C compiler is used) will have to be recompiled to be -used with 5.38.2. If you find you do need to rebuild an extension with -5.38.2, you may safely do so without disturbing the older +used with 5.40.1. If you find you do need to rebuild an extension with +5.40.1, you may safely do so without disturbing the older installations. (See L<"Coexistence with earlier versions of perl 5"> above.) @@ -2709,15 +2710,15 @@ Firstly, the bare minimum to run this sc print("$f\n"); } -in Linux with perl-5.38.2 is as follows (under $Config{prefix}): +in Linux with perl-5.40.1 is as follows (under $Config{prefix}): ./bin/perl - ./lib/perl5/5.38.2/strict.pm - ./lib/perl5/5.38.2/warnings.pm - ./lib/perl5/5.38.2/i686-linux/File/Glob.pm - ./lib/perl5/5.38.2/feature.pm - ./lib/perl5/5.38.2/XSLoader.pm - ./lib/perl5/5.38.2/i686-linux/auto/File/Glob/Glob.so + ./lib/perl5/5.40.1/strict.pm + ./lib/perl5/5.40.1/warnings.pm + ./lib/perl5/5.40.1/i686-linux/File/Glob.pm + ./lib/perl5/5.40.1/feature.pm + ./lib/perl5/5.40.1/XSLoader.pm + ./lib/perl5/5.40.1/i686-linux/auto/File/Glob/Glob.so Secondly, for perl-5.10.1, the Debian perl-base package contains 591 files, (of which 510 are for lib/unicore) totaling about 3.5MB in its Index: gnu/usr.bin/perl/MANIFEST =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/MANIFEST,v diff -u -p -a -u -p -r1.72 MANIFEST --- gnu/usr.bin/perl/MANIFEST 14 May 2024 19:40:17 -0000 1.72 +++ gnu/usr.bin/perl/MANIFEST 22 Jan 2025 00:37:42 -0000 @@ -1,6 +1,5 @@ .dir-locals.el Emacs control file .editorconfig EditorConfig style file -.lgtm.yml LGTM.com configuration file .metaconf-exclusions.txt Symbols that should ignored when generating Configure Artistic The "Artistic License" asan_ignore Errors to skip under clang's Addresss Sanitizer @@ -63,12 +62,12 @@ keywords.c Perl_keyword(), generated keywords.h The keyword numbers l1_char_class_tab.h 256 word bit table of character classes (for handy.h) locale.c locale-specific utility functions +locale_table.h header for locale.c make_ext.pl Used by Makefile to execute extension Makefiles make_patchnum.pl Script to generate git_version.h and lib/Config_git.pl files for all OS'es makedef.pl Create symbol export lists for linking makedepend.SH Precursor to makedepend makedepend_file.SH Precursor to makedepend_file -Makefile.micro microperl Makefile Makefile.SH A script that generates Makefile malloc.c A version of malloc you might not want malloc_ctl.h A version of malloc you might not want @@ -150,7 +149,6 @@ README.jp Perl for Japanese (in EUC-J README.ko Perl for Korean (in EUC-KR) README.linux Perl notes for Linux README.macosx Perl notes for Mac OS X -README.micro Notes about microperl README.openbsd Perl notes for OpenBSD README.os2 Perl notes for OS/2 README.os390 Perl notes for OS/390 @@ -199,9 +197,6 @@ time64.c 64 bit clean time.h (code) time64.h 64 bit clean time.h (header) time64_config.h 64 bit clean time.h (configuration) toke.c The tokener -uconfig.h Configuration header for microperl -uconfig.sh Configuration script for microperl -uconfig64.sh Configuration script for microperl for LP64 uni_keywords.h Map unicode property names to numbers unicode_constants.h compile-time macros for Unicode code points universal.c The default UNIVERSAL package methods @@ -237,9 +232,8 @@ cpan/Archive-Tar/t/03_file.t Archive cpan/Archive-Tar/t/04_resolved_issues.t Archive::Tar tests cpan/Archive-Tar/t/05_iter.t Archive::Tar tests cpan/Archive-Tar/t/06_error.t Archive::Tar tests -cpan/Archive-Tar/t/08_ptargrep.t -cpan/Archive-Tar/t/09_roundtrip.t -cpan/Archive-Tar/t/90_symlink.t Archive::Tar tests +cpan/Archive-Tar/t/08_ptargrep.t Test file related to Archive::Tar +cpan/Archive-Tar/t/09_roundtrip.t Test file related to Archive::Tar cpan/Archive-Tar/t/99_pod.t Archive::Tar tests cpan/Archive-Tar/t/src/header/signed.tar Archive::Tar tests cpan/Archive-Tar/t/src/linktest/linktest_missing_dir.tar Archive::Tar tests @@ -248,6 +242,7 @@ cpan/Archive-Tar/t/src/long/b Archiv cpan/Archive-Tar/t/src/long/bar.tar Archive::Tar tests cpan/Archive-Tar/t/src/long/foo.tbz Archive::Tar tests cpan/Archive-Tar/t/src/long/foo.tgz Archive::Tar tests +cpan/Archive-Tar/t/src/long/prefix-directory-concat.tar Archive-Tar cpan/Archive-Tar/t/src/short/b Archive::Tar tests cpan/Archive-Tar/t/src/short/bar.tar Archive::Tar tests cpan/Archive-Tar/t/src/short/foo.tbz Archive::Tar tests @@ -256,32 +251,32 @@ cpan/autodie/lib/autodie.pm Functions cpan/autodie/lib/autodie/exception.pm Exception class for autodie cpan/autodie/lib/autodie/exception/system.pm Exception class for autodying system() cpan/autodie/lib/autodie/hints.pm Hinting interface for autodie -cpan/autodie/lib/autodie/Scope/Guard.pm -cpan/autodie/lib/autodie/Scope/GuardStack.pm -cpan/autodie/lib/autodie/skip.pm -cpan/autodie/lib/autodie/Util.pm +cpan/autodie/lib/autodie/Scope/Guard.pm Module related to autodie +cpan/autodie/lib/autodie/Scope/GuardStack.pm Module related to autodie +cpan/autodie/lib/autodie/skip.pm Module related to autodie +cpan/autodie/lib/autodie/Util.pm Module related to autodie cpan/autodie/lib/Fatal.pm Make errors in functions/builtins fatal cpan/autodie/t/00-load.t autodie - basic load -cpan/autodie/t/args.t +cpan/autodie/t/args.t Test file related to autodie cpan/autodie/t/autodie.t autodie - Basic functionality -cpan/autodie/t/autodie_skippy.pm +cpan/autodie/t/autodie_skippy.pm Module related to autodie cpan/autodie/t/autodie_test_module.pm autodie - test helper cpan/autodie/t/backcompat.t autodie - More Fatal backcompat cpan/autodie/t/basic_exceptions.t autodie - Basic exception tests cpan/autodie/t/binmode.t autodie - Binmode testing cpan/autodie/t/blog_hints.t autodie - Tests fro PJF's blog cpan/autodie/t/caller.t autodie - Caller diagnostics -cpan/autodie/t/chmod.t -cpan/autodie/t/chown.t +cpan/autodie/t/chmod.t Test file related to autodie +cpan/autodie/t/chown.t Test file related to autodie cpan/autodie/t/context.t autodie - Context clobbering tests cpan/autodie/t/context_lexical.t autodie - Context clobbering lexically -cpan/autodie/t/core-trampoline-slurp.t +cpan/autodie/t/core-trampoline-slurp.t Test file related to autodie cpan/autodie/t/crickey.t autodie - Like an Australian cpan/autodie/t/dbmopen.t autodie - dbm tests -cpan/autodie/t/eval_error.t +cpan/autodie/t/eval_error.t Test file related to autodie cpan/autodie/t/exception_class.t autodie - Exception class subclasses -cpan/autodie/t/exception_nonref.t -cpan/autodie/t/exceptions.t autodie - 5.10 exception tests. +cpan/autodie/t/exception_nonref.t Test file related to autodie +cpan/autodie/t/exceptions-smartmatch.t autodie cpan/autodie/t/exec.t autodie - exec tests. cpan/autodie/t/Fatal.t autodie - Fatal backcompatibility cpan/autodie/t/filehandles.t autodie - filehandle tests @@ -294,10 +289,10 @@ cpan/autodie/t/hints_pod_examples.t au cpan/autodie/t/hints_provider_does.t autodie - Test hints/does roles cpan/autodie/t/hints_provider_easy_does_it.t autodie - Test easy hints/does cpan/autodie/t/hints_provider_isa.t autodie - Test hints/inheritance -cpan/autodie/t/import-into.t +cpan/autodie/t/import-into.t Test file related to autodie cpan/autodie/t/internal.t autodie - internal interface tests cpan/autodie/t/internal-backcompat.t autodie - Back-compatibility tests -cpan/autodie/t/kill.t +cpan/autodie/t/kill.t Test file related to autodie cpan/autodie/t/lethal.t autodie - lethal is the one true name cpan/autodie/t/lib/autodie/test/au.pm autodie - Australian helper cpan/autodie/t/lib/autodie/test/au/exception.pm autodie - Australian helper @@ -311,122 +306,121 @@ cpan/autodie/t/lib/Hints_provider_isa.pm cpan/autodie/t/lib/Hints_test.pm autodie - Hints test helper cpan/autodie/t/lib/lethal.pm autodie - with a better name cpan/autodie/t/lib/my/autodie.pm autodie - blog_hints.t helper -cpan/autodie/t/lib/my/pragma.pm +cpan/autodie/t/lib/my/pragma.pm Module related to autodie cpan/autodie/t/lib/OtherTypes.pm autodie - Format clobberer helper. cpan/autodie/t/lib/pujHa/ghach.pm autodie - Like a Klingon cpan/autodie/t/lib/pujHa/ghach/Dotlh.pm autodie - With Klingon honour cpan/autodie/t/lib/Some/Module.pm autodie - blog_hints.t helper cpan/autodie/t/mkdir.t autodie - filesystem tests -cpan/autodie/t/no-default.t -cpan/autodie/t/no_carp.t +cpan/autodie/t/no-default.t Test file related to autodie +cpan/autodie/t/no_carp.t Test file related to autodie cpan/autodie/t/open.t autodie - Testing open -cpan/autodie/t/read.t +cpan/autodie/t/read.t Test file related to autodie cpan/autodie/t/recv.t autodie - send/recv tests cpan/autodie/t/repeat.t autodie - repeat autodie leak tests -cpan/autodie/t/rt-74246.t +cpan/autodie/t/rt-74246.t Test file related to autodie cpan/autodie/t/scope_leak.t autodie - file scope leak tests -cpan/autodie/t/skip.t +cpan/autodie/t/skip.t Test file related to autodie cpan/autodie/t/string-eval-basic.t autodie - Basic string eval test cpan/autodie/t/string-eval-leak.t autodie - String eval leak test cpan/autodie/t/sysopen.t autodie - sysopen tests -cpan/autodie/t/touch_me cpan/autodie/t/truncate.t autodie - File truncation tests cpan/autodie/t/unlink.t autodie - Unlink system tests. cpan/autodie/t/user-context.t autodie - Context changes for usersubs cpan/autodie/t/usersub.t autodie - user subroutine tests -cpan/autodie/t/utf8_open.t -cpan/autodie/t/utime.t +cpan/autodie/t/utf8_open.t Test file related to autodie +cpan/autodie/t/utime.t Test file related to autodie cpan/autodie/t/version.t autodie - versioning tests -cpan/autodie/t/version_tag.t +cpan/autodie/t/version_tag.t Test file related to autodie cpan/AutoLoader/lib/AutoLoader.pm Autoloader base class cpan/AutoLoader/lib/AutoSplit.pm Split up autoload functions cpan/AutoLoader/t/01AutoLoader.t See if AutoLoader works cpan/AutoLoader/t/02AutoSplit.t See if AutoSplit works -cpan/bignum/gentest/backend.sh -cpan/bignum/gentest/scope-nested-const.sh -cpan/bignum/gentest/scope-nested-hex-oct.sh -cpan/bignum/lib/bigfloat.pm +cpan/bignum/gentest/backend.sh bignum +cpan/bignum/gentest/scope-nested-const.sh bignum +cpan/bignum/gentest/scope-nested-hex-oct.sh bignum +cpan/bignum/lib/bigfloat.pm Module related to bignum cpan/bignum/lib/bigint.pm bigint cpan/bignum/lib/bignum.pm bignum cpan/bignum/lib/bigrat.pm bigrat cpan/bignum/lib/Math/BigFloat/Trace.pm bignum tracing cpan/bignum/lib/Math/BigInt/Trace.pm bignum tracing -cpan/bignum/lib/Math/BigRat/Trace.pm -cpan/bignum/t/backend-gmp-bigfloat.t -cpan/bignum/t/backend-gmp-bigint.t -cpan/bignum/t/backend-gmp-bignum.t -cpan/bignum/t/backend-gmp-bigrat.t -cpan/bignum/t/backend-pari-bigfloat.t -cpan/bignum/t/backend-pari-bigint.t -cpan/bignum/t/backend-pari-bignum.t -cpan/bignum/t/backend-pari-bigrat.t +cpan/bignum/lib/Math/BigRat/Trace.pm Module related to bignum +cpan/bignum/t/backend-gmp-bigfloat.t Test file related to bignum +cpan/bignum/t/backend-gmp-bigint.t Test file related to bignum +cpan/bignum/t/backend-gmp-bignum.t Test file related to bignum +cpan/bignum/t/backend-gmp-bigrat.t Test file related to bignum +cpan/bignum/t/backend-pari-bigfloat.t Test file related to bignum +cpan/bignum/t/backend-pari-bigint.t Test file related to bignum +cpan/bignum/t/backend-pari-bignum.t Test file related to bignum +cpan/bignum/t/backend-pari-bigrat.t Test file related to bignum cpan/bignum/t/bigexp.t See if bignum works -cpan/bignum/t/bigfloat.t +cpan/bignum/t/bigfloat.t Test file related to bignum cpan/bignum/t/bigint.t See if bigint works cpan/bignum/t/bignum.t See if bignum works cpan/bignum/t/bigrat.t See if bigrat works -cpan/bignum/t/const-bigfloat.t -cpan/bignum/t/const-bigint.t -cpan/bignum/t/const-bignum.t -cpan/bignum/t/const-bigrat.t -cpan/bignum/t/down-mbi-up-mbf.t -cpan/bignum/t/down-mbi-up-mbr.t -cpan/bignum/t/down-mbi-up-undef.t -cpan/bignum/t/down-undef-up-mbf.t -cpan/bignum/t/e_pi-bigfloat.t -cpan/bignum/t/e_pi-bigint.t -cpan/bignum/t/e_pi-bignum.t -cpan/bignum/t/e_pi-bigrat.t -cpan/bignum/t/import-bigfloat.t -cpan/bignum/t/import-bigint.t -cpan/bignum/t/import-bignum.t -cpan/bignum/t/import-bigrat.t +cpan/bignum/t/const-bigfloat.t Test file related to bignum +cpan/bignum/t/const-bigint.t Test file related to bignum +cpan/bignum/t/const-bignum.t Test file related to bignum +cpan/bignum/t/const-bigrat.t Test file related to bignum +cpan/bignum/t/down-mbi-up-mbf.t Test file related to bignum +cpan/bignum/t/down-mbi-up-mbr.t Test file related to bignum +cpan/bignum/t/down-mbi-up-undef.t Test file related to bignum +cpan/bignum/t/down-undef-up-mbf.t Test file related to bignum +cpan/bignum/t/e_pi-bigfloat.t Test file related to bignum +cpan/bignum/t/e_pi-bigint.t Test file related to bignum +cpan/bignum/t/e_pi-bignum.t Test file related to bignum +cpan/bignum/t/e_pi-bigrat.t Test file related to bignum +cpan/bignum/t/import-bigfloat.t Test file related to bignum +cpan/bignum/t/import-bigint.t Test file related to bignum +cpan/bignum/t/import-bignum.t Test file related to bignum +cpan/bignum/t/import-bigrat.t Test file related to bignum cpan/bignum/t/in_effect.t See if in_effect() works -cpan/bignum/t/infnan-bigfloat.t -cpan/bignum/t/infnan-bigint.t -cpan/bignum/t/infnan-bignum-mbf.t -cpan/bignum/t/infnan-bignum-mbr.t -cpan/bignum/t/infnan-bigrat.t +cpan/bignum/t/infnan-bigfloat.t Test file related to bignum +cpan/bignum/t/infnan-bigint.t Test file related to bignum +cpan/bignum/t/infnan-bignum-mbf.t Test file related to bignum +cpan/bignum/t/infnan-bignum-mbr.t Test file related to bignum +cpan/bignum/t/infnan-bigrat.t Test file related to bignum cpan/bignum/t/option_a.t See if bignum a => X works -cpan/bignum/t/option_a-bignum.t -cpan/bignum/t/option_l-bigfloat.t -cpan/bignum/t/option_l-bigint.t -cpan/bignum/t/option_l-bignum.t -cpan/bignum/t/option_l-bigrat.t +cpan/bignum/t/option_a-bignum.t Test file related to bignum +cpan/bignum/t/option_l-bigfloat.t Test file related to bignum +cpan/bignum/t/option_l-bigint.t Test file related to bignum +cpan/bignum/t/option_l-bignum.t Test file related to bignum +cpan/bignum/t/option_l-bigrat.t Test file related to bignum cpan/bignum/t/option_p.t See if bignum p => X works -cpan/bignum/t/option_p-bignum.t +cpan/bignum/t/option_p-bignum.t Test file related to bignum cpan/bignum/t/overrides.t See if global overrides behave cpan/bignum/t/ratopt_a.t See if bigrat a => X works -cpan/bignum/t/scope-bigfloat.t -cpan/bignum/t/scope-bigint.t -cpan/bignum/t/scope-bignum.t -cpan/bignum/t/scope-bigrat.t -cpan/bignum/t/scope-nested-const.t -cpan/bignum/t/scope-nested-hex-oct.t -cpan/Compress-Raw-Bzip2/Bzip2.xs -cpan/Compress-Raw-Bzip2/bzip2-src/blocksort.c -cpan/Compress-Raw-Bzip2/bzip2-src/bzip2.patch -cpan/Compress-Raw-Bzip2/bzip2-src/bzlib.c -cpan/Compress-Raw-Bzip2/bzip2-src/bzlib.h -cpan/Compress-Raw-Bzip2/bzip2-src/bzlib_private.h -cpan/Compress-Raw-Bzip2/bzip2-src/compress.c -cpan/Compress-Raw-Bzip2/bzip2-src/crctable.c -cpan/Compress-Raw-Bzip2/bzip2-src/decompress.c -cpan/Compress-Raw-Bzip2/bzip2-src/huffman.c -cpan/Compress-Raw-Bzip2/bzip2-src/LICENSE -cpan/Compress-Raw-Bzip2/bzip2-src/randtable.c -cpan/Compress-Raw-Bzip2/fallback/constants.h -cpan/Compress-Raw-Bzip2/fallback/constants.xs -cpan/Compress-Raw-Bzip2/lib/Compress/Raw/Bzip2.pm -cpan/Compress-Raw-Bzip2/Makefile.PL -cpan/Compress-Raw-Bzip2/private/MakeUtil.pm -cpan/Compress-Raw-Bzip2/t/000prereq.t -cpan/Compress-Raw-Bzip2/t/01bzip2.t -cpan/Compress-Raw-Bzip2/t/09limitoutput.t -cpan/Compress-Raw-Bzip2/t/19nonpv.t -cpan/Compress-Raw-Bzip2/t/99pod.t -cpan/Compress-Raw-Bzip2/t/compress/CompTestUtils.pm -cpan/Compress-Raw-Bzip2/typemap +cpan/bignum/t/scope-bigfloat.t Test file related to bignum +cpan/bignum/t/scope-bigint.t Test file related to bignum +cpan/bignum/t/scope-bignum.t Test file related to bignum +cpan/bignum/t/scope-bigrat.t Test file related to bignum +cpan/bignum/t/scope-nested-const.t Test file related to bignum +cpan/bignum/t/scope-nested-hex-oct.t Test file related to bignum +cpan/Compress-Raw-Bzip2/Bzip2.xs Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/bzip2-src/blocksort.c Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/bzip2-src/bzip2.patch Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/bzip2-src/bzlib.c Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/bzip2-src/bzlib.h Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/bzip2-src/bzlib_private.h Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/bzip2-src/compress.c Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/bzip2-src/crctable.c Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/bzip2-src/decompress.c Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/bzip2-src/huffman.c Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/bzip2-src/LICENSE Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/bzip2-src/randtable.c Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/fallback/constants.h Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/fallback/constants.xs Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/lib/Compress/Raw/Bzip2.pm Module related to Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/Makefile.PL Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/private/MakeUtil.pm Module related to Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/t/000prereq.t Test file related to Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/t/01bzip2.t Test file related to Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/t/09limitoutput.t Test file related to Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/t/19nonpv.t Test file related to Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/t/99pod.t Test file related to Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/t/compress/CompTestUtils.pm Module related to Compress::Raw::Bzip2 +cpan/Compress-Raw-Bzip2/typemap Compress::Raw::Bzip2 cpan/Compress-Raw-Zlib/config.in Compress::Raw::Zlib cpan/Compress-Raw-Zlib/fallback/constants.h Compress::Raw::Zlib cpan/Compress-Raw-Zlib/fallback/constants.xs Compress::Raw::Zlib @@ -438,8 +432,8 @@ cpan/Compress-Raw-Zlib/t/02zlib.t Comp cpan/Compress-Raw-Zlib/t/07bufsize.t Compress::Raw::Zlib cpan/Compress-Raw-Zlib/t/09limitoutput.t Compress::Raw::Zlib cpan/Compress-Raw-Zlib/t/18lvalue.t Compress::Raw::Zlib -cpan/Compress-Raw-Zlib/t/19nonpv.t -cpan/Compress-Raw-Zlib/t/compress/CompTestUtils.pm +cpan/Compress-Raw-Zlib/t/19nonpv.t Test file related to Compress::Raw::Zlib +cpan/Compress-Raw-Zlib/t/compress/CompTestUtils.pm Module related to Compress::Raw::Zlib cpan/Compress-Raw-Zlib/typemap Compress::Raw::Zlib cpan/Compress-Raw-Zlib/Zlib.xs Compress::Raw::Zlib cpan/Compress-Raw-Zlib/zlib-src/adler32.c Compress::Raw::Zlib @@ -641,6 +635,7 @@ cpan/CPAN-Meta/t/repository.t cpan/CPAN-Meta/t/save-load.t cpan/CPAN-Meta/t/validator.t cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements.pm +cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements/Range.pm cpan/CPAN-Meta-Requirements/t/accepts.t cpan/CPAN-Meta-Requirements/t/bad_version_hook.t cpan/CPAN-Meta-Requirements/t/basic.t @@ -703,11 +698,11 @@ cpan/DB_File/config.in Part of Berkele cpan/DB_File/DB_File.pm Berkeley DB extension Perl module cpan/DB_File/DB_File.xs Berkeley DB extension external subroutines cpan/DB_File/dbinfo Berkeley DB database version checker -cpan/DB_File/hints/bitrig.pl +cpan/DB_File/hints/bitrig.pl Script related to DB_File cpan/DB_File/hints/dynixptx.pl Hint for DB_File for named architecture -cpan/DB_File/hints/minix.pl -cpan/DB_File/hints/netbsd.pl -cpan/DB_File/hints/openbsd.pl +cpan/DB_File/hints/minix.pl Script related to DB_File +cpan/DB_File/hints/netbsd.pl Script related to DB_File +cpan/DB_File/hints/openbsd.pl Script related to DB_File cpan/DB_File/hints/sco.pl Hint for DB_File for named architecture cpan/DB_File/Makefile.PL Berkeley DB extension makefile writer cpan/DB_File/t/db-btree.t See if DB_File works @@ -738,7 +733,7 @@ cpan/Digest-MD5/t/files.t See if Digest cpan/Digest-MD5/t/md5-aaa.t See if Digest::MD5 extension works cpan/Digest-MD5/t/threads.t See if Digest::MD5 extension works cpan/Digest-MD5/t/utf8.t See if Digest::MD5 extension works -cpan/Digest-MD5/t/warns.t +cpan/Digest-MD5/t/warns.t Test file related to Digest::MD5 cpan/Digest-MD5/typemap Digest::MD5 extension cpan/Digest-SHA/lib/Digest/SHA.pm Digest::SHA extension cpan/Digest-SHA/Makefile.PL Digest::SHA Makefile.PL @@ -829,8 +824,8 @@ cpan/Encode/t/big5-eten.utf test data cpan/Encode/t/big5-hkscs.enc test data cpan/Encode/t/big5-hkscs.utf test data cpan/Encode/t/CJKT.t test script -cpan/Encode/t/cow.t -cpan/Encode/t/decode.t +cpan/Encode/t/cow.t Test file related to Encode +cpan/Encode/t/decode.t Test file related to Encode cpan/Encode/t/enc_data.t test script for utf8 DATA cpan/Encode/t/enc_eucjp.t test script cpan/Encode/t/enc_module.enc test data for t/enc_module.t @@ -847,7 +842,7 @@ cpan/Encode/t/gb2312.utf test data cpan/Encode/t/grow.t test script cpan/Encode/t/gsm0338.t test script cpan/Encode/t/guess.t test script -cpan/Encode/t/isa.t +cpan/Encode/t/isa.t Test file related to Encode cpan/Encode/t/jis7-fallback.t test script cpan/Encode/t/jisx0201.enc test data cpan/Encode/t/jisx0201.utf test data @@ -871,18 +866,18 @@ cpan/Encode/t/rt65541.t test script cpan/Encode/t/rt76824.t test script cpan/Encode/t/rt85489.t test script cpan/Encode/t/rt86327.t test script -cpan/Encode/t/taint.t -cpan/Encode/t/truncated_utf8.t -cpan/Encode/t/undef.t +cpan/Encode/t/taint.t Test file related to Encode +cpan/Encode/t/truncated_utf8.t Test file related to Encode +cpan/Encode/t/undef.t Test file related to Encode cpan/Encode/t/unibench.pl benchmark script cpan/Encode/t/Unicode.t test script -cpan/Encode/t/Unicode_trailing_nul.t -cpan/Encode/t/use-Encode-Alias.t -cpan/Encode/t/utf32warnings.t +cpan/Encode/t/Unicode_trailing_nul.t Test file related to Encode +cpan/Encode/t/use-Encode-Alias.t Test file related to Encode +cpan/Encode/t/utf32warnings.t Test file related to Encode cpan/Encode/t/utf8ref.t test script cpan/Encode/t/utf8strict.t test script -cpan/Encode/t/utf8warnings.t -cpan/Encode/t/xml.t +cpan/Encode/t/utf8warnings.t Test file related to Encode +cpan/Encode/t/xml.t Test file related to Encode cpan/Encode/TW/Makefile.PL Encode extension cpan/Encode/TW/TW.pm Encode extension cpan/Encode/ucm/8859-1.ucm Unicode Character Map @@ -991,9 +986,9 @@ cpan/Encode/ucm/viscii.ucm Unicode Ch cpan/Encode/Unicode/Makefile.PL Encode extension cpan/Encode/Unicode/Unicode.pm Encode extension cpan/Encode/Unicode/Unicode.xs Encode extension -cpan/experimental/lib/experimental.pm -cpan/experimental/lib/stable.pm -cpan/experimental/t/basic.t +cpan/experimental/lib/experimental.pm Module related to experimental +cpan/experimental/lib/stable.pm Module related to experimental +cpan/experimental/t/basic.t Test file related to experimental cpan/ExtUtils-Constant/lib/ExtUtils/Constant.pm generate XS code to import C header constants cpan/ExtUtils-Constant/lib/ExtUtils/Constant/Base.pm generate XS code to import C header constants cpan/ExtUtils-Constant/lib/ExtUtils/Constant/ProxySubs.pm generate XS code for proxy constants @@ -1156,117 +1151,120 @@ cpan/Filter-Util-Call/t/call.t See if cpan/Filter-Util-Call/t/rt_101033.pm cpan/Filter-Util-Call/t/rt_101033.t cpan/Filter-Util-Call/t/rt_54452-rebless.t -cpan/Getopt-Long/lib/Getopt/Long.pm Fetch command options (GetOptions) -cpan/Getopt-Long/t/gol-basic.t See if Getopt::Long works -cpan/Getopt-Long/t/gol-linkage.t See if Getopt::Long works -cpan/Getopt-Long/t/gol-oo.t See if Getopt::Long works -cpan/Getopt-Long/t/gol-xargv.t See if Getopt::Long works -cpan/Getopt-Long/t/gol-xstring.t See if Getopt::Long works -cpan/HTTP-Tiny/corpus/auth-01.txt -cpan/HTTP-Tiny/corpus/auth-02.txt -cpan/HTTP-Tiny/corpus/auth-03.txt -cpan/HTTP-Tiny/corpus/auth-04.txt -cpan/HTTP-Tiny/corpus/auth-05.txt -cpan/HTTP-Tiny/corpus/cookies-01.txt -cpan/HTTP-Tiny/corpus/cookies-02.txt -cpan/HTTP-Tiny/corpus/cookies-03.txt -cpan/HTTP-Tiny/corpus/cookies-04.txt -cpan/HTTP-Tiny/corpus/cookies-05.txt -cpan/HTTP-Tiny/corpus/cookies-06.txt -cpan/HTTP-Tiny/corpus/cookies-07.txt -cpan/HTTP-Tiny/corpus/delete-01.txt -cpan/HTTP-Tiny/corpus/form-01.txt -cpan/HTTP-Tiny/corpus/form-02.txt -cpan/HTTP-Tiny/corpus/form-03.txt -cpan/HTTP-Tiny/corpus/form-04.txt -cpan/HTTP-Tiny/corpus/form-05.txt -cpan/HTTP-Tiny/corpus/get-01.txt -cpan/HTTP-Tiny/corpus/get-02.txt -cpan/HTTP-Tiny/corpus/get-03.txt -cpan/HTTP-Tiny/corpus/get-04.txt -cpan/HTTP-Tiny/corpus/get-05.txt -cpan/HTTP-Tiny/corpus/get-06.txt -cpan/HTTP-Tiny/corpus/get-07.txt -cpan/HTTP-Tiny/corpus/get-08.txt -cpan/HTTP-Tiny/corpus/get-09.txt -cpan/HTTP-Tiny/corpus/get-10.txt -cpan/HTTP-Tiny/corpus/get-11.txt -cpan/HTTP-Tiny/corpus/get-12.txt -cpan/HTTP-Tiny/corpus/get-13.txt -cpan/HTTP-Tiny/corpus/get-14.txt -cpan/HTTP-Tiny/corpus/get-15.txt -cpan/HTTP-Tiny/corpus/get-16.txt -cpan/HTTP-Tiny/corpus/get-17.txt -cpan/HTTP-Tiny/corpus/get-18.txt -cpan/HTTP-Tiny/corpus/get-19.txt -cpan/HTTP-Tiny/corpus/get-20.txt -cpan/HTTP-Tiny/corpus/get-21.txt -cpan/HTTP-Tiny/corpus/get-22.txt -cpan/HTTP-Tiny/corpus/get-23.txt -cpan/HTTP-Tiny/corpus/head-01.txt -cpan/HTTP-Tiny/corpus/keepalive-01.txt -cpan/HTTP-Tiny/corpus/keepalive-02.txt -cpan/HTTP-Tiny/corpus/keepalive-03.txt -cpan/HTTP-Tiny/corpus/keepalive-04.txt -cpan/HTTP-Tiny/corpus/keepalive-05.txt -cpan/HTTP-Tiny/corpus/mirror-01.txt -cpan/HTTP-Tiny/corpus/mirror-02.txt -cpan/HTTP-Tiny/corpus/mirror-03.txt -cpan/HTTP-Tiny/corpus/mirror-04.txt -cpan/HTTP-Tiny/corpus/mirror-05.txt -cpan/HTTP-Tiny/corpus/post-01.txt -cpan/HTTP-Tiny/corpus/post-02.txt -cpan/HTTP-Tiny/corpus/proxy-auth-01.txt -cpan/HTTP-Tiny/corpus/put-01.txt -cpan/HTTP-Tiny/corpus/put-02.txt -cpan/HTTP-Tiny/corpus/put-03.txt -cpan/HTTP-Tiny/corpus/put-04.txt -cpan/HTTP-Tiny/corpus/put-05.txt -cpan/HTTP-Tiny/corpus/put-06.txt -cpan/HTTP-Tiny/corpus/put-07.txt -cpan/HTTP-Tiny/corpus/put-08.txt -cpan/HTTP-Tiny/corpus/redirect-01.txt -cpan/HTTP-Tiny/corpus/redirect-02.txt -cpan/HTTP-Tiny/corpus/redirect-03.txt -cpan/HTTP-Tiny/corpus/redirect-04.txt -cpan/HTTP-Tiny/corpus/redirect-05.txt -cpan/HTTP-Tiny/corpus/redirect-06.txt -cpan/HTTP-Tiny/corpus/redirect-07.txt -cpan/HTTP-Tiny/corpus/redirect-08.txt -cpan/HTTP-Tiny/corpus/redirect-09.txt -cpan/HTTP-Tiny/corpus/redirect-10.txt -cpan/HTTP-Tiny/lib/HTTP/Tiny.pm -cpan/HTTP-Tiny/t/000_load.t -cpan/HTTP-Tiny/t/001_api.t -cpan/HTTP-Tiny/t/002_croakage.t -cpan/HTTP-Tiny/t/003_agent.t -cpan/HTTP-Tiny/t/004_timeout.t -cpan/HTTP-Tiny/t/010_url.t -cpan/HTTP-Tiny/t/020_headers.t -cpan/HTTP-Tiny/t/030_response.t -cpan/HTTP-Tiny/t/040_content.t -cpan/HTTP-Tiny/t/050_chunked_body.t -cpan/HTTP-Tiny/t/060_http_date.t -cpan/HTTP-Tiny/t/070_cookie_jar.t -cpan/HTTP-Tiny/t/100_get.t -cpan/HTTP-Tiny/t/101_head.t -cpan/HTTP-Tiny/t/102_put.t -cpan/HTTP-Tiny/t/103_delete.t -cpan/HTTP-Tiny/t/104_post.t -cpan/HTTP-Tiny/t/110_mirror.t -cpan/HTTP-Tiny/t/130_redirect.t -cpan/HTTP-Tiny/t/140_proxy.t -cpan/HTTP-Tiny/t/141_no_proxy.t -cpan/HTTP-Tiny/t/150_post_form.t -cpan/HTTP-Tiny/t/160_cookies.t -cpan/HTTP-Tiny/t/161_basic_auth.t -cpan/HTTP-Tiny/t/162_proxy_auth.t -cpan/HTTP-Tiny/t/170_keepalive.t -cpan/HTTP-Tiny/t/180_verify_SSL.t -cpan/HTTP-Tiny/t/BrokenCookieJar.pm -cpan/HTTP-Tiny/t/SimpleCookieJar.pm -cpan/HTTP-Tiny/t/Util.pm -cpan/IO-Compress/bin/streamzip +cpan/Getopt-Long/lib/Getopt/Long.pm Fetch command options (GetOptions) +cpan/Getopt-Long/lib/Getopt/Long/Parser.pm Getopt-Long +cpan/Getopt-Long/t/gol-basic.t See if Getopt::Long works +cpan/Getopt-Long/t/gol-linkage.t See if Getopt::Long works +cpan/Getopt-Long/t/gol-load1.t Getopt-Long +cpan/Getopt-Long/t/gol-load2.t Getopt-Long +cpan/Getopt-Long/t/gol-oo.t See if Getopt::Long works +cpan/Getopt-Long/t/gol-xargv.t See if Getopt::Long works +cpan/Getopt-Long/t/gol-xstring.t See if Getopt::Long works +cpan/HTTP-Tiny/corpus/auth-01.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/auth-02.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/auth-03.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/auth-04.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/auth-05.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/cookies-01.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/cookies-02.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/cookies-03.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/cookies-04.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/cookies-05.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/cookies-06.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/cookies-07.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/delete-01.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/form-01.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/form-02.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/form-03.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/form-04.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/form-05.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-01.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-02.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-03.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-04.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-05.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-06.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-07.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-08.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-09.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-10.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-11.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-12.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-13.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-14.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-15.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-16.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-17.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-18.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-19.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-20.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-21.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-22.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/get-23.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/head-01.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/keepalive-01.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/keepalive-02.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/keepalive-03.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/keepalive-04.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/keepalive-05.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/mirror-01.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/mirror-02.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/mirror-03.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/mirror-04.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/mirror-05.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/post-01.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/post-02.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/proxy-auth-01.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/put-01.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/put-02.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/put-03.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/put-04.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/put-05.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/put-06.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/put-07.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/put-08.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/redirect-01.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/redirect-02.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/redirect-03.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/redirect-04.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/redirect-05.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/redirect-06.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/redirect-07.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/redirect-08.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/redirect-09.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/corpus/redirect-10.txt Test file related to HTTP::Tiny +cpan/HTTP-Tiny/lib/HTTP/Tiny.pm Module related to HTTP::Tiny +cpan/HTTP-Tiny/t/000_load.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/001_api.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/002_croakage.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/003_agent.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/004_timeout.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/010_url.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/020_headers.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/030_response.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/040_content.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/050_chunked_body.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/060_http_date.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/070_cookie_jar.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/100_get.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/101_head.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/102_put.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/103_delete.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/104_post.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/110_mirror.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/130_redirect.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/140_proxy.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/141_no_proxy.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/150_post_form.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/160_cookies.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/161_basic_auth.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/162_proxy_auth.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/170_keepalive.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/180_verify_SSL.t Test file related to HTTP::Tiny +cpan/HTTP-Tiny/t/BrokenCookieJar.pm Module related to HTTP::Tiny +cpan/HTTP-Tiny/t/SimpleCookieJar.pm Module related to HTTP::Tiny +cpan/HTTP-Tiny/t/Util.pm Module related to HTTP::Tiny +cpan/IO-Compress/bin/streamzip IO-Compress cpan/IO-Compress/bin/zipdetails IO::Compress cpan/IO-Compress/lib/Compress/Zlib.pm IO::Compress cpan/IO-Compress/lib/File/GlobMapper.pm IO::Compress @@ -1298,7 +1296,6 @@ cpan/IO-Compress/lib/IO/Uncompress/RawIn cpan/IO-Compress/lib/IO/Uncompress/Unzip.pm IO::Compress cpan/IO-Compress/Makefile.PL IO::Compress cpan/IO-Compress/private/MakeUtil.pm IO::Compress -cpan/IO-Compress/t/000prereq.t IO::Compress cpan/IO-Compress/t/001bzip2.t IO::Compress cpan/IO-Compress/t/001zlib-generic-deflate.t IO::Compress cpan/IO-Compress/t/001zlib-generic-gzip.t IO::Compress @@ -1312,7 +1309,7 @@ cpan/IO-Compress/t/002any-zip.t IO::C cpan/IO-Compress/t/004gziphdr.t IO::Compress cpan/IO-Compress/t/005defhdr.t IO::Compress cpan/IO-Compress/t/006zip.t IO::Compress -cpan/IO-Compress/t/011-streamzip.t +cpan/IO-Compress/t/011-streamzip.t Test file related to IO-Compress cpan/IO-Compress/t/01misc.t IO::Compress cpan/IO-Compress/t/020isize.t IO::Compress cpan/IO-Compress/t/050interop-gzip.t IO::Compress @@ -1360,7 +1357,7 @@ cpan/IO-Compress/t/107multi-deflate.t cpan/IO-Compress/t/107multi-gzip.t IO::Compress cpan/IO-Compress/t/107multi-rawdeflate.t IO::Compress cpan/IO-Compress/t/107multi-zip.t IO::Compress -cpan/IO-Compress/t/107multi-zip-only.t +cpan/IO-Compress/t/107multi-zip-only.t Test file related to IO-Compress cpan/IO-Compress/t/108anyunc-bzip2.t IO::Compress cpan/IO-Compress/t/108anyunc-deflate.t IO::Compress cpan/IO-Compress/t/108anyunc-gzip.t IO::Compress @@ -1377,8 +1374,8 @@ cpan/IO-Compress/t/110encode-gzip.t IO cpan/IO-Compress/t/110encode-rawdeflate.t IO::Compress cpan/IO-Compress/t/110encode-zip.t IO::Compress cpan/IO-Compress/t/111const-deflate.t IO::Compress -cpan/IO-Compress/t/112utf8-zip.t -cpan/IO-Compress/t/113issues.t +cpan/IO-Compress/t/112utf8-zip.t Test file related to IO-Compress +cpan/IO-Compress/t/113issues.t Test file related to IO-Compress cpan/IO-Compress/t/999pod.t IO::Compress cpan/IO-Compress/t/compress/any.pl Compress::Zlib cpan/IO-Compress/t/compress/anyunc.pl Compress::Zlib @@ -1399,14 +1396,15 @@ cpan/IO-Compress/t/cz-03zlib-v1.t IO:: cpan/IO-Compress/t/cz-06gzsetp.t IO::Compress cpan/IO-Compress/t/cz-08encoding.t IO::Compress cpan/IO-Compress/t/cz-14gzopen.t IO::Compress -cpan/IO-Compress/t/files/bad-efs.zip -cpan/IO-Compress/t/files/encrypt-aes.zip -cpan/IO-Compress/t/files/encrypt-standard.zip -cpan/IO-Compress/t/files/jar.zip -cpan/IO-Compress/t/files/meta.xml -cpan/IO-Compress/t/files/test.ods -cpan/IO-Compress/t/files/testfile1.odt +cpan/IO-Compress/t/files/bad-efs.zip IO-Compress +cpan/IO-Compress/t/files/encrypt-aes.zip IO-Compress +cpan/IO-Compress/t/files/encrypt-standard.zip IO-Compress +cpan/IO-Compress/t/files/jar.zip IO-Compress +cpan/IO-Compress/t/files/meta.xml IO-Compress +cpan/IO-Compress/t/files/test.ods IO-Compress +cpan/IO-Compress/t/files/testfile1.odt IO-Compress cpan/IO-Compress/t/globmapper.t IO::Compress +cpan/IO-Socket-IP/.editorconfig IO-Socket-IP cpan/IO-Socket-IP/lib/IO/Socket/IP.pm IO::Socket::IP cpan/IO-Socket-IP/t/00use.t IO::Socket::IP tests cpan/IO-Socket-IP/t/01local-client-v4.t IO::Socket::IP tests @@ -1427,7 +1425,7 @@ cpan/IO-Socket-IP/t/18fdopen.t IO::So cpan/IO-Socket-IP/t/19no-addrs.t IO::Socket::IP tests cpan/IO-Socket-IP/t/20subclass.t IO::Socket::IP tests cpan/IO-Socket-IP/t/21as-inet.t IO::Socket::IP tests -cpan/IO-Socket-IP/t/22timeout.t +cpan/IO-Socket-IP/t/22timeout.t Test file related to IO::Socket::IP cpan/IO-Socket-IP/t/30nonblocking-connect.t IO::Socket::IP tests cpan/IO-Socket-IP/t/31nonblocking-connect-internet.t IO::Socket::IP tests cpan/IO-Socket-IP/t/99pod.t IO::Socket::IP tests @@ -1573,103 +1571,85 @@ cpan/Locale-Maketext-Simple/t/po_with_i_ cpan/Locale-Maketext-Simple/t/po_with_i_default/i_default.po Locale::Simple tests cpan/Locale-Maketext-Simple/t/po_without_i_default/en.po Locale::Simple tests cpan/Locale-Maketext-Simple/t/po_without_i_default/fr.po Locale::Simple tests -cpan/Math-BigInt/lib/Math/BigFloat.pm An arbitrary precision floating-point arithmetic package -cpan/Math-BigInt/lib/Math/BigInt.pm An arbitrary precision integer arithmetic package -cpan/Math-BigInt/lib/Math/BigInt/Calc.pm Pure Perl module to support Math::BigInt -cpan/Math-BigInt/lib/Math/BigInt/Lib.pm -cpan/Math-BigInt/t/alias.inc Support for BigInt tests -cpan/Math-BigInt/t/bare_mbf.t Test MBF under Math::BigInt::BareCalc -cpan/Math-BigInt/t/bare_mbi.t Test MBI under Math::BigInt::BareCalc -cpan/Math-BigInt/t/bare_mif.t Rounding tests under BareCalc -cpan/Math-BigInt/t/big_pi_e.t test bpi() and bexp() -cpan/Math-BigInt/t/bigfltpm.inc Shared tests for bigfltpm.t and sub_mbf.t -cpan/Math-BigInt/t/bigfltpm.t See if BigFloat.pm works -cpan/Math-BigInt/t/bigintc.t See if BigInt/Calc.pm works -cpan/Math-BigInt/t/bigintc-import.t -cpan/Math-BigInt/t/bigintpm.inc Shared tests for bigintpm.t and sub_mbi.t -cpan/Math-BigInt/t/bigintpm.t See if BigInt.pm works -cpan/Math-BigInt/t/bigints.t See if BigInt.pm works -cpan/Math-BigInt/t/biglog.t Test the log function -cpan/Math-BigInt/t/bigroot.t Test the broot function -cpan/Math-BigInt/t/calling-class-methods.t Test Math::BigInt -cpan/Math-BigInt/t/calling-constant.t -cpan/Math-BigInt/t/calling-instance-methods.t Test Math::BigInt -cpan/Math-BigInt/t/calling-lib1.t -cpan/Math-BigInt/t/calling-lib2.t -cpan/Math-BigInt/t/config.t Test Math::BigInt->config() -cpan/Math-BigInt/t/downgrade.t Test if use Math::BigInt(); under downgrade works -cpan/Math-BigInt/t/inf_nan.t Special tests for inf and *NaN* handling -cpan/Math-BigInt/t/isa.t Test for Math::BigInt inheritance -cpan/Math-BigInt/t/Math/BigFloat/Subclass.pm Empty subclass of BigFloat for test -cpan/Math-BigInt/t/Math/BigInt/BareCalc.pm Bigint's simulation of Calc -cpan/Math-BigInt/t/Math/BigInt/Lib/Minimal.pm -cpan/Math-BigInt/t/Math/BigInt/Lib/TestUtil.pm Test Math::BigInt -cpan/Math-BigInt/t/Math/BigInt/Scalar.pm Pure Perl module to support Math::BigInt -cpan/Math-BigInt/t/Math/BigInt/Subclass.pm Empty subclass of BigInt for test -cpan/Math-BigInt/t/mbf_ali.t Tests for BigFloat -cpan/Math-BigInt/t/mbi_ali.t Tests for BigInt -cpan/Math-BigInt/t/mbi_rand.t Test Math::BigInt randomly -cpan/Math-BigInt/t/mbimbf.inc Actual BigInt/BigFloat accuracy, precision and fallback, round_mode tests -cpan/Math-BigInt/t/mbimbf.t BigInt/BigFloat accuracy, precision and fallback, round_mode -cpan/Math-BigInt/t/nan_cmp.t overloaded comparison involving *NaN* -cpan/Math-BigInt/t/new_overloaded.t test overloaded numbers in BigFloat's new() -cpan/Math-BigInt/t/req_mbf0.t test: require Math::BigFloat; ->bzero(); -cpan/Math-BigInt/t/req_mbf1.t test: require Math::BigFloat; ->bone(); -cpan/Math-BigInt/t/req_mbfa.t test: require Math::BigFloat; ->bnan(); -cpan/Math-BigInt/t/req_mbfi.t test: require Math::BigFloat; ->binf(); -cpan/Math-BigInt/t/req_mbfn.t test: require Math::BigFloat; ->new(); -cpan/Math-BigInt/t/req_mbfw.t require Math::BigFloat; import ( with => ); -cpan/Math-BigInt/t/require.t Test if require Math::BigInt works -cpan/Math-BigInt/t/round.t Test rounding with non-integer A and P -cpan/Math-BigInt/t/rt-16221.t Tests for objectify() w/foreign objs -cpan/Math-BigInt/t/sub_ali.t Tests for aliases in BigInt subclasses -cpan/Math-BigInt/t/sub_mbf.t Empty subclass test of BigFloat -cpan/Math-BigInt/t/sub_mbi.t Empty subclass test of BigInt -cpan/Math-BigInt/t/sub_mif.t Test A & P with subclasses using mbimbf.inc -cpan/Math-BigInt/t/trap.t Test whether trap_nan and trap_inf work -cpan/Math-BigInt/t/upgrade.inc Actual tests for upgrade.t -cpan/Math-BigInt/t/upgrade.t Test if use Math::BigInt(); under upgrade works -cpan/Math-BigInt/t/upgrade2.t Test that two upgrade levels work -cpan/Math-BigInt/t/upgradef.t Test if use Math::BigFloat(); under upgrade works -cpan/Math-BigInt/t/use.t Test if use Math::BigInt(); works -cpan/Math-BigInt/t/use_lib1.t Test combinations of Math::BigInt and BigFloat -cpan/Math-BigInt/t/use_lib2.t Test combinations of Math::BigInt and BigFloat -cpan/Math-BigInt/t/use_lib3.t Test combinations of Math::BigInt and BigFloat -cpan/Math-BigInt/t/use_lib4.t Test combinations of Math::BigInt and BigFloat -cpan/Math-BigInt/t/use_lib5.t -cpan/Math-BigInt/t/use_lib6.t -cpan/Math-BigInt/t/use_mbfw.t use BigFloat w/ with and lib at the same time -cpan/Math-BigInt/t/with_sub.t Test use Math::BigFloat with => package +cpan/Math-BigInt/lib/Math/BigFloat.pm An arbitrary precision floating-point arithmetic package +cpan/Math-BigInt/lib/Math/BigInt.pm An arbitrary precision integer arithmetic package +cpan/Math-BigInt/lib/Math/BigInt/Calc.pm Pure Perl module to support Math::BigInt +cpan/Math-BigInt/lib/Math/BigInt/Lib.pm Module related to Math::BigInt +cpan/Math-BigInt/lib/Math/BigRat.pm Math-BigInt +cpan/Math-BigInt/t/alias.inc Support for BigInt tests +cpan/Math-BigInt/t/bare_mbf.t Test MBF under Math::BigInt::BareCalc +cpan/Math-BigInt/t/bare_mbi.t Test MBI under Math::BigInt::BareCalc +cpan/Math-BigInt/t/bare_mbr.t Math-BigInt +cpan/Math-BigInt/t/bare_mif.t Rounding tests under BareCalc +cpan/Math-BigInt/t/bfround_numify.t Test file related to Math::BigInt +cpan/Math-BigInt/t/big_ap.t Math-BigInt +cpan/Math-BigInt/t/big_pi_e.t test bpi() and bexp() +cpan/Math-BigInt/t/bigfltpm.inc Shared tests for bigfltpm.t and sub_mbf.t +cpan/Math-BigInt/t/bigfltpm.t See if BigFloat.pm works +cpan/Math-BigInt/t/bigfltrt.t Math-BigInt +cpan/Math-BigInt/t/bigintc.t See if BigInt/Calc.pm works +cpan/Math-BigInt/t/bigintc-import.t Test file related to Math::BigInt +cpan/Math-BigInt/t/bigintpm.inc Shared tests for bigintpm.t and sub_mbi.t +cpan/Math-BigInt/t/bigintpm.t See if BigInt.pm works +cpan/Math-BigInt/t/bigints.t See if BigInt.pm works +cpan/Math-BigInt/t/biglog.t Test the log function +cpan/Math-BigInt/t/bigrat.t Math-BigInt +cpan/Math-BigInt/t/bigratpm.inc Math-BigInt +cpan/Math-BigInt/t/bigratpm.t Math-BigInt +cpan/Math-BigInt/t/bigratup.t Math-BigInt +cpan/Math-BigInt/t/bigroot.t Test the broot function +cpan/Math-BigInt/t/bitwise-mbr.t Math-BigInt +cpan/Math-BigInt/t/calling-class-methods.t Test Math::BigInt +cpan/Math-BigInt/t/calling-constant.t Test file related to Math::BigInt +cpan/Math-BigInt/t/calling-instance-methods.t Test Math::BigInt +cpan/Math-BigInt/t/calling-lib1.t Test file related to Math::BigInt +cpan/Math-BigInt/t/calling-lib2.t Test file related to Math::BigInt +cpan/Math-BigInt/t/config.t Test Math::BigInt->config() +cpan/Math-BigInt/t/downgrade-mbi-mbf.t Math-BigInt +cpan/Math-BigInt/t/downgrade-mbi-mbr.t Math-BigInt +cpan/Math-BigInt/t/hang-mbr.t Math-BigInt +cpan/Math-BigInt/t/inf_nan.t Special tests for inf and *NaN* handling +cpan/Math-BigInt/t/isa.t Test for Math::BigInt inheritance +cpan/Math-BigInt/t/Math/BigFloat/BareSubclass.pm Math-BigInt +cpan/Math-BigInt/t/Math/BigFloat/Subclass.pm Empty subclass of BigFloat for test +cpan/Math-BigInt/t/Math/BigInt/BareCalc.pm Bigint's simulation of Calc +cpan/Math-BigInt/t/Math/BigInt/Lib/Minimal.pm Module related to Math::BigInt +cpan/Math-BigInt/t/Math/BigInt/Lib/TestUtil.pm Test Math::BigInt +cpan/Math-BigInt/t/Math/BigInt/Scalar.pm Pure Perl module to support Math::BigInt +cpan/Math-BigInt/t/Math/BigInt/Subclass.pm Empty subclass of BigInt for test +cpan/Math-BigInt/t/Math/BigRat/Subclass.pm Math-BigInt +cpan/Math-BigInt/t/mbf_ali.t Tests for BigFloat +cpan/Math-BigInt/t/mbi_ali.t Tests for BigInt +cpan/Math-BigInt/t/mbi_rand.t Test Math::BigInt randomly +cpan/Math-BigInt/t/mbimbf.inc Actual BigInt/BigFloat accuracy, precision and fallback, round_mode tests +cpan/Math-BigInt/t/mbimbf.t BigInt/BigFloat accuracy, precision and fallback, round_mode +cpan/Math-BigInt/t/mbr_ali.t Math-BigInt +cpan/Math-BigInt/t/nan_cmp.t overloaded comparison involving *NaN* +cpan/Math-BigInt/t/new_overloaded.t test overloaded numbers in BigFloat's new() +cpan/Math-BigInt/t/round.t Test rounding with non-integer A and P +cpan/Math-BigInt/t/rt-16221.t Tests for objectify() w/foreign objs +cpan/Math-BigInt/t/rt121139.t Math-BigInt +cpan/Math-BigInt/t/sub_ali.t Tests for aliases in BigInt subclasses +cpan/Math-BigInt/t/sub_mbf.t Empty subclass test of BigFloat +cpan/Math-BigInt/t/sub_mbi.t Empty subclass test of BigInt +cpan/Math-BigInt/t/sub_mbr.t Math-BigInt +cpan/Math-BigInt/t/sub_mif.t Test A & P with subclasses using mbimbf.inc +cpan/Math-BigInt/t/trap.t Test whether trap_nan and trap_inf work +cpan/Math-BigInt/t/upgrade.inc Actual tests for upgrade.t +cpan/Math-BigInt/t/upgrade.t Test if use Math::BigInt(); under upgrade works +cpan/Math-BigInt/t/upgrade2.t Test that two upgrade levels work +cpan/Math-BigInt/t/upgradef.t Test if use Math::BigFloat(); under upgrade works +cpan/Math-BigInt/t/use.t Test if use Math::BigInt(); works +cpan/Math-BigInt/t/use_mbfw.t use BigFloat w/ with and lib at the same time +cpan/Math-BigInt/t/with_sub.t Test use Math::BigFloat with => package cpan/Math-BigInt-FastCalc/FastCalc.xs Math::BigInt::FastCalc extension cpan/Math-BigInt-FastCalc/lib/Math/BigInt/FastCalc.pm Math::BigInt::FastCalc extension cpan/Math-BigInt-FastCalc/t/bigintfc.t Math::BigInt::FastCalc extension -cpan/Math-BigInt-FastCalc/t/biglog.t -cpan/Math-BigInt-FastCalc/t/bigroot.t +cpan/Math-BigInt-FastCalc/t/biglog.t Test file related to Math::BigInt::FastCalc +cpan/Math-BigInt-FastCalc/t/bigroot.t Test file related to Math::BigInt::FastCalc cpan/Math-BigInt-FastCalc/t/bootstrap.t Math::BigInt::FastCalc extension cpan/Math-BigInt-FastCalc/t/leak.t test for memory leaks in Math::BigInt::FastCalc cpan/Math-BigInt-FastCalc/t/mbi_rand.t Math::BigInt::FastCalc extension -cpan/Math-BigRat/lib/Math/BigRat.pm Math::BigRat -cpan/Math-BigRat/t/badd-mbr.t -cpan/Math-BigRat/t/big_ap.t Math::BigRat test -cpan/Math-BigRat/t/bigfltpm.inc Math::BigRat test -cpan/Math-BigRat/t/bigfltrt.t Math::BigRat test -cpan/Math-BigRat/t/bigrat.t Math::BigRat test -cpan/Math-BigRat/t/bigratpm.inc Math::BigRat test -cpan/Math-BigRat/t/bigratpm.t Math::BigRat test -cpan/Math-BigRat/t/bigratup.t test under $Math::BigInt::upgrade -cpan/Math-BigRat/t/binv-mbr.t -cpan/Math-BigRat/t/bitwise.t Math::BigRat test -cpan/Math-BigRat/t/bnok-mbr.t -cpan/Math-BigRat/t/const-mbr.t -cpan/Math-BigRat/t/downgrade.t -cpan/Math-BigRat/t/dparts-mbr.t -cpan/Math-BigRat/t/fparts-mbr.t -cpan/Math-BigRat/t/hang.t Math::BigRat test for bug #34584 - hang in exp() -cpan/Math-BigRat/t/Math/BigRat/Test.pm Math::BigRat test helper -cpan/Math-BigRat/t/new-mbr.t -cpan/Math-BigRat/t/requirer.t see if require works properly -cpan/Math-BigRat/t/rt121139.t -cpan/Math-BigRat/t/trap.t see if trap_nan and trap_inf work cpan/Memoize/Memoize.pm Memoize cpan/Memoize/Memoize/AnyDBM_File.pm Memoize glue layer for AnyDBM_File cpan/Memoize/Memoize/Expire.pm Memoize expiry manager example @@ -1797,26 +1777,23 @@ cpan/PerlIO-via-QuotedPrint/t/critic.t cpan/PerlIO-via-QuotedPrint/t/pod.t cpan/PerlIO-via-QuotedPrint/t/pod_coverage.t cpan/PerlIO-via-QuotedPrint/t/QuotedPrint.t PerlIO::via::QuotedPrint -cpan/Pod-Checker/lib/Pod/Checker.pm -cpan/Pod-Checker/scripts/podchecker.PL -cpan/Pod-Checker/t/pod/contains_bad_pod.xr -cpan/Pod-Checker/t/pod/empty.xr -cpan/Pod-Checker/t/pod/podchkenc.t -cpan/Pod-Checker/t/pod/podchkenc.xr -cpan/Pod-Checker/t/pod/podchklink.t -cpan/Pod-Checker/t/pod/poderrs.t -cpan/Pod-Checker/t/pod/poderrs.xr -cpan/Pod-Checker/t/pod/podname.t -cpan/Pod-Checker/t/pod/selfcheck.t -cpan/Pod-Checker/t/pod/testcmp.pl -cpan/Pod-Checker/t/pod/testpchk.pl +cpan/Pod-Checker/lib/Pod/Checker.pm Module related to Pod::Checker +cpan/Pod-Checker/scripts/podchecker.PL Pod::Checker +cpan/Pod-Checker/t/pod/contains_bad_pod.xr Pod::Checker +cpan/Pod-Checker/t/pod/empty.xr Pod::Checker +cpan/Pod-Checker/t/pod/podchkenc.t Test file related to Pod::Checker +cpan/Pod-Checker/t/pod/podchkenc.xr Pod::Checker +cpan/Pod-Checker/t/pod/podchklink.t Test file related to Pod::Checker +cpan/Pod-Checker/t/pod/poderrs.t Test file related to Pod::Checker +cpan/Pod-Checker/t/pod/poderrs.xr Pod::Checker +cpan/Pod-Checker/t/pod/podname.t Test file related to Pod::Checker +cpan/Pod-Checker/t/pod/selfcheck.t Test file related to Pod::Checker +cpan/Pod-Checker/t/pod/testcmp.pl Script related to Pod::Checker +cpan/Pod-Checker/t/pod/testpchk.pl Script related to Pod::Checker cpan/Pod-Escapes/lib/Pod/Escapes.pm Pod::Escapes cpan/Pod-Escapes/t/01_about_verbose.t test Pod::Escapes cpan/Pod-Escapes/t/10_main.t test Pod::Escapes cpan/Pod-Escapes/t/15_name2charnum.t test Pod::Escapes -cpan/Pod-Perldoc/corpus/no-head.pod test file for Pod-Perldoc -cpan/Pod-Perldoc/corpus/perlfunc.pod test file for Pod-Perldoc -cpan/Pod-Perldoc/corpus/utf8.pod test file for Pod-Perldoc cpan/Pod-Perldoc/lib/Pod/Perldoc.pm guts of the 'perldoc' utility cpan/Pod-Perldoc/lib/Pod/Perldoc/BaseTo.pm utility module for perldoc cpan/Pod-Perldoc/lib/Pod/Perldoc/GetOptsOO.pm options parsing for perldoc @@ -1846,7 +1823,7 @@ cpan/Pod-Simple/lib/Pod/Simple/DumpAsXML cpan/Pod-Simple/lib/Pod/Simple/HTML.pm convert Pod to HTML cpan/Pod-Simple/lib/Pod/Simple/HTMLBatch.pm convert several Pod files to several HTML files cpan/Pod-Simple/lib/Pod/Simple/HTMLLegacy.pm Pod::Simple::HTMLLegacy -cpan/Pod-Simple/lib/Pod/Simple/JustPod.pm +cpan/Pod-Simple/lib/Pod/Simple/JustPod.pm Module related to Pod::Simple cpan/Pod-Simple/lib/Pod/Simple/LinkSection.pm represent "section" attributes of L codes cpan/Pod-Simple/lib/Pod/Simple/Methody.pm turn Pod::Simple events into method calls cpan/Pod-Simple/lib/Pod/Simple/Progress.pm Pod::Simple::Progress @@ -1868,11 +1845,10 @@ cpan/Pod-Simple/lib/Pod/Simple/Transcode cpan/Pod-Simple/lib/Pod/Simple/XHTML.pm turn Pod into XHTML cpan/Pod-Simple/lib/Pod/Simple/XMLOutStream.pm turn Pod into XML cpan/Pod-Simple/t/00about.t Pod::Simple test file -cpan/Pod-Simple/t/20_skip.t Pod::Simple test file cpan/Pod-Simple/t/ac_d.t Pod::Simple test file cpan/Pod-Simple/t/accept01.t Pod::Simple test file cpan/Pod-Simple/t/accept05.t Pod::Simple test file -cpan/Pod-Simple/t/ascii_order.pl +cpan/Pod-Simple/t/ascii_order.pl Script related to Pod::Simple cpan/Pod-Simple/t/basic.t Pod::Simple test file cpan/Pod-Simple/t/begin.t Pod::Simple test file cpan/Pod-Simple/t/cbacks.t Pod::Simple test file @@ -1900,10 +1876,10 @@ cpan/Pod-Simple/t/corpus/encwarn01.txt cpan/Pod-Simple/t/corpus/encwarn01.xml Pod::Simple test file cpan/Pod-Simple/t/corpus/encwarn02.txt Pod::Simple test file cpan/Pod-Simple/t/corpus/encwarn02.xml Pod::Simple test file -cpan/Pod-Simple/t/corpus/encwarn03.txt -cpan/Pod-Simple/t/corpus/encwarn03.xml -cpan/Pod-Simple/t/corpus/encwarn04.txt -cpan/Pod-Simple/t/corpus/encwarn04.xml +cpan/Pod-Simple/t/corpus/encwarn03.txt Test file related to Pod::Simple +cpan/Pod-Simple/t/corpus/encwarn03.xml Pod::Simple +cpan/Pod-Simple/t/corpus/encwarn04.txt Test file related to Pod::Simple +cpan/Pod-Simple/t/corpus/encwarn04.xml Pod::Simple cpan/Pod-Simple/t/corpus/fet_cont.txt Pod::Simple test file cpan/Pod-Simple/t/corpus/fet_cont.xml Pod::Simple test file cpan/Pod-Simple/t/corpus/fet_dup.txt Pod::Simple test file @@ -1951,11 +1927,11 @@ cpan/Pod-Simple/t/corpus2/polish_utf8_bo cpan/Pod-Simple/t/corpus2/polish_utf8_bom2.xml Pod::Simple test file cpan/Pod-Simple/t/corpus2/README Pod::Simple test file cpan/Pod-Simple/t/emptylists.t Pod::Simple test file -cpan/Pod-Simple/t/enc-chars.t +cpan/Pod-Simple/t/enc-chars.t Test file related to Pod::Simple cpan/Pod-Simple/t/encod01.t Pod::Simple test file cpan/Pod-Simple/t/encod02.t Pod::Simple test file cpan/Pod-Simple/t/encod03.t Pod::Simple test file -cpan/Pod-Simple/t/encod04.t +cpan/Pod-Simple/t/encod04.t Test file related to Pod::Simple cpan/Pod-Simple/t/end_over.t Pod::Simple test file cpan/Pod-Simple/t/eol.t Pod::Simple test file cpan/Pod-Simple/t/eol2.t Pod::Simple test file @@ -1966,7 +1942,7 @@ cpan/Pod-Simple/t/fcodes_l.t Pod::Sim cpan/Pod-Simple/t/fcodes_s.t Pod::Simple test file cpan/Pod-Simple/t/for.t Pod::Simple test file cpan/Pod-Simple/t/fornot.t Pod::Simple test file -cpan/Pod-Simple/t/github_issue_79.t +cpan/Pod-Simple/t/github_issue_79.t Test file related to Pod::Simple cpan/Pod-Simple/t/heads.t Pod::Simple test file cpan/Pod-Simple/t/html01.t Pod::Simple test file cpan/Pod-Simple/t/html02.t Pod::Simple test file @@ -1979,9 +1955,9 @@ cpan/Pod-Simple/t/junk1.pod Pod::Simp cpan/Pod-Simple/t/junk1o.txt Pod::Simple test file cpan/Pod-Simple/t/junk2.pod Pod::Simple test file cpan/Pod-Simple/t/junk2o.txt Pod::Simple test file -cpan/Pod-Simple/t/JustPod01.t -cpan/Pod-Simple/t/JustPod02.t -cpan/Pod-Simple/t/JustPod_corpus.t +cpan/Pod-Simple/t/JustPod01.t Test file related to Pod::Simple +cpan/Pod-Simple/t/JustPod02.t Test file related to Pod::Simple +cpan/Pod-Simple/t/JustPod_corpus.t Test file related to Pod::Simple cpan/Pod-Simple/t/lib/helpers.pm Pod::Simple test file cpan/Pod-Simple/t/linkclas.t Pod::Simple test file cpan/Pod-Simple/t/output.t Pod::Simple test file @@ -1995,7 +1971,7 @@ cpan/Pod-Simple/t/puller.t Pod::Simpl cpan/Pod-Simple/t/pulltitl.t Pod::Simple test file cpan/Pod-Simple/t/reinit.t Pod::Simple test file cpan/Pod-Simple/t/render.t Pod::Simple test file -cpan/Pod-Simple/t/rtf_utf8.t +cpan/Pod-Simple/t/rtf_utf8.t Test file related to Pod::Simple cpan/Pod-Simple/t/search05.t Pod::Simple test file cpan/Pod-Simple/t/search10.t Pod::Simple test file cpan/Pod-Simple/t/search12.t Pod::Simple test file @@ -2038,14 +2014,15 @@ cpan/Pod-Simple/t/testlib3/squaa/Vliff.p cpan/Pod-Simple/t/tiedfh.t Pod::Simple test file cpan/Pod-Simple/t/verb_fmt.t Pod::Simple test file cpan/Pod-Simple/t/verbatim.t Pod::Simple test file -cpan/Pod-Simple/t/whine.t +cpan/Pod-Simple/t/whine.t Test file related to Pod::Simple cpan/Pod-Simple/t/x_nixer.t Pod::Simple test file -cpan/Pod-Simple/t/xhtml-bkb.t +cpan/Pod-Simple/t/xhtml-bkb.t Test file related to Pod::Simple cpan/Pod-Simple/t/xhtml01.t Pod::Simple test file cpan/Pod-Simple/t/xhtml05.t Pod::Simple test file cpan/Pod-Simple/t/xhtml10.t Pod::Simple test file cpan/Pod-Simple/t/xhtml15.t Pod::Simple test file cpan/Pod-Simple/t/xhtml20.t Pod::Simple test file +cpan/Pod-Simple/t/xhtml25.t Pod-Simple cpan/Pod-Usage/lib/Pod/Usage.pm cpan/Pod-Usage/scripts/pod2usage.PL cpan/Pod-Usage/t/inc/Pod/InputObjects.pm @@ -2289,10 +2266,10 @@ cpan/Socket/t/getaddrinfo.t See if Sock cpan/Socket/t/getnameinfo.t See if Socket::getnameinfo works cpan/Socket/t/ip_mreq.t See if (un)pack_ip_mreq work cpan/Socket/t/ipv6_mreq.t See if (un)pack_ipv6_mreq work -cpan/Socket/t/sockaddr.t +cpan/Socket/t/sockaddr.t Test file related to Socket cpan/Socket/t/Socket.t See if Socket works cpan/Socket/t/socketpair.t See if socketpair works -cpan/Socket/typemap +cpan/Socket/typemap Socket cpan/Sys-Syslog/fallback/const-c.inc Sys::Syslog constants fallback file cpan/Sys-Syslog/fallback/const-xs.inc Sys::Syslog constants fallback file cpan/Sys-Syslog/fallback/syslog.h Sys::Syslog header fallback file @@ -2338,6 +2315,21 @@ cpan/Term-ReadKey/ReadKey.pm.PL Term:: cpan/Term-ReadKey/README Term::ReadKey cpan/Term-ReadKey/t/01_basic.t Term::ReadKey cpan/Term-ReadKey/t/02_terminal_functions.t Term::ReadKey +cpan/Term-Table/lib/Term/Table.pm Term-Table +cpan/Term-Table/lib/Term/Table/Cell.pm Term-Table +cpan/Term-Table/lib/Term/Table/CellStack.pm Term-Table +cpan/Term-Table/lib/Term/Table/HashBase.pm Term-Table +cpan/Term-Table/lib/Term/Table/LineBreak.pm Term-Table +cpan/Term-Table/lib/Term/Table/Spacer.pm Term-Table +cpan/Term-Table/lib/Term/Table/Util.pm Term-Table +cpan/Term-Table/t/bad_blank_line.t Term-Table +cpan/Term-Table/t/HashBase.t Term-Table +cpan/Term-Table/t/honor_env_in_non_tty.t Term-Table +cpan/Term-Table/t/issue-9.t Term-Table +cpan/Term-Table/t/Table.t Term-Table +cpan/Term-Table/t/Table/Cell.t Term-Table +cpan/Term-Table/t/Table/CellStack.t Term-Table +cpan/Term-Table/t/Table/LineBreak.t Term-Table cpan/Test-Harness/bin/prove The prove harness utility cpan/Test-Harness/lib/App/Prove.pm Gubbins for the prove utility cpan/Test-Harness/lib/App/Prove/State.pm Gubbins for the prove utility @@ -2353,7 +2345,7 @@ cpan/Test-Harness/lib/TAP/Formatter/File cpan/Test-Harness/lib/TAP/Formatter/File/Session.pm A parser for Test Anything Protocol cpan/Test-Harness/lib/TAP/Formatter/Session.pm A parser for Test Anything Protocol cpan/Test-Harness/lib/TAP/Harness.pm A parser for Test Anything Protocol -cpan/Test-Harness/lib/TAP/Harness/Beyond.pod +cpan/Test-Harness/lib/TAP/Harness/Beyond.pod Test::Harness cpan/Test-Harness/lib/TAP/Harness/Env.pm A parser for Test Anything Protocol cpan/Test-Harness/lib/TAP/Object.pm A parser for Test Anything Protocol cpan/Test-Harness/lib/TAP/Parser.pm A parser for Test Anything Protocol @@ -2380,11 +2372,11 @@ cpan/Test-Harness/lib/TAP/Parser/Schedul cpan/Test-Harness/lib/TAP/Parser/Scheduler/Spinner.pm A parser for Test Anything Protocol cpan/Test-Harness/lib/TAP/Parser/Source.pm A parser for Test Anything Protocol cpan/Test-Harness/lib/TAP/Parser/SourceHandler.pm A parser for Test Anything Protocol -cpan/Test-Harness/lib/TAP/Parser/SourceHandler/Executable.pm -cpan/Test-Harness/lib/TAP/Parser/SourceHandler/File.pm -cpan/Test-Harness/lib/TAP/Parser/SourceHandler/Handle.pm -cpan/Test-Harness/lib/TAP/Parser/SourceHandler/Perl.pm -cpan/Test-Harness/lib/TAP/Parser/SourceHandler/RawTAP.pm +cpan/Test-Harness/lib/TAP/Parser/SourceHandler/Executable.pm Module related to Test::Harness +cpan/Test-Harness/lib/TAP/Parser/SourceHandler/File.pm Module related to Test::Harness +cpan/Test-Harness/lib/TAP/Parser/SourceHandler/Handle.pm Module related to Test::Harness +cpan/Test-Harness/lib/TAP/Parser/SourceHandler/Perl.pm Module related to Test::Harness +cpan/Test-Harness/lib/TAP/Parser/SourceHandler/RawTAP.pm Module related to Test::Harness cpan/Test-Harness/lib/TAP/Parser/YAMLish/Reader.pm A parser for Test Anything Protocol cpan/Test-Harness/lib/TAP/Parser/YAMLish/Writer.pm A parser for Test Anything Protocol cpan/Test-Harness/lib/Test/Harness.pm A test harness @@ -2407,7 +2399,7 @@ cpan/Test-Harness/t/console.t Test:: cpan/Test-Harness/t/data/catme.1 Test data for Test::Harness cpan/Test-Harness/t/data/proverc Test data for Test::Harness cpan/Test-Harness/t/data/sample.yml Test data for Test::Harness -cpan/Test-Harness/t/env_opts.t +cpan/Test-Harness/t/env_opts.t Test file related to Test::Harness cpan/Test-Harness/t/errors.t Test::Harness test cpan/Test-Harness/t/file.t Test::Harness test cpan/Test-Harness/t/glob-to-regexp.t Test::Harness test @@ -2432,7 +2424,7 @@ cpan/Test-Harness/t/lib/MyResultFactory. cpan/Test-Harness/t/lib/MySourceHandler.pm Test::Harness test cpan/Test-Harness/t/lib/NoFork.pm Module for testing Test::Harness cpan/Test-Harness/t/lib/NOP.pm Module for testing Test::Harness -cpan/Test-Harness/t/lib/TAP/Harness/TestSubclass.pm +cpan/Test-Harness/t/lib/TAP/Harness/TestSubclass.pm Module related to Test::Harness cpan/Test-Harness/t/lib/TAP/Parser/SubclassTest.pm Module for testing Test::Harness cpan/Test-Harness/t/multiplexer.t Test::Harness test cpan/Test-Harness/t/nested.t Test::Harness test @@ -2452,7 +2444,7 @@ cpan/Test-Harness/t/proverun.t Test: cpan/Test-Harness/t/proveversion.t Test::Harness test cpan/Test-Harness/t/regression.t Test::Harness test cpan/Test-Harness/t/results.t Test::Harness test -cpan/Test-Harness/t/rulesfile.t +cpan/Test-Harness/t/rulesfile.t Test file related to Test::Harness cpan/Test-Harness/t/sample-tests/bailout Test data for Test::Harness cpan/Test-Harness/t/sample-tests/bignum Test data for Test::Harness cpan/Test-Harness/t/sample-tests/bignum_many Test data for Test::Harness @@ -2494,7 +2486,7 @@ cpan/Test-Harness/t/sample-tests/skipall cpan/Test-Harness/t/sample-tests/skipall_nomsg Test data for Test::Harness cpan/Test-Harness/t/sample-tests/skipall_v13 Test data for Test::Harness cpan/Test-Harness/t/sample-tests/space_after_plan Test data for Test::Harness -cpan/Test-Harness/t/sample-tests/space_after_plan_v13 +cpan/Test-Harness/t/sample-tests/space_after_plan_v13 Test::Harness cpan/Test-Harness/t/sample-tests/stdout_stderr Test data for Test::Harness cpan/Test-Harness/t/sample-tests/strict Test data for Test::Harness cpan/Test-Harness/t/sample-tests/switches Test data for Test::Harness @@ -2528,7 +2520,7 @@ cpan/Test-Harness/t/source_tests/source. cpan/Test-Harness/t/source_tests/source.t Test::Harness test cpan/Test-Harness/t/source_tests/source.tap Test::Harness test cpan/Test-Harness/t/source_tests/source_args.sh Test::Harness test -cpan/Test-Harness/t/source_tests/test.tap +cpan/Test-Harness/t/source_tests/test.tap Test file related to Test::Harness cpan/Test-Harness/t/spool.t Test::Harness test cpan/Test-Harness/t/state.t Test::Harness test cpan/Test-Harness/t/state_results.t Test::Harness test @@ -2823,6 +2815,7 @@ cpan/Test-Simple/t/Test2/behavior/Subtes cpan/Test-Simple/t/Test2/behavior/Subtest_todo.t Test file related to Test::Simple cpan/Test-Simple/t/Test2/behavior/Taint.t Test file related to Test::Simple cpan/Test-Simple/t/Test2/behavior/trace_signature.t Test file related to Test::Simple +cpan/Test-Simple/t/Test2/behavior/trace_stamps.t Test-Simple cpan/Test-Simple/t/Test2/behavior/uuid.t Test file related to Test::Simple cpan/Test-Simple/t/Test2/legacy/TAP.t Test file related to Test::Simple cpan/Test-Simple/t/Test2/modules/API.t Test file related to Test::Simple @@ -2877,6 +2870,259 @@ cpan/Test-Simple/t/Test2/regression/693_ cpan/Test-Simple/t/Test2/regression/746-forking-subtest.t Test file related to Test::Simple cpan/Test-Simple/t/Test2/regression/gh_16.t Test file related to Test::Simple cpan/Test-Simple/t/Test2/regression/ipc_files_abort_exit.t Test file related to Test::Simple +cpan/Test2-Suite/lib/Test2/AsyncSubtest.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/AsyncSubtest/Event/Attach.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/AsyncSubtest/Event/Detach.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/AsyncSubtest/Formatter.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/AsyncSubtest/Hub.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Bundle.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Bundle/Extended.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Bundle/More.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Bundle/Simple.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Array.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Bag.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Base.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Bool.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Custom.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/DeepRef.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Delta.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Event.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/EventMeta.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Float.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Hash.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Isa.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Meta.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Negatable.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Number.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Object.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/OrderedSubset.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Pattern.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Ref.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Regex.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Scalar.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Set.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/String.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Undef.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Compare/Wildcard.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Anatomy.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Anatomy/API.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Anatomy/Context.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Anatomy/EndToEnd.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Anatomy/Event.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Anatomy/Hubs.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Anatomy/IPC.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Anatomy/Utilities.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Concurrency.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Contributing.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Testing.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Testing/Introduction.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Testing/Migrating.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Testing/Planning.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Testing/Todo.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Tooling.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Tooling/FirstTool.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Tooling/Formatter.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Tooling/Nesting.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Tooling/Plugin/TestExit.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Tooling/Plugin/TestingDone.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Tooling/Plugin/ToolCompletes.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Tooling/Plugin/ToolStarts.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Tooling/Subtest.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Tooling/TestBuilder.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Manual/Tooling/Testing.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Mock.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Plugin.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Plugin/BailOnFail.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Plugin/DieOnFail.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Plugin/ExitSummary.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Plugin/SRand.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Plugin/Times.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Plugin/UTF8.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Require.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Require/AuthorTesting.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Require/AutomatedTesting.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Require/EnvVar.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Require/ExtendedTesting.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Require/Fork.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Require/Module.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Require/NonInteractiveTesting.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Require/Perl.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Require/RealFork.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Require/ReleaseTesting.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Require/Threads.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Suite.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Todo.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/AsyncSubtest.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Basic.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Class.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/ClassicCompare.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Compare.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Defer.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Encoding.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Event.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Exception.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Exports.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/GenTemp.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Grab.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Mock.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Ref.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Refcount.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Spec.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Subtest.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Target.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Tester.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Tools/Warnings.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Util/Grabber.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Util/Guard.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Util/Importer.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Util/Ref.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Util/Stash.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Util/Sub.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Util/Table.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Util/Table/Cell.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Util/Table/LineBreak.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Util/Term.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Util/Times.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/V0.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Workflow.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Workflow/BlockBase.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Workflow/Build.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Workflow/Runner.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Workflow/Task.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Workflow/Task/Action.pm Test2-Suite +cpan/Test2-Suite/lib/Test2/Workflow/Task/Group.pm Test2-Suite +cpan/Test2-Suite/t/acceptance/OO.t Test2-Suite +cpan/Test2-Suite/t/acceptance/skip.t Test2-Suite +cpan/Test2-Suite/t/acceptance/spec.t Test2-Suite +cpan/Test2-Suite/t/acceptance/Tools.t Test2-Suite +cpan/Test2-Suite/t/acceptance/Workflow-Acceptance2.t Test2-Suite +cpan/Test2-Suite/t/acceptance/Workflow-Acceptance3.t Test2-Suite +cpan/Test2-Suite/t/acceptance/Workflow-Acceptance4.t Test2-Suite +cpan/Test2-Suite/t/acceptance/Workflow-Acceptance5.t Test2-Suite +cpan/Test2-Suite/t/behavior/async_trace.t Test2-Suite +cpan/Test2-Suite/t/behavior/filtering.t Test2-Suite +cpan/Test2-Suite/t/behavior/Mocking.t Test2-Suite +cpan/Test2-Suite/t/behavior/no_done_testing.t Test2-Suite +cpan/Test2-Suite/t/behavior/no_leaks_any.t Test2-Suite +cpan/Test2-Suite/t/behavior/no_leaks_no_fork.t Test2-Suite +cpan/Test2-Suite/t/behavior/no_leaks_no_iso.t Test2-Suite +cpan/Test2-Suite/t/behavior/no_leaks_no_threads.t Test2-Suite +cpan/Test2-Suite/t/behavior/simple.t Test2-Suite +cpan/Test2-Suite/t/lib/MyTest/Target.pm Test2-Suite +cpan/Test2-Suite/t/load_manual.t Test2-Suite +cpan/Test2-Suite/t/modules/AsyncSubtest.t Test2-Suite +cpan/Test2-Suite/t/modules/AsyncSubtest/Event/Attach.t Test2-Suite +cpan/Test2-Suite/t/modules/AsyncSubtest/Event/Detach.t Test2-Suite +cpan/Test2-Suite/t/modules/AsyncSubtest/Hub.t Test2-Suite +cpan/Test2-Suite/t/modules/Bundle.t Test2-Suite +cpan/Test2-Suite/t/modules/Bundle/Extended.t Test2-Suite +cpan/Test2-Suite/t/modules/Bundle/More.t Test2-Suite +cpan/Test2-Suite/t/modules/Bundle/Simple.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Array.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Bag.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Base.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Bool.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Custom.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Delta.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Event.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/EventMeta.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Float.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Hash.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Isa.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Meta.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Number.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Object.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/OrderedSubset.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Pattern.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Ref.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Regex.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Scalar.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Set.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/String.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Undef.t Test2-Suite +cpan/Test2-Suite/t/modules/Compare/Wildcard.t Test2-Suite +cpan/Test2-Suite/t/modules/Mock.t Test2-Suite +cpan/Test2-Suite/t/modules/Plugin.t Test2-Suite +cpan/Test2-Suite/t/modules/Plugin/BailOnFail.t Test2-Suite +cpan/Test2-Suite/t/modules/Plugin/DieOnFail.t Test2-Suite +cpan/Test2-Suite/t/modules/Plugin/ExitSummary.t Test2-Suite +cpan/Test2-Suite/t/modules/Plugin/SRand.t Test2-Suite +cpan/Test2-Suite/t/modules/Plugin/Times.t Test2-Suite +cpan/Test2-Suite/t/modules/Plugin/UTF8.t Test2-Suite +cpan/Test2-Suite/t/modules/Require.t Test2-Suite +cpan/Test2-Suite/t/modules/Require/AuthorTesting.t Test2-Suite +cpan/Test2-Suite/t/modules/Require/AutomatedTesting.t Test2-Suite +cpan/Test2-Suite/t/modules/Require/EnvVar.t Test2-Suite +cpan/Test2-Suite/t/modules/Require/ExtendedTesting.t Test2-Suite +cpan/Test2-Suite/t/modules/Require/Fork.t Test2-Suite +cpan/Test2-Suite/t/modules/Require/Module.t Test2-Suite +cpan/Test2-Suite/t/modules/Require/NonInteractiveTesting.t Test2-Suite +cpan/Test2-Suite/t/modules/Require/Perl.t Test2-Suite +cpan/Test2-Suite/t/modules/Require/RealFork.t Test2-Suite +cpan/Test2-Suite/t/modules/Require/ReleaseTesting.t Test2-Suite +cpan/Test2-Suite/t/modules/Require/Threads.t Test2-Suite +cpan/Test2-Suite/t/modules/Suite.t Test2-Suite +cpan/Test2-Suite/t/modules/Todo.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/AsyncSubtest.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Basic.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Class.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/ClassicCompare.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/ClassicCompare2.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Compare.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Defer.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Encoding.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Event.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Exception.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Exports.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/GenTemp.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Grab.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Mock.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Ref.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Spec.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Subtest.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Target.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Test-Refcount/01count.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Test-Refcount/02one.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Test-Refcount/03weak.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Test-Refcount/04reftypes.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Tester.t Test2-Suite +cpan/Test2-Suite/t/modules/Tools/Warnings.t Test2-Suite +cpan/Test2-Suite/t/modules/Util/Grabber.t Test2-Suite +cpan/Test2-Suite/t/modules/Util/Ref.t Test2-Suite +cpan/Test2-Suite/t/modules/Util/Stash.t Test2-Suite +cpan/Test2-Suite/t/modules/Util/Sub.t Test2-Suite +cpan/Test2-Suite/t/modules/Util/Table.t Test2-Suite +cpan/Test2-Suite/t/modules/Util/Table/Cell.t Test2-Suite +cpan/Test2-Suite/t/modules/Util/Table/LineBreak.t Test2-Suite +cpan/Test2-Suite/t/modules/Util/Times.t Test2-Suite +cpan/Test2-Suite/t/modules/V0.t Test2-Suite +cpan/Test2-Suite/t/modules/Workflow.t Test2-Suite +cpan/Test2-Suite/t/modules/Workflow/BlockBase.t Test2-Suite +cpan/Test2-Suite/t/modules/Workflow/Build.t Test2-Suite +cpan/Test2-Suite/t/modules/Workflow/Runner.t Test2-Suite +cpan/Test2-Suite/t/modules/Workflow/Task.t Test2-Suite +cpan/Test2-Suite/t/modules/Workflow/Task/Action.t Test2-Suite +cpan/Test2-Suite/t/modules/Workflow/Task/Group.t Test2-Suite +cpan/Test2-Suite/t/regression/10-set_and_dne.t Test2-Suite +cpan/Test2-Suite/t/regression/132-bool.t Test2-Suite +cpan/Test2-Suite/t/regression/247_check_ref_bool.t Test2-Suite +cpan/Test2-Suite/t/regression/27-1-Test2-Bundle-More.t Test2-Suite +cpan/Test2-Suite/t/regression/27-2-Test2-Tools-Compare.t Test2-Suite +cpan/Test2-Suite/t/regression/27-3-Test2-Tools-ClassicCompare.t Test2-Suite +cpan/Test2-Suite/t/regression/285-wrap-nonexisting.t Test2-Suite +cpan/Test2-Suite/t/regression/289-compare-array-bounds.t Test2-Suite +cpan/Test2-Suite/t/regression/291-async-subtest-done-testing.t Test2-Suite +cpan/Test2-Suite/t/regression/43-bag-on-empty.t Test2-Suite +cpan/Test2-Suite/t/regression/async_subtest_missing_parent.t Test2-Suite +cpan/Test2-Suite/t/regression/Test2-Mock.t Test2-Suite +cpan/Test2-Suite/t/regression/Test2-Tools-Class.t Test2-Suite +cpan/Test2-Suite/t/regression/todo_and_facets.t Test2-Suite +cpan/Test2-Suite/t/regression/utf8-mock.t Test2-Suite cpan/Text-Balanced/lib/Text/Balanced.pm Text::Balanced cpan/Text-Balanced/t/01_compile.t See if Text::Balanced works cpan/Text-Balanced/t/02_extbrk.t See if Text::Balanced works @@ -2897,21 +3143,24 @@ cpan/Text-ParseWords/t/ParseWords.t See cpan/Text-ParseWords/t/taint.t See if Text::ParseWords works with tainting cpan/Text-Tabs/lib/Text/Tabs.pm Do expand and unexpand cpan/Text-Tabs/lib/Text/Wrap.pm Paragraph formatter +cpan/Text-Tabs/t/124024.t See if Text::Tabs is working +cpan/Text-Tabs/t/148291.t See if Text::Tabs is working cpan/Text-Tabs/t/37000.t See if Text::Tabs is working cpan/Text-Tabs/t/39548.t See if Text::Tabs is working cpan/Text-Tabs/t/79766.t See if Text::Tabs is working +cpan/Text-Tabs/t/95823.t See if Text::Tabs is working cpan/Text-Tabs/t/belg4mit.t See if Text::Tabs is working cpan/Text-Tabs/t/dandv.t See if Text::Tabs is working cpan/Text-Tabs/t/fill.t See if Text::Wrap::fill works cpan/Text-Tabs/t/Jacobson.t See if Text::Tabs is working cpan/Text-Tabs/t/Jacobson2.t See if Text::Tabs is working cpan/Text-Tabs/t/Jochen.t See if Text::Tabs is working -cpan/Text-Tabs/t/lib/ok.pl +cpan/Text-Tabs/t/lib/ok.pl Script related to Text-Tabs+Wrap cpan/Text-Tabs/t/sep.t See if Text::Tabs is working cpan/Text-Tabs/t/sep2.t See if Text::Tabs is working cpan/Text-Tabs/t/tabs.t See if Text::Tabs works cpan/Text-Tabs/t/Tabs-ElCid.t See if Text::Tabs works -cpan/Text-Tabs/t/undef.t +cpan/Text-Tabs/t/undef.t Test file related to Text-Tabs+Wrap cpan/Text-Tabs/t/wrap.t See if Text::Wrap::wrap works cpan/Text-Tabs/t/Wrap-JLB.t See if Text::Wrap::wrap works cpan/Text-Tabs/t/wrap_separator2.t See if Text::Wrap::wrap works @@ -4067,6 +4316,7 @@ dist/IO/t/io_dup.t See if dup()-relate dist/IO/t/io_file.t See if binmode()-related methods on IO::File work dist/IO/t/io_file_export.t Test IO::File exports dist/IO/t/io_getline.t Test getline and getlines +dist/IO/t/io_handle.t Test non-XS IO::Handle methods available dist/IO/t/io_leak.t See if IO leaks SVs (only run in core) dist/IO/t/io_linenum.t See if I/O line numbers are tracked correctly dist/IO/t/io_multihomed.t See if INET sockets work with multi-homed hosts @@ -4200,6 +4450,7 @@ dist/Safe/t/safenamedcap.t Tests that T dist/Safe/t/safeops.t Tests that all ops can be trapped by Safe dist/Safe/t/saferegexp.t Tests Safe with regular expressions dist/Safe/t/safesecurity.t Tests misc. security fixes in Safe +dist/Safe/t/safesig.t Tests %SIG being cleared and restored dist/Safe/t/safesort.t Tests Safe with sort dist/Safe/t/safeuniversal.t Tests Safe with functions from universal.c dist/Safe/t/safeutf8.t Tests Safe with utf8.pm @@ -4675,10 +4926,7 @@ ext/PerlIO-encoding/t/nolooping.t Tests ext/PerlIO-encoding/t/threads.t Tests PerlIO::encoding and threads ext/PerlIO-mmap/mmap.pm PerlIO layer for memory maps ext/PerlIO-mmap/mmap.xs PerlIO layer for memory maps -ext/PerlIO-scalar/scalar.pm PerlIO layer for scalars -ext/PerlIO-scalar/scalar.xs PerlIO layer for scalars -ext/PerlIO-scalar/t/scalar.t See if PerlIO::scalar works -ext/PerlIO-scalar/t/scalar_ungetc.t Tests for PerlIO layer for scalars +ext/PerlIO-scalar/scalar.pm PerlIO layer for in-memory handles ext/PerlIO-via/hints/aix.pl Hint for PerlIO::via for named architecture ext/PerlIO-via/t/thread.t See if PerlIO::via works with threads ext/PerlIO-via/t/via.t See if PerlIO::via works @@ -4926,6 +5174,7 @@ ext/XS-APItest/t/ptr_table.t Test ptr_ ext/XS-APItest/t/push.t XS::APItest extension ext/XS-APItest/t/refs.t Test typemap ref handling ext/XS-APItest/t/rmagical.t XS::APItest extension +ext/XS-APItest/t/rpp_invoke_xs.t XS::APItest: test rpp_invoke_xs() ext/XS-APItest/t/rv2cv_op_cv.t test rv2cv_op_cv() API ext/XS-APItest/t/savehints.t test SAVEHINTS() API ext/XS-APItest/t/savestack.t test savestack behavior, currently only in the regex engine @@ -4972,6 +5221,7 @@ ext/XS-APItest/t/whichsig.t XS::APItes ext/XS-APItest/t/win32.t Test Win32 specific APIs ext/XS-APItest/t/xs_special_subs.t Test that XS BEGIN/CHECK/INIT/END work ext/XS-APItest/t/xs_special_subs_require.t for require too +ext/XS-APItest/t/xsppwrap.t Tests for XSPP_wrapped() macro ext/XS-APItest/t/xsub_h.t Tests for XSUB.h ext/XS-APItest/typemap ext/XS-APItest/XSUB-redefined-macros.xs XS code needing redefined macros. @@ -5065,6 +5315,7 @@ hints/sco_2_3_1.sh Hints for named arc hints/sco_2_3_2.sh Hints for named architecture hints/sco_2_3_3.sh Hints for named architecture hints/sco_2_3_4.sh Hints for named architecture +hints/serenity.sh Hints for named architecture hints/solaris_2.sh Hints for named architecture hints/stellar.sh Hints for named architecture hints/sunos_4_0.sh Hints for named architecture @@ -5094,9 +5345,9 @@ lib/blib.pm For "use blib" lib/blib.t blib.pm test lib/builtin.pm builtin function namespace lib/builtin.t test builtin function namespace +lib/builtin-taint.t test builtin function namespace in taint mode lib/bytes.pm Pragma to enable byte operations lib/bytes.t bytes.pm test -lib/bytes_heavy.pl Support routines for byte pragma lib/charnames.pm Character names lib/charnames.t See if character names work lib/Class/Struct.pm Declare struct-like datatypes as Perl classes @@ -5196,6 +5447,7 @@ lib/perl5db/t/filename-line-breakpoint lib/perl5db/t/gh-17660 Tests for the Perl debugger lib/perl5db/t/gh-17661 Tests for the Perl debugger lib/perl5db/t/gh-17661b Tests for the Perl debugger +lib/perl5db/t/gh-21350 Tests for the Perl debugger lib/perl5db/t/load-modules Tests for the Perl debugger lib/perl5db/t/lsub-n Test script used by perl5db.t lib/perl5db/t/lvalue-bug Tests for the Perl debugger @@ -6035,6 +6287,8 @@ pod/perl5362delta.pod Perl changes in pod/perl5363delta.pod Perl changes in version 5.36.3 pod/perl5380delta.pod Perl changes in version 5.38.0 pod/perl5381delta.pod Perl changes in version 5.38.1 +pod/perl5382delta.pod Perl changes in version 5.38.2 +pod/perl5400delta.pod Perl changes in version 5.40.0 pod/perl561delta.pod Perl changes in version 5.6.1 pod/perl56delta.pod Perl changes in version 5.6 pod/perl581delta.pod Perl changes in version 5.8.1 @@ -6056,7 +6310,7 @@ pod/perlcall.pod Perl calling conventi pod/perlcheat.pod Perl cheat sheet pod/perlclass.pod Perl class syntax pod/perlclassguts.pod Internals of class syntax -pod/perlclib.pod Internal replacements for standard C library functions +pod/perlclib.pod Interacting with standard C library functions pod/perlcommunity.pod Perl community information pod/perldata.pod Perl data structures pod/perldbmfilter.pod Perl DBM filters @@ -6100,7 +6354,7 @@ pod/perlnewmod.pod Perl modules: prepa pod/perlnumber.pod Perl number semantics pod/perlobj.pod Perl objects pod/perlootut.pod Perl OO tutorial for beginners -pod/perlop.pod Perl operators and precedence +pod/perlop.pod Perl expressions: operators, precedence, string literals pod/perlopentut.pod Perl open() tutorial pod/perlpacktut.pod Perl pack() and unpack() tutorial pod/perlperf.pod Perl Performance and Optimization Techniques @@ -6127,7 +6381,7 @@ pod/perlsecpolicy.pod Perl security re pod/perlsource.pod Guide to the Perl source tree pod/perlstyle.pod Perl style guide pod/perlsub.pod Perl subroutines -pod/perlsyn.pod Perl syntax +pod/perlsyn.pod Perl syntax: declarations, statements, comments pod/perlthrtut.pod Perl threads tutorial pod/perltie.pod Perl objects hidden behind simple variables pod/perltodo.pod @@ -6237,6 +6491,7 @@ regen/genpacksizetables.pl Generate the regen/HeaderParser.pm Module used to parse header files regen/keywords.pl Program to write keywords.h regen/lib_cleanup.pl Generate lib/.gitignore from MANIFEST +regen/locale.pl Program to write locale_table.h regen/mg_vtable.pl generate mg_vtable.h regen/miniperlmain.pl generate miniperlmain.c regen/mk_invlists.pl Generates charclass_invlists.h @@ -6253,7 +6508,6 @@ regen/regcomp.pl Builder of regnodes.h regen/regen_lib.pl Common file routines for generator scripts regen/scope_types.pl Regenerate scope_types.h regen/tidy_embed.pl Program to clean up embed.fnc manually -regen/uconfig_h.pl generate uconfig.h (requires /bin/sh) regen/unicode_constants.pl generate unicode_constants.h regen/warnings.pl Program to write warnings.h and lib/warnings.pm t/base/cond.t See if conditionals work @@ -6271,9 +6525,14 @@ t/bigmem/index.t Check that index() ha t/bigmem/pos.t Check that pos() handles large offsets t/bigmem/read.t Check read() handles large offsets t/bigmem/regexp.t Test regular expressions with large strings +t/bigmem/stack.t Check handling of large value stacks (including MARK values) +t/bigmem/stack_over.t Check handling of stack overflows with 32-bit MARK on 64-bit systems +t/bigmem/str.t Test string primitives with large strings t/bigmem/subst.t Test s/// with large strings +t/bigmem/subst2.t Test s//EXPR/e with large strings t/bigmem/vec.t Check vec() handles large offsets t/charset_tools.pl To aid in portable testing across platforms with different character sets +t/class/accessor.t See if accessor methods work t/class/class.t See if class declarations work t/class/construct.t See if class constructors work t/class/destruct.t See if class destruction works @@ -6282,6 +6541,7 @@ t/class/inherit.t See if class inherit t/class/method.t See if class method declarations work t/class/phasers.t See if class phaser blocks work t/class/threads.t See if classes work across multiple threads +t/class/utf8.t See if class syntax works with non-ASCII UTF-8 t/cmd/elsif.t See if else-if works t/cmd/for.t See if for loops work t/cmd/mod.t See if statement modifiers work @@ -6349,6 +6609,8 @@ t/io/print.t See if print commands wo t/io/pvbm.t See if PVBMs break IO commands t/io/read.t See if read works t/io/say.t See if say works +t/io/scalar.t See if PerlIO::scalar works +t/io/scalar_ungetc.t Tests for PerlIO layer for scalars t/io/sem.t See if SysV semaphores work t/io/semctl.t See if SysV semaphore semctl works t/io/shm.t See if SysV shared memory works @@ -6367,6 +6629,8 @@ t/lib/caller/Foo.pm test Module for ca t/lib/caller/Tricycle.pm test Module for t/op/hook/require.t (cyclic) t/lib/CannotParse.pm For test case in op/require_errors.t t/lib/charnames/alias Tests of "use charnames" with aliases. +t/lib/class/A.pm Test class loading of hierarchical parent +t/lib/class/A/B.pm Test class loading of hierarchical parent t/lib/Cname.pm Test charnames in regexes (op/pat.t) t/lib/common.pl Helper for lib/{warnings,feature}.t t/lib/commonsense.t See if configuration meets basic needs @@ -6376,6 +6640,7 @@ t/lib/croak/class Test croak calls fro t/lib/croak/gv Test croak calls from gv.c t/lib/croak/mg Test croak calls from mg.c t/lib/croak/op Test croak calls from op.c +t/lib/croak/parser Test parser errors t/lib/croak/pp Test croak calls from pp.c t/lib/croak/pp_ctl Test croak calls from pp_ctl.c t/lib/croak/pp_hot Test croak calls from pp_hot.c @@ -6419,6 +6684,7 @@ t/lib/strict/refs Tests of "use strict t/lib/strict/subs Tests of "use strict 'subs'" for strict.t t/lib/strict/vars Tests of "use strict 'vars'" for strict.t t/lib/subs/subs Tests of "use subs" +t/lib/test_22121.pm A test file for t/lib/warnings/op t/lib/test_require.pm A test file for t/op/inccode.t t/lib/test_use.pm A test pragma for t/comp/use.t t/lib/test_use_14937.pm A test pragma for t/comp/use.t @@ -6684,6 +6950,7 @@ t/op/readdir.t See if readdir() works t/op/readline.t See if <> / readline / rcatline work t/op/recurse.t See if deep recursion works t/op/ref.t See if refs and objects work +t/op/refstack.t See if a ref counted stack fixes things t/op/repeat.t See if x operator works t/op/require_37033.t See if require always closes rsfp t/op/require_errors.t See if errors from require are reported correctly @@ -6804,6 +7071,7 @@ t/porting/header_parser.t Check that re t/porting/known_pod_issues.dat Data file for porting/podcheck.t t/porting/libperl.t Check libperl.a sanity t/porting/maintainers.t Test that Porting/Maintainers.pl is up to date +t/porting/makerel.t Test that files used by Porting/makerel exist t/porting/manifest.t Test that this MANIFEST file is well formed t/porting/perlfunc.t Test that Functions_pm.PL can parse perlfunc.pod t/porting/pod_rules.t Check that various pod lists are consistent @@ -7033,6 +7301,7 @@ win32/config_H.gc Win32 config header win32/config_h.PL Perl code to convert Win32 config.sh to config.h win32/config_H.vc Win32 config header (Visual C++ build) win32/config_sh.PL Perl code to update Win32 config.sh from Makefile +win32/configure/rt.c identify default runtime win32/create_perllibst_h.pl creates perllibst.h file for inclusion from perllib.c win32/distclean.bat Remove _ALL_ files not listed here in MANIFEST win32/fcrypt.c crypt() implementation Index: gnu/usr.bin/perl/META.json =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/META.json,v diff -u -p -a -u -p -r1.15 META.json --- gnu/usr.bin/perl/META.json 14 May 2024 19:38:53 -0000 1.15 +++ gnu/usr.bin/perl/META.json 22 Jan 2025 00:37:42 -0000 @@ -74,7 +74,6 @@ "ext/ODBM_File/t", "ext/Opcode/t", "ext/PerlIO-encoding/t", - "ext/PerlIO-scalar/t", "ext/PerlIO-via/t", "ext/Pod-Functions/t", "ext/Pod-Html/t", @@ -119,6 +118,6 @@ "url" : "https://github.com/Perl/perl5" } }, - "version" : "5.038002", + "version" : "5.040001", "x_serialization_backend" : "JSON::PP version 4.16" } Index: gnu/usr.bin/perl/META.yml =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/META.yml,v diff -u -p -a -u -p -r1.15 META.yml --- gnu/usr.bin/perl/META.yml 14 May 2024 19:38:53 -0000 1.15 +++ gnu/usr.bin/perl/META.yml 22 Jan 2025 00:37:42 -0000 @@ -72,7 +72,6 @@ no_index: - ext/ODBM_File/t - ext/Opcode/t - ext/PerlIO-encoding/t - - ext/PerlIO-scalar/t - ext/PerlIO-via/t - ext/Pod-Functions/t - ext/Pod-Html/t @@ -106,5 +105,5 @@ resources: homepage: https://www.perl.org/ license: https://dev.perl.org/licenses/ repository: https://github.com/Perl/perl5 -version: '5.038002' +version: '5.040001' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Index: gnu/usr.bin/perl/Makefile.SH =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Makefile.SH,v diff -u -p -a -u -p -r1.65 Makefile.SH --- gnu/usr.bin/perl/Makefile.SH 14 May 2024 19:40:17 -0000 1.65 +++ gnu/usr.bin/perl/Makefile.SH 22 Jan 2025 00:37:42 -0000 @@ -529,21 +529,24 @@ unidatafiles = lib/unicore/Decomposition # Directories of Unicode data files generated by mktables unidatadirs = lib/unicore/To lib/unicore/lib -h1 = EXTERN.h INTERN.h XSUB.h av.h $(CONFIGH) cop.h cv.h dosish.h -h2 = embed.h form.h gv.h handy.h hv.h hv_func.h keywords.h mg.h op.h opcode.h -h3 = pad.h patchlevel.h perl.h perlapi.h perly.h pp.h proto.h regcomp.h regcomp_internal.h -h4 = regexp.h scope.h sv.h unixish.h util.h iperlsys.h thread.h -h5 = utf8.h warnings.h mydtrace.h op_reg_common.h l1_char_class_tab.h -h6 = charclass_invlists.h -h = $(h1) $(h2) $(h3) $(h4) $(h5) $(h6) - -c1 = av.c scope.c op.c peep.c doop.c doio.c dump.c gv.c hv.c mg.c reentr.c mro_core.c perl.c -c2 = perly.c pp.c pp_hot.c pp_ctl.c pp_sys.c utf8.c sv.c -c3 = taint.c toke.c util.c deb.c run.c builtin.c universal.c class.c pad.c globals.c keywords.c -c4 = perlio.c numeric.c mathoms.c locale.c pp_pack.c pp_sort.c caretx.c dquote.c time64.c -c5 = regcomp.c regcomp_debug.c regcomp_invlist.c regcomp_study.c regcomp_trie.c regexec.c -c5 = $(mallocsrc) syscall_emulator.c -c_base = $(c1) $(c2) $(c3) $(c4) $(c5) $(c6) +h = \ + EXTERN.h INTERN.h XSUB.h \ + av.h charclass_invlists.h cop.h cv.h dosish.h embed.h form.h gv.h \ + handy.h hv.h hv_func.h iperlsys.h keywords.h l1_char_class_tab.h \ + mg.h mydtrace.h op.h op_reg_common.h opcode.h pad.h patchlevel.h \ + perl.h perlapi.h perly.h pp.h proto.h regcomp.h regcomp_internal.h \ + regexp.h scope.h sv.h thread.h unixish.h utf8.h util.h warnings.h \ + $(CONFIGH) + +c_base = \ + av.c builtin.c caretx.c class.c deb.c doio.c doop.c dquote.c dump.c \ + globals.c gv.c hv.c keywords.c locale.c mathoms.c mg.c mro_core.c \ + numeric.c op.c pad.c peep.c perl.c perlio.c perly.c \ + pp.c pp_ctl.c pp_hot.c pp_pack.c pp_sort.c pp_sys.c \ + reentr.c regcomp.c regcomp_debug.c regcomp_invlist.c regcomp_study.c \ + regcomp_trie.c regexec.c run.c scope.c sv.c taint.c time64.c toke.c \ + universal.c utf8.c util.c syscall_emulator.c \ + $(mallocsrc) !NO!SUBS! @@ -557,22 +560,24 @@ $spitshell >>$Makefile <<'!NO!SUBS!' c = $(c_base) miniperlmain.c $(mini_only_src) -obj1 = $(mallocobj) gv$(OBJ_EXT) toke$(OBJ_EXT) perly$(OBJ_EXT) pad$(OBJ_EXT) -obj2 = regcomp$(OBJ_EXT) regcomp_debug$(OBJ_EXT) regcomp_invlist$(OBJ_EXT) regcomp_study$(OBJ_EXT) regcomp_trie$(OBJ_EXT) -obj3 = regexec$(OBJ_EXT) dump$(OBJ_EXT) util$(OBJ_EXT) mg$(OBJ_EXT) reentr$(OBJ_EXT) mro_core$(OBJ_EXT) -obj4 = keywords$(OBJ_EXT) builtin$(OBJ_EXT) class$(OBJ_EXT) -obj5 = hv$(OBJ_EXT) av$(OBJ_EXT) run$(OBJ_EXT) pp_hot$(OBJ_EXT) sv$(OBJ_EXT) pp$(OBJ_EXT) -obj6 = scope$(OBJ_EXT) pp_ctl$(OBJ_EXT) pp_sys$(OBJ_EXT) peep$(OBJ_EXT) -obj7 = doop$(OBJ_EXT) doio$(OBJ_EXT) utf8$(OBJ_EXT) taint$(OBJ_EXT) -obj8 = deb$(OBJ_EXT) globals$(OBJ_EXT) perlio$(OBJ_EXT) numeric$(OBJ_EXT) mathoms$(OBJ_EXT) -obj9 = locale$(OBJ_EXT) pp_pack$(OBJ_EXT) pp_sort$(OBJ_EXT) caretx$(OBJ_EXT) dquote$(OBJ_EXT) -obj10 = time64$(OBJ_EXT) syscall_emulator$(OBJ_EXT) - # split the objects into 3 exclusive sets: those used by both miniperl and # perl, and those used by just one or the other. Doesn't include the # actual perl(mini)main.o, nor any dtrace objects. -common_objs = $(obj1) $(obj2) $(obj3) $(obj4) $(obj5) $(obj6) $(obj7) $(obj8) $(obj9) $(obj10) $(ARCHOBJS) +common_objs = \ + av$(OBJ_EXT) builtin$(OBJ_EXT) caretx$(OBJ_EXT) class$(OBJ_EXT) \ + deb$(OBJ_EXT) doio$(OBJ_EXT) doop$(OBJ_EXT) dquote$(OBJ_EXT) \ + dump$(OBJ_EXT) globals$(OBJ_EXT) gv$(OBJ_EXT) hv$(OBJ_EXT) \ + keywords$(OBJ_EXT) locale$(OBJ_EXT) mathoms$(OBJ_EXT) mg$(OBJ_EXT) \ + mro_core$(OBJ_EXT) numeric$(OBJ_EXT) pad$(OBJ_EXT) peep$(OBJ_EXT) \ + perlio$(OBJ_EXT) perly$(OBJ_EXT) pp$(OBJ_EXT) pp_ctl$(OBJ_EXT) \ + pp_hot$(OBJ_EXT) pp_pack$(OBJ_EXT) pp_sort$(OBJ_EXT) pp_sys$(OBJ_EXT) \ + reentr$(OBJ_EXT) regcomp$(OBJ_EXT) regcomp_debug$(OBJ_EXT) \ + regcomp_invlist$(OBJ_EXT) regcomp_study$(OBJ_EXT) regcomp_trie$(OBJ_EXT) \ + regexec$(OBJ_EXT) run$(OBJ_EXT) scope$(OBJ_EXT) sv$(OBJ_EXT) \ + taint$(OBJ_EXT) time64$(OBJ_EXT) toke$(OBJ_EXT) utf8$(OBJ_EXT) \ + util$(OBJ_EXT) syscall_emulator$(OBJ_EXT) \ + $(mallocobj) $(ARCHOBJS) miniperl_objs_nodt = $(mini_only_objs) $(common_objs) miniperlmain$(OBJ_EXT) perllib_objs_nodt = $(main_only_objs) $(common_objs) @@ -623,7 +628,7 @@ esac $spitshell >>$Makefile <<'!NO!SUBS!' -perltoc_pod_prereqs = extra.pods pod/perl5382delta.pod pod/perlapi.pod pod/perlintern.pod pod/perlmodlib.pod +perltoc_pod_prereqs = extra.pods pod/perl5401delta.pod pod/perlapi.pod pod/perlintern.pod pod/perlmodlib.pod generated_pods = pod/perltoc.pod $(perltoc_pod_prereqs) generated_headers = uudmap.h bitcount.h mg_data.h @@ -1074,14 +1079,6 @@ $(PERL_EXE): $& $(perlmain_dep) $(LIBPER $spitshell >>$Makefile <<'!NO!SUBS!' -# Microperl. This is just a convenience thing if one happens to -# build also the full Perl and therefore the real big Makefile: -# usually one should manually explicitly issue the below command. - -.PHONY: microperl -microperl: - $(MAKE) -f Makefile.micro - !NO!SUBS! fi @@ -1138,9 +1135,9 @@ pod/perlintern.pod: $(MINIPERL_EXE) auto pod/perlmodlib.pod: $(MINIPERL_EXE) pod/perlmodlib.PL MANIFEST $(MINIPERL) pod/perlmodlib.PL -q -pod/perl5382delta.pod: pod/perldelta.pod - $(RMS) pod/perl5382delta.pod - $(LNS) perldelta.pod pod/perl5382delta.pod +pod/perl5401delta.pod: pod/perldelta.pod + $(RMS) pod/perl5401delta.pod + $(LNS) perldelta.pod pod/perl5401delta.pod extra.pods: $(MINIPERL_EXE) -@test ! -f extra.pods || rm -f `cat extra.pods` @@ -1264,6 +1261,7 @@ CHMOD_W = chmod +w # regcomp.pl: regnodes.h # warnings.pl: warnings.h lib/warnings.pm # feature.pl: feature.h lib/feature.pm +# locale.pl: locale_table.h # The correct versions should be already supplied with the perl kit, # in case you don't have perl available. # To force them to be regenerated, run @@ -1275,11 +1273,9 @@ CHMOD_W = chmod +w regen: FORCE -perl regen.pl - -perl regen/uconfig_h.pl regen_headers regen-headers: FORCE -perl regen.pl -v - -perl regen/uconfig_h.pl -v regen_meta regen-meta: META.yml META.json @@ -1369,7 +1365,7 @@ _mopup: -rm -f perl.export perl.dll perl.libexp perl.map perl.def -rm -f *perl.xok -rm -f cygwin.c libperl*.def libperl*.dll cygperl*.dll *.exe.stackdump - -rm -f $(PERL_EXE) $(MINIPERL_EXE) $(LIBPERL) libperl.* microperl + -rm -f $(PERL_EXE) $(MINIPERL_EXE) $(LIBPERL) libperl.* -rm -f $(DTRACE_H) _cleaner1: @@ -1421,44 +1417,51 @@ _cleaner2: -rmdir lib/autodie/exception lib/autodie/Scope lib/autodie lib/XS -rmdir lib/Win32API lib/VMS lib/Unicode/Collate/Locale -rmdir lib/Unicode/Collate/CJK lib/Unicode/Collate lib/Tie/Hash - -rmdir lib/Thread lib/Text lib/Test2/Util lib/Test2/Tools - -rmdir lib/Test2/IPC/Driver lib/Test2/IPC lib/Test2/Hub/Interceptor - -rmdir lib/Test2/Hub lib/Test2/Formatter lib/Test2/EventFacet/Info - -rmdir lib/Test2/EventFacet lib/Test2/Event/TAP lib/Test2/Event - -rmdir lib/Test2/API/InterceptResult lib/Test2/API lib/Test2 - -rmdir lib/Test/use lib/Test/Tester lib/Test/Builder/Tester - -rmdir lib/Test/Builder/IO lib/Test/Builder lib/Test lib/Term - -rmdir lib/TAP/Parser/YAMLish lib/TAP/Parser/SourceHandler - -rmdir lib/TAP/Parser/Scheduler lib/TAP/Parser/Result - -rmdir lib/TAP/Parser/Iterator lib/TAP/Parser lib/TAP/Harness - -rmdir lib/TAP/Formatter/File lib/TAP/Formatter/Console - -rmdir lib/TAP/Formatter lib/TAP lib/Sys/Syslog lib/Sys lib/Sub - -rmdir lib/Search lib/Scalar lib/Pod/Text lib/Pod/Simple - -rmdir lib/Pod/Perldoc lib/Pod/Html lib/PerlIO/via lib/PerlIO lib/Perl - -rmdir lib/Parse/CPAN lib/Parse lib/Params lib/OpenBSD lib/Net/FTP - -rmdir lib/Module/Load lib/Module/CoreList lib/Module lib/Memoize - -rmdir lib/Math/BigRat lib/Math/BigInt lib/Math/BigFloat lib/Math - -rmdir lib/MIME lib/Locale/Maketext lib/Locale lib/List/Util lib/List + -rmdir lib/Thread lib/Text lib/Test2/Workflow/Task lib/Test2/Workflow + -rmdir lib/Test2/Util/Table lib/Test2/Util lib/Test2/Tools + -rmdir lib/Test2/Require lib/Test2/Plugin + -rmdir lib/Test2/Manual/Tooling/Plugin lib/Test2/Manual/Tooling + -rmdir lib/Test2/Manual/Testing lib/Test2/Manual/Anatomy + -rmdir lib/Test2/Manual lib/Test2/IPC/Driver lib/Test2/IPC + -rmdir lib/Test2/Hub/Interceptor lib/Test2/Hub lib/Test2/Formatter + -rmdir lib/Test2/EventFacet/Info lib/Test2/EventFacet + -rmdir lib/Test2/Event/TAP lib/Test2/Event lib/Test2/Compare + -rmdir lib/Test2/Bundle lib/Test2/AsyncSubtest/Event + -rmdir lib/Test2/AsyncSubtest lib/Test2/API/InterceptResult + -rmdir lib/Test2/API lib/Test2 lib/Test/use lib/Test/Tester + -rmdir lib/Test/Builder/Tester lib/Test/Builder/IO lib/Test/Builder + -rmdir lib/Test lib/Term/Table lib/Term lib/TAP/Parser/YAMLish + -rmdir lib/TAP/Parser/SourceHandler lib/TAP/Parser/Scheduler + -rmdir lib/TAP/Parser/Result lib/TAP/Parser/Iterator lib/TAP/Parser + -rmdir lib/TAP/Harness lib/TAP/Formatter/File + -rmdir lib/TAP/Formatter/Console lib/TAP/Formatter lib/TAP + -rmdir lib/Sys/Syslog lib/Sys lib/Sub lib/Search lib/Scalar + -rmdir lib/Pod/Text lib/Pod/Simple lib/Pod/Perldoc lib/Pod/Html + -rmdir lib/PerlIO/via lib/PerlIO lib/Perl lib/Parse/CPAN lib/Parse + -rmdir lib/Params lib/OpenBSD lib/Net/FTP lib/Module/Load + -rmdir lib/Module/CoreList lib/Module lib/Memoize lib/Math/BigRat + -rmdir lib/Math/BigInt lib/Math/BigFloat lib/Math lib/MIME + -rmdir lib/Locale/Maketext lib/Locale lib/List/Util lib/List -rmdir lib/JSON/PP lib/JSON lib/IPC lib/IO/Uncompress/Adapter -rmdir lib/IO/Uncompress lib/IO/Socket lib/IO/Compress/Zlib -rmdir lib/IO/Compress/Zip lib/IO/Compress/Gzip lib/IO/Compress/Base -rmdir lib/IO/Compress/Adapter lib/IO/Compress lib/IO -rmdir lib/I18N/LangTags lib/I18N lib/Hash/Util lib/Hash lib/HTTP - -rmdir lib/Filter/Util lib/Filter lib/File/Spec lib/ExtUtils/Typemaps - -rmdir lib/ExtUtils/ParseXS lib/ExtUtils/MakeMaker/version - -rmdir lib/ExtUtils/MakeMaker lib/ExtUtils/Liblist - -rmdir lib/ExtUtils/Constant lib/ExtUtils/Command + -rmdir lib/Getopt/Long lib/Filter/Util lib/Filter lib/File/Spec + -rmdir lib/ExtUtils/Typemaps lib/ExtUtils/ParseXS + -rmdir lib/ExtUtils/MakeMaker/version lib/ExtUtils/MakeMaker + -rmdir lib/ExtUtils/Liblist lib/ExtUtils/Constant lib/ExtUtils/Command -rmdir lib/ExtUtils/CBuilder/Platform/Windows -rmdir lib/ExtUtils/CBuilder/Platform lib/ExtUtils/CBuilder -rmdir lib/Exporter lib/Encode/Unicode lib/Encode/MIME/Header -rmdir lib/Encode/MIME lib/Encode/KR lib/Encode/JP lib/Encode/CN -rmdir lib/Encode lib/Digest lib/Devel lib/Data lib/Config/Perl -rmdir lib/Compress/Raw lib/Compress lib/Carp lib/CPAN/Plugin - -rmdir lib/CPAN/Meta/History lib/CPAN/Meta lib/CPAN/LWP - -rmdir lib/CPAN/Kwalify lib/CPAN/HTTP lib/CPAN/FTP lib/CPAN/Exception - -rmdir lib/CPAN/API lib/CPAN lib/Attribute lib/Archive/Tar lib/Archive - -rmdir lib/App/Prove/State/Result lib/App/Prove/State lib/App/Prove - -rmdir lib/App lib/Amiga + -rmdir lib/CPAN/Meta/Requirements lib/CPAN/Meta/History lib/CPAN/Meta + -rmdir lib/CPAN/LWP lib/CPAN/Kwalify lib/CPAN/HTTP lib/CPAN/FTP + -rmdir lib/CPAN/Exception lib/CPAN/API lib/CPAN lib/Attribute + -rmdir lib/Archive/Tar lib/Archive lib/App/Prove/State/Result + -rmdir lib/App/Prove/State lib/App/Prove lib/App lib/Amiga _realcleaner: @$(LDLIBPTH) $(MAKE) _cleaner1 CLEAN=distclean @@ -1589,11 +1592,20 @@ test_prep test-prep: test_prep_pre \$(MI ;; esac +if test "$dlext" = "none"; then +# this is a static build so we do NOT need to make_ext.pl for the re extension. +$spitshell >>$Makefile <<'!NO!SUBS!' +test_prep_reonly: $(MINIPERL_EXE) $(PERL_EXE) $(TEST_PERL_DLL) + cd t && (rm -f $(PERL_EXE); $(LNS) ../$(PERL_EXE) $(PERL_EXE)) +!NO!SUBS! +else +# this is a dynamic build so we DO need to make_ext.pl for the re extension. $spitshell >>$Makefile <<'!NO!SUBS!' test_prep_reonly: $(MINIPERL_EXE) $(PERL_EXE) $(dynamic_ext_re) $(TEST_PERL_DLL) $(MINIPERL) make_ext.pl $(dynamic_ext_re) MAKE="$(MAKE)" LIBPERL_A=$(LIBPERL) LINKTYPE=dynamic cd t && (rm -f $(PERL_EXE); $(LNS) ../$(PERL_EXE) $(PERL_EXE)) !NO!SUBS! +fi case "$targethost" in '') $spitshell >>$Makefile <<'!NO!SUBS!' Index: gnu/usr.bin/perl/Makefile.bsd-wrapper1 =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Makefile.bsd-wrapper1,v diff -u -p -a -u -p -r1.46 Makefile.bsd-wrapper1 --- gnu/usr.bin/perl/Makefile.bsd-wrapper1 14 May 2024 19:39:39 -0000 1.46 +++ gnu/usr.bin/perl/Makefile.bsd-wrapper1 22 Jan 2025 00:37:42 -0000 @@ -95,6 +95,7 @@ _quick3p= perl5380delta 1 pod/perl5380delta.pod \ perl5381delta 1 pod/perl5381delta.pod \ perl5382delta 1 pod/perl5382delta.pod \ + perl5400delta 1 pod/perl5400delta.pod \ perl561delta 1 pod/perl561delta.pod \ perl56delta 1 pod/perl56delta.pod \ perl581delta 1 pod/perl581delta.pod \ @@ -298,6 +299,7 @@ _quick3p= CPAN::Meta::Merge 3p lib/CPAN/Meta/Merge.pm \ CPAN::Meta::Prereqs 3p lib/CPAN/Meta/Prereqs.pm \ CPAN::Meta::Requirements 3p lib/CPAN/Meta/Requirements.pm \ + CPAN::Meta::Requirements::Range 3p lib/CPAN/Meta/Requirements/Range.pm \ CPAN::Meta::Spec 3p lib/CPAN/Meta/Spec.pm \ CPAN::Meta::Validator 3p lib/CPAN/Meta/Validator.pm \ CPAN::Meta::YAML 3p lib/CPAN/Meta/YAML.pm \ @@ -448,6 +450,7 @@ _quick3p= Filter::Util::Call 3p lib/Filter/Util/Call.pm \ FindBin 3p lib/FindBin.pm \ Getopt::Long 3p lib/Getopt/Long.pm \ + Getopt::Long::Parser 3p lib/Getopt/Long/Parser.pm \ Getopt::Std 3p lib/Getopt/Std.pm \ Hash::Util 3p lib/Hash/Util.pm \ Hash::Util::FieldHash 3p lib/Hash/Util/FieldHash.pm \ @@ -686,6 +689,12 @@ _quick3p= Term::Complete 3p lib/Term/Complete.pm \ Term::ReadKey 3p lib/Term/ReadKey.pm \ Term::ReadLine 3p lib/Term/ReadLine.pm \ + Term::Table 3p lib/Term/Table.pm \ + Term::Table::Cell 3p lib/Term/Table/Cell.pm \ + Term::Table::CellStack 3p lib/Term/Table/CellStack.pm \ + Term::Table::HashBase 3p lib/Term/Table/HashBase.pm \ + Term::Table::LineBreak 3p lib/Term/Table/LineBreak.pm \ + Term::Table::Util 3p lib/Term/Table/Util.pm \ Test 3p lib/Test.pm \ Test2 3p lib/Test2.pm \ Test2::API 3p lib/Test2/API.pm \ @@ -697,6 +706,40 @@ _quick3p= Test2::API::InterceptResult::Hub 3p lib/Test2/API/InterceptResult/Hub.pm \ Test2::API::InterceptResult::Squasher 3p lib/Test2/API/InterceptResult/Squasher.pm \ Test2::API::Stack 3p lib/Test2/API/Stack.pm \ + Test2::AsyncSubtest 3p lib/Test2/AsyncSubtest.pm \ + Test2::AsyncSubtest::Event::Attach 3p lib/Test2/AsyncSubtest/Event/Attach.pm \ + Test2::AsyncSubtest::Event::Detach 3p lib/Test2/AsyncSubtest/Event/Detach.pm \ + Test2::AsyncSubtest::Hub 3p lib/Test2/AsyncSubtest/Hub.pm \ + Test2::Bundle 3p lib/Test2/Bundle.pm \ + Test2::Bundle::Extended 3p lib/Test2/Bundle/Extended.pm \ + Test2::Bundle::More 3p lib/Test2/Bundle/More.pm \ + Test2::Bundle::Simple 3p lib/Test2/Bundle/Simple.pm \ + Test2::Compare 3p lib/Test2/Compare.pm \ + Test2::Compare::Array 3p lib/Test2/Compare/Array.pm \ + Test2::Compare::Bag 3p lib/Test2/Compare/Bag.pm \ + Test2::Compare::Base 3p lib/Test2/Compare/Base.pm \ + Test2::Compare::Bool 3p lib/Test2/Compare/Bool.pm \ + Test2::Compare::Custom 3p lib/Test2/Compare/Custom.pm \ + Test2::Compare::DeepRef 3p lib/Test2/Compare/DeepRef.pm \ + Test2::Compare::Delta 3p lib/Test2/Compare/Delta.pm \ + Test2::Compare::Event 3p lib/Test2/Compare/Event.pm \ + Test2::Compare::EventMeta 3p lib/Test2/Compare/EventMeta.pm \ + Test2::Compare::Float 3p lib/Test2/Compare/Float.pm \ + Test2::Compare::Hash 3p lib/Test2/Compare/Hash.pm \ + Test2::Compare::Isa 3p lib/Test2/Compare/Isa.pm \ + Test2::Compare::Meta 3p lib/Test2/Compare/Meta.pm \ + Test2::Compare::Negatable 3p lib/Test2/Compare/Negatable.pm \ + Test2::Compare::Number 3p lib/Test2/Compare/Number.pm \ + Test2::Compare::Object 3p lib/Test2/Compare/Object.pm \ + Test2::Compare::OrderedSubset 3p lib/Test2/Compare/OrderedSubset.pm \ + Test2::Compare::Pattern 3p lib/Test2/Compare/Pattern.pm \ + Test2::Compare::Ref 3p lib/Test2/Compare/Ref.pm \ + Test2::Compare::Regex 3p lib/Test2/Compare/Regex.pm \ + Test2::Compare::Scalar 3p lib/Test2/Compare/Scalar.pm \ + Test2::Compare::Set 3p lib/Test2/Compare/Set.pm \ + Test2::Compare::String 3p lib/Test2/Compare/String.pm \ + Test2::Compare::Undef 3p lib/Test2/Compare/Undef.pm \ + Test2::Compare::Wildcard 3p lib/Test2/Compare/Wildcard.pm \ Test2::Event 3p lib/Test2/Event.pm \ Test2::Event::Bail 3p lib/Test2/Event/Bail.pm \ Test2::Event::Diag 3p lib/Test2/Event/Diag.pm \ @@ -736,13 +779,100 @@ _quick3p= Test2::IPC 3p lib/Test2/IPC.pm \ Test2::IPC::Driver 3p lib/Test2/IPC/Driver.pm \ Test2::IPC::Driver::Files 3p lib/Test2/IPC/Driver/Files.pm \ + Test2::Manual 3p lib/Test2/Manual.pm \ + Test2::Manual::Anatomy 3p lib/Test2/Manual/Anatomy.pm \ + Test2::Manual::Anatomy::API 3p lib/Test2/Manual/Anatomy/API.pm \ + Test2::Manual::Anatomy::Context 3p lib/Test2/Manual/Anatomy/Context.pm \ + Test2::Manual::Anatomy::Event 3p lib/Test2/Manual/Anatomy/Event.pm \ + Test2::Manual::Anatomy::Hubs 3p lib/Test2/Manual/Anatomy/Hubs.pm \ + Test2::Manual::Anatomy::IPC 3p lib/Test2/Manual/Anatomy/IPC.pm \ + Test2::Manual::Anatomy::Utilities 3p lib/Test2/Manual/Anatomy/Utilities.pm \ + Test2::Manual::Concurrency 3p lib/Test2/Manual/Concurrency.pm \ + Test2::Manual::Contributing 3p lib/Test2/Manual/Contributing.pm \ + Test2::Manual::EndToEnd 3p lib/Test2/Manual/Anatomy/EndToEnd.pm \ + Test2::Manual::Testing 3p lib/Test2/Manual/Testing.pm \ + Test2::Manual::Testing::Introduction 3p lib/Test2/Manual/Testing/Introduction.pm \ + Test2::Manual::Testing::Migrating 3p lib/Test2/Manual/Testing/Migrating.pm \ + Test2::Manual::Testing::Planning 3p lib/Test2/Manual/Testing/Planning.pm \ + Test2::Manual::Testing::Todo 3p lib/Test2/Manual/Testing/Todo.pm \ + Test2::Manual::Tooling 3p lib/Test2/Manual/Tooling.pm \ + Test2::Manual::Tooling::FirstTool 3p lib/Test2/Manual/Tooling/FirstTool.pm \ + Test2::Manual::Tooling::Formatter 3p lib/Test2/Manual/Tooling/Formatter.pm \ + Test2::Manual::Tooling::Nesting 3p lib/Test2/Manual/Tooling/Nesting.pm \ + Test2::Manual::Tooling::Plugin::TestExit 3p lib/Test2/Manual/Tooling/Plugin/TestExit.pm \ + Test2::Manual::Tooling::Plugin::TestingDone 3p lib/Test2/Manual/Tooling/Plugin/TestingDone.pm \ + Test2::Manual::Tooling::Plugin::ToolCompletes 3p lib/Test2/Manual/Tooling/Plugin/ToolCompletes.pm \ + Test2::Manual::Tooling::Plugin::ToolStarts 3p lib/Test2/Manual/Tooling/Plugin/ToolStarts.pm \ + Test2::Manual::Tooling::Subtest 3p lib/Test2/Manual/Tooling/Subtest.pm \ + Test2::Manual::Tooling::TestBuilder 3p lib/Test2/Manual/Tooling/TestBuilder.pm \ + Test2::Manual::Tooling::Testing 3p lib/Test2/Manual/Tooling/Testing.pm \ + Test2::Mock 3p lib/Test2/Mock.pm \ + Test2::Plugin 3p lib/Test2/Plugin.pm \ + Test2::Plugin::BailOnFail 3p lib/Test2/Plugin/BailOnFail.pm \ + Test2::Plugin::DieOnFail 3p lib/Test2/Plugin/DieOnFail.pm \ + Test2::Plugin::ExitSummary 3p lib/Test2/Plugin/ExitSummary.pm \ + Test2::Plugin::SRand 3p lib/Test2/Plugin/SRand.pm \ + Test2::Plugin::Times 3p lib/Test2/Plugin/Times.pm \ + Test2::Plugin::UTF8 3p lib/Test2/Plugin/UTF8.pm \ + Test2::Require 3p lib/Test2/Require.pm \ + Test2::Require::AuthorTesting 3p lib/Test2/Require/AuthorTesting.pm \ + Test2::Require::AutomatedTesting 3p lib/Test2/Require/AutomatedTesting.pm \ + Test2::Require::EnvVar 3p lib/Test2/Require/EnvVar.pm \ + Test2::Require::ExtendedTesting 3p lib/Test2/Require/ExtendedTesting.pm \ + Test2::Require::Fork 3p lib/Test2/Require/Fork.pm \ + Test2::Require::Module 3p lib/Test2/Require/Module.pm \ + Test2::Require::NonInteractiveTesting 3p lib/Test2/Require/NonInteractiveTesting.pm \ + Test2::Require::Perl 3p lib/Test2/Require/Perl.pm \ + Test2::Require::RealFork 3p lib/Test2/Require/RealFork.pm \ + Test2::Require::ReleaseTesting 3p lib/Test2/Require/ReleaseTesting.pm \ + Test2::Require::Threads 3p lib/Test2/Require/Threads.pm \ + Test2::Suite 3p lib/Test2/Suite.pm \ + Test2::Todo 3p lib/Test2/Todo.pm \ + Test2::Tools 3p lib/Test2/Tools.pm \ + Test2::Tools::AsyncSubtest 3p lib/Test2/Tools/AsyncSubtest.pm \ + Test2::Tools::Basic 3p lib/Test2/Tools/Basic.pm \ + Test2::Tools::Class 3p lib/Test2/Tools/Class.pm \ + Test2::Tools::ClassicCompare 3p lib/Test2/Tools/ClassicCompare.pm \ + Test2::Tools::Compare 3p lib/Test2/Tools/Compare.pm \ + Test2::Tools::Defer 3p lib/Test2/Tools/Defer.pm \ + Test2::Tools::Encoding 3p lib/Test2/Tools/Encoding.pm \ + Test2::Tools::Event 3p lib/Test2/Tools/Event.pm \ + Test2::Tools::Exception 3p lib/Test2/Tools/Exception.pm \ + Test2::Tools::Exports 3p lib/Test2/Tools/Exports.pm \ + Test2::Tools::GenTemp 3p lib/Test2/Tools/GenTemp.pm \ + Test2::Tools::Grab 3p lib/Test2/Tools/Grab.pm \ + Test2::Tools::Mock 3p lib/Test2/Tools/Mock.pm \ + Test2::Tools::Ref 3p lib/Test2/Tools/Ref.pm \ + Test2::Tools::Refcount 3p lib/Test2/Tools/Refcount.pm \ + Test2::Tools::Spec 3p lib/Test2/Tools/Spec.pm \ + Test2::Tools::Subtest 3p lib/Test2/Tools/Subtest.pm \ + Test2::Tools::Target 3p lib/Test2/Tools/Target.pm \ + Test2::Tools::Tester 3p lib/Test2/Tools/Tester.pm \ Test2::Tools::Tiny 3p lib/Test2/Tools/Tiny.pm \ + Test2::Tools::Warnings 3p lib/Test2/Tools/Warnings.pm \ Test2::Transition 3p lib/Test2/Transition.pod \ Test2::Util 3p lib/Test2/Util.pm \ Test2::Util::ExternalMeta 3p lib/Test2/Util/ExternalMeta.pm \ Test2::Util::Facets2Legacy 3p lib/Test2/Util/Facets2Legacy.pm \ + Test2::Util::Grabber 3p lib/Test2/Util/Grabber.pm \ + Test2::Util::Guard 3p lib/Test2/Util/Guard.pm \ Test2::Util::HashBase 3p lib/Test2/Util/HashBase.pm \ + Test2::Util::Importer 3p lib/Test2/Util/Importer.pm \ + Test2::Util::Ref 3p lib/Test2/Util/Ref.pm \ + Test2::Util::Stash 3p lib/Test2/Util/Stash.pm \ + Test2::Util::Sub 3p lib/Test2/Util/Sub.pm \ + Test2::Util::Table 3p lib/Test2/Util/Table.pm \ + Test2::Util::Table::LineBreak 3p lib/Test2/Util/Table/LineBreak.pm \ + Test2::Util::Times 3p lib/Test2/Util/Times.pm \ Test2::Util::Trace 3p lib/Test2/Util/Trace.pm \ + Test2::V0 3p lib/Test2/V0.pm \ + Test2::Workflow 3p lib/Test2/Workflow.pm \ + Test2::Workflow::BlockBase 3p lib/Test2/Workflow/BlockBase.pm \ + Test2::Workflow::Build 3p lib/Test2/Workflow/Build.pm \ + Test2::Workflow::Runner 3p lib/Test2/Workflow/Runner.pm \ + Test2::Workflow::Task 3p lib/Test2/Workflow/Task.pm \ + Test2::Workflow::Task::Action 3p lib/Test2/Workflow/Task/Action.pm \ + Test2::Workflow::Task::Group 3p lib/Test2/Workflow/Task/Group.pm \ Test::Builder 3p lib/Test/Builder.pm \ Test::Builder::Formatter 3p lib/Test/Builder/Formatter.pm \ Test::Builder::IO::Scalar 3p lib/Test/Builder/IO/Scalar.pm \ @@ -807,7 +937,7 @@ _quick3p= warnings 3p lib/warnings.pm \ warnings::register 3p lib/warnings/register.pm \ XS::APItest 3p lib/XS/APItest.pm \ - XS::Typemap 3p ext/XS-Typemap/Typemap.pm \ + XS::Typemap 3p lib/XS/Typemap.pm \ XSLoader 3p lib/XSLoader.pm . ifndef NOMAN MAN+= ${page}.${sect} Index: gnu/usr.bin/perl/Makefile.micro =================================================================== RCS file: gnu/usr.bin/perl/Makefile.micro diff -N gnu/usr.bin/perl/Makefile.micro --- gnu/usr.bin/perl/Makefile.micro 14 May 2024 19:38:53 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,211 +0,0 @@ -LD = $(CC) -CCFLAGS = -c -DEFINES = -DPERL_CORE -DPERL_MICRO -DNO_MATHOMS -OPTIMIZE = -CFLAGS = $(DEFINES) $(OPTIMIZE) -LDFLAGS = -LIBS = -lm -_O = .o -ENV = env -PERL = perl -_X = -RUN = - -all: microperl - -O = uav$(_O) udeb$(_O) udoio$(_O) udoop$(_O) udquote$(_O) udump$(_O) \ - uglobals$(_O) ugv$(_O) uhv$(_O) umro$(_O)\ - umg$(_O) uperlmain$(_O) uop$(_O) ureentr$(_O) \ - upad$(_O) uperl$(_O) uperlio$(_O) uperly$(_O) upp$(_O) \ - upp_ctl$(_O) upp_hot$(_O) upp_sys$(_O) upp_pack$(_O) upp_sort$(_O) \ - uregcomp$(_O) uregcomp_debug$(_O) uregcomp_invlist$(_O) \ - uregcomp_study$(_O) uregcomp_trie$(_O) uregexec$(_O) urun$(_O) \ - uscope$(_O) usv$(_O) utaint$(_O) utime64$(_O) utoke$(_O) \ - unumeric$(_O) ulocale$(_O) umathoms$(_O) \ - uuniversal$(_O) uutf8$(_O) uutil$(_O) ukeywords$(_O) - -microperl: $(O) - $(LD) -o $@ $(O) $(LDFLAGS) $(LIBS) - -generated_headers = uuudmap.h ubitcount.h umg_data.h -H = av.h uconfig.h cop.h cv.h embed.h embedvar.h form.h gv.h handy.h \ - hv.h hv_func.h intrpvar.h iperlsys.h mg.h op.h opcode.h opnames.h pad.h \ - patchlevel.h perl.h perlsdio.h perlvars.h perly.h pp.h \ - pp_proto.h proto.h reentr.h regexp.h scope.h sv.h \ - thread.h unixish.h utf8.h util.h warnings.h $(generated_headers) - -HE = $(H) EXTERN.h - -clean: - -rm -f $(O) microperl ugenerate_uudmap$(_X) $(generated_headers) - -distclean: clean - -# The microconfiguration. - -# Cannot use $$ in the command line itself, so using var expansion instead. -Config = '$$Config{$$1}' -patch_uconfig: - $(PERL) -MConfig -pi -e "s/^((?:short|int|long(?:dbl|long)?|ptr|double|[iun]v|u?quad|[iu]\d+|fpos|lseek)(?:size|type)|byteorder|d_quad|quadkind|use64.+)=.*/\\1='"$(Config)"'/g" uconfig.sh - -regen_uconfig: uconfig.sh config_h.SH - $(ENV) CONFIG_SH=uconfig.sh CONFIG_H=uconfig.h sh ./config_h.SH - -regen_uconfig64: uconfig64.sh config_h.SH - $(ENV) CONFIG_SH=uconfig64.sh CONFIG_H=uconfig.h sh ./config_h.SH - -# Do not regenerate perly.c and perly.h. - -perly.c: perly.y - -@echo perly.c is uptodate - -perly.h: perly.y - -@echo perly.h is uptodate - -# The microperl objects. - -uav$(_O): $(HE) av.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) av.c - -udeb$(_O): $(HE) deb.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) deb.c - -udoio$(_O): $(HE) doio.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) doio.c - -udoop$(_O): $(HE) doop.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) doop.c - -udquote$(_O): $(HE) dquote.c regcomp.h regnodes.h - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) dquote.c - -udump$(_O): $(HE) dump.c regcomp.h regnodes.h - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) dump.c - -uglobals$(_O): $(H) globals.c INTERN.h $(generated_headers) - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) globals.c - -ugv$(_O): $(HE) gv.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) gv.c - -umro$(_O): $(HE) mro_core.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) mro_core.c - -uhv$(_O): $(HE) hv.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) hv.c - -ukeywords$(_O): $(HE) keywords.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) keywords.c - -umg$(_O): $(HE) mg.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) mg.c - -uperlmain$(_O): $(HE) miniperlmain.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) miniperlmain.c - -uop$(_O): $(HE) op.c keywords.h - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) -DPERL_EXTERNAL_GLOB op.c - -ureentr$(_O): $(HE) reentr.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) reentr.c - -upad$(_O): $(HE) pad.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) pad.c - -uperl$(_O): $(HE) perl.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) perl.c - -uperlio$(_O): $(HE) perlio.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) perlio.c - -uperly$(_O): $(HE) perly.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) perly.c - -upp$(_O): $(HE) pp.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) pp.c - -upp_ctl$(_O): $(HE) pp_ctl.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) pp_ctl.c - -upp_hot$(_O): $(HE) pp_hot.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) pp_hot.c - -upp_sys$(_O): $(HE) pp_sys.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) pp_sys.c - -upp_pack$(_O): $(HE) pp_pack.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) pp_pack.c - -upp_sort$(_O): $(HE) pp_sort.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) pp_sort.c - -uregcomp$(_O): $(HE) regcomp.c regcomp_internal.h regcomp.h regnodes.h INTERN.h - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) regcomp.c - -uregcomp_debug$(_O): $(HE) regcomp_debug.c regcomp_internal.h regcomp.h regnodes.h INTERN.h - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) regcomp.c - -uregcomp_invlist$(_O): $(HE) regcomp_invlist.c regcomp_internal.h regcomp.h regnodes.h INTERN.h - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) regcomp.c - -uregcomp_study$(_O): $(HE) regcomp_study.c regcomp_internal.h regcomp.h regnodes.h INTERN.h - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) regcomp.c - -uregcomp_trie$(_O): $(HE) regcomp_trie.c regcomp_internal.h regcomp.h regnodes.h INTERN.h - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) regcomp.c - -uregexec$(_O): $(HE) regexec.c regcomp.h regnodes.h - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) regexec.c - -urun$(_O): $(HE) run.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) run.c - -uscope$(_O): $(HE) scope.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) scope.c - -usv$(_O): $(HE) sv.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) sv.c - -utaint$(_O): $(HE) taint.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) taint.c - -utime64$(_O): $(HE) time64.c time64.h time64_config.h - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) time64.c - -utoke$(_O): $(HE) toke.c keywords.h - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) toke.c - -ulocale$(_O): $(HE) locale.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) locale.c - -unumeric$(_O): $(HE) numeric.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) numeric.c - -umathoms$(_O): $(HE) mathoms.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) mathoms.c - -uuniversal$(_O): $(HE) universal.c XSUB.h - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) universal.c - -uutf8$(_O): $(HE) utf8.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) utf8.c - -uutil$(_O): $(HE) util.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) util.c - -uuudmap.h umg_data.h: ubitcount.h - -ubitcount.h: ugenerate_uudmap$(_X) - $(RUN) ./ugenerate_uudmap$(_X) $(generated_headers) - -ugenerate_uudmap$(_O): generate_uudmap.c - $(CC) $(CCFLAGS) -o $@ $(CFLAGS) generate_uudmap.c - -ugenerate_uudmap$(_X): ugenerate_uudmap$(_O) - $(LD) -o ugenerate_uudmap $(LDFLAGS) ugenerate_uudmap$(_O) $(LIBS) - -microtest: microperl - - cd t && (rm -f perl; ln -s ../microperl perl) \ - && ./perl TEST base/*.t cmd/*.t - -# That's it, folks! Index: gnu/usr.bin/perl/README =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/README,v diff -u -p -a -u -p -r1.24 README --- gnu/usr.bin/perl/README 14 May 2024 19:38:53 -0000 1.24 +++ gnu/usr.bin/perl/README 22 Jan 2025 00:37:42 -0000 @@ -1,4 +1,4 @@ -Perl is Copyright (C) 1993 - 2023 by Larry Wall and others. +Perl is Copyright (C) 1993 - 2025 by Larry Wall and others. All rights reserved. Index: gnu/usr.bin/perl/README.haiku =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/README.haiku,v diff -u -p -a -u -p -r1.15 README.haiku --- gnu/usr.bin/perl/README.haiku 14 May 2024 19:38:53 -0000 1.15 +++ gnu/usr.bin/perl/README.haiku 22 Jan 2025 00:37:42 -0000 @@ -24,9 +24,9 @@ The build procedure is completely standa Make perl executable and create a symlink for libperl: chmod a+x /boot/common/bin/perl - cd /boot/common/lib; ln -s perl5/5.38.2/BePC-haiku/CORE/libperl.so . + cd /boot/common/lib; ln -s perl5/5.40.1/BePC-haiku/CORE/libperl.so . -Replace C<5.38.2> with your respective version of Perl. +Replace C<5.40.1> with your respective version of Perl. =head1 KNOWN PROBLEMS @@ -59,7 +59,7 @@ fail. This is due to bugs in Haiku's net =head1 CONTACT For Haiku specific problems contact the HaikuPorts developers: -L +L The initial Haiku port was done by Ingo Weinhold . Index: gnu/usr.bin/perl/README.macosx =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/README.macosx,v diff -u -p -a -u -p -r1.15 README.macosx --- gnu/usr.bin/perl/README.macosx 14 May 2024 19:38:53 -0000 1.15 +++ gnu/usr.bin/perl/README.macosx 22 Jan 2025 00:37:42 -0000 @@ -12,9 +12,9 @@ perlmacosx - Perl under Mac OS X This document briefly describes Perl under Mac OS X. - curl -O https://www.cpan.org/src/perl-5.38.2.tar.gz - tar -xzf perl-5.38.2.tar.gz - cd perl-5.38.2 + curl -O https://www.cpan.org/src/perl-5.40.1.tar.gz + tar -xzf perl-5.40.1.tar.gz + cd perl-5.40.1 ./Configure -des -Dprefix=/usr/local/ make make test @@ -22,7 +22,7 @@ This document briefly describes Perl und =head1 DESCRIPTION -The latest Perl release (5.38.2 as of this writing) builds without changes +The latest Perl release (5.40.1 as of this writing) builds without changes under all versions of Mac OS X from 10.3 "Panther" onwards. In order to build your own version of Perl you will need 'make', Index: gnu/usr.bin/perl/README.micro =================================================================== RCS file: gnu/usr.bin/perl/README.micro diff -N gnu/usr.bin/perl/README.micro --- gnu/usr.bin/perl/README.micro 25 Mar 2013 20:06:36 -0000 1.1.1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,49 +0,0 @@ -microperl is supposed to be a really minimal perl, even more -minimal than miniperl. No Configure is needed to build microperl, -on the other hand this means that interfaces between Perl and your -operating system are left very -- minimal. - -All this is experimental. If you don't know what to do with microperl -you probably shouldn't. Please don't report bugs in microperl; fix the -bugs. (Bugs reports about microperl without fixes/patches are equivalent -to wishlist requests - they won't be discarded, but they likely won't get -worked on either, unless they chance to coincide with someone's personal itch) - -We assume ANSI C89 plus the following: -- , -- rename() -- opendir(), readdir(), closedir() (via dirent.h) -- memchr(), memcmp(), memcpy(), memset() (via string.h) -- (a safe) putenv() (via stdlib.h) -- strtoul() (via stdlib.h) -(grep for 'define' in uconfig.sh.) -Also, Perl times() is defined to always return zeroes. - -If you are still reading this and you are itching to try out microperl: - - make -f Makefile.micro - -The defaults assume a little endian LP32 platform - ie long and pointers are -32 bits, so sizeof(long) and sizeof(void *) are 4 -If your platform is little endian LP64 - ie long and pointers are 64 bits, -sizeof(long) and sizeof(void *) are 8, then you first need to run - - make -f Makefile.micro regen_uconfig64 - -to generate a suitable uconfig.h - -If you make changes to uconfig.sh, run - - make -f Makefile.micro regen_uconfig - -to regenerate uconfig.h. (or regen_uconfig64 if you're editing uconfig64.sh) - - -If neither of the above default configs work on your platform, you might want -to try - - make -f Makefile.micro patch_uconfig - -*before* the "make -f Makefile.micro". This tries to minimally patch -the uconfig.sh using your *current* Perl so that your microperl has -the correct basic types and sizes and byteorder. Index: gnu/usr.bin/perl/README.os2 =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/README.os2,v diff -u -p -a -u -p -r1.31 README.os2 --- gnu/usr.bin/perl/README.os2 14 May 2024 19:38:53 -0000 1.31 +++ gnu/usr.bin/perl/README.os2 22 Jan 2025 00:37:42 -0000 @@ -475,7 +475,7 @@ should be done "correctly". =back -=head2 C<``> and pipe-C do not work under DOS. +=head2 C<``> and pipe-C do not work under DOS This may a variant of just L, or a deeper problem. Basically: you I RSX (see L) @@ -621,7 +621,7 @@ C in F, =item Additional Perl modules - unzip perl_ste.zip -d f:/perllib/lib/site_perl/5.38.2/ + unzip perl_ste.zip -d f:/perllib/lib/site_perl/5.40.1/ Same remark as above applies. Additionally, if this directory is not one of directories on @INC (and @INC is influenced by C), you @@ -1549,7 +1549,7 @@ Here is the sample C file: =head1 Build FAQ -=head2 Some C became C<\> in pdksh. +=head2 Some C became C<\> in pdksh You have a very old pdksh. See L. Index: gnu/usr.bin/perl/README.riscos =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/README.riscos,v diff -u -p -a -u -p -r1.1.1.3 README.riscos --- gnu/usr.bin/perl/README.riscos 14 May 2024 19:36:29 -0000 1.1.1.3 +++ gnu/usr.bin/perl/README.riscos 22 Jan 2025 00:37:42 -0000 @@ -11,19 +11,18 @@ perlriscos - Perl version 5 for RISC OS =head1 DESCRIPTION This document gives instructions for building Perl for RISC OS. It is -complicated by the need to cross compile. There is a binary version of -perl available from L which you may wish to +complicated by the need to cross-compile. There is a binary version of +perl available from L which you may wish to use instead of trying to compile it yourself. =head1 BUILD -You need an installed and working gccsdk cross compiler -L and REXEN -L - -Firstly, copy the source and build a native copy of perl for your host -system. -Then, in the source to be cross compiled: +You need an installed and working +L cross-compiler +and L. + +First, copy the source and build a native copy of perl for your host system. +Then, in the source to be cross-compiled: =over 4 @@ -33,13 +32,13 @@ Then, in the source to be cross compiled =item 2. -Select the riscos hint file. The default answers for the rest of the -questions are usually sufficient. +Select the RISC OS hint file (F). +The default answers for the rest of the questions are usually sufficient. -Note that, if you wish to run Configure non-interactively (see the INSTALL -document for details), to have it select the correct hint file, you'll -need to provide the argument -Dhintfile=riscos on the Configure -command-line. +Note that, if you wish to run C non-interactively +(see the F document for details), to have it select the correct hint +file, you'll need to provide the argument C<-Dhintfile=riscos> on the +C command-line. =item 3. @@ -47,12 +46,12 @@ command-line. =item 4. -This should build miniperl and then fail when it tries to run it. +This should build C and then fail when it tries to run it. =item 5. -Copy the miniperl executable from the native build done earlier to -replace the cross compiled miniperl. +Copy the F executable from the native build done earlier to +replace the cross-compiled F. =item 6. @@ -60,7 +59,7 @@ replace the cross compiled miniperl. =item 7. -This will use miniperl to complete the rest of the build. +This will use C to complete the rest of the build. =back Index: gnu/usr.bin/perl/README.solaris =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/README.solaris,v diff -u -p -a -u -p -r1.13 README.solaris --- gnu/usr.bin/perl/README.solaris 14 May 2024 19:38:53 -0000 1.13 +++ gnu/usr.bin/perl/README.solaris 22 Jan 2025 00:37:42 -0000 @@ -75,7 +75,7 @@ Note also that the perl command-line uti that are added by modules that you install will be under /usr/perl5/bin, so that directory should be added to your PATH. -=head2 Solaris Version Numbers. +=head2 Solaris Version Numbers For consistency with common usage, perl's Configure script performs some minor manipulations on the operating system name and version @@ -122,7 +122,7 @@ All Solaris documentation is available o =head1 SETTING UP -=head2 File Extraction Problems on Solaris. +=head2 File Extraction Problems on Solaris Be sure to use a tar program compiled under Solaris (not SunOS 4.x) to extract the perl-5.x.x.tar.gz file. Do not use GNU tar compiled @@ -134,13 +134,13 @@ If you found this advice too late and us anyway, you must find the incorrectly renamed file and move it back to lib/locale.pm. -=head2 Compiler and Related Tools on Solaris. +=head2 Compiler and Related Tools on Solaris You must use an ANSI C compiler to build perl. Perl can be compiled with either Sun's add-on C compiler or with gcc. The C compiler that shipped with SunOS4 will not do. -=head3 Include /usr/ccs/bin/ in your PATH. +=head3 Include /usr/ccs/bin/ in your PATH Several tools needed to build perl are located in /usr/ccs/bin/: ar, as, ld, and make. Make sure that /usr/ccs/bin/ is in your PATH. @@ -175,7 +175,7 @@ This will display a line like this: The last item listed (SUNWhea in this example) is the package you need. -=head3 Avoid /usr/ucb/cc. +=head3 Avoid /usr/ucb/cc You don't need to have /usr/ucb/ in your PATH to build perl. If you want /usr/ucb/ in your PATH anyway, make sure that /usr/ucb/ is NOT @@ -279,7 +279,7 @@ the set-group-id bit is not set. If it that /usr/ccs/bin/make is before GNU make or else have the system administrator disable the set-group-id bit on GNU make. -=head3 Avoid libucb. +=head3 Avoid libucb Solaris provides some BSD-compatibility functions in /usr/ucblib/libucb.a. Perl will not build and run correctly if linked against -lucb since it @@ -319,13 +319,13 @@ interception failed' errors! The runtim "/usr/lib/libdl.so.1.0" and links in internal implementations of those functions instead. [Thanks to Tim Bunce for this explanation.] -=head1 RUN CONFIGURE. +=head1 RUN CONFIGURE See the INSTALL file for general information regarding Configure. Only Solaris-specific issues are discussed here. Usually, the defaults should be fine. -=head2 64-bit perl on Solaris. +=head2 64-bit perl on Solaris See the INSTALL file for general information regarding 64-bit compiles. In general, the defaults should be fine for most people. @@ -333,7 +333,7 @@ In general, the defaults should be fine By default, perl-5.6.0 (or later) is compiled as a 32-bit application with largefile and long-long support. -=head3 General 32-bit vs. 64-bit issues. +=head3 General 32-bit vs. 64-bit issues Solaris 7 and above will run in either 32 bit or 64 bit mode on SPARC CPUs, via a reboot. You can build 64 bit apps whilst running 32 bit @@ -450,17 +450,17 @@ in that release: All this should be handled automatically by the hints file, if requested. -=head3 Long Doubles. +=head3 Long Doubles As of 5.8.1, long doubles are working if you use the Sun compilers (needed for additional math routines not included in libm). -=head2 Threads in perl on Solaris. +=head2 Threads in perl on Solaris It is possible to build a threaded version of perl on Solaris. The entire perl thread implementation is still experimental, however, so beware. -=head2 Malloc Issues with perl on Solaris. +=head2 Malloc Issues with perl on Solaris Starting from perl 5.7.1 perl uses the Solaris malloc, since the perl malloc breaks when dealing with more than 2GB of memory, and the Solaris @@ -478,7 +478,7 @@ appears to go away under -DDEBUGGING, so track down. Sun's compiler appears to be okay with or without perl's malloc. [XXX further investigation is needed here.] -=head1 MAKE PROBLEMS. +=head1 MAKE PROBLEMS =over 4 @@ -546,7 +546,7 @@ Solaris x86 looks something like this: The lddlflags addition is the only abnormal bit. -=head1 PREBUILT BINARIES OF PERL FOR SOLARIS. +=head1 PREBUILT BINARIES OF PERL FOR SOLARIS You can pick up prebuilt binaries for Solaris from L, L, @@ -556,9 +556,9 @@ page. There are probably other sources these sites are under the control of their respective owners, not the perl developers. -=head1 RUNTIME ISSUES FOR PERL ON SOLARIS. +=head1 RUNTIME ISSUES FOR PERL ON SOLARIS -=head2 Limits on Numbers of Open Files on Solaris. +=head2 Limits on Numbers of Open Files on Solaris The stdio(3C) manpage notes that for LP32 applications, only 255 files may be opened using fopen(), and only file descriptors 0 @@ -571,13 +571,13 @@ also that the default resource limit for Solaris is 255, so you will have to modify your ulimit or rctl (Solaris 9 onwards) appropriately. -=head1 SOLARIS-SPECIFIC MODULES. +=head1 SOLARIS-SPECIFIC MODULES See the modules under the Solaris:: and Sun::Solaris namespaces on CPAN, see L and L. -=head1 SOLARIS-SPECIFIC PROBLEMS WITH MODULES. +=head1 SOLARIS-SPECIFIC PROBLEMS WITH MODULES =head2 Proc::ProcessTable on Solaris Index: gnu/usr.bin/perl/README.vms =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/README.vms,v diff -u -p -a -u -p -r1.32 README.vms --- gnu/usr.bin/perl/README.vms 14 May 2024 19:38:53 -0000 1.32 +++ gnu/usr.bin/perl/README.vms 22 Jan 2025 00:37:42 -0000 @@ -139,11 +139,11 @@ You may need to set up a foreign symbol choice. Once you have done so, use a command like the following to unpack the archive: - vmstar -xvf perl-5^.38^.2.tar + vmstar -xvf perl-5^.40^.1.tar Then set default to the top-level source directory like so: - set default [.perl-5^.38^.2] + set default [.perl-5^.40^.1] and proceed with configuration as described in the next section. Index: gnu/usr.bin/perl/README.win32 =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/README.win32,v diff -u -p -a -u -p -r1.23 README.win32 --- gnu/usr.bin/perl/README.win32 14 May 2024 19:38:53 -0000 1.23 +++ gnu/usr.bin/perl/README.win32 22 Jan 2025 00:37:42 -0000 @@ -41,7 +41,7 @@ additional software to run (other than w system). Currently, this port is capable of using one of the following compilers on the Intel x86 and x86_64 architectures: - Microsoft Visual C++ version 12.0 or later + Microsoft Visual C++ Visual C++ 2015 (version 14.0) or later Intel C++ Compiler (experimental) Gcc by mingw.org gcc version 3.4.5-5.3.0 Gcc by mingw-w64.org gcc version 4.4.3 or later @@ -65,14 +65,8 @@ that are also supported by perl's makefi =back The Microsoft Visual C++ compilers are also now being given away free. They -are available as "Visual C++ 2013-2022 Community Edition" and are the same -compilers that ship with "Visual C++ 2013-2022 Professional". - -Visual C++ 2013 is capable of B XP and Windows Server 2003 but the -build host requirement is Windows 7/Windows Server 2012. For more details see -https://docs.microsoft.com/en-us/visualstudio/productinfo/vs2013-compatibility-vs -and -https://docs.microsoft.com/en-us/visualstudio/productinfo/vs2013-sysrequirements-vs +are available as "Visual C++ 2015-2022 Community Edition" and are the same +compilers that ship with "Visual C++ 2015-2022 Professional". The MinGW64 compiler is available at L. The latter is actually a cross-compiler targeting Win64. There's also a trimmed @@ -129,23 +123,23 @@ console already set up for your target a With the newer compilers, you may also use the older batch files if you choose so. -=item Microsoft Visual C++ 2013-2022 Community Edition +=item Microsoft Visual C++ 2015-2022 Community Edition -These free versions of Visual C++ 2013-2022 Professional contain the same +These free versions of Visual C++ 2015-2022 Professional contain the same compilers and linkers that ship with the full versions, and also contain everything necessary to build Perl. These packages can be downloaded from L. -Install Visual C++ 2013-2022 Community, then setup your environment +Install Visual C++ 2015-2022 Community, then setup your environment using, e.g. -F +F (assuming the default installation location was chosen). Perl should now build using the F. You will need to edit that -file to set C to one of C-C first. +file to set C to one of C-C first. =item Microsoft C++ Build Tools @@ -239,7 +233,7 @@ Be sure to read the instructions near th Type C (or C if you are using that version of C). This should build everything. Specifically, it will create F, -F at the perl toplevel, and various other extension DLL's +F at the perl toplevel, and various other extension DLL's under the F directory. If the build fails for any reason, make sure you have done the previous steps correctly. @@ -263,15 +257,6 @@ Type "gmake test" (or "nmake test"). Th of the tests from the testsuite (many tests will be skipped). There should be no test failures. - -If you build with Visual C++ 2013 then three tests currently may fail with -Daylight Saving Time related problems: F, -F and F. The failures are -caused by bugs in the CRT in VC++ 2013 which are fixed in VC++2015 and -later, as explained by Microsoft here: -L. In the meantime, -if you need fixed C and C functions then have a look at the -CPAN distribution Win32::UTCFileTime. If you build with Visual C++ 2015 or later then F may crash (after all its tests have passed). This is due to a regression in the Index: gnu/usr.bin/perl/TestInit.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/TestInit.pm,v diff -u -p -a -u -p -r1.5 TestInit.pm --- gnu/usr.bin/perl/TestInit.pm 1 Mar 2021 23:19:42 -0000 1.5 +++ gnu/usr.bin/perl/TestInit.pm 22 Jan 2025 00:37:42 -0000 @@ -37,7 +37,7 @@ package TestInit; -$VERSION = 1.04; +our $VERSION = 1.05; # Let tests know they're running in the perl core. Useful for modules # which live dual lives on CPAN. Index: gnu/usr.bin/perl/XSUB.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/XSUB.h,v diff -u -p -a -u -p -r1.22 XSUB.h --- gnu/usr.bin/perl/XSUB.h 14 May 2024 19:38:53 -0000 1.22 +++ gnu/usr.bin/perl/XSUB.h 22 Jan 2025 00:37:42 -0000 @@ -37,12 +37,12 @@ Variable which is setup by C to XSUB. This is always the proper type for the C++ object. See C> and L. -=for apidoc Amn|I32|ax +=for apidoc Amn|Stack_off_t|ax Variable which is setup by C to indicate the stack base offset, used by the C, C and C macros. The C macro must be called prior to setup the C variable. -=for apidoc Amn|I32|items +=for apidoc Amn|Stack_off_t|items Variable which is setup by C to indicate the number of items on the stack. See L. @@ -157,13 +157,13 @@ is a lexical C<$_> in scope. * Try explicitly using XS_INTERNAL/XS_EXTERNAL instead, please. */ #define XS(name) XS_EXTERNAL(name) -#define dAX const I32 ax = (I32)(MARK - PL_stack_base + 1) +#define dAX const Stack_off_t ax = (Stack_off_t)(MARK - PL_stack_base + 1) #define dAXMARK \ - I32 ax = POPMARK; \ + Stack_off_t ax = POPMARK; \ SV **mark = PL_stack_base + ax++ -#define dITEMS I32 items = (I32)(SP - MARK) +#define dITEMS Stack_off_t items = (Stack_off_t)(SP - MARK) #define dXSARGS \ dSP; dAXMARK; dITEMS @@ -174,16 +174,16 @@ is a lexical C<$_> in scope. Note these macros are not drop in replacements for dXSARGS since they set PL_xsubfilename. */ #define dXSBOOTARGSXSAPIVERCHK \ - I32 ax = XS_BOTHVERSION_SETXSUBFN_POPMARK_BOOTCHECK; \ + Stack_off_t ax = XS_BOTHVERSION_SETXSUBFN_POPMARK_BOOTCHECK; \ SV **mark = PL_stack_base + ax - 1; dSP; dITEMS #define dXSBOOTARGSAPIVERCHK \ - I32 ax = XS_APIVERSION_SETXSUBFN_POPMARK_BOOTCHECK; \ + Stack_off_t ax = XS_APIVERSION_SETXSUBFN_POPMARK_BOOTCHECK; \ SV **mark = PL_stack_base + ax - 1; dSP; dITEMS /* dXSBOOTARGSNOVERCHK has no API in xsubpp to choose it so do #undef dXSBOOTARGSXSAPIVERCHK #define dXSBOOTARGSXSAPIVERCHK dXSBOOTARGSNOVERCHK */ #define dXSBOOTARGSNOVERCHK \ - I32 ax = XS_SETXSUBFN_POPMARK; \ + Stack_off_t ax = XS_SETXSUBFN_POPMARK; \ SV **mark = PL_stack_base + ax - 1; dSP; dITEMS #define dXSTARG SV * const targ = ((PL_op->op_private & OPpENTERSUB_HASTARG) \ @@ -504,7 +504,6 @@ Rethrows a previously caught exception. # undef fgetpos # undef ioctl # undef getlogin -# undef setjmp # undef getc # undef ungetc # undef fileno @@ -609,8 +608,6 @@ Rethrows a previously caught exception. # define sleep PerlProc_sleep # define times PerlProc_times # define wait PerlProc_wait -# define setjmp PerlProc_setjmp -# define longjmp PerlProc_longjmp # define signal PerlProc_signal # define getpid PerlProc_getpid # define gettimeofday PerlProc_gettimeofday Index: gnu/usr.bin/perl/autodoc.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/autodoc.pl,v diff -u -p -a -u -p -r1.7 autodoc.pl --- gnu/usr.bin/perl/autodoc.pl 14 May 2024 19:38:53 -0000 1.7 +++ gnu/usr.bin/perl/autodoc.pl 22 Jan 2025 00:37:42 -0000 @@ -69,6 +69,12 @@ my %extra_input_pods = ( 'dist/ExtUtils- use strict; use warnings; +my $config_h = 'config.h'; +if (@ARGV >= 2 && $ARGV[0] eq "-c") { + shift; + $config_h = shift; +} + my $nroff_min_indent = 4; # for non-heading lines # 80 column terminal - 2 for pager adding 2 columns; my $max_width = 80 - 2 - $nroff_min_indent; @@ -138,6 +144,7 @@ my $memory_scn = 'Memory Management'; my $MRO_scn = 'MRO'; my $multicall_scn = 'Multicall Functions'; my $numeric_scn = 'Numeric Functions'; +my $rpp_scn = 'Reference-counted stack manipulation'; # Now combined, as unclear which functions go where, but separate names kept # to avoid 1) other code changes; 2) in case it seems better to split again @@ -320,6 +327,14 @@ my %valid_sections = ( See L. EOT }, + $rpp_scn => { + header => <<~'EOT', + Functions for pushing and pulling items on the stack when the + stack is reference counted. They are intended as replacements + for the old PUSHs, POPi, EXTEND etc pp macros within pp + functions. + EOT + }, $signals_scn => {}, $site_scn => { header => <<~'EOT', @@ -505,7 +520,7 @@ sub autodoc ($$) { # parse a file and ex } elsif ($in=~ /^ =for [ ]+ apidoc \B /x) { # Otherwise better be a # plain apidoc line - die "Unkown apidoc-type line '$in'" unless $in=~ /^=for apidoc_item/; + die "Unknown apidoc-type line '$in'" unless $in=~ /^=for apidoc_item/; die "apidoc_item doesn't immediately follow an apidoc entry: '$in'"; } else { # Plain apidoc @@ -529,12 +544,13 @@ sub autodoc ($$) { # parse a file and ex } die "flag '$1' is not legal (for function $element_name (from $file))" - if $flags =~ / ( [^AabCDdEeFfGhiIMmNnTOoPpRrSsUuWXxy;#] ) /x; + if $flags =~ / ( [^AabCDdEeFfGhiIMmNnTOoPpRrSsUuvWXxy;#] ) /x; die "'u' flag must also have 'm' or 'y' flags' for $element_name" if $flags =~ /u/ && $flags !~ /[my]/; warn ("'$element_name' not \\w+ in '$proto_in_file' in $file") - if $flags !~ /N/ && $element_name !~ / ^ [_[:alpha:]] \w* $ /x; + if $flags !~ /N/ && + $element_name !~ / ^ (?:struct\s+)? [_[:alpha:]] \w* $ /x; if ($flags =~ /#/) { die "Return type must be empty for '$element_name'" @@ -703,11 +719,9 @@ my @has_r_defs; # Reentrant symbols my @include_defs; sub parse_config_h { - use re '/aa'; # Everthing is ASCII in this file + use re '/aa'; # Everything is ASCII in this file # Process config.h - my $config_h = 'config.h'; - $config_h = 'win32/config.h' unless -e $config_h; die "Can't find $config_h" unless -e $config_h; open my $fh, '<', $config_h or die "Can't open $config_h: $!"; while (<$fh>) { @@ -978,12 +992,16 @@ sub parse_config_h { chomp $was; if ($was ne "" && $was !~ m/$link_text/) { die "Multiple descriptions for $name\n" - . "$section contained '$was'"; + . "The '$section' section contained\n'$was'"; } $docs{'api'}{$section}{$name}->{pod} = $configs{$name}{pod}; $configs{$name}{section} = $section; last; } + elsif (exists $docs{'intern'}{$section}{$name}) { + die "'$name' is in 'config.h' meaning it is part of the API,\n" + . " but it is also in 'perlintern', meaning it isn't API\n"; + } } my $handled = 0; # Haven't handled this yet @@ -1014,7 +1032,7 @@ sub parse_config_h { # things in config.h, and should be adjusted as necessary as # deficiencies are found. # - # This is the default section for macros with a definiton but + # This is the default section for macros with a definition but # no arguments, meaning it is replaced unconditionally # my $sb = qr/ _ | \b /x; # segment boundary @@ -1145,7 +1163,7 @@ sub parse_config_h { # and there is no verbatim text in the pod or links to/from it # (which would add value). That means that it is likely the # intent of the variable can be gleaned from just its name, - # and unlikely the description adds signficant value, so just + # and unlikely the description adds significant value, so just # listing them suffices. Giving their descriptions would # expand this pod significantly with little added value. if ( ! $has_defn @@ -1531,107 +1549,13 @@ sub construct_missings_section { # Sort the elements. my @missings = sort dictionary_order $missings_ref->@*; + # Make a table of the missings in columns. Give the subroutine a width + # one less than you might expect, as we indent each line by one, to mark + # it as verbatim. + my $table .= columnarize_list(\@missings, $max_width - 1); + $table =~ s/^/ /gm; - $text .= "\n"; - - use integer; - - # Look through all the elements in the list and see how many columns we - # could place them in the output what will fit in the available width. - my $min_spacer = 2; # Need this much space between columns - my $columns; - my $rows; - my @col_widths; - - COLUMN: - # We start with more columns, and work down until we find a number that - # can accommodate all the data. This algorithm doesn't require the - # resulting columns to all have the same width. This can allow for - # as tight of packing as the data will possibly allow. - for ($columns = 7; $columns >= 1; $columns--) { - - # For this many columns, we will need this many rows (final row might - # not be completely filled) - $rows = (@missings + $columns - 1) / $columns; - - # We only need to execute this final iteration to calculate the number - # of rows, as we can't get fewer than a single column. - last if $columns == 1; - - my $row_width = 1; # For 1 space indent - my $i = 0; # Which missing element - - # For each column ... - for my $col (0 .. $columns - 1) { - - # Calculate how wide the column needs to be, which is based on the - # widest element in it - $col_widths[$col] = 0; - - # Look through all the rows to find the widest element - for my $row (0 .. $rows - 1) { - - # Skip if this row doesn't have an entry for this column - last if $i >= @missings; - - # This entry occupies this many bytes. - my $this_width = length $missings[$i]; - - # All but the final column need a spacer between it and the - # next column over. - $this_width += $min_spacer if $col < $columns - 1; - - - # This column will need to have enough width to accommodate - # this element - if ($this_width > $col_widths[$col]) { - - # We can't have this many columns if the total width - # exceeds the available; bail now and try fewer columns - next COLUMN if $row_width + $this_width > $max_width; - - $col_widths[$col] = $this_width; - } - - $i++; # The next row will contain the next item - } - - $row_width += $col_widths[$col]; - next COLUMN if $row_width > $max_width; - } - - # If we get this far, this many columns works - last; - } - - # Here, have calculated the number of rows ($rows) and columns ($columns) - # required to list the elements. @col_widths contains the width of each - # column. - - $text .= "\n"; - - # Assemble the output - for my $row (0 .. $rows - 1) { - for my $col (0 .. $columns - 1) { - $text .= " " if $col == 0; # Indent one to mark as verbatim - - my $index = $row + $rows * $col; # Convert 2 dimensions to 1 - - # Skip if this row doesn't have an entry for this column - next if $index >= @missings; - - my $element = $missings[$index]; - $text .= $element; - - # Add alignment spaces for all but final column - $text .= " " x ($col_widths[$col] - length $element) - if $col < $columns - 1; - } - - $text .= "\n"; # End of row - } - - return $text; + return $text . "\n\n" . $table; } sub dictionary_order { @@ -1715,7 +1639,7 @@ sub output { # We allow empty sections in perlintern. if (! $section_info && $podname eq 'perlapi') { - warn "Empty section '$section_name'; skipped"; + warn "Empty section '$section_name' for $podname; skipped"; next; } Index: gnu/usr.bin/perl/av.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/av.c,v diff -u -p -a -u -p -r1.23 av.c --- gnu/usr.bin/perl/av.c 14 May 2024 19:39:39 -0000 1.23 +++ gnu/usr.bin/perl/av.c 22 Jan 2025 00:37:42 -0000 @@ -42,8 +42,8 @@ Perl_av_reify(pTHX_ AV *av) SvREFCNT_inc_simple_void(sv); } key = AvARRAY(av) - AvALLOC(av); - while (key) - AvALLOC(av)[--key] = NULL; + if (key) + Zero(AvALLOC(av), key, SV*); AvREIFY_off(av); AvREAL_on(av); } @@ -633,7 +633,6 @@ to it. void Perl_av_clear(pTHX_ AV *av) { - SSize_t extra; bool real; SSize_t orig_ix = 0; @@ -678,12 +677,9 @@ Perl_av_clear(pTHX_ AV *av) SvREFCNT_dec(sv); } } - extra = AvARRAY(av) - AvALLOC(av); - if (extra) { - AvMAX(av) += extra; - AvARRAY(av) = AvALLOC(av); - } AvFILLp(av) = -1; + av_remove_offset(av); + if (real) { /* disarm av's premature free guard */ if (LIKELY(PL_tmps_ix == orig_ix)) @@ -902,6 +898,9 @@ Perl_av_unshift(pTHX_ AV *av, SSize_t nu AvMAX(av) += i; AvFILLp(av) += i; AvARRAY(av) = AvARRAY(av) - i; +#ifdef PERL_RC_STACK + Zero(AvARRAY(av), i, SV*); +#endif } if (num) { SV **ary; @@ -955,8 +954,10 @@ Perl_av_shift(pTHX_ AV *av) if (AvFILL(av) < 0) return &PL_sv_undef; retval = *AvARRAY(av); +#ifndef PERL_RC_STACK if (AvREAL(av)) *AvARRAY(av) = NULL; +#endif AvARRAY(av) = AvARRAY(av) + 1; AvMAX(av)--; AvFILLp(av)--; Index: gnu/usr.bin/perl/av.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/av.h,v diff -u -p -a -u -p -r1.18 av.h --- gnu/usr.bin/perl/av.h 15 Feb 2023 01:36:12 -0000 1.18 +++ gnu/usr.bin/perl/av.h 22 Jan 2025 00:37:42 -0000 @@ -113,6 +113,7 @@ Note that there are both real and fake A 'av.c' =for apidoc newAV +=for apidoc_item newAV_mortal =for apidoc_item newAV_alloc_x =for apidoc_item newAV_alloc_xz @@ -169,6 +170,11 @@ or implicitly when the first element is Unused array elements are typically initialized by C. +=item C form + +This also creates the whole-array data structure, but also mortalises it. +(That is to say, a reference to the AV is added to the C stack.) + =item C form This effectively does a C followed by also allocating (uninitialized) @@ -210,6 +216,7 @@ to fit one element without extending: */ #define newAV() MUTABLE_AV(newSV_type(SVt_PVAV)) +#define newAV_mortal() MUTABLE_AV(newSV_type_mortal(SVt_PVAV)) #define newAV_alloc_x(size) av_new_alloc(size,0) #define newAV_alloc_xz(size) av_new_alloc(size,1) Index: gnu/usr.bin/perl/builtin.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/builtin.c,v diff -u -p -a -u -p -r1.1.1.2 builtin.c --- gnu/usr.bin/perl/builtin.c 14 May 2024 19:36:26 -0000 1.1.1.2 +++ gnu/usr.bin/perl/builtin.c 22 Jan 2025 00:37:42 -0000 @@ -12,39 +12,45 @@ */ #include "EXTERN.h" +#define PERL_IN_BUILTIN_C #include "perl.h" #include "XSUB.h" +/* copied from op.c */ +#define SHORTVER(maj,min) (((maj) << 8) | (min)) + struct BuiltinFuncDescriptor { const char *name; + U16 since_ver; XSUBADDR_t xsub; OP *(*checker)(pTHX_ OP *, GV *, SV *); IV ckval; + bool is_experimental; }; -#define warn_experimental_builtin(name, prefix) S_warn_experimental_builtin(aTHX_ name, prefix) -static void S_warn_experimental_builtin(pTHX_ const char *name, bool prefix) +#define warn_experimental_builtin(name) S_warn_experimental_builtin(aTHX_ name) +static void S_warn_experimental_builtin(pTHX_ const char *name) { /* diag_listed_as: Built-in function '%s' is experimental */ Perl_ck_warner_d(aTHX_ packWARN(WARN_EXPERIMENTAL__BUILTIN), - "Built-in function '%s%s' is experimental", - prefix ? "builtin::" : "", name); + "Built-in function 'builtin::%s' is experimental", name); } /* These three utilities might want to live elsewhere to be reused from other * code sometime */ -#define prepare_export_lexical() S_prepare_export_lexical(aTHX) -static void S_prepare_export_lexical(pTHX) +void +Perl_prepare_export_lexical(pTHX) { assert(PL_compcv); /* We need to have PL_comppad / PL_curpad set correctly for lexical importing */ ENTER; SAVESPTR(PL_comppad_name); PL_comppad_name = PadlistNAMES(CvPADLIST(PL_compcv)); - SAVESPTR(PL_comppad); PL_comppad = PadlistARRAY(CvPADLIST(PL_compcv))[1]; - SAVESPTR(PL_curpad); PL_curpad = PadARRAY(PL_comppad); + SAVECOMPPAD(); + PL_comppad = PadlistARRAY(CvPADLIST(PL_compcv))[1]; + PL_curpad = PadARRAY(PL_comppad); } #define export_lexical(name, sv) S_export_lexical(aTHX_ name, sv) @@ -55,8 +61,8 @@ static void S_export_lexical(pTHX_ SV *n PL_curpad[off] = SvREFCNT_inc(sv); } -#define finish_export_lexical() S_finish_export_lexical(aTHX) -static void S_finish_export_lexical(pTHX) +void +Perl_finish_export_lexical(pTHX) { intro_my(); @@ -68,9 +74,9 @@ XS(XS_builtin_true); XS(XS_builtin_true) { dXSARGS; - warn_experimental_builtin("true", true); if(items) croak_xs_usage(cv, ""); + EXTEND(SP, 1); XSRETURN_YES; } @@ -78,22 +84,45 @@ XS(XS_builtin_false); XS(XS_builtin_false) { dXSARGS; - warn_experimental_builtin("false", true); if(items) croak_xs_usage(cv, ""); + EXTEND(SP, 1); XSRETURN_NO; } +XS(XS_builtin_inf); +XS(XS_builtin_inf) +{ + dXSARGS; + if(items) + croak_xs_usage(cv, ""); + EXTEND(SP, 1); + XSRETURN_NV(NV_INF); +} + +XS(XS_builtin_nan); +XS(XS_builtin_nan) +{ + dXSARGS; + if(items) + croak_xs_usage(cv, ""); + EXTEND(SP, 1); + XSRETURN_NV(NV_NAN); +} + enum { BUILTIN_CONST_FALSE, BUILTIN_CONST_TRUE, + BUILTIN_CONST_INF, + BUILTIN_CONST_NAN, }; static OP *ck_builtin_const(pTHX_ OP *entersubop, GV *namegv, SV *ckobj) { const struct BuiltinFuncDescriptor *builtin = NUM2PTR(const struct BuiltinFuncDescriptor *, SvUV(ckobj)); - warn_experimental_builtin(builtin->name, false); + if(builtin->is_experimental) + warn_experimental_builtin(builtin->name); SV *prototype = newSVpvs(""); SAVEFREESV(prototype); @@ -106,6 +135,8 @@ static OP *ck_builtin_const(pTHX_ OP *en switch(builtin->ckval) { case BUILTIN_CONST_FALSE: constval = &PL_sv_no; break; case BUILTIN_CONST_TRUE: constval = &PL_sv_yes; break; + case BUILTIN_CONST_INF: constval = newSVnv(NV_INF); break; + case BUILTIN_CONST_NAN: constval = newSVnv(NV_NAN); break; default: DIE(aTHX_ "panic: unrecognised builtin_const value %" IVdf, builtin->ckval); @@ -123,13 +154,12 @@ XS(XS_builtin_func1_scalar) dXSARGS; dXSI32; - warn_experimental_builtin(PL_op_name[ix], true); - if(items != 1) croak_xs_usage(cv, "arg"); switch(ix) { case OP_IS_BOOL: + warn_experimental_builtin(PL_op_name[ix]); Perl_pp_is_bool(aTHX); break; @@ -161,6 +191,19 @@ XS(XS_builtin_func1_scalar) Perl_pp_is_tainted(aTHX); break; + case OP_STRINGIFY: + { + /* we could only call pp_stringify if we're sure there is a TARG + and if the XSUB is called from call_sv() or goto it may not + have one. + */ + dXSTARG; + sv_copypv(TARG, *PL_stack_sp); + SvSETMAGIC(TARG); + rpp_replace_1_1_NN(TARG); + } + break; + default: Perl_die(aTHX_ "panic: unhandled opcode %" IVdf " for xs_builtin_func1_scalar()", (IV) ix); @@ -174,13 +217,11 @@ XS(XS_builtin_trim) { dXSARGS; - warn_experimental_builtin("trim", true); - if (items != 1) { croak_xs_usage(cv, "arg"); } - dTARGET; + dXSTARG; SV *source = TOPs; STRLEN len; const U8 *start; @@ -268,7 +309,7 @@ XS(XS_builtin_export_lexically) { dXSARGS; - warn_experimental_builtin("export_lexically", true); + warn_experimental_builtin("export_lexically"); if(!PL_compcv) Perl_croak(aTHX_ @@ -342,8 +383,6 @@ XS(XS_builtin_func1_void) dXSARGS; dXSI32; - warn_experimental_builtin(PL_op_name[ix], true); - if(items != 1) croak_xs_usage(cv, "arg"); @@ -398,7 +437,8 @@ static OP *ck_builtin_func1(pTHX_ OP *en { const struct BuiltinFuncDescriptor *builtin = NUM2PTR(const struct BuiltinFuncDescriptor *, SvUV(ckobj)); - warn_experimental_builtin(builtin->name, false); + if(builtin->is_experimental) + warn_experimental_builtin(builtin->name); SV *prototype = newSVpvs("$"); SAVEFREESV(prototype); @@ -429,7 +469,25 @@ static OP *ck_builtin_func1(pTHX_ OP *en op_free(entersubop); - return newUNOP(opcode, wantflags, argop); + if(opcode == OP_STRINGIFY) + /* Even though pp_stringify only looks at TOPs and conceptually works + * on a single argument, it happens to be a LISTOP. I've no idea why + */ + return newLISTOPn(opcode, wantflags, + argop, + NULL); + else { + OP * const op = newUNOP(opcode, wantflags, argop); + + /* since these pp funcs can be called from XS, and XS may be called + without a normal ENTERSUB, we need to indicate to them that a targ + has been allocated. + */ + if (op->op_targ) + op->op_private |= OPpENTERSUB_HASTARG; + + return op; + } } XS(XS_builtin_indexed) @@ -466,11 +524,79 @@ XS(XS_builtin_indexed) XSRETURN(retcount); } +XS(XS_builtin_load_module); +XS(XS_builtin_load_module) +{ + dXSARGS; + if (items != 1) + croak_xs_usage(cv, "arg"); + SV *module_name = newSVsv(ST(0)); + if (!SvPOK(module_name)) { + SvREFCNT_dec(module_name); + croak_xs_usage(cv, "defined string"); + } + load_module(PERL_LOADMOD_NOIMPORT, module_name, NULL, NULL); + /* The loaded module's name is left intentionally on the stack for the + * caller's benefit, and becomes load_module's return value. */ + XSRETURN(1); +} + +/* These pp_ funcs all need to use dXSTARG */ + +PP(pp_refaddr) +{ + dXSTARG; + SV *arg = *PL_stack_sp; + + SvGETMAGIC(arg); + + if(SvROK(arg)) + sv_setuv_mg(TARG, PTR2UV(SvRV(arg))); + else + sv_setsv(TARG, &PL_sv_undef); + + rpp_replace_1_1_NN(TARG); + return NORMAL; +} + +PP(pp_reftype) +{ + dXSTARG; + SV *arg = *PL_stack_sp; + + SvGETMAGIC(arg); + + if(SvROK(arg)) + sv_setpv_mg(TARG, sv_reftype(SvRV(arg), FALSE)); + else + sv_setsv(TARG, &PL_sv_undef); + + rpp_replace_1_1_NN(TARG); + return NORMAL; +} + +PP(pp_ceil) +{ + dXSTARG; + TARGn(Perl_ceil(SvNVx(*PL_stack_sp)), 1); + rpp_replace_1_1_NN(TARG); + return NORMAL; +} + +PP(pp_floor) +{ + dXSTARG; + TARGn(Perl_floor(SvNVx(*PL_stack_sp)), 1); + rpp_replace_1_1_NN(TARG); + return NORMAL; +} + static OP *ck_builtin_funcN(pTHX_ OP *entersubop, GV *namegv, SV *ckobj) { const struct BuiltinFuncDescriptor *builtin = NUM2PTR(const struct BuiltinFuncDescriptor *, SvUV(ckobj)); - warn_experimental_builtin(builtin->name, false); + if(builtin->is_experimental) + warn_experimental_builtin(builtin->name); SV *prototype = newSVpvs("@"); SAVEFREESV(prototype); @@ -483,33 +609,126 @@ static OP *ck_builtin_funcN(pTHX_ OP *en static const char builtin_not_recognised[] = "'%" SVf "' is not recognised as a builtin function"; +#define NO_BUNDLE SHORTVER(255,255) + static const struct BuiltinFuncDescriptor builtins[] = { /* constants */ - { "builtin::true", &XS_builtin_true, &ck_builtin_const, BUILTIN_CONST_TRUE }, - { "builtin::false", &XS_builtin_false, &ck_builtin_const, BUILTIN_CONST_FALSE }, + { "true", SHORTVER(5,39), &XS_builtin_true, &ck_builtin_const, BUILTIN_CONST_TRUE, false }, + { "false", SHORTVER(5,39), &XS_builtin_false, &ck_builtin_const, BUILTIN_CONST_FALSE, false }, + { "inf", NO_BUNDLE, &XS_builtin_inf, &ck_builtin_const, BUILTIN_CONST_INF, true }, + { "nan", NO_BUNDLE, &XS_builtin_nan, &ck_builtin_const, BUILTIN_CONST_NAN, true }, /* unary functions */ - { "builtin::is_bool", &XS_builtin_func1_scalar, &ck_builtin_func1, OP_IS_BOOL }, - { "builtin::weaken", &XS_builtin_func1_void, &ck_builtin_func1, OP_WEAKEN }, - { "builtin::unweaken", &XS_builtin_func1_void, &ck_builtin_func1, OP_UNWEAKEN }, - { "builtin::is_weak", &XS_builtin_func1_scalar, &ck_builtin_func1, OP_IS_WEAK }, - { "builtin::blessed", &XS_builtin_func1_scalar, &ck_builtin_func1, OP_BLESSED }, - { "builtin::refaddr", &XS_builtin_func1_scalar, &ck_builtin_func1, OP_REFADDR }, - { "builtin::reftype", &XS_builtin_func1_scalar, &ck_builtin_func1, OP_REFTYPE }, - { "builtin::ceil", &XS_builtin_func1_scalar, &ck_builtin_func1, OP_CEIL }, - { "builtin::floor", &XS_builtin_func1_scalar, &ck_builtin_func1, OP_FLOOR }, - { "builtin::is_tainted", &XS_builtin_func1_scalar, &ck_builtin_func1, OP_IS_TAINTED }, - { "builtin::trim", &XS_builtin_trim, &ck_builtin_func1, 0 }, + { "is_bool", NO_BUNDLE, &XS_builtin_func1_scalar, &ck_builtin_func1, OP_IS_BOOL, true }, + { "weaken", SHORTVER(5,39), &XS_builtin_func1_void, &ck_builtin_func1, OP_WEAKEN, false }, + { "unweaken", SHORTVER(5,39), &XS_builtin_func1_void, &ck_builtin_func1, OP_UNWEAKEN, false }, + { "is_weak", SHORTVER(5,39), &XS_builtin_func1_scalar, &ck_builtin_func1, OP_IS_WEAK, false }, + { "blessed", SHORTVER(5,39), &XS_builtin_func1_scalar, &ck_builtin_func1, OP_BLESSED, false }, + { "refaddr", SHORTVER(5,39), &XS_builtin_func1_scalar, &ck_builtin_func1, OP_REFADDR, false }, + { "reftype", SHORTVER(5,39), &XS_builtin_func1_scalar, &ck_builtin_func1, OP_REFTYPE, false }, + { "ceil", SHORTVER(5,39), &XS_builtin_func1_scalar, &ck_builtin_func1, OP_CEIL, false }, + { "floor", SHORTVER(5,39), &XS_builtin_func1_scalar, &ck_builtin_func1, OP_FLOOR, false }, + { "is_tainted", SHORTVER(5,39), &XS_builtin_func1_scalar, &ck_builtin_func1, OP_IS_TAINTED, false }, + { "trim", SHORTVER(5,39), &XS_builtin_trim, &ck_builtin_func1, 0, false }, + { "stringify", NO_BUNDLE, &XS_builtin_func1_scalar, &ck_builtin_func1, OP_STRINGIFY, true }, - { "builtin::created_as_string", &XS_builtin_created_as_string, &ck_builtin_func1, 0 }, - { "builtin::created_as_number", &XS_builtin_created_as_number, &ck_builtin_func1, 0 }, + { "created_as_string", NO_BUNDLE, &XS_builtin_created_as_string, &ck_builtin_func1, 0, true }, + { "created_as_number", NO_BUNDLE, &XS_builtin_created_as_number, &ck_builtin_func1, 0, true }, + + { "load_module", NO_BUNDLE, &XS_builtin_load_module, &ck_builtin_func1, 0, true }, /* list functions */ - { "builtin::indexed", &XS_builtin_indexed, &ck_builtin_funcN, 0 }, - { "builtin::export_lexically", &XS_builtin_export_lexically, NULL, 0 }, - { 0 } + { "indexed", SHORTVER(5,39), &XS_builtin_indexed, &ck_builtin_funcN, 0, false }, + { "export_lexically", NO_BUNDLE, &XS_builtin_export_lexically, NULL, 0, true }, + + { NULL, 0, NULL, NULL, 0, false } }; +static bool S_parse_version(const char *vstr, const char *vend, UV *vmajor, UV *vminor) +{ + /* Parse a string like "5.35" to yield 5 and 35. Ignores an optional + * trailing third component e.g. "5.35.7". Returns false on parse errors. + */ + + const char *end = vend; + if (!grok_atoUV(vstr, vmajor, &end)) + return FALSE; + + vstr = end; + if (*vstr++ != '.') + return FALSE; + + end = vend; + if (!grok_atoUV(vstr, vminor, &end)) + return FALSE; + + if(*vminor > 255) + return FALSE; + + vstr = end; + + if(vstr[0] == '.') { + vstr++; + + UV _dummy; + if(!grok_atoUV(vstr, &_dummy, &end)) + return FALSE; + if(_dummy > 255) + return FALSE; + + vstr = end; + } + + if(vstr != vend) + return FALSE; + + return TRUE; +} + +#define import_sym(sym) S_import_sym(aTHX_ sym) +static void S_import_sym(pTHX_ SV *sym) +{ + SV *ampname = sv_2mortal(Perl_newSVpvf(aTHX_ "&%" SVf, SVfARG(sym))); + SV *fqname = sv_2mortal(Perl_newSVpvf(aTHX_ "builtin::%" SVf, SVfARG(sym))); + + CV *cv = get_cv(SvPV_nolen(fqname), SvUTF8(fqname) ? SVf_UTF8 : 0); + if(!cv) + Perl_croak(aTHX_ builtin_not_recognised, sym); + + export_lexical(ampname, (SV *)cv); +} + +#define cv_is_builtin(cv) S_cv_is_builtin(aTHX_ cv) +static bool S_cv_is_builtin(pTHX_ CV *cv) +{ + char *file = CvFILE(cv); + return file && strEQ(file, __FILE__); +} + +void +Perl_import_builtin_bundle(pTHX_ U16 ver) +{ + SV *ampname = sv_newmortal(); + + for(int i = 0; builtins[i].name; i++) { + sv_setpvf(ampname, "&%s", builtins[i].name); + + bool want = (builtins[i].since_ver <= ver); + + bool got = false; + PADOFFSET off = pad_findmy_sv(ampname, 0); + CV *cv; + if(off != NOT_IN_PAD && + SvTYPE((cv = (CV *)PL_curpad[off])) == SVt_PVCV && + cv_is_builtin(cv)) + got = true; + + if(!got && want) { + import_sym(newSVpvn_flags(builtins[i].name, strlen(builtins[i].name), SVs_TEMP)); + } + } +} + XS(XS_builtin_import); XS(XS_builtin_import) { @@ -523,17 +742,30 @@ XS(XS_builtin_import) for(int i = 1; i < items; i++) { SV *sym = ST(i); - if(strEQ(SvPV_nolen(sym), "import")) + STRLEN symlen; + const char *sympv = SvPV(sym, symlen); + if(strEQ(sympv, "import")) Perl_croak(aTHX_ builtin_not_recognised, sym); - SV *ampname = sv_2mortal(Perl_newSVpvf(aTHX_ "&%" SVf, SVfARG(sym))); - SV *fqname = sv_2mortal(Perl_newSVpvf(aTHX_ "builtin::%" SVf, SVfARG(sym))); + if(sympv[0] == ':') { + UV vmajor, vminor; + if(!S_parse_version(sympv + 1, sympv + symlen, &vmajor, &vminor)) + Perl_croak(aTHX_ "Invalid version bundle %" SVf_QUOTEDPREFIX, sym); + + U16 want_ver = SHORTVER(vmajor, vminor); + + if(want_ver < SHORTVER(5,39) || + /* round up devel version to next major release; e.g. 5.39 => 5.40 */ + want_ver > SHORTVER(PERL_REVISION, PERL_VERSION + (PERL_VERSION % 2))) + Perl_croak(aTHX_ "Builtin version bundle \"%s\" is not supported by Perl " PERL_VERSION_STRING, + sympv); - CV *cv = get_cv(SvPV_nolen(fqname), SvUTF8(fqname) ? SVf_UTF8 : 0); - if(!cv) - Perl_croak(aTHX_ builtin_not_recognised, sym); + import_builtin_bundle(want_ver); + + continue; + } - export_lexical(ampname, (SV *)cv); + import_sym(sym); } finish_export_lexical(); @@ -551,9 +783,23 @@ Perl_boot_core_builtin(pTHX) proto = ""; else if(builtin->checker == &ck_builtin_func1) proto = "$"; + else if(builtin->checker == &ck_builtin_funcN) + proto = "@"; - CV *cv = newXS_flags(builtin->name, builtin->xsub, __FILE__, proto, 0); + SV *name = newSVpvs_flags("builtin::", SVs_TEMP); + sv_catpv(name, builtin->name); + CV *cv = newXS_flags(SvPV_nolen(name), builtin->xsub, __FILE__, proto, 0); XSANY.any_i32 = builtin->ckval; + + if ( builtin->xsub == &XS_builtin_func1_void + || builtin->xsub == &XS_builtin_func1_scalar) + { + /* these XS functions just call out to the relevant pp() + * functions, so they must operate with a reference-counted + * stack if the pp() do too. + */ + CvXS_RCSTACK_on(cv); + } if(builtin->checker) { cv_set_call_checker_flags(cv, builtin->checker, newSVuv(PTR2UV(builtin)), 0); Index: gnu/usr.bin/perl/charclass_invlists.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/charclass_invlists.h,v diff -u -p -a -u -p -r1.7 charclass_invlists.h --- gnu/usr.bin/perl/charclass_invlists.h 14 May 2024 19:38:53 -0000 1.7 +++ gnu/usr.bin/perl/charclass_invlists.h 22 Jan 2025 00:37:42 -0000 @@ -436078,7 +436078,7 @@ static const U8 WB_table[23][23] = { * 3f4f32ed2a577344a508114527e721d7a8b633d32f38945d47fe0c743650c585 lib/unicore/extracted/DLineBreak.txt * 710abf2d581ac9c57f244c0834f9d9969d9781e0396adccd330eaae658ac7d6b lib/unicore/extracted/DNumType.txt * 6bd30f385f3baf3ab5d5308c111a81de87bea5f494ba0ba69e8ab45263b8c34d lib/unicore/extracted/DNumValues.txt - * f7265069b38ba9a0675a18600e241b1ec6fc8c55fd806fe4c13bc5d8cb0dc508 lib/unicore/mktables + * 8968a5ee00063fa31ff15474b95ccb6b9c228e3ebad6c20bc77f4225187e2023 lib/unicore/mktables * 55d90fdc3f902e5c0b16b3378f9eaa36e970a1c09723c33de7d47d0370044012 lib/unicore/version * 0a6b5ab33bb1026531f816efe81aea1a8ffcd34a27cbea37dd6a70a63d73c844 regen/charset_translations.pl * c7ff8e0d207d3538c7feb4a1a152b159e5e902d20293b303569ea8323e84633e regen/mk_PL_charclass.pl Index: gnu/usr.bin/perl/class.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/class.c,v diff -u -p -a -u -p -r1.1.1.1 class.c --- gnu/usr.bin/perl/class.c 14 May 2024 19:36:27 -0000 1.1.1.1 +++ gnu/usr.bin/perl/class.c 22 Jan 2025 00:37:42 -0000 @@ -47,7 +47,6 @@ Perl_newSVobject(pTHX_ Size_t fieldcount PP(pp_initfield) { - dSP; UNOP_AUX_item *aux = cUNOP_AUX->op_aux; SV *self = PAD_SVl(PADIX_SELF); @@ -62,8 +61,10 @@ PP(pp_initfield) switch(PL_op->op_private & (OPpINITFIELD_AV|OPpINITFIELD_HV)) { case 0: - if(PL_op->op_flags & OPf_STACKED) - val = newSVsv(POPs); + if(PL_op->op_flags & OPf_STACKED) { + val = newSVsv(*PL_stack_sp); + rpp_popfree_1(); + } else val = newSV(0); break; @@ -73,15 +74,15 @@ PP(pp_initfield) AV *av; if(PL_op->op_flags & OPf_STACKED) { SV **svp = PL_stack_base + POPMARK + 1; - STRLEN count = SP - svp + 1; + STRLEN count = PL_stack_sp - svp + 1; av = newAV_alloc_x(count); - av_extend(av, count); - while(svp <= SP) { + while(svp <= PL_stack_sp) { av_push_simple(av, newSVsv(*svp)); svp++; } + rpp_popfree_to(PL_stack_sp - count); } else av = newAV(); @@ -94,18 +95,19 @@ PP(pp_initfield) HV *hv = newHV(); if(PL_op->op_flags & OPf_STACKED) { SV **svp = PL_stack_base + POPMARK + 1; - STRLEN svcount = SP - svp + 1; + STRLEN svcount = PL_stack_sp - svp + 1; if(svcount % 2) Perl_warner(aTHX_ packWARN(WARN_MISC), "Odd number of elements in hash field initialization"); - while(svp <= SP) { + while(svp <= PL_stack_sp) { SV *key = *svp; svp++; - SV *val = svp <= SP ? *svp : &PL_sv_undef; svp++; + SV *val = svp <= PL_stack_sp ? *svp : &PL_sv_undef; svp++; (void)hv_store_ent(hv, key, newSVsv(val), 0); } + rpp_popfree_to(PL_stack_sp - svcount); } val = (SV *)hv; break; @@ -121,7 +123,7 @@ PP(pp_initfield) save_freesv(sv); } - RETURN; + return NORMAL; } XS(injected_constructor); @@ -138,13 +140,18 @@ XS(injected_constructor) Perl_warn(aTHX_ "Odd number of arguments passed to %" HvNAMEf_QUOTEDPREFIX " constructor", HvNAMEfARG(stash)); + if (!aux->xhv_class_initfields_cv) { + Perl_croak(aTHX_ "Cannot create an object of incomplete class %" HvNAMEf_QUOTEDPREFIX, + HvNAMEfARG(stash)); + } + HV *params = NULL; { /* Set up params HV */ params = newHV(); SAVEFREESV((SV *)params); - for(I32 i = 1; i < items; i += 2) { + for(SSize_t i = 1; i < items; i += 2) { SV *name = ST(i); SV *val = (i+1 < items) ? ST(i+1) : &PL_sv_undef; @@ -239,7 +246,9 @@ XS(injected_constructor) /* TODO: People would probably expect to find this in pp.c ;) */ PP(pp_methstart) { - SV *self = av_shift(GvAV(PL_defgv)); + /* note that if AvREAL(@_), be careful not to leak self: + * so keep it in @_ for now, and only shift it later */ + SV *self = *(av_fetch(GvAV(PL_defgv), 0, 1)); SV *rv = NULL; /* pp_methstart happens before the first OP_NEXTSTATE of the method body, @@ -297,6 +306,11 @@ PP(pp_methstart) } } + /* safe to shift and free self now */ + self = av_shift(GvAV(PL_defgv)); + if (AvREAL(GvAV(PL_defgv))) + SvREFCNT_dec_NN(self); + if(PL_op->op_private & OPpINITFIELDS) { SV *params = *av_fetch(GvAV(PL_defgv), 0, 0); if(params && SvTYPE(params) == SVt_PVHV) { @@ -438,15 +452,10 @@ static const char *S_split_package_ver(p #define ensure_module_version(module, version) S_ensure_module_version(aTHX_ module, version) static void S_ensure_module_version(pTHX_ SV *module, SV *version) { - dSP; - ENTER; - PUSHMARK(SP); - PUSHs(module); - PUSHs(version); - PUTBACK; - + PUSHMARK(PL_stack_sp); + rpp_xpush_2(module, version); call_method("VERSION", G_VOID); LEAVE; @@ -485,6 +494,8 @@ static void S_split_attr_nameval(pTHX_ S if(value_max >= value_at) *valp = sv_2mortal(newSVpvn_utf8(value_at, value_max - value_at + 1, do_utf8)); + else + *valp = NULL; } else { *namp = sv; @@ -508,7 +519,7 @@ apply_class_attribute_isa(pTHX_ HV *stas croak("Class already has a superclass, cannot add another"); HV *superstash = gv_stashsv(superclassname, 0); - if(!superstash) { + if (!superstash || !HvSTASH_IS_CLASS(superstash)) { /* Try to `require` the module then attempt a second time */ load_module(PERL_LOADMOD_NOIMPORT, newSVsv(superclassname), NULL, NULL); superstash = gv_stashsv(superclassname, 0); @@ -570,7 +581,7 @@ static struct { .requires_value = true, .apply = &apply_class_attribute_isa, }, - {0} + { NULL, false, NULL } }; static void @@ -622,16 +633,6 @@ Perl_class_apply_attributes(pTHX_ HV *st op_free(attrlist); } -static OP * -S_newCROAKOP(pTHX_ SV *message) -{ - OP *o = newLISTOP(OP_LIST, 0, - newOP(OP_PUSHMARK, 0), - newSVOP(OP_CONST, 0, message)); - return op_convert_list(OP_DIE, 0, o); -} -#define newCROAKOP(message) S_newCROAKOP(aTHX_ message) - void Perl_class_seal_stash(pTHX_ HV *stash) { @@ -640,8 +641,8 @@ Perl_class_seal_stash(pTHX_ HV *stash) assert(HvSTASH_IS_CLASS(stash)); struct xpvhv_aux *aux = HvAUX(stash); - /* generate initfields CV */ - { + if (PL_parser->error_count == 0) { + /* generate initfields CV */ I32 floor_ix = PL_savestack_ix; SAVEI32(PL_subline); save_item(PL_subname); @@ -678,20 +679,17 @@ Perl_class_seal_stash(pTHX_ HV *stash) struct xpvhv_aux *superaux = HvAUX(superstash); /* Build an OP_ENTERSUB */ - OP *o = NULL; - o = op_append_list(OP_LIST, o, - newPADxVOP(OP_PADSV, 0, PADIX_SELF)); - o = op_append_list(OP_LIST, o, - newPADxVOP(OP_PADHV, OPf_REF, PADIX_PARAMS)); - /* TODO: This won't work at all well under `use threads` because - * it embeds the CV * to the superclass initfields CV right into - * the optree. Maybe we'll have to pop it in the pad or something - */ - o = op_append_list(OP_LIST, o, - newSVOP(OP_CONST, 0, (SV *)superaux->xhv_class_initfields_cv)); + OP *o = newLISTOPn(OP_ENTERSUB, OPf_WANT_VOID|OPf_STACKED, + newPADxVOP(OP_PADSV, 0, PADIX_SELF), + newPADxVOP(OP_PADHV, OPf_REF, PADIX_PARAMS), + /* TODO: This won't work at all well under `use threads` because + * it embeds the CV * to the superclass initfields CV right into + * the optree. Maybe we'll have to pop it in the pad or something + */ + newSVOP(OP_CONST, 0, (SV *)superaux->xhv_class_initfields_cv), + NULL); - ops = op_append_list(OP_LINESEQ, ops, - op_convert_list(OP_ENTERSUB, OPf_WANT_VOID|OPf_STACKED, o)); + ops = op_append_list(OP_LINESEQ, ops, o); } PADNAMELIST *fieldnames = aux->xhv_class_fields; @@ -712,7 +710,6 @@ Perl_class_seal_stash(pTHX_ HV *stash) /* have to clear the OPf_KIDS flag or op_free() will get upset */ valop->op_flags &= ~OPf_KIDS; op_free(valop); - assert(valop->op_type == OP_FREED); OP *fieldcop = o; assert(fieldcop->op_type == OP_NEXTSTATE || fieldcop->op_type == OP_DBSTATE); @@ -731,11 +728,14 @@ Perl_class_seal_stash(pTHX_ HV *stash) switch(sigil) { case '$': if(paramname) { - if(!valop) - valop = newCROAKOP( + if(!valop) { + SV *message = newSVpvf("Required parameter '%" SVf "' is missing for %" HvNAMEf_QUOTEDPREFIX " constructor", - SVfARG(paramname), HvNAMEfARG(stash)) - ); + SVfARG(paramname), HvNAMEfARG(stash)); + valop = newLISTOPn(OP_DIE, 0, + newSVOP(OP_CONST, 0, message), + NULL); + } OP *helemop = newBINOP(OP_HELEM, 0, @@ -776,7 +776,8 @@ Perl_class_seal_stash(pTHX_ HV *stash) } UNOP_AUX_item *aux; - Newx(aux, 2, UNOP_AUX_item); + aux = (UNOP_AUX_item *)PerlMemShared_malloc( + sizeof(UNOP_AUX_item) * 2); aux[0].uv = fieldix; @@ -800,6 +801,16 @@ Perl_class_seal_stash(pTHX_ HV *stash) aux->xhv_class_initfields_cv = initfields; } + else { + /* we had errors, clean up and don't populate initfields */ + PADNAMELIST *fieldnames = aux->xhv_class_fields; + if (fieldnames) { + for(SSize_t i = PadnamelistMAX(fieldnames); i >= 0 ; i--) { + PADNAME *pn = PadnamelistARRAY(fieldnames)[i]; + op_free(PadnameFIELDINFO(pn)->defop); + } + } + } } void @@ -847,6 +858,13 @@ Perl_class_wrap_method_body(pTHX_ OP *o) if(!o) return o; + /* Walk the pad of this CV looking for lexicals with field info. These + * will be the fields used by this particular method, which we build into + * a list for the OP_METHSTART op. This ensures we only set up the fields + * needed by this particular method body, rather than every available + * field in the whole class + */ + PADNAMELIST *pnl = PadlistNAMES(CvPADLIST(PL_compcv)); AV *fieldmap = newAV(); @@ -863,14 +881,17 @@ Perl_class_wrap_method_body(pTHX_ OP *o) if(fieldix > max_fieldix) max_fieldix = fieldix; - av_push(fieldmap, newSVuv(padix)); - av_push(fieldmap, newSVuv(fieldix)); + av_push_simple(fieldmap, newSVuv(padix)); + av_push_simple(fieldmap, newSVuv(fieldix)); } UNOP_AUX_item *aux = NULL; if(av_count(fieldmap)) { - Newx(aux, 2 + av_count(fieldmap), UNOP_AUX_item); + aux = (UNOP_AUX_item *)PerlMemShared_malloc( + sizeof(UNOP_AUX_item) + * (2 + av_count(fieldmap)) + ); UNOP_AUX_item *ap = aux; @@ -946,6 +967,88 @@ apply_field_attribute_param(pTHX_ PADNAM (void)hv_store_ent(aux->xhv_class_param_map, value, newSVuv(PadnameFIELDINFO(pn)->fieldix), 0); } +static void +apply_field_attribute_reader(pTHX_ PADNAME *pn, SV *value) +{ + if(value) + SvREFCNT_inc(value); + else + /* Default to name minus the sigil */ + value = newSVpvn_utf8(PadnamePV(pn) + 1, PadnameLEN(pn) - 1, PadnameUTF8(pn)); + + PADOFFSET fieldix = PadnameFIELDINFO(pn)->fieldix; + + I32 floor_ix = start_subparse(FALSE, 0); + SAVEFREESV(PL_compcv); + + I32 save_ix = block_start(TRUE); + + PADOFFSET padix; + + padix = pad_add_name_pvs("$self", 0, NULL, NULL); + assert(padix == PADIX_SELF); + + padix = pad_add_name_pvn(PadnamePV(pn), PadnameLEN(pn), 0, NULL, NULL); + intro_my(); + + OP *methstartop; + { + UNOP_AUX_item *aux; + aux = (UNOP_AUX_item *)PerlMemShared_malloc( + sizeof(UNOP_AUX_item) * (2 + 2)); + + UNOP_AUX_item *ap = aux; + (ap++)->uv = 1; /* fieldcount */ + (ap++)->uv = fieldix; /* max_fieldix */ + + (ap++)->uv = padix; + (ap++)->uv = fieldix; + + methstartop = newUNOP_AUX(OP_METHSTART, 0, NULL, aux); + } + + OP *argcheckop; + { + struct op_argcheck_aux *aux = (struct op_argcheck_aux *) + PerlMemShared_malloc(sizeof(*aux)); + + aux->params = 0; + aux->opt_params = 0; + aux->slurpy = 0; + + argcheckop = newUNOP_AUX(OP_ARGCHECK, 0, NULL, (UNOP_AUX_item *)aux); + } + + OP *retop; + { + OPCODE optype = 0; + switch(PadnamePV(pn)[0]) { + case '$': optype = OP_PADSV; break; + case '@': optype = OP_PADAV; break; + case '%': optype = OP_PADHV; break; + default: NOT_REACHED; + } + + retop = newLISTOP(OP_RETURN, 0, + newOP(OP_PUSHMARK, 0), + newPADxVOP(optype, 0, padix)); + } + + OP *ops = newLISTOPn(OP_LINESEQ, 0, + methstartop, + argcheckop, + retop, + NULL); + + SvREFCNT_inc(PL_compcv); + ops = block_end(save_ix, ops); + + OP *nameop = newSVOP(OP_CONST, 0, value); + + CV *cv = newATTRSUB(floor_ix, nameop, NULL, NULL, ops); + CvIsMETHOD_on(cv); +} + static struct { const char *name; bool requires_value; @@ -955,7 +1058,11 @@ static struct { .requires_value = false, .apply = &apply_field_attribute_param, }, - {0} + { .name = "reader", + .requires_value = false, + .apply = &apply_field_attribute_reader, + }, + { NULL, false, NULL } }; static void @@ -1016,10 +1123,12 @@ Perl_class_set_field_defop(pTHX_ PADNAME assert(HvSTASH_IS_CLASS(PL_curstash)); - forbid_outofblock_ops(defop, "field initialiser expression"); + op_free(PadnameFIELDINFO(pn)->defop); - if(PadnameFIELDINFO(pn)->defop) - op_free(PadnameFIELDINFO(pn)->defop); + /* set here to ensure clean up if forbid_outofblock_ops() throws */ + PadnameFIELDINFO(pn)->defop = defop; + + forbid_outofblock_ops(defop, "field initialiser expression"); char sigil = PadnamePV(pn)[0]; switch(sigil) { @@ -1057,6 +1166,28 @@ Perl_class_add_ADJUST(pTHX_ HV *stash, C aux->xhv_class_adjust_blocks = newAV(); av_push(aux->xhv_class_adjust_blocks, (SV *)cv); +} + +OP * +Perl_ck_classname(pTHX_ OP *o) +{ + if(!CvIsMETHOD(PL_compcv)) + croak("Cannot use __CLASS__ outside of a method or field initializer expression"); + + return o; +} + +PP(pp_classname) +{ + dTARGET; + + SV *self = PAD_SVl(PADIX_SELF); + assert(SvTYPE(SvRV(self)) == SVt_PVOBJ); + + rpp_xpush_1(TARG); + sv_ref(TARG, SvRV(self), true); + + return NORMAL; } /* Index: gnu/usr.bin/perl/config_h.SH =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/config_h.SH,v diff -u -p -a -u -p -r1.25 config_h.SH --- gnu/usr.bin/perl/config_h.SH 14 May 2024 19:38:53 -0000 1.25 +++ gnu/usr.bin/perl/config_h.SH 22 Jan 2025 00:37:42 -0000 @@ -3178,10 +3178,16 @@ sed <$CONFIG_H -e 's!^#und /* HAS_NL_LANGINFO: * This symbol, if defined, indicates that the nl_langinfo routine is - * available to return local data. You will also need + * available to return locale data. You will also need + * and therefore I_LANGINFO. + */ +/* HAS_NL_LANGINFO_L: + * This symbol, if defined, indicates that the nl_langinfo_l routine is + * available to return locale data. You will also need * and therefore I_LANGINFO. */ #$d_nl_langinfo HAS_NL_LANGINFO /**/ +#$d_nl_langinfo_l HAS_NL_LANGINFO_L /**/ /* HAS_OFF64_T: * This symbol will be defined if the C compiler supports off64_t. @@ -3645,6 +3651,31 @@ sed <$CONFIG_H -e 's!^#und */ #$default_inc_excludes_dot DEFAULT_INC_EXCLUDES_DOT /**/ +/* PERL_LC_ALL_USES_NAME_VALUE_PAIRS: + * This symbol, if defined, indicates to the C program that the string + * returned by setlocale(LC_ALL, NULL) uses 'name=value;' pairs to + * indicate what each category's locale is when they aren't all set to the + * same locale. For example, "LC_NUMERIC=C;LC_CTYPE=de_DE;..." + * When not defined, the system uses positional notation. + */ +/* PERL_LC_ALL_SEPARATOR: + * This symbol, if defined, gives the string returned by + * setlocale(LC_ALL, NULL) to separate categories that are in different + * locales on systems that use a positional notation as opposed to + * 'name=value' pairs. An example on some platforms could be the '/' in + * "C/de_DE/C/en_UK/C/C" + */ +/* PERL_LC_ALL_CATEGORY_POSITIONS_INIT: + * This symbol, when defined, gives the C initializer for an array whose + * element [0] is the first category in the string returned by + * setlocale(LC_ALL, NULL) when not all categories are the same, on + * systems that use a positional notation. After element [0] is + * LC_ALL_SEPARATOR, then the category given by element [1] and so on. + */ +#$d_perl_lc_all_uses_name_value_pairs PERL_LC_ALL_USES_NAME_VALUE_PAIRS /**/ +#$d_perl_lc_all_separator PERL_LC_ALL_SEPARATOR $perl_lc_all_separator /**/ +#$d_perl_lc_all_category_positions_init PERL_LC_ALL_CATEGORY_POSITIONS_INIT $perl_lc_all_category_positions_init /**/ + /* USE_DYNAMIC_LOADING: * This symbol, if defined, indicates that dynamic loading of * some sort is available. @@ -4990,17 +5021,6 @@ sed <$CONFIG_H -e 's!^#und * available to convert a multi-byte character into a wide character. */ #$d_mbrtowc HAS_MBRTOWC /**/ - -/* HAS_NL_LANGINFO_L: - * This symbol, when defined, indicates presence of the nl_langinfo_l() - * function - */ -/* HAS_THREAD_SAFE_NL_LANGINFO_L: - * This symbol, when defined, indicates presence of the nl_langinfo_l() - * function, and that it is thread-safe. - */ -#$d_nl_langinfo_l HAS_NL_LANGINFO_L /**/ -#$d_thread_safe_nl_langinfo_l HAS_THREAD_SAFE_NL_LANGINFO_L /**/ /* OLD_PTHREAD_CREATE_JOINABLE: * This symbol, if defined, indicates how to create pthread Index: gnu/usr.bin/perl/configure.com =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/configure.com,v diff -u -p -a -u -p -r1.12 configure.com --- gnu/usr.bin/perl/configure.com 14 May 2024 19:38:53 -0000 1.12 +++ gnu/usr.bin/perl/configure.com 22 Jan 2025 00:37:42 -0000 @@ -1,3 +1,4 @@ + $! OpenVMS configuration procedure for Perl -- do not attempt to run under DOS $ sav_ver = 'F$VERIFY(0)' $ on control_y then goto clean_up @@ -2199,7 +2200,6 @@ $ echo4 "...and architecture name al $ ENDIF $ ENDIF $! -$ bool_dflt = "n" $ vms_prefix = "perl_root" $ vms_prefixup = F$EDIT(vms_prefix,"UPCASE") $! @@ -4050,8 +4050,8 @@ $ WS "#include " $ WS "#include " $ WS "int main()" $ WS "{" -$ WS " long double x = NaN; -$ WS " return isnanl(x) ? EXIT_SUCCESS : EXIT_FAILURE; +$ WS " long double x = NaN;" +$ WS " return isnanl(x) ? EXIT_SUCCESS : EXIT_FAILURE;" $ WS "}" $ CS $ tmp = "isnanl" @@ -4065,8 +4065,8 @@ $ WS "#include " $ WS "#include " $ WS "int main()" $ WS "{" -$ WS " long long x = llrint(1.5); -$ WS " return x == 2 ? EXIT_SUCCESS : EXIT_FAILURE; +$ WS " long long x = llrint(1.5);" +$ WS " return x == 2 ? EXIT_SUCCESS : EXIT_FAILURE;" $ WS "}" $ CS $ tmp = "llrint" @@ -4080,8 +4080,8 @@ $ WS "#include " $ WS "#include " $ WS "int main()" $ WS "{" -$ WS " long long x = llrintl(1.5); -$ WS " return x == 2 ? EXIT_SUCCESS : EXIT_FAILURE; +$ WS " long long x = llrintl(1.5);" +$ WS " return x == 2 ? EXIT_SUCCESS : EXIT_FAILURE;" $ WS "}" $ CS $ tmp = "llrintl" @@ -4095,8 +4095,8 @@ $ WS "#include " $ WS "#include " $ WS "int main()" $ WS "{" -$ WS " long long x = llround(1.5); -$ WS " return x == 2 ? EXIT_SUCCESS : EXIT_FAILURE; +$ WS " long long x = llround(1.5);" +$ WS " return x == 2 ? EXIT_SUCCESS : EXIT_FAILURE;" $ WS "}" $ CS $ tmp = "llround" @@ -4110,8 +4110,8 @@ $ WS "#include " $ WS "#include " $ WS "int main()" $ WS "{" -$ WS " long long x = llroundl(1.5); -$ WS " return x == 2 ? EXIT_SUCCESS : EXIT_FAILURE; +$ WS " long long x = llroundl(1.5);" +$ WS " return x == 2 ? EXIT_SUCCESS : EXIT_FAILURE;" $ WS "}" $ CS $ tmp = "llroundl" @@ -4125,8 +4125,8 @@ $ WS "#include " $ WS "#include " $ WS "int main()" $ WS "{" -$ WS " double x = llroundl(1.5); -$ WS " return x == 2.0 ? EXIT_SUCCESS : EXIT_FAILURE; +$ WS " double x = llroundl(1.5);" +$ WS " return x == 2.0 ? EXIT_SUCCESS : EXIT_FAILURE;" $ WS "}" $ CS $ tmp = "nearbyint" @@ -4140,8 +4140,8 @@ $ WS "#include " $ WS "#include " $ WS "int main()" $ WS "{" -$ WS " double x = round(1.5); -$ WS " return x == 2.0 ? EXIT_SUCCESS : EXIT_FAILURE; +$ WS " double x = round(1.5);" +$ WS " return x == 2.0 ? EXIT_SUCCESS : EXIT_FAILURE;" $ WS "}" $ CS $ tmp = "round" @@ -4155,8 +4155,8 @@ $ WS "#include " $ WS "#include " $ WS "int main()" $ WS "{" -$ WS " double x = scalbn(1.0, 3); -$ WS " return x == 8.0 ? EXIT_SUCCESS : EXIT_FAILURE; +$ WS " double x = scalbn(1.0, 3);" +$ WS " return x == 8.0 ? EXIT_SUCCESS : EXIT_FAILURE;" $ WS "}" $ CS $ tmp = "scalbn" @@ -4170,8 +4170,8 @@ $ WS "#include " $ WS "#include " $ WS "int main()" $ WS "{" -$ WS " long double x = scalbn(1.0, 3); -$ WS " return x == 8.0 ? EXIT_SUCCESS : EXIT_FAILURE; +$ WS " long double x = scalbn(1.0, 3);" +$ WS " return x == 8.0 ? EXIT_SUCCESS : EXIT_FAILURE;" $ WS "}" $ CS $ tmp = "scalbnl" @@ -5091,9 +5091,9 @@ $ OS $ WS "#include " $ WS "#include " $ WS "#if defined(__DECC) || defined(__DECCXX)" -$ WS "#include +$ WS "#include " $ WS "#endif" -$ WS "int main() { +$ WS "int main() {" $ WS "#''uselargefiles' _LARGEFILE" $ WS "#ifdef _LARGEFILE" $ WS " printf(""%d\n"", sizeof(__ino64_t));" @@ -6215,6 +6215,10 @@ $ WC "d_oldpthreads='" + d_oldpthreads + $ WC "d_oldsock='undef'" $ WC "d_open3='define'" $ WC "d_openat='undef'" +$ WC "d_perl_lc_all_category_positions_init='define'" +$ WC "d_perl_lc_all_separator='undef'" +$ WC "d_perl_lc_all_uses_name_value_pairs='undef'" +$ WC "perl_lc_all_category_positions_init='{ 0, 1, 5, 2, 3, 4 }'" $ WC "d_unlinkat='undef'" $ WC "d_renameat='undef'" $ WC "d_linkat='undef'" @@ -6679,6 +6683,8 @@ $ WC "package='" + package + "'" $ WC "pager='" + pager + "'" $ WC "patchlevel='" + patchlevel + "'" $ WC "path_sep='|'" +$ WC "perl_lc_all_category_positions_init='undef'" +$ WC "perl_lc_all_separator='undef'" $ WC "perl_root='" + perl_root + "'" ! VMS specific $trnlnm() $ WC "perladmin='" + perladmin + "'" $ WC "perllibs='" + perllibs + "'" Index: gnu/usr.bin/perl/cop.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cop.h,v diff -u -p -a -u -p -r1.23 cop.h --- gnu/usr.bin/perl/cop.h 14 May 2024 19:38:53 -0000 1.23 +++ gnu/usr.bin/perl/cop.h 22 Jan 2025 00:37:42 -0000 @@ -29,6 +29,8 @@ * GSAR 97-03-27 */ +MSVC_DIAG_IGNORE(4324) + struct jmpenv { struct jmpenv * je_prev; Sigjmp_buf je_buf; /* uninit if je_prev is NULL */ @@ -38,9 +40,11 @@ struct jmpenv { SSize_t je_old_stack_hwm; }; +MSVC_DIAG_RESTORE + typedef struct jmpenv JMPENV; -#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY +#if defined PERL_USE_HWM # define JE_OLD_STACK_HWM_zero PL_start_env.je_old_stack_hwm = 0 # define JE_OLD_STACK_HWM_save(je) \ (je).je_old_stack_hwm = PL_curstackinfo->si_stack_hwm @@ -885,12 +889,14 @@ struct block_format { } STMT_END /* junk in @_ spells trouble when cloning CVs and in pp_caller(), so don't - * leave any (a fast av_clear(ary), basically) */ + * leave any (a fast av_clear(ary), basically). + * New code should probably be using Perl_clear_defarray_simple() + * and/or Perl_clear_defarray() + */ #define CLEAR_ARGARRAY(ary) \ STMT_START { \ - AvMAX(ary) += AvARRAY(ary) - AvALLOC(ary); \ - AvARRAY(ary) = AvALLOC(ary); \ AvFILLp(ary) = -1; \ + av_remove_offset(ary); \ } STMT_END @@ -930,7 +936,7 @@ struct block_loop { IV ix; /* index relative to base of array */ } ary; struct { /* CXt_LOOP_LIST, C */ - I32 basesp; /* first element of list on stack */ + SSize_t basesp; /* first element of list on stack */ IV ix; /* index relative to basesp */ } stack; struct { /* CXt_LOOP_LAZYIV, C */ @@ -989,12 +995,12 @@ struct block { U16 blku_u16; /* used by block_sub and block_eval (so far) */ I32 blku_oldsaveix; /* saved PL_savestack_ix */ /* all the fields above must be aligned with same-sized fields as sbu */ - I32 blku_oldsp; /* current sp floor: where nextstate pops to */ - I32 blku_oldmarksp; /* mark stack index */ + SSize_t blku_oldsp; /* current sp floor: where nextstate pops to */ COP * blku_oldcop; /* old curcop pointer */ PMOP * blku_oldpm; /* values of pattern match vars */ SSize_t blku_old_tmpsfloor; /* saved PL_tmps_floor */ I32 blku_oldscopesp; /* scope stack index */ + I32 blku_oldmarksp; /* mark stack index */ union { struct block_sub blku_sub; @@ -1213,6 +1219,7 @@ struct context { #define G_RE_REPARSING 0x800 /* compiling a run-time /(?{..})/ */ #define G_METHOD_NAMED 0x1000 /* calling named method, eg without :: or ' */ #define G_RETHROW 0x2000 /* eval_sv(): re-throw any error */ +#define G_USEHINTS 0x4000 /* eval_sv(): use current hints/features */ /* flag bits for PL_in_eval */ #define EVAL_NULL 0 /* not in an eval */ @@ -1255,7 +1262,16 @@ struct stackinfo { I32 si_markoff; /* offset where markstack begins for us. * currently used only with DEBUGGING, * but not #ifdef-ed for bincompat */ -#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY + +#ifdef PERL_RC_STACK + /* index of first entry in the argument + stack which is not ref-counted. If + set to 0 (default), all stack + elements are ref-counted */ + I32 si_stack_nonrc_base; +#endif + +#ifdef PERL_USE_HWM /* high water mark: for checking if the stack was correctly extended / * tested for extension by each pp function */ SSize_t si_stack_hwm; @@ -1282,60 +1298,37 @@ typedef struct stackinfo PERL_SI; # define SET_MARK_OFFSET NOOP #endif -#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY +#ifdef PERL_USE_HWM # define PUSHSTACK_INIT_HWM(si) ((si)->si_stack_hwm = 0) #else # define PUSHSTACK_INIT_HWM(si) NOOP #endif +/* for backcompat; use push_stackinfo() instead */ + #define PUSHSTACKi(type) \ - STMT_START { \ - PERL_SI *next = PL_curstackinfo->si_next; \ - DEBUG_l({ \ - int i = 0; PERL_SI *p = PL_curstackinfo; \ - while (p) { i++; p = p->si_prev; } \ - Perl_deb(aTHX_ "push STACKINFO %d in %s at %s:%d\n", \ - i, SAFE_FUNCTION__, __FILE__, __LINE__);}) \ - if (!next) { \ - next = new_stackinfo(32, 2048/sizeof(PERL_CONTEXT) - 1); \ - next->si_prev = PL_curstackinfo; \ - PL_curstackinfo->si_next = next; \ - } \ - next->si_type = type; \ - next->si_cxix = -1; \ - next->si_cxsubix = -1; \ - PUSHSTACK_INIT_HWM(next); \ - AvFILLp(next->si_stack) = 0; \ - SWITCHSTACK(PL_curstack,next->si_stack); \ - PL_curstackinfo = next; \ - SET_MARK_OFFSET; \ + STMT_START { \ + PL_stack_sp = sp; \ + push_stackinfo(type, 0);\ + sp = PL_stack_sp ; \ } STMT_END #define PUSHSTACK PUSHSTACKi(PERLSI_UNKNOWN) -/* POPSTACK works with PL_stack_sp, so it may need to be bracketed by + +/* for backcompat; use pop_stackinfo() instead. + * + * POPSTACK works with PL_stack_sp, so it may need to be bracketed by * PUTBACK/SPAGAIN to flush/refresh any local SP that may be active */ -#define POPSTACK \ - STMT_START { \ - dSP; \ - PERL_SI * const prev = PL_curstackinfo->si_prev; \ - DEBUG_l({ \ - int i = -1; PERL_SI *p = PL_curstackinfo; \ - while (p) { i++; p = p->si_prev; } \ - Perl_deb(aTHX_ "pop STACKINFO %d in %s at %s:%d\n", \ - i, SAFE_FUNCTION__, __FILE__, __LINE__);}) \ - if (!prev) { \ - Perl_croak_popstack(); \ - } \ - SWITCHSTACK(PL_curstack,prev->si_stack); \ - /* don't free prev here, free them all at the END{} */ \ - PL_curstackinfo = prev; \ - } STMT_END + +#define POPSTACK pop_stackinfo() + #define POPSTACK_TO(s) \ STMT_START { \ while (PL_curstack != s) { \ dounwind(-1); \ + rpp_obliterate_stack_to(0); \ POPSTACK; \ } \ } STMT_END Index: gnu/usr.bin/perl/cv.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cv.h,v diff -u -p -a -u -p -r1.21 cv.h --- gnu/usr.bin/perl/cv.h 14 May 2024 19:38:53 -0000 1.21 +++ gnu/usr.bin/perl/cv.h 22 Jan 2025 00:37:43 -0000 @@ -129,7 +129,7 @@ See L. #endif #define CVf_DYNFILE 0x1000 /* The filename is malloced */ #define CVf_AUTOLOAD 0x2000 /* SvPVX contains AUTOLOADed sub name */ -#define CVf_HASEVAL 0x4000 /* contains string eval */ +/* 0x4000 previously CVf_HASEVAL */ #define CVf_NAMED 0x8000 /* Has a name HEK */ #define CVf_LEXICAL 0x10000 /* Omit package from name */ #define CVf_ANONCONST 0x20000 /* :const - create anonconst op */ @@ -138,6 +138,8 @@ See L. #define CVf_IsMETHOD 0x100000 /* CV is a (real) method of a real class. Not to be confused with what used to be called CVf_METHOD; now CVf_NOWARN_AMBIGUOUS */ +#define CVf_XS_RCSTACK 0x200000 /* the XS function understands a + reference-counted stack */ /* This symbol for optimised communication between toke.c and op.c: */ #define CVf_BUILTIN_ATTRS (CVf_NOWARN_AMBIGUOUS|CVf_LVALUE|CVf_ANONCONST) @@ -211,10 +213,6 @@ See L. #define CvAUTOLOAD_on(cv) (CvFLAGS(cv) |= CVf_AUTOLOAD) #define CvAUTOLOAD_off(cv) (CvFLAGS(cv) &= ~CVf_AUTOLOAD) -#define CvHASEVAL(cv) (CvFLAGS(cv) & CVf_HASEVAL) -#define CvHASEVAL_on(cv) (CvFLAGS(cv) |= CVf_HASEVAL) -#define CvHASEVAL_off(cv) (CvFLAGS(cv) &= ~CVf_HASEVAL) - #define CvNAMED(cv) (CvFLAGS(cv) & CVf_NAMED) #define CvNAMED_on(cv) (CvFLAGS(cv) |= CVf_NAMED) #define CvNAMED_off(cv) (CvFLAGS(cv) &= ~CVf_NAMED) @@ -263,6 +261,10 @@ Helper macro to turn off the C stack_max) break; + PerlIO_printf(Perl_debug_log, "%-4s ", SvPEEK(stack_base[i])); + + if (nonrc_base && nonrc_base == i + 1) + PerlIO_printf(Perl_debug_log, "| "); } while (1); PerlIO_printf(Perl_debug_log, "\n"); @@ -182,6 +189,7 @@ S_deb_stack_n(pTHX_ SV** stack_base, I32 PERL_UNUSED_ARG(stack_max); PERL_UNUSED_ARG(mark_min); PERL_UNUSED_ARG(mark_max); + PERL_UNUSED_ARG(nonrc_base); #endif /* DEBUGGING */ } @@ -202,11 +210,17 @@ Perl_debstack(pTHX) return 0; PerlIO_printf(Perl_debug_log, " => "); - deb_stack_n(PL_stack_base, + S_deb_stack_n(aTHX_ PL_stack_base, 0, PL_stack_sp - PL_stack_base, PL_curstackinfo->si_markoff, - PL_markstack_ptr - PL_markstack); + PL_markstack_ptr - PL_markstack, +# ifdef PERL_RC_STACK + PL_curstackinfo->si_stack_nonrc_base +# else + 0 +# endif + ); #endif /* SKIP_DEBUGGING */ @@ -254,8 +268,16 @@ Perl_deb_stack_all(pTHX) si_name_ix < C_ARRAY_LENGTH(si_names) ? si_names[si_name_ix] : "????"; I32 ix; - PerlIO_printf(Perl_debug_log, "STACK %" IVdf ": %s\n", - (IV)si_ix, si_name); + PerlIO_printf(Perl_debug_log, "STACK %" IVdf ": %s%s\n", + (IV)si_ix, si_name, +# ifdef PERL_RC_STACK + AvREAL(si->si_stack) + ? (si->si_stack_nonrc_base ? " (partial real)" : " (real)") + : "" +# else + "" +# endif + ); for (ix=0; ix<=si->si_cxix; ix++) { @@ -335,8 +357,14 @@ Perl_deb_stack_all(pTHX) mark_max = PL_markstack_ptr - PL_markstack; } - deb_stack_n(AvARRAY(si->si_stack), - stack_min, stack_max, mark_min, mark_max); + S_deb_stack_n(aTHX_ AvARRAY(si->si_stack), + stack_min, stack_max, mark_min, mark_max, +# ifdef PERL_RC_STACK + si->si_stack_nonrc_base +# else + 0 +# endif + ); if (CxTYPE(cx) == CXt_EVAL || CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) Index: gnu/usr.bin/perl/doio.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/doio.c,v diff -u -p -a -u -p -r1.26 doio.c --- gnu/usr.bin/perl/doio.c 14 May 2024 19:38:53 -0000 1.26 +++ gnu/usr.bin/perl/doio.c 22 Jan 2025 00:37:44 -0000 @@ -66,6 +66,8 @@ Perl_setfd_cloexec(int fd) assert(fd >= 0); #if defined(HAS_FCNTL) && defined(F_SETFD) && defined(FD_CLOEXEC) (void) fcntl(fd, F_SETFD, FD_CLOEXEC); +#elif !defined(DEBUGGING) + PERL_UNUSED_ARG(fd); #endif } @@ -75,6 +77,8 @@ Perl_setfd_inhexec(int fd) assert(fd >= 0); #if defined(HAS_FCNTL) && defined(F_SETFD) && defined(FD_CLOEXEC) (void) fcntl(fd, F_SETFD, 0); +#elif !defined(DEBUGGING) + PERL_UNUSED_ARG(fd); #endif } @@ -1033,7 +1037,6 @@ S_openn_cleanup(pTHX_ GV *gv, IO *io, Pe (void) PerlIO_close(fp); goto say_false; } -#ifndef PERL_MICRO if (S_ISSOCK(statbuf.st_mode)) IoTYPE(io) = IoTYPE_SOCKET; /* in case a socket was passed in to us */ #ifdef HAS_SOCKET @@ -1050,7 +1053,6 @@ S_openn_cleanup(pTHX_ GV *gv, IO *io, Pe /* but some return 0 for streams too, sigh */ } #endif /* HAS_SOCKET */ -#endif /* !PERL_MICRO */ } /* Eeek - FIXME !!! @@ -1358,6 +1360,36 @@ static const MGVTBL argvout_vtbl = NULL /* svt_local */ }; +static bool +S_is_fork_open(const char *name) { + /* return true if name matches /^\A\s*(\|\s+-|\-\s+|)\s*\z/ */ + while (isSPACE(*name)) + name++; + if (*name == '|') { + ++name; + while (isSPACE(*name)) + name++; + if (*name != '-') + return false; + ++name; + } + else if (*name == '-') { + ++name; + while (isSPACE(*name)) + name++; + if (*name != '|') + return false; + ++name; + } + else + return false; + + while (isSPACE(*name)) + name++; + + return *name == 0; +} + PerlIO * Perl_nextargv(pTHX_ GV *gv, bool nomagicopen) { @@ -1400,11 +1432,22 @@ Perl_nextargv(pTHX_ GV *gv, bool nomagic SvSETMAGIC(GvSV(gv)); PL_oldname = SvPVx(GvSV(gv), oldlen); if (LIKELY(!PL_inplace)) { - if (nomagicopen - ? do_open6(gv, "<", 1, NULL, &GvSV(gv), 1) - : do_open6(gv, PL_oldname, oldlen, NULL, NULL, 0) - ) { - return IoIFP(GvIOp(gv)); + if (nomagicopen) { + if (do_open6(gv, "<", 1, NULL, &GvSV(gv), 1)) { + return IoIFP(GvIOp(gv)); + } + } + else { + if (is_fork_open(PL_oldname)) { + Perl_ck_warner_d(aTHX_ packWARN(WARN_INPLACE), + "Forked open '%s' not meaningful in <>", + PL_oldname); + continue; + } + + if ( do_open6(gv, PL_oldname, oldlen, NULL, NULL, 0) ) { + return IoIFP(GvIOp(gv)); + } } } else { @@ -2225,7 +2268,6 @@ Perl_do_print(pTHX_ SV *sv, PerlIO *fp) I32 Perl_my_stat_flags(pTHX_ const U32 flags) { - dSP; IO *io; GV* gv; @@ -2265,7 +2307,7 @@ Perl_my_stat_flags(pTHX_ const U32 flags == OPpFT_STACKED) return PL_laststatval; else { - SV* const sv = TOPs; + SV* const sv = *PL_stack_sp; const char *s, *d; STRLEN len; if ((gv = MAYBE_DEREF_GV_flags(sv,flags))) { @@ -2302,10 +2344,9 @@ I32 Perl_my_lstat_flags(pTHX_ const U32 flags) { static const char* const no_prev_lstat = "The stat preceding -l _ wasn't an lstat"; - dSP; const char *file; STRLEN len; - SV* const sv = TOPs; + SV* const sv = *PL_stack_sp; bool isio = FALSE; if (PL_op->op_flags & OPf_REF) { if (cGVOP_gv == PL_defgv) { @@ -2566,11 +2607,11 @@ leave: #endif /* OS2 || WIN32 */ -I32 +SSize_t Perl_apply(pTHX_ I32 type, SV **mark, SV **sp) { I32 val; - I32 tot = 0; + SSize_t tot = 0; const char *const what = PL_op_name[type]; const char *s; STRLEN len; @@ -2835,9 +2876,9 @@ nothing in the core. else { Zero(&utbuf, sizeof utbuf, char); #ifdef HAS_FUTIMES - utbuf[0].tv_sec = (long)SvIV(accessed); /* time accessed */ + utbuf[0].tv_sec = (time_t)SvIV(accessed); /* time accessed */ utbuf[0].tv_usec = 0; - utbuf[1].tv_sec = (long)SvIV(modified); /* time modified */ + utbuf[1].tv_sec = (time_t)SvIV(modified); /* time modified */ utbuf[1].tv_usec = 0; #elif defined(BIG_TIME) utbuf.actime = (Time_t)SvNV(accessed); /* time accessed */ @@ -2930,6 +2971,7 @@ Perl_cando(pTHX_ Mode_t mode, bool effec /* Atari stat() does pretty much the same thing. we set x_bit_set_in_stat * too so it will actually look into the files for magic numbers */ + PERL_UNUSED_ARG(effective); return cBOOL(mode & statbufp->st_mode); #else /* ! DOSISH */ @@ -2961,16 +3003,17 @@ Perl_cando(pTHX_ Mode_t mode, bool effec } #endif /* ! VMS */ +#ifndef DOSISH static bool S_ingroup(pTHX_ Gid_t testgid, bool effective) { -#ifndef PERL_IMPLICIT_SYS +# ifndef PERL_IMPLICIT_SYS /* PERL_IMPLICIT_SYS like Win32: getegid() etc. require the context. */ PERL_UNUSED_CONTEXT; -#endif +# endif if (testgid == (effective ? PerlProc_getegid() : PerlProc_getgid())) return TRUE; -#ifdef HAS_GETGROUPS +# ifdef HAS_GETGROUPS { Groups_t *gary = NULL; I32 anum; @@ -2990,10 +3033,11 @@ S_ingroup(pTHX_ Gid_t testgid, bool effe } return rc; } -#else +# else return FALSE; -#endif +# endif } +#endif /* ! DOSISH */ #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) @@ -3183,18 +3227,20 @@ I32 Perl_do_msgsnd(pTHX_ SV **mark, SV **sp) { #ifdef HAS_MSG + PERL_ARGS_ASSERT_DO_MSGSND; + PERL_UNUSED_ARG(sp); + STRLEN len; const I32 id = SvIVx(*++mark); SV * const mstr = *++mark; const I32 flags = SvIVx(*++mark); const char * const mbuf = SvPVbyte(mstr, len); - const I32 msize = len - sizeof(long); - - PERL_ARGS_ASSERT_DO_MSGSND; - PERL_UNUSED_ARG(sp); - if (msize < 0) + if (len < sizeof(long)) Perl_croak(aTHX_ "Arg too short for msgsnd"); + + const STRLEN msize = len - sizeof(long); + SETERRNO(0,0); if (id >= 0 && flags >= 0) { return msgsnd(id, (struct msgbuf *)mbuf, msize, flags); @@ -3211,13 +3257,13 @@ Perl_do_msgsnd(pTHX_ SV **mark, SV **sp) #endif } -I32 +SSize_t Perl_do_msgrcv(pTHX_ SV **mark, SV **sp) { #ifdef HAS_MSG char *mbuf; long mtype; - I32 msize, flags, ret; + I32 flags; const I32 id = SvIVx(*++mark); SV * const mstr = *++mark; @@ -3227,14 +3273,15 @@ Perl_do_msgrcv(pTHX_ SV **mark, SV **sp) /* suppress warning when reading into undef var --jhi */ if (! SvOK(mstr)) SvPVCLEAR(mstr); - msize = SvIVx(*++mark); + SSize_t msize = SvIVx(*++mark); mtype = (long)SvIVx(*++mark); flags = SvIVx(*++mark); - SvPV_force_nolen(mstr); - mbuf = SvGROW(mstr, sizeof(long)+msize+1); + SvPV_force_nomg_nolen(mstr); SETERRNO(0,0); + SSize_t ret; if (id >= 0 && msize >= 0 && flags >= 0) { + mbuf = SvGROW(mstr, sizeof(long)+msize+1); ret = msgrcv(id, (struct msgbuf *)mbuf, msize, mtype, flags); } else { SETERRNO(EINVAL,LIB_INVARG); @@ -3244,9 +3291,11 @@ Perl_do_msgrcv(pTHX_ SV **mark, SV **sp) SvCUR_set(mstr, sizeof(long)+ret); SvPOK_only(mstr); *SvEND(mstr) = '\0'; + SvSETMAGIC(mstr); /* who knows who has been playing with this message? */ SvTAINTED_on(mstr); } + return ret; #else PERL_UNUSED_ARG(sp); Index: gnu/usr.bin/perl/doop.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/doop.c,v diff -u -p -a -u -p -r1.22 doop.c --- gnu/usr.bin/perl/doop.c 14 May 2024 19:38:53 -0000 1.22 +++ gnu/usr.bin/perl/doop.c 22 Jan 2025 00:37:44 -0000 @@ -24,9 +24,7 @@ #include "perl.h" #include "invlist_inline.h" -#ifndef PERL_MICRO #include -#endif /* Helper function for do_trans(). @@ -635,6 +633,13 @@ Perl_do_trans(pTHX_ SV *sv) } } +#ifdef DEBUGGING +/* make it small to exercise the logic */ +# define JOIN_DELIM_BUFSIZE 2 +#else +# define JOIN_DELIM_BUFSIZE 40 +#endif + /* =for apidoc_section $string =for apidoc do_join @@ -660,13 +665,30 @@ Magic and tainting are handled. void Perl_do_join(pTHX_ SV *sv, SV *delim, SV **mark, SV **sp) { + PERL_ARGS_ASSERT_DO_JOIN; + SV ** const oldmark = mark; - I32 items = sp - mark; + SSize_t items = sp - mark; STRLEN len; STRLEN delimlen; - const char * const delims = SvPV_const(delim, delimlen); - - PERL_ARGS_ASSERT_DO_JOIN; + const char * delimpv = SvPV_const(delim, delimlen); + char delim_buf[JOIN_DELIM_BUFSIZE]; + bool delim_do_utf8 = DO_UTF8(delim); + + if (items >= 2) { + /* Make a copy of the delim, since G or A magic may modify the delim SV. + Use a local buffer if possible to avoid the cost of allocation and + clean up. + */ + if (delimlen <= JOIN_DELIM_BUFSIZE) { + Copy(delimpv, delim_buf, delimlen, char); + delimpv = delim_buf; + } + else { + delimpv = savepvn(delimpv, delimlen); + SAVEFREEPV(delimpv); + } + } mark++; len = (items > 0 ? (delimlen * (items - 1) ) : 0); @@ -701,11 +723,11 @@ Perl_do_join(pTHX_ SV *sv, SV *delim, SV } if (delimlen) { - const U32 delimflag = DO_UTF8(delim) ? SV_CATUTF8 : SV_CATBYTES; + const U32 delimflag = delim_do_utf8 ? SV_CATUTF8 : SV_CATBYTES; for (; items > 0; items--,mark++) { STRLEN len; const char *s; - sv_catpvn_flags(sv,delims,delimlen,delimflag); + sv_catpvn_flags(sv, delimpv, delimlen, delimflag); s = SvPV_const(*mark,len); sv_catpvn_flags(sv,s,len, DO_UTF8(*mark) ? SV_CATUTF8 : SV_CATBYTES); @@ -886,7 +908,7 @@ Perl_do_vecset(pTHX_ SV *sv) assert(!(errflags & ~(LVf_NEG_OFF|LVf_OUT_OF_RANGE))); if (errflags & LVf_NEG_OFF) Perl_croak_nocontext("Negative offset to vec in lvalue context"); - Perl_croak_nocontext("Out of memory!"); + Perl_croak_nocontext("Out of memory during vec in lvalue context"); } if (!targ) @@ -916,7 +938,7 @@ Perl_do_vecset(pTHX_ SV *sv) else if (size > 8) { int n = size/8; if (offset > Size_t_MAX / n - 1) /* would overflow */ - Perl_croak_nocontext("Out of memory!"); + Perl_croak_nocontext("Out of memory during vec in lvalue context"); offset *= n; } @@ -1185,8 +1207,7 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV PP(do_kv) { - dSP; - HV * const keys = MUTABLE_HV(POPs); + HV * const keys = MUTABLE_HV(*PL_stack_sp); const U8 gimme = GIMME_V; const I32 dokeys = (PL_op->op_type == OP_KEYS) @@ -1208,8 +1229,10 @@ PP(do_kv) (void)hv_iterinit(keys); /* always reset iterator regardless */ - if (gimme == G_VOID) - RETURN; + if (gimme == G_VOID) { + rpp_popfree_1(); + return NORMAL; + } if (gimme == G_SCALAR) { if (PL_op->op_flags & OPf_MOD || LVRET) { /* lvalue */ @@ -1217,7 +1240,7 @@ PP(do_kv) sv_magic(ret, NULL, PERL_MAGIC_nkeys, NULL, 0); LvTYPE(ret) = 'k'; LvTARG(ret) = SvREFCNT_inc_simple(keys); - PUSHs(ret); + rpp_replace_1_1(ret); } else { IV i; @@ -1235,11 +1258,14 @@ PP(do_kv) i = 0; while (hv_iternext(keys)) i++; } - PUSHi( i ); + TARGi(i,1); + rpp_replace_1_1(targ); } - RETURN; + return NORMAL; } + /* list context only here */ + if (UNLIKELY(PL_op->op_private & OPpMAYBE_LVSUB)) { const I32 flags = is_lvalue_sub(); if (flags && !(flags & OPpENTERSUB_INARGS)) @@ -1247,8 +1273,23 @@ PP(do_kv) Perl_croak(aTHX_ "Can't modify keys in list assignment"); } - PUTBACK; + /* push all keys and/or values onto stack */ +#ifdef PERL_RC_STACK + SSize_t sp_base = PL_stack_sp - PL_stack_base; + hv_pushkv(keys, (dokeys | (dovalues << 1))); + /* Now safe to free the original arg on the stack and shuffle + * down one place anything pushed on top of it */ + SSize_t nitems = PL_stack_sp - (PL_stack_base + sp_base); + SV *old_sv = PL_stack_sp[-nitems]; + if (nitems) + Move(PL_stack_sp - nitems + 1, + PL_stack_sp - nitems, nitems, SV*); + PL_stack_sp--; + SvREFCNT_dec_NN(old_sv); +#else + rpp_popfree_1(); hv_pushkv(keys, (dokeys | (dovalues << 1))); +#endif return NORMAL; } Index: gnu/usr.bin/perl/dump.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/dump.c,v diff -u -p -a -u -p -r1.22 dump.c --- gnu/usr.bin/perl/dump.c 14 May 2024 19:38:53 -0000 1.22 +++ gnu/usr.bin/perl/dump.c 22 Jan 2025 00:37:44 -0000 @@ -1774,7 +1774,6 @@ const struct flag_to_name cv_flags_names {CVf_CVGV_RC, "CVGV_RC,"}, {CVf_DYNFILE, "DYNFILE,"}, {CVf_AUTOLOAD, "AUTOLOAD,"}, - {CVf_HASEVAL, "HASEVAL,"}, {CVf_SLABBED, "SLABBED,"}, {CVf_NAMED, "NAMED,"}, {CVf_LEXICAL, "LEXICAL,"}, @@ -1782,8 +1781,8 @@ const struct flag_to_name cv_flags_names {CVf_ANONCONST, "ANONCONST,"}, {CVf_SIGNATURE, "SIGNATURE,"}, {CVf_REFCOUNTED_ANYSV, "REFCOUNTED_ANYSV,"}, - {CVf_IsMETHOD, "IsMETHOD,"} - + {CVf_IsMETHOD, "IsMETHOD,"}, + {CVf_XS_RCSTACK, "XS_RCSTACK,"} }; const struct flag_to_name hv_flags_names[] = { @@ -2809,12 +2808,18 @@ Perl_hv_dump(pTHX_ HV *hv) int Perl_runops_debug(pTHX) { -#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY +#ifdef PERL_USE_HWM SSize_t orig_stack_hwm = PL_curstackinfo->si_stack_hwm; PL_curstackinfo->si_stack_hwm = PL_stack_sp - PL_stack_base; #endif +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + assert(PL_stack_base + PL_curstackinfo->si_stack_nonrc_base + <= PL_stack_sp); +#endif + if (!PL_op) { Perl_ck_warner_d(aTHX_ packWARN(WARN_DEBUGGING), "NULL OP IN RUN"); return 0; @@ -2824,7 +2829,7 @@ Perl_runops_debug(pTHX) #ifdef PERL_TRACE_OPS ++PL_op_exec_cnt[PL_op->op_type]; #endif -#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY +#ifdef PERL_USE_HWM if (PL_curstackinfo->si_stack_hwm < PL_stack_sp - PL_stack_base) Perl_croak_nocontext( "panic: previous op failed to extend arg stack: " @@ -2862,7 +2867,7 @@ Perl_runops_debug(pTHX) DEBUG_l(Perl_deb(aTHX_ "leaving RUNOPS level\n")); PERL_ASYNC_CHECK(); -#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY +#ifdef PERL_USE_HWM if (PL_curstackinfo->si_stack_hwm < orig_stack_hwm) PL_curstackinfo->si_stack_hwm = orig_stack_hwm; #endif Index: gnu/usr.bin/perl/embed.fnc =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/embed.fnc,v diff -u -p -a -u -p -r1.15 embed.fnc --- gnu/usr.bin/perl/embed.fnc 14 May 2024 19:38:53 -0000 1.15 +++ gnu/usr.bin/perl/embed.fnc 22 Jan 2025 00:37:44 -0000 @@ -14,7 +14,7 @@ : real (full) name, with any appropriate thread context paramaters, thus hiding : that detail from the typical code. : -: Most macros (as opposed to function) listed here are the complete full name. +: Most macros (as opposed to functions) listed here are the complete full name. : : All non-static functions defined by perl need to be listed in this file. : embed.pl uses the entries here to construct: @@ -65,9 +65,6 @@ : backport the fixed version to modules. The only disadvantage khw can think : of is the namespace pollution one. : -: Since we don't require a C compiler to support variadic macros (C99), the -: macros can't be generated in such situations. -: : WARNING: Any macro created in a header file is visible to XS code, unless : care is taken to wrap it within C preprocessor guards like the following : @@ -450,8 +447,7 @@ : characters, and a warning is raised otherwise. This flag suppresses : that warning, so that weird things can be documented : -: 'n' Has no arguments. Perhaps a better name would have been '0'. (used -: only in =for apidoc entries) +: 'n' Has no arguments (used only in =for apidoc entries) : : The macro (it can't be a function) is used without any parameters nor : empty parentheses. @@ -558,6 +554,12 @@ : : 'U' autodoc.pl will not output a usage example : +: 'v' Guard the macro by !MULTIPLICITY || PERL_CORE if it uses __VA_ARGS__. +: This flag exists for backward-compatibility to ensure that code does +: not break when calling older functions without an aTHX in scope. It +: should not be added to newly-added functions as they will have no such +: compatibility issues. +: : 'W' Add a comma_pDEPTH argument to function prototypes, and a comma_aDEPTH argument : to the function calls. This means that under DEBUGGING a depth : argument is added to the functions, which is used for example by the @@ -634,7 +636,7 @@ ETXip |void |append_utf8_from_native_byt |const U8 byte \ |NN U8 **dest : FIXME - this is only called by pp_chown. They should be merged. -p |I32 |apply |I32 type \ +p |SSize_t|apply |I32 type \ |NN SV **mark \ |NN SV **sp Apx |void |apply_attrs_string \ @@ -692,6 +694,8 @@ Adip |void |av_push_simple |NN AV *av |NN SV *val : Used in scope.c, and by Data::Alias EXp |void |av_reify |NN AV *av +ipx |void |av_remove_offset \ + |NN AV *av ARdp |SV * |av_shift |NN AV *av Adp |SV ** |av_store |NN AV *av \ |SSize_t key \ @@ -727,8 +731,8 @@ p |OP * |build_infix_plugin \ |NN OP *lhs \ |NN OP *rhs \ |NN void *tokendata -EXp |char * |_byte_dump_string \ - |NN const U8 * const start \ +EXp |const char *|_byte_dump_string \ + |NULLOK const U8 * const start \ |const STRLEN len \ |const bool format Adp |int |bytes_cmp_utf8 |NN const U8 *b \ @@ -745,7 +749,7 @@ CTdpx |U8 * |bytes_from_utf8_loc \ |NULLOK const U8 **first_unconverted Adpx |U8 * |bytes_to_utf8 |NN const U8 *s \ |NN STRLEN *lenp -AOdp |I32 |call_argv |NN const char *sub_name \ +AOdp |SSize_t|call_argv |NN const char *sub_name \ |I32 flags \ |NN char **argv @@ -758,14 +762,14 @@ Adp |const PERL_CONTEXT *|caller_cx |NULLOK const PERL_CONTEXT **dbcxp Cp |void |call_list |I32 oldscope \ |NN AV *paramList -AOdp |I32 |call_method |NN const char *methname \ +AOdp |SSize_t|call_method |NN const char *methname \ |I32 flags CTadop |Malloc_t|calloc |MEM_SIZE elements \ |MEM_SIZE size -AOdp |I32 |call_pv |NN const char *sub_name \ +AOdp |SSize_t|call_pv |NN const char *sub_name \ + |I32 flags +AOdp |SSize_t|call_sv |NN SV *sv \ |I32 flags -AOdp |I32 |call_sv |NN SV *sv \ - |volatile I32 flags : Used in several source files Rp |bool |cando |Mode_t mode \ |bool effective \ @@ -794,10 +798,10 @@ Adp |OP * |ck_entersub_args_proto_or_lis CPop |bool |ckwarn |U32 w CPop |bool |ckwarn_d |U32 w -Adfp |void |ck_warner |U32 err \ +Adfpv |void |ck_warner |U32 err \ |NN const char *pat \ |... -Adfp |void |ck_warner_d |U32 err \ +Adfpv |void |ck_warner_d |U32 err \ |NN const char *pat \ |... @@ -806,6 +810,8 @@ Adfp |void |ck_warner_d |U32 err \ Cp |void |clear_defarray |NN AV *av \ |bool abandon +Cipx |void |clear_defarray_simple \ + |NN AV *av p |const COP *|closest_cop|NN const COP *cop \ |NULLOK const OP *o \ |NULLOK const OP *curop \ @@ -840,14 +846,18 @@ p |OP * |coresub_op |NN SV * const corea : Used in op.c and perl.c px |void |create_eval_scope \ |NULLOK OP *retop \ + |NN SV **sp \ |U32 flags : croak()'s first parm can be NULL. Otherwise, mod_perl breaks. -Adfpr |void |croak |NULLOK const char *pat \ +Adfprv |void |croak |NULLOK const char *pat \ |... -Tfpr |void |croak_caller |NULLOK const char *pat \ +Tfprv |void |croak_caller |NULLOK const char *pat \ |... CTrs |void |croak_memory_wrap Tpr |void |croak_no_mem +Tpr |void |croak_no_mem_ext \ + |NN const char *context \ + |STRLEN len ATdpr |void |croak_no_modify TXpr |void |croak_popstack Adpr |void |croak_sv |NN SV *baseex @@ -913,7 +923,7 @@ p |void |cv_undef_flags |NN CV *cv \ Cp |void |cx_dump |NN PERL_CONTEXT *cx : Used by CXINC, which appears to be in widespread use CRp |I32 |cxinc -Adfp |void |deb |NN const char *pat \ +Adfpv |void |deb |NN const char *pat \ |... Cdp |I32 |debop |NN const OP *o Cdp |void |debprofdump @@ -941,7 +951,7 @@ ETXdp |char * |delimcpy_no_escape \ |const int delim \ |NN I32 *retlen Cp |void |despatch_signals -Adfpr |OP * |die |NULLOK const char *pat \ +Adfprv |OP * |die |NULLOK const char *pat \ |... Adpr |OP * |die_sv |NN SV *baseex : Used in util.c @@ -1087,7 +1097,7 @@ Adp |void |dump_all p |void |dump_all_perl |bool justperl Adhp |void |dump_eval Adp |void |dump_form |NN const GV *gv -Cfp |void |dump_indent |I32 level \ +Cfpv |void |dump_indent |I32 level \ |NN PerlIO *file \ |NN const char *pat \ |... @@ -1110,8 +1120,11 @@ EXopx |void |emulate_cop_io |NN const CO |NN SV * const sv AOdp |SV * |eval_pv |NN const char *p \ |I32 croak_on_error -AOdp |I32 |eval_sv |NN SV *sv \ +AOdp |SSize_t|eval_sv |NN SV *sv \ |I32 flags +Adfpv |void |fatal_warner |U32 err \ + |NN const char *pat \ + |... Adp |void |fbm_compile |NN SV *sv \ |U32 flags ARdp |char * |fbm_instr |NN unsigned char *big \ @@ -1167,13 +1180,13 @@ Cp |I32 |foldEQ_utf8_flags \ Adpx |void |forbid_outofblock_ops \ |NN OP *o \ |NN const char *blockname -Tp |void |force_locale_unlock +p |void |force_locale_unlock Cp |void |_force_out_malformed_utf8_message \ |NN const U8 * const p \ |NN const U8 * const e \ |const U32 flags \ |const bool die_here -Adfp |char * |form |NN const char *pat \ +Adfpv |char * |form |NN const char *pat \ |... : Only used in perl.c p |void |free_tied_hv_pool @@ -1196,8 +1209,7 @@ eop |void |get_db_sub |NULLOK SV **svp |NN CV *cv ERTXp |const char *|get_deprecated_property_msg \ |const Size_t warning_offset -: Used in mg.c -Tp |int |get_extended_os_errno +MTp |int |get_extended_os_errno : Only used in perl.c p |void |get_hash_seed |NN unsigned char * const seed_buffer AOdp |HV * |get_hv |NN const char *name \ @@ -1762,14 +1774,14 @@ ERXp |HV * |load_charnames |NN SV *char_ |NN const char *context \ |const STRLEN context_len \ |NN const char **error_msg -AFdp |void |load_module |U32 flags \ +AFdpv |void |load_module |U32 flags \ |NN SV *name \ |NULLOK SV *ver \ |... -CTopr |void |locale_panic |NN const char *msg \ - |NN const char *file_name \ - |const line_t line \ - |const int errnum +CTopr |void |locale_panic |NN const char *msg \ + |const line_t immediate_caller_line \ + |NN const char * const higher_caller_file \ + |const line_t higher_caller_line : Used in perly.y p |OP * |localize |NN OP *o \ |I32 lex @@ -1853,7 +1865,7 @@ p |int |magic_getvec |NN SV *sv \ p |int |magic_killbackrefs \ |NN SV *sv \ |NN MAGIC *mg -Fdop |SV * |magic_methcall |NN SV *sv \ +Fdopv |SV * |magic_methcall |NN SV *sv \ |NN const MAGIC *mg \ |NN SV *meth \ |U32 flags \ @@ -1937,11 +1949,11 @@ p |int |magic_wipepack |NN SV *sv \ |NN MAGIC *mg CTadop |Malloc_t|malloc |MEM_SIZE nbytes -Cp |I32 * |markstack_grow +Cp |Stack_off_t *|markstack_grow EXp |int |mbtowc_ |NULLOK const wchar_t *pwc \ |NULLOK const char *s \ |const Size_t len -Adfp |SV * |mess |NN const char *pat \ +Adfpv |SV * |mess |NN const char *pat \ |... Adp |SV * |mess_sv |NN SV *basemsg \ |bool consume @@ -2054,7 +2066,7 @@ Cdp |PerlIO *|my_popen_list |NN const ch Adp |void |my_setenv |NULLOK const char *nam \ |NULLOK const char *val -AMTdfp |int |my_snprintf |NN char *buffer \ +AMTdfpv |int |my_snprintf |NN char *buffer \ |const Size_t len \ |NN const char *format \ |... @@ -2077,18 +2089,6 @@ Adfp |char * |my_strftime |NN const char |int wday \ |int yday \ |int isdst -EXfp |char * |my_strftime8_temp \ - |NN const char *fmt \ - |int sec \ - |int min \ - |int hour \ - |int mday \ - |int mon \ - |int year \ - |int wday \ - |int yday \ - |int isdst \ - |NULLOK utf8ness_t *utf8ness ARTdp |NV |my_strtod |NN const char * const s \ |NULLOK char **e : Used in pp_ctl.c @@ -2097,13 +2097,13 @@ AMTdp |int |my_vsnprintf |NN char *buffe |const Size_t len \ |NN const char *format \ |va_list ap -Ap |OP * |newANONATTRSUB |I32 floor \ +Adp |OP * |newANONATTRSUB |I32 floor \ |NULLOK OP *proto \ |NULLOK OP *attrs \ |NULLOK OP *block -ARp |OP * |newANONHASH |NULLOK OP *o -ARp |OP * |newANONLIST |NULLOK OP *o -Ap |OP * |newANONSUB |I32 floor \ +ARdp |OP * |newANONHASH |NULLOK OP *o +ARdp |OP * |newANONLIST |NULLOK OP *o +Adp |OP * |newANONSUB |I32 floor \ |NULLOK OP *proto \ |NULLOK OP *block ARdp |OP * |newARGDEFELEMOP|I32 flags \ @@ -2129,7 +2129,8 @@ ARdm |AV * |newAV_alloc_x |SSize_t size ARdm |AV * |newAV_alloc_xz |SSize_t size ARdp |AV * |newAVav |NULLOK AV *oav ARdp |AV * |newAVhv |NULLOK HV *ohv -ARp |OP * |newAVREF |NN OP *o +ARdm |AV * |newAV_mortal +ARdp |OP * |newAVREF |NN OP *o ARdp |OP * |newBINOP |I32 type \ |I32 flags \ |NULLOK OP *first \ @@ -2147,7 +2148,7 @@ Adp |CV * |newCONSTSUB_flags \ |STRLEN len \ |U32 flags \ |NULLOK SV *sv -ARp |OP * |newCVREF |I32 flags \ +ARdp |OP * |newCVREF |I32 flags \ |NULLOK OP *o ARdpx |OP * |newDEFEROP |I32 flags \ |NN OP *block @@ -2171,16 +2172,19 @@ ARdp |GV * |newGVgen_flags |NN const cha ARdp |OP * |newGVOP |I32 type \ |I32 flags \ |NN GV *gv -ARp |OP * |newGVREF |I32 type \ +ARdp |OP * |newGVREF |I32 type \ |NULLOK OP *o AMRbdp |HV * |newHV ARdp |HV * |newHVhv |NULLOK HV *hv -ARp |OP * |newHVREF |NN OP *o +ARdp |OP * |newHVREF |NN OP *o AMRbdp |IO * |newIO ARdp |OP * |newLISTOP |I32 type \ |I32 flags \ |NULLOK OP *first \ |NULLOK OP *last +AFRdp |OP * |newLISTOPn |I32 type \ + |I32 flags \ + |... ARdp |OP * |newLOGOP |I32 optype \ |I32 flags \ |NN OP *first \ @@ -2197,7 +2201,7 @@ ARdp |OP * |newMETHOP |I32 type \ ARdp |OP * |newMETHOP_named|I32 type \ |I32 flags \ |NN SV * const_meth -Cp |CV * |newMYSUB |I32 floor \ +Cdp |CV * |newMYSUB |I32 floor \ |NN OP *o \ |NULLOK OP *proto \ |NULLOK OP *attrs \ @@ -2230,6 +2234,10 @@ ARdp |OP * |newSLICEOP |I32 flags \ |NULLOK OP *listop CRp |PERL_SI *|new_stackinfo|I32 stitems \ |I32 cxitems +CRp |PERL_SI *|new_stackinfo_flags \ + |I32 stitems \ + |I32 cxitems \ + |UV flags ARdp |OP * |newSTATEOP |I32 flags \ |NULLOK char *label \ |NULLOK OP *o @@ -2254,7 +2262,7 @@ ARdp |OP * |newSVOP |I32 type \ |NN SV *sv ARdp |SV * |newSVpv |NULLOK const char * const s \ |const STRLEN len -ARdfp |SV * |newSVpvf |NN const char * const pat \ +ARdfpv |SV * |newSVpvf |NN const char * const pat \ |... ARdp |SV * |newSVpvn |NULLOK const char * const buffer \ |const STRLEN len @@ -2266,7 +2274,7 @@ ARdp |SV * |newSVpvn_share |NULLOK const |U32 hash ARdp |SV * |newSVpv_share |NULLOK const char *s \ |U32 hash -ARp |OP * |newSVREF |NN OP *o +ARdp |OP * |newSVREF |NN OP *o Adp |SV * |newSVrv |NN SV * const rv \ |NULLOK const char * const classname AMRbdp |SV * |newSVsv |NULLOK SV * const old @@ -2331,7 +2339,7 @@ AMPTdp |char * |ninstr |NN const char * p |void |no_bareword_filehandle \ |NN const char *fhname -Tefpr |void |noperl_die |NN const char *pat \ +Tefprv |void |noperl_die |NN const char *pat \ |... Adp |int |nothreadhook p |void |notify_parser_that_changed_to_utf8 @@ -2481,6 +2489,11 @@ ATdo |void |perl_free |NN PerlInterprete Cop |const char *|PerlIO_context_layers \ |NULLOK const char *mode +ATdo |const char *|Perl_langinfo \ + |const nl_item item +ATdo |const char *|Perl_langinfo8 \ + |const nl_item item \ + |NN utf8ness_t *utf8ness p |int |PerlLIO_dup2_cloexec \ |int oldfd \ |int newfd @@ -2518,11 +2531,12 @@ p |OP * |pmruntime |NN OP *o \ |NULLOK OP *repl \ |UV flags \ |I32 floor -Xiop |I32 |POPMARK +Xiop |Stack_off_t|POPMARK Cdp |void |pop_scope +Cipx |void |pop_stackinfo : Used in perl.c and toke.c -Fop |void |populate_isa |NN const char *name \ +Fopv |void |populate_isa |NN const char *name \ |STRLEN len \ |... Adhp |REGEXP *|pregcomp |NN SV * const pattern \ @@ -2553,6 +2567,8 @@ Adp |void |ptr_table_store|NN PTR_TBL_t |NULLOK const void * const oldsv \ |NN void * const newsv Cdp |void |push_scope +Cipx |void |push_stackinfo |I32 type \ + |UV flags Adp |char * |pv_display |NN SV *dsv \ |NN const char *pv \ |STRLEN cur \ @@ -2591,7 +2607,7 @@ Adp |REGEXP *|re_compile |NN SV * const |U32 orig_rx_flags Cp |void |reentrant_free Cp |void |reentrant_init -CFTp |void * |reentrant_retry|NN const char *f \ +CFTpv |void * |reentrant_retry|NN const char *f \ |... Cp |void |reentrant_size @@ -2725,7 +2741,7 @@ Xp |REGEXP *|re_op_compile |NULLOK SV ** ATdp |void |repeatcpy |NN char *to \ |NN const char *from \ - |I32 len \ + |SSize_t len \ |IV count : Used in doio.c, pp_hot.c, pp_sys.c p |void |report_evil_fh |NULLOK const GV *gv @@ -2747,6 +2763,65 @@ APTdp |char * |rninstr |NN const char *b |NN const char *little \ |NN const char *lend p |void |rpeep |NULLOK OP *o +Adipx |void |rpp_context |NN SV **mark \ + |U8 gimme \ + |SSize_t extra +Adipx |void |rpp_extend |SSize_t n +Xopx |void |rpp_free_2_ |NN SV * const sv1 \ + |NN SV * const sv2 \ + |const U32 rc1 \ + |const U32 rc2 +Adipx |void |rpp_invoke_xs |NN CV *cv +Adipx |bool |rpp_is_lone |NN SV *sv +Cpx |void |rpp_obliterate_stack_to \ + |I32 ix +Adipx |void |rpp_popfree_1 +Adipx |void |rpp_popfree_2 +Adipx |void |rpp_popfree_1_NN +Adipx |void |rpp_popfree_2_NN +Adipx |void |rpp_popfree_to |NN SV **sp +Adipx |void |rpp_popfree_to_NN \ + |NN SV **sp +Adipx |SV * |rpp_pop_1_norc +Adipx |void |rpp_push_1 |NN SV *sv +Adipx |void |rpp_push_2 |NN SV *sv1 \ + |NN SV *sv2 +Adipx |void |rpp_push_IMM |NN SV *sv +Adipx |void |rpp_push_1_norc|NN SV *sv +Adipx |void |rpp_replace_1_1|NN SV *sv +Adipx |void |rpp_replace_2_1|NN SV *sv +Adipx |void |rpp_replace_at |NN SV **sp \ + |NN SV *sv +Adipx |void |rpp_replace_at_NN \ + |NN SV **sp \ + |NN SV *sv +Adipx |void |rpp_replace_at_norc \ + |NN SV **sp \ + |NN SV *sv +Adipx |void |rpp_replace_at_norc_NN \ + |NN SV **sp \ + |NN SV *sv +Cipx |void |rpp_replace_2_1_COMMON \ + |NN SV *sv +Adipx |void |rpp_replace_1_IMM_NN \ + |NN SV *sv +Adipx |void |rpp_replace_2_IMM_NN \ + |NN SV *sv +Adipx |void |rpp_replace_1_1_NN \ + |NN SV *sv +Adipx |void |rpp_replace_2_1_NN \ + |NN SV *sv +Adipx |bool |rpp_stack_is_rc +Adipx |bool |rpp_try_AMAGIC_1 \ + |int method \ + |int flags +Adipx |bool |rpp_try_AMAGIC_2 \ + |int method \ + |int flags +Adipx |void |rpp_xpush_1 |NN SV *sv +Adipx |void |rpp_xpush_2 |NN SV *sv1 \ + |NN SV *sv2 +Adipx |void |rpp_xpush_IMM |NN SV *sv Adp |Sighandler_t|rsignal |int i \ |Sighandler_t t : Used in pp_sys.c @@ -2923,8 +2998,12 @@ p |void |setfd_cloexec_or_inhexec_by_sys Tp |void |setfd_inhexec |int fd p |void |setfd_inhexec_for_sysfd \ |int fd -Xp |void |set_numeric_standard -Xp |void |set_numeric_underlying +Xp |void |set_numeric_standard \ + |NN const char *file \ + |const line_t caller_line +Xp |void |set_numeric_underlying \ + |NN const char *file \ + |const line_t caller_line Cp |HEK * |share_hek |NN const char *str \ |SSize_t len \ |U32 hash @@ -2973,13 +3052,13 @@ Adp |bool |sv_cat_decode |NN SV *dsv |int tlen Adp |void |sv_catpv |NN SV * const dsv \ |NULLOK const char *sstr -Adfp |void |sv_catpvf |NN SV * const sv \ +Adfpv |void |sv_catpvf |NN SV * const sv \ |NN const char * const pat \ |... Adp |void |sv_catpv_flags |NN SV *dsv \ |NN const char *sstr \ |const I32 flags -Adfp |void |sv_catpvf_mg |NN SV * const sv \ +Adfpv |void |sv_catpvf_mg |NN SV * const sv \ |NN const char * const pat \ |... Adp |void |sv_catpv_mg |NN SV * const dsv \ @@ -3004,7 +3083,7 @@ AMbdp |void |sv_catsv_mg |NN SV *dsv Adp |void |sv_chop |NN SV * const sv \ |NULLOK const char * const ptr : Used only in perl.c -dp |I32 |sv_clean_all +dp |SSize_t|sv_clean_all : Used only in perl.c dp |void |sv_clean_objs Adp |void |sv_clear |NN SV * const orig_sv @@ -3108,7 +3187,7 @@ Adp |void |sv_insert_flags|NN SV * const Adp |IO * |sv_2io |NN SV * const sv Adp |int |sv_isa |NULLOK SV *sv \ |NN const char * const name -ARdpx |bool |sv_isa_sv |NN SV *sv \ +ARdp |bool |sv_isa_sv |NN SV *sv \ |NN SV *namesv Adp |int |sv_isobject |NULLOK SV *sv Adip |IV |SvIV |NN SV *sv @@ -3116,6 +3195,7 @@ CMbp |IV |sv_2iv |NN SV *sv Adp |IV |sv_2iv_flags |NN SV * const sv \ |const I32 flags Adip |IV |SvIV_nomg |NN SV *sv +Adp |SV * |sv_langinfo |const nl_item item Adp |STRLEN |sv_len |NULLOK SV * const sv Adp |STRLEN |sv_len_utf8 |NULLOK SV * const sv Adp |STRLEN |sv_len_utf8_nomg \ @@ -3266,10 +3346,10 @@ Adp |char *|sv_setpv_bufsize \ |NN SV * const sv \ |const STRLEN cur \ |const STRLEN len -Adfp |void |sv_setpvf |NN SV * const sv \ +Adfpv |void |sv_setpvf |NN SV * const sv \ |NN const char * const pat \ |... -Adfp |void |sv_setpvf_mg |NN SV * const sv \ +Adfpv |void |sv_setpvf_mg |NN SV * const sv \ |NN const char * const pat \ |... Cipx |char *|sv_setpv_freshbuf \ @@ -3329,6 +3409,19 @@ Adm |bool |sv_streq |NULLOK SV *sv1 \ Adp |bool |sv_streq_flags |NULLOK SV *sv1 \ |NULLOK SV *sv2 \ |const U32 flags +EXpx |SV * |sv_strftime_ints \ + |NN SV *fmt \ + |int sec \ + |int min \ + |int hour \ + |int mday \ + |int mon \ + |int year \ + |int wday \ + |int yday \ + |int isdst +Adp |SV * |sv_strftime_tm |NN SV *fmt \ + |NN const struct tm *mytm Adp |SV * |sv_string_from_errnum \ |int errnum \ |NULLOK SV *tgtsv @@ -3427,6 +3520,7 @@ Adp |void |sv_vsetpvfn |NN SV * const sv |NULLOK SV ** const svargs \ |const Size_t sv_count \ |NULLOK bool * const maybe_tainted +Cipx |void |switch_argstack|NN AV *to Adp |void |switch_to_global_locale Adp |bool |sync_locale CTop |void |sys_init |NN int *argc \ @@ -3439,18 +3533,16 @@ CTop |void |sys_term Cdp |void |taint_env Cdp |void |taint_proper |NULLOK const char *f \ |NN const char * const s -Apx |void |thread_locale_init -Apx |void |thread_locale_term -Fp |OP * |tied_method |NN SV *methname \ - |NN SV **sp \ +Fpv |OP * |tied_method |NN SV *methname \ + |NN SV **mark \ |NN SV * const sv \ |NN const MAGIC * const mg \ |const U32 flags \ |U32 argc \ |... Xp |SSize_t|tmps_grow_p |SSize_t ix -Xiop |I32 |TOPMARK +Xiop |Stack_off_t|TOPMARK Cm |UV |to_uni_fold |UV c \ |NN U8 *p \ |NN STRLEN *lenp @@ -3620,7 +3712,7 @@ Cp |U8 * |uvoffuni_to_utf8_flags_msgs |UV input_uv \ |const UV flags \ |NULLOK HV **msgs -Cp |U8 * |uvuni_to_utf8 |NN U8 *d \ +CDbp |U8 * |uvuni_to_utf8 |NN U8 *d \ |UV uv EXdpx |bool |validate_proto |NN SV *name \ |NULLOK SV *proto \ @@ -3635,6 +3727,9 @@ Adpr |void |vcroak |NULLOK const char * |NULLOK va_list *args Adp |void |vdeb |NN const char *pat \ |NULLOK va_list *args +Adp |void |vfatal_warner |U32 err \ + |NN const char *pat \ + |NULLOK va_list *args Adp |char * |vform |NN const char *pat \ |NULLOK va_list *args : Used by Data::Alias @@ -3663,12 +3758,11 @@ Adp |void |vwarner |U32 err \ p |I32 |wait4pid |Pid_t pid \ |NN int *statusp \ |int flags -Adfp |void |warn |NN const char *pat \ +Adfpv |void |warn |NN const char *pat \ |... -Adfp |void |warner |U32 err \ +Adfpv |void |warner |U32 err \ |NN const char *pat \ |... -TXp |void |_warn_problematic_locale Adp |void |warn_sv |NN SV *baseex : Used in cop.h RXop |I32 |was_lvalue_sub @@ -3690,9 +3784,10 @@ Adp |void |wrap_op_checker|Optype opcode |NN Perl_check_t *old_checker_p : Used in pp_ctl.c p |void |write_to_stderr|NN SV *msv -Xp |void |xs_boot_epilog |const I32 ax +Xp |void |xs_boot_epilog |const SSize_t ax -FTXop |I32 |xs_handshake |const U32 key \ +FTXopv |Stack_off_t|xs_handshake \ + |const U32 key \ |NN void *v_my_perl \ |NN const char *file \ |... @@ -3754,7 +3849,7 @@ p |I32 |do_ipcget |I32 optype \ |NN SV **mark \ |NN SV **sp : Defined in doio.c, used only in pp_sys.c -p |I32 |do_msgrcv |NN SV **mark \ +p |SSize_t|do_msgrcv |NN SV **mark \ |NN SV **sp : Defined in doio.c, used only in pp_sys.c p |I32 |do_msgsnd |NN SV **mark \ @@ -3767,19 +3862,6 @@ p |I32 |do_shmio |I32 optype \ |NN SV **mark \ |NN SV **sp #endif /* defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) */ -#if defined(HAS_NL_LANGINFO) && defined(PERL_LANGINFO_H) -ATdo |const char *|Perl_langinfo \ - |const nl_item item -ATdo |const char *|Perl_langinfo8 \ - |const nl_item item \ - |NULLOK utf8ness_t *utf8ness -#else -ATdo |const char *|Perl_langinfo \ - |const int item -ATdo |const char *|Perl_langinfo8 \ - |const int item \ - |NULLOK utf8ness_t *utf8ness -#endif #if defined(HAS_PIPE) Rp |int |PerlProc_pipe_cloexec \ |NN int *pipefd @@ -3843,47 +3925,47 @@ pr |int |magic_regdatum_set \ |NN MAGIC *mg #endif #if defined(MULTIPLICITY) -ATdfpr |void |croak_nocontext|NULLOK const char *pat \ +ATdfprv |void |croak_nocontext|NULLOK const char *pat \ |... -ATdfp |void |deb_nocontext |NN const char *pat \ +ATdfpv |void |deb_nocontext |NN const char *pat \ |... -ATdfpr |OP * |die_nocontext |NULLOK const char *pat \ +ATdfprv |OP * |die_nocontext |NULLOK const char *pat \ |... -ATdfp |char * |form_nocontext |NN const char *pat \ +ATdfpv |char * |form_nocontext |NN const char *pat \ |... -AFTdp |void |load_module_nocontext \ +AFTdpv |void |load_module_nocontext \ |U32 flags \ |NN SV *name \ |NULLOK SV *ver \ |... -ATdfp |SV * |mess_nocontext |NN const char *pat \ +ATdfpv |SV * |mess_nocontext |NN const char *pat \ |... Cdop |void * |my_cxt_init |NN int *indexp \ |size_t size -ATdfp |SV * |newSVpvf_nocontext \ +ATdfpv |SV * |newSVpvf_nocontext \ |NN const char * const pat \ |... -ATdfp |void |sv_catpvf_mg_nocontext \ +ATdfpv |void |sv_catpvf_mg_nocontext \ |NN SV * const sv \ |NN const char * const pat \ |... -ATdfp |void |sv_catpvf_nocontext \ +ATdfpv |void |sv_catpvf_nocontext \ |NN SV * const sv \ |NN const char * const pat \ |... -ATdfp |void |sv_setpvf_mg_nocontext \ +ATdfpv |void |sv_setpvf_mg_nocontext \ |NN SV * const sv \ |NN const char * const pat \ |... -ATdfp |void |sv_setpvf_nocontext \ +ATdfpv |void |sv_setpvf_nocontext \ |NN SV * const sv \ |NN const char * const pat \ |... -ATdfp |void |warner_nocontext \ +ATdfpv |void |warner_nocontext \ |U32 err \ |NN const char *pat \ |... -ATdfp |void |warn_nocontext |NN const char *pat \ +ATdfpv |void |warn_nocontext |NN const char *pat \ |... #endif /* defined(MULTIPLICITY) */ #if defined(MYMALLOC) @@ -3993,6 +4075,12 @@ i |bool |PerlEnv_putenv |NN char *str #if defined(PERL_IN_AV_C) S |MAGIC *|get_aux_mg |NN AV *av #endif +#if defined(PERL_IN_BUILTIN_C) || defined(PERL_IN_OP_C) +p |void |finish_export_lexical +p |void |import_builtin_bundle \ + |U16 ver +p |void |prepare_export_lexical +#endif #if defined(PERL_IN_CLASS_C) || defined(PERL_IN_OP_C) || \ defined(PERL_IN_PAD_C) || defined(PERL_IN_PERLY_C) || \ defined(PERL_IN_TOKE_C) @@ -4028,10 +4116,11 @@ Cp |void |croak_kw_unless_class \ defined(PERL_IN_TOKE_C) */ #if defined(PERL_IN_DEB_C) S |void |deb_stack_n |NN SV **stack_base \ - |I32 stack_min \ - |I32 stack_max \ - |I32 mark_min \ - |I32 mark_max + |SSize_t stack_min \ + |SSize_t stack_max \ + |SSize_t mark_min \ + |SSize_t mark_max \ + |SSize_t nonrc_base #endif #if defined(PERL_IN_DOIO_C) S |bool |argvout_final |NN MAGIC *mg \ @@ -4040,8 +4129,7 @@ S |bool |argvout_final |NN MAGIC *mg S |void |exec_failed |NN const char *cmd \ |int fd \ |int do_report -RS |bool |ingroup |Gid_t testgid \ - |bool effective +ST |bool |is_fork_open |NN const char *name S |bool |openn_cleanup |NN GV *gv \ |NN IO *io \ |NULLOK PerlIO *fp \ @@ -4061,6 +4149,10 @@ S |IO * |openn_setup |NN GV *gv \ |NN PerlIO **saveofp \ |NN int *savefd \ |NN char *savetype +# if !defined(DOSISH) +RS |bool |ingroup |Gid_t testgid \ + |bool effective +# endif #endif #if defined(PERL_IN_DOOP_C) RS |Size_t |do_trans_complex \ @@ -4318,74 +4410,135 @@ S |utf8ness_t|get_locale_string_utf8ness |NULLOK const char *string \ |const locale_utf8ness_t known_utf8 \ |NULLOK const char *locale \ - |const unsigned cat_index + |const locale_category_index cat_index +S |void |ints_to_tm |NN struct tm *my_tm \ + |NN const char *locale \ + |int sec \ + |int min \ + |int hour \ + |int mday \ + |int mon \ + |int year \ + |int wday \ + |int yday \ + |int isdst S |bool |is_locale_utf8 |NN const char *locale -# if defined(HAS_LOCALECONV) S |HV * |my_localeconv |const int item -S |void |populate_hash_from_localeconv \ +S |void |populate_hash_from_C_localeconv \ |NN HV *hv \ |NN const char *locale \ |const U32 which_mask \ |NN const lconv_offset_t *strings[2] \ - |NULLOK const lconv_offset_t *integers + |NN const lconv_offset_t *integers[2] +S |bool |strftime8 |NN const char *fmt \ + |NN SV *sv \ + |NN const char *locale \ + |NN const struct tm *mytm \ + |const utf8ness_t fmt_utf8ness \ + |NN utf8ness_t *result_utf8ness \ + |const bool called_externally +Sf |bool |strftime_tm |NN const char *fmt \ + |NN SV *sv \ + |NN const char *locale \ + |NN const struct tm *mytm +S |SV * |sv_strftime_common \ + |NN SV *fmt \ + |NN const char *locale \ + |NN const struct tm *mytm +# if defined(HAS_MISSING_LANGINFO_ITEM_) || !defined(HAS_NL_LANGINFO) +S |const char *|emulate_langinfo \ + |const PERL_INTMAX_T item \ + |NN const char *locale \ + |NN SV *sv \ + |NULLOK utf8ness_t *utf8ness # endif # if defined(USE_LOCALE) -ST |unsigned int|get_category_index \ +S |const char *|calculate_LC_ALL_string \ + |NULLOK const char **category_locales_list \ + |const calc_LC_ALL_format format \ + |const calc_LC_ALL_return returning \ + |const line_t caller_line +S |const char *|external_call_langinfo \ + |const nl_item item \ + |NN SV *sv \ + |NULLOK utf8ness_t *utf8ness +RS |locale_category_index|get_category_index_helper \ |const int category \ - |NULLOK const char *locale -ST |int |get_category_index_nowarn \ - |const int category + |NULLOK bool *success \ + |const line_t caller_line Ri |const char *|mortalized_pv_copy \ |NULLOK const char * const pv -S |void |new_LC_ALL |NULLOK const char *unused \ +S |const char *|native_querylocale_i \ + |const locale_category_index cat_index +S |void |new_LC_ALL |NN const char *lc_all \ |bool force +S |void |output_check_environment_warning \ + |NULLOK const char * const language \ + |NULLOK const char * const lc_all \ + |NULLOK const char * const lang +S |parse_LC_ALL_string_return|parse_LC_ALL_string \ + |NN const char *string \ + |NN const char **output \ + |const parse_LC_ALL_STRING_action \ + |bool always_use_full_array \ + |const bool panic_on_error \ + |const line_t caller_line So |void |restore_toggled_locale_i \ - |const unsigned cat_index \ + |const locale_category_index cat_index \ |NULLOK const char *original_locale \ |const line_t caller_line -ST |const char *|save_to_buffer \ +S |const char *|save_to_buffer \ |NULLOK const char *string \ - |NULLOK const char **buf \ + |NULLOK char **buf \ |NULLOK Size_t *buf_size -Sr |void |setlocale_failure_panic_i \ - |const unsigned int cat_index \ +Sr |void |setlocale_failure_panic_via_i \ + |const locale_category_index cat_index \ |NULLOK const char *current \ |NN const char *failed \ - |const line_t caller_0_line \ - |const line_t caller_1_line -S |const char *|stdize_locale \ - |const int category \ - |NULLOK const char *input_locale \ - |NULLOK const char **buf \ - |NULLOK Size_t *buf_size \ - |line_t caller_line + |const line_t proxy_caller_line \ + |const line_t immediate_caller_line \ + |NN const char *higher_caller_file \ + |const line_t higher_caller_line +S |void |set_save_buffer_min_size \ + |const Size_t min_len \ + |NULLOK char **buf \ + |NULLOK Size_t *buf_size So |const char *|toggle_locale_i \ - |const unsigned switch_cat_index \ + |const locale_category_index cat_index \ |NN const char *new_locale \ |const line_t caller_line # if defined(DEBUGGING) RS |char * |my_setlocale_debug_string_i \ - |const unsigned cat_index \ + |const locale_category_index cat_index \ |NULLOK const char *locale \ |NULLOK const char *retval \ |const line_t line # endif -# if defined(HAS_NL_LANGINFO) || defined(HAS_NL_LANGINFO_L) -S |const char *|my_langinfo_i \ +# if defined(HAS_LOCALECONV) && \ + ( defined(USE_LOCALE_MONETARY) || defined(USE_LOCALE_NUMERIC) ) +S |void |populate_hash_from_localeconv \ + |NN HV *hv \ + |NN const char *locale \ + |const U32 which_mask \ + |NN const lconv_offset_t *strings[2] \ + |NN const lconv_offset_t *integers[2] +# endif +# if defined(HAS_NL_LANGINFO) +S |const char *|langinfo_sv_i \ |const nl_item item \ - |const unsigned int cat_index \ + |locale_category_index cat_index \ |NN const char *locale \ - |NN const char **retbufp \ - |NULLOK Size_t *retbuf_sizep \ + |NN SV *sv \ |NULLOK utf8ness_t *utf8ness +# endif +# if defined(LC_ALL) +S |void |give_perl_locale_control \ + |NN const char *lc_all_string \ + |const line_t caller_line # else -S |const char *|my_langinfo_i \ - |const int item \ - |const unsigned int cat_index \ - |NN const char *locale \ - |NN const char **retbufp \ - |NULLOK Size_t *retbuf_sizep \ - |NULLOK utf8ness_t *utf8ness +S |void |give_perl_locale_control \ + |NN const char **curlocales \ + |const line_t caller_line # endif # if defined(USE_LOCALE_COLLATE) S |void |new_collate |NN const char *newcoll \ @@ -4413,51 +4566,30 @@ S |void |new_numeric |NN const char *new S |const char *|get_LC_ALL_display # endif # if defined(USE_POSIX_2008_LOCALE) -S |const char *|emulate_setlocale_i \ - |const unsigned int index \ - |NULLOK const char *new_locale \ - |const recalc_lc_all_t recalc_LC_ALL \ - |const line_t line -S |const char *|my_querylocale_i \ - |const unsigned int index -S |const char *|setlocale_from_aggregate_LC_ALL \ - |NN const char *locale \ +S |bool |bool_setlocale_2008_i \ + |const locale_category_index index \ + |NN const char *new_locale \ + |const line_t caller_line +S |const char *|querylocale_2008_i \ + |const locale_category_index index \ |const line_t line S |locale_t|use_curlocale_scratch -# if defined(USE_QUERYLOCALE) -S |const char *|calculate_LC_ALL \ - |const locale_t cur_obj -# else -S |const char *|update_PL_curlocales_i \ - |const unsigned int index \ +# if !defined(USE_QUERYLOCALE) +S |void |update_PL_curlocales_i \ + |const locale_category_index index \ |NN const char *new_locale \ - |recalc_lc_all_t recalc_LC_ALL + |const line_t caller_line # endif -# elif defined(USE_LOCALE_THREADS) && \ - !defined(USE_THREAD_SAFE_LOCALE) && \ - !defined(USE_THREAD_SAFE_LOCALE_EMULATION) /* && - !defined(USE_POSIX_2008_LOCALE) */ -S |const char *|less_dicey_setlocale_r \ - |const int category \ - |NULLOK const char *locale -: Not currently used -S |void |less_dicey_void_setlocale_i \ - |const unsigned cat_index \ - |NN const char *locale \ - |const line_t line -# if 0 +# elif defined(USE_LOCALE_THREADS) && !defined(USE_THREAD_SAFE_LOCALE) && \ + !defined(USE_THREAD_SAFE_LOCALE_EMULATION) S |bool |less_dicey_bool_setlocale_r \ |const int cat \ |NN const char *locale -# endif -# endif -# if !( defined(USE_POSIX_2008_LOCALE) && defined(USE_QUERYLOCALE) ) && \ - ( !defined(LC_ALL) || defined(USE_POSIX_2008_LOCALE) || \ - defined(WIN32) ) -S |const char *|calculate_LC_ALL \ - |NN const char **individ_locales +S |const char *|less_dicey_setlocale_r \ + |const int category \ + |NULLOK const char *locale # endif -# if defined(WIN32) +# if defined(WIN32) || defined(WIN32_USE_FAKE_OLD_MINGW_LOCALES) ST |wchar_t *|Win_byte_string_to_wstring \ |const UINT code_page \ |NULLOK const char *byte_string @@ -4471,13 +4603,13 @@ S |const char *|wrap_wsetlocale \ |const int category \ |NULLOK const char *locale # endif -# if defined(WIN32) || \ +# if defined(WIN32) || defined(WIN32_USE_FAKE_OLD_MINGW_LOCALES) || \ ( defined(USE_POSIX_2008_LOCALE) && !defined(USE_QUERYLOCALE) ) S |const char *|find_locale_from_environment \ - |const unsigned int index + |const locale_category_index index # endif # endif /* defined(USE_LOCALE) */ -# if defined(USE_POSIX_2008_LOCALE) || defined(DEBUGGING) +# if defined(USE_LOCALE) || defined(DEBUGGING) S |const char *|get_displayable_string \ |NN const char * const s \ |NN const char * const e \ @@ -4582,6 +4714,8 @@ S |void |inplace_aassign|NN OP *o RST |bool |is_handle_constructor \ |NN const OP *o \ |I32 numargs +Ti |bool |is_standard_filehandle_name \ + |NN const char *fhname S |OP * |listkids |NULLOK OP *o S |bool |looks_like_bool|NN const OP *o S |OP * |modkids |NULLOK OP *o \ @@ -4779,8 +4913,7 @@ RTi |bool |lossless_NV_to_IV \ : Used in pp_hot.c Reop |GV * |softref2xv |NN SV * const sv \ |NN const char * const what \ - |const svtype type \ - |NN SV ***spp + |const svtype type #endif #if defined(PERL_IN_PP_C) || defined(PERL_IN_REGCOMP_ANY) || \ defined(PERL_IN_TOKE_C) || defined(PERL_IN_UNIVERSAL_C) @@ -4970,8 +5103,6 @@ ERTix |UV |invlist_highest_range_start ERTi |bool |invlist_is_iterating \ |NN const SV * const invlist ERTix |UV |invlist_lowest |NN SV * const invlist -ETp |bool |is_ssc_worth_it|NN const RExC_state_t *pRExC_state \ - |NN const regnode_ssc *ssc Ep |U32 |join_exact |NN RExC_state_t *pRExC_state \ |NN regnode *scan \ |NN UV *min_subtract \ @@ -5002,8 +5133,6 @@ Ep |void |set_ANYOF_arg |NN RExC_state_t |NULLOK SV * const cp_list \ |NULLOK SV * const runtime_defns \ |NULLOK SV * const only_utf8_locale_list -Ep |void |ssc_finalize |NN RExC_state_t *pRExC_state \ - |NN regnode_ssc *ssc Ep |void |ssc_init |NN const RExC_state_t *pRExC_state \ |NN regnode_ssc *ssc Ep |SSize_t|study_chunk |NN RExC_state_t *pRExC_state \ @@ -5114,6 +5243,8 @@ ES |SV * |handle_user_defined_property |NN bool *user_defined_ptr \ |NN SV *msg \ |const STRLEN level +EST |bool |is_ssc_worth_it|NN const RExC_state_t *pRExC_state \ + |NN const regnode_ssc *ssc ES |void |nextchar |NN RExC_state_t *pRExC_state ES |U8 |optimize_regclass \ |NN RExC_state_t *pRExC_state \ @@ -5142,7 +5273,7 @@ ES |SV * |parse_uniprop_string \ |NN bool *user_defined_ptr \ |NN SV *msg \ |const STRLEN level -Sfr |void |re_croak |bool utf8 \ +Sfrv |void |re_croak |bool utf8 \ |NN const char *pat \ |... ES |regnode_offset|reg |NN RExC_state_t *pRExC_state \ @@ -5212,6 +5343,8 @@ ES |void |skip_to_be_ignored_text \ |NN RExC_state_t *pRExC_state \ |NN char **p \ |const bool force_to_xmod +ES |void |ssc_finalize |NN RExC_state_t *pRExC_state \ + |NN regnode_ssc *ssc # if defined(DEBUGGING) ES |regnode_offset|regnode_guts_debug \ |NN RExC_state_t *pRExC_state \ @@ -5491,7 +5624,7 @@ ES |void |dump_exec_pos |NN const char * |const bool do_utf8 \ |const U32 depth -EFp |int |re_exec_indentf|NN const char *fmt \ +EFpv |int |re_exec_indentf|NN const char *fmt \ |U32 depth \ |... # endif @@ -5534,10 +5667,10 @@ Ep |void |regprop |NULLOK const regexp * |NN const regnode *o \ |NULLOK const regmatch_info *reginfo \ |NULLOK const RExC_state_t *pRExC_state -EFp |int |re_indentf |NN const char *fmt \ +EFpv |int |re_indentf |NN const char *fmt \ |U32 depth \ |... -Efp |int |re_printf |NN const char *fmt \ +Efpv |int |re_printf |NN const char *fmt \ |... # endif # if defined(PERL_EXT_RE_BUILD) @@ -5652,11 +5785,13 @@ S |void |utf8_mg_pos_cache_update \ |const STRLEN byte \ |const STRLEN utf8 \ |const STRLEN blen -S |I32 |visit |NN SVFUNC_t f \ +S |SSize_t|visit |NN SVFUNC_t f \ |const U32 flags \ |const U32 mask # if defined(DEBUGGING) S |void |del_sv |NN SV *p +p |void |sv_mark_arenas +p |void |sv_sweep_arenas # endif # if !defined(NV_PRESERVES_UV) # if defined(DEBUGGING) @@ -5881,8 +6016,8 @@ Ti |U32 |ptr_hash |PTRV u S |SV * |with_queued_errors \ |NN SV *ex So |void |xs_version_bootcheck \ - |U32 items \ - |U32 ax \ + |SSize_t items \ + |SSize_t ax \ |NN const char *xs_p \ |STRLEN xs_len # if defined(PERL_MEM_LOG) && !defined(PERL_MEM_LOG_NOIMPL) @@ -5972,6 +6107,14 @@ Cipx |void |cx_pushwhen |NN PERL_CONTEXT Cipx |void |cx_topblock |NN PERL_CONTEXT *cx Cipx |U8 |gimme_V #endif /* !defined(PERL_NO_INLINE_FUNCTIONS) */ +#if defined(PERL_RC_STACK) +EXopx |OP * |pp_wrap |NN Perl_ppaddr_t real_pp_fn \ + |I32 nargs \ + |int nlists +Cpx |int |runops_wrap +EXopx |void |xs_wrap |NN XSUBADDR_t xsub \ + |NN CV *cv +#endif #if defined(PERL_USE_3ARG_SIGHANDLER) CTp |Signal_t|csighandler |int sig \ |NULLOK Siginfo_t *info \ @@ -6113,6 +6256,9 @@ Ep |char * |mem_collxfrm_ |NN const char |bool utf8 # endif #endif /* defined(USE_LOCALE_COLLATE) */ +#if defined(USE_LOCALE_CTYPE) +TXop |void |warn_problematic_locale +#endif #if defined(USE_PERLIO) Adhp |void |PerlIO_clearerr|NULLOK PerlIO *f Adhp |int |PerlIO_close |NULLOK PerlIO *f @@ -6158,13 +6304,17 @@ Adhp |SSize_t|PerlIO_write |NULLOK PerlI |Size_t count #endif /* defined(USE_PERLIO) */ #if defined(USE_PERL_SWITCH_LOCALE_CONTEXT) -CTop |void |switch_locale_context +Cop |void |switch_locale_context #endif #if defined(USE_QUADMATH) Tdp |bool |quadmath_format_needed \ |NN const char *format Tdp |bool |quadmath_format_valid \ |NN const char *format +#endif +#if defined(USE_THREADS) +Apx |void |thread_locale_init +Apx |void |thread_locale_term #endif #if defined(VMS) || defined(WIN32) Cp |int |do_aspawn |NULLOK SV *really \ Index: gnu/usr.bin/perl/embed.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/embed.h,v diff -u -p -a -u -p -r1.30 embed.h --- gnu/usr.bin/perl/embed.h 14 May 2024 19:38:53 -0000 1.30 +++ gnu/usr.bin/perl/embed.h 22 Jan 2025 00:37:44 -0000 @@ -71,10 +71,9 @@ # define perl_init_i18nl10n(a) init_i18nl10n(a) # define perl_require_pv(a) require_pv(a) -/* varargs functions can't be handled with CPP macros. :-( - This provides a set of compatibility functions that don't take - an extra argument but grab the context pointer using the macro - dTHX. +/* Before C99, macros could not wrap varargs functions. This + provides a set of compatibility functions that don't take an + extra argument but grab the context pointer using the macro dTHX. */ # if defined(MULTIPLICITY) && !defined(PERL_NO_SHORT_NAMES) @@ -175,6 +174,7 @@ # define ck_entersub_args_proto(a,b,c) Perl_ck_entersub_args_proto(aTHX_ a,b,c) # define ck_entersub_args_proto_or_list(a,b,c) Perl_ck_entersub_args_proto_or_list(aTHX_ a,b,c) # define clear_defarray(a,b) Perl_clear_defarray(aTHX_ a,b) +# define clear_defarray_simple(a) Perl_clear_defarray_simple(aTHX_ a) # define cop_fetch_label(a,b,c) Perl_cop_fetch_label(aTHX_ a,b,c) # define cop_store_label(a,b,c,d) Perl_cop_store_label(aTHX_ a,b,c,d) # define croak_memory_wrap Perl_croak_memory_wrap @@ -402,6 +402,7 @@ # define newHVREF(a) Perl_newHVREF(aTHX_ a) # define newHVhv(a) Perl_newHVhv(aTHX_ a) # define newLISTOP(a,b,c,d) Perl_newLISTOP(aTHX_ a,b,c,d) +# define newLISTOPn(a,...) Perl_newLISTOPn(aTHX_ a,__VA_ARGS__) # define newLOGOP(a,b,c,d) Perl_newLOGOP(aTHX_ a,b,c,d) # define newLOOPEX(a,b) Perl_newLOOPEX(aTHX_ a,b) # define newLOOPOP(a,b,c,d) Perl_newLOOPOP(aTHX_ a,b,c,d) @@ -450,6 +451,7 @@ # define newXS(a,b,c) Perl_newXS(aTHX_ a,b,c) # define newXS_flags(a,b,c,d,e) Perl_newXS_flags(aTHX_ a,b,c,d,e) # define new_stackinfo(a,b) Perl_new_stackinfo(aTHX_ a,b) +# define new_stackinfo_flags(a,b,c) Perl_new_stackinfo_flags(aTHX_ a,b,c) # define new_version(a) Perl_new_version(aTHX_ a) # define nothreadhook() Perl_nothreadhook(aTHX) # define op_append_elem(a,b,c) Perl_op_append_elem(aTHX_ a,b,c) @@ -495,6 +497,7 @@ # define perly_sighandler Perl_perly_sighandler # define pmop_dump(a) Perl_pmop_dump(aTHX_ a) # define pop_scope() Perl_pop_scope(aTHX) +# define pop_stackinfo() Perl_pop_stackinfo(aTHX) # define pregcomp(a,b) Perl_pregcomp(aTHX_ a,b) # define pregexec(a,b,c,d,e,f,g) Perl_pregexec(aTHX_ a,b,c,d,e,f,g) # define pregfree(a) Perl_pregfree(aTHX_ a) @@ -506,6 +509,7 @@ # define ptr_table_split(a) Perl_ptr_table_split(aTHX_ a) # define ptr_table_store(a,b,c) Perl_ptr_table_store(aTHX_ a,b,c) # define push_scope() Perl_push_scope(aTHX) +# define push_stackinfo(a,b) Perl_push_stackinfo(aTHX_ a,b) # define pv_display(a,b,c,d,e) Perl_pv_display(aTHX_ a,b,c,d,e) # define pv_escape(a,b,c,d,e,f) Perl_pv_escape(aTHX_ a,b,c,d,e,f) # define pv_pretty(a,b,c,d,e,f,g) Perl_pv_pretty(aTHX_ a,b,c,d,e,f,g) @@ -533,6 +537,39 @@ # define repeatcpy Perl_repeatcpy # define require_pv(a) Perl_require_pv(aTHX_ a) # define rninstr Perl_rninstr +# define rpp_context(a,b,c) Perl_rpp_context(aTHX_ a,b,c) +# define rpp_extend(a) Perl_rpp_extend(aTHX_ a) +# define rpp_invoke_xs(a) Perl_rpp_invoke_xs(aTHX_ a) +# define rpp_is_lone(a) Perl_rpp_is_lone(aTHX_ a) +# define rpp_obliterate_stack_to(a) Perl_rpp_obliterate_stack_to(aTHX_ a) +# define rpp_pop_1_norc() Perl_rpp_pop_1_norc(aTHX) +# define rpp_popfree_1() Perl_rpp_popfree_1(aTHX) +# define rpp_popfree_1_NN() Perl_rpp_popfree_1_NN(aTHX) +# define rpp_popfree_2() Perl_rpp_popfree_2(aTHX) +# define rpp_popfree_2_NN() Perl_rpp_popfree_2_NN(aTHX) +# define rpp_popfree_to(a) Perl_rpp_popfree_to(aTHX_ a) +# define rpp_popfree_to_NN(a) Perl_rpp_popfree_to_NN(aTHX_ a) +# define rpp_push_1(a) Perl_rpp_push_1(aTHX_ a) +# define rpp_push_1_norc(a) Perl_rpp_push_1_norc(aTHX_ a) +# define rpp_push_2(a,b) Perl_rpp_push_2(aTHX_ a,b) +# define rpp_push_IMM(a) Perl_rpp_push_IMM(aTHX_ a) +# define rpp_replace_1_1(a) Perl_rpp_replace_1_1(aTHX_ a) +# define rpp_replace_1_1_NN(a) Perl_rpp_replace_1_1_NN(aTHX_ a) +# define rpp_replace_1_IMM_NN(a) Perl_rpp_replace_1_IMM_NN(aTHX_ a) +# define rpp_replace_2_1(a) Perl_rpp_replace_2_1(aTHX_ a) +# define rpp_replace_2_1_COMMON(a) Perl_rpp_replace_2_1_COMMON(aTHX_ a) +# define rpp_replace_2_1_NN(a) Perl_rpp_replace_2_1_NN(aTHX_ a) +# define rpp_replace_2_IMM_NN(a) Perl_rpp_replace_2_IMM_NN(aTHX_ a) +# define rpp_replace_at(a,b) Perl_rpp_replace_at(aTHX_ a,b) +# define rpp_replace_at_NN(a,b) Perl_rpp_replace_at_NN(aTHX_ a,b) +# define rpp_replace_at_norc(a,b) Perl_rpp_replace_at_norc(aTHX_ a,b) +# define rpp_replace_at_norc_NN(a,b) Perl_rpp_replace_at_norc_NN(aTHX_ a,b) +# define rpp_stack_is_rc() Perl_rpp_stack_is_rc(aTHX) +# define rpp_try_AMAGIC_1(a,b) Perl_rpp_try_AMAGIC_1(aTHX_ a,b) +# define rpp_try_AMAGIC_2(a,b) Perl_rpp_try_AMAGIC_2(aTHX_ a,b) +# define rpp_xpush_1(a) Perl_rpp_xpush_1(aTHX_ a) +# define rpp_xpush_2(a,b) Perl_rpp_xpush_2(aTHX_ a,b) +# define rpp_xpush_IMM(a) Perl_rpp_xpush_IMM(aTHX_ a) # define rsignal(a,b) Perl_rsignal(aTHX_ a,b) # define rsignal_state(a) Perl_rsignal_state(aTHX_ a) # define runops_debug() Perl_runops_debug(aTHX) @@ -655,6 +692,7 @@ # define sv_isa(a,b) Perl_sv_isa(aTHX_ a,b) # define sv_isa_sv(a,b) Perl_sv_isa_sv(aTHX_ a,b) # define sv_isobject(a) Perl_sv_isobject(aTHX_ a) +# define sv_langinfo(a) Perl_sv_langinfo(aTHX_ a) # define sv_len(a) Perl_sv_len(aTHX_ a) # define sv_len_utf8(a) Perl_sv_len_utf8(aTHX_ a) # define sv_len_utf8_nomg(a) Perl_sv_len_utf8_nomg(aTHX_ a) @@ -710,6 +748,7 @@ # define sv_setuv(a,b) Perl_sv_setuv(aTHX_ a,b) # define sv_setuv_mg(a,b) Perl_sv_setuv_mg(aTHX_ a,b) # define sv_streq_flags(a,b,c) Perl_sv_streq_flags(aTHX_ a,b,c) +# define sv_strftime_tm(a,b) Perl_sv_strftime_tm(aTHX_ a,b) # define sv_string_from_errnum(a,b) Perl_sv_string_from_errnum(aTHX_ a,b) # define sv_tainted(a) Perl_sv_tainted(aTHX_ a) # define sv_true(a) Perl_sv_true(aTHX_ a) @@ -731,12 +770,11 @@ # define sv_vsetpvf(a,b,c) Perl_sv_vsetpvf(aTHX_ a,b,c) # define sv_vsetpvf_mg(a,b,c) Perl_sv_vsetpvf_mg(aTHX_ a,b,c) # define sv_vsetpvfn(a,b,c,d,e,f,g) Perl_sv_vsetpvfn(aTHX_ a,b,c,d,e,f,g) +# define switch_argstack(a) Perl_switch_argstack(aTHX_ a) # define switch_to_global_locale() Perl_switch_to_global_locale(aTHX) # define sync_locale() Perl_sync_locale(aTHX) # define taint_env() Perl_taint_env(aTHX) # define taint_proper(a,b) Perl_taint_proper(aTHX_ a,b) -# define thread_locale_init() Perl_thread_locale_init(aTHX) -# define thread_locale_term() Perl_thread_locale_term(aTHX) # define to_uni_lower(a,b,c) Perl_to_uni_lower(aTHX_ a,b,c) # define to_uni_title(a,b,c) Perl_to_uni_title(aTHX_ a,b,c) # define to_uni_upper(a,b,c) Perl_to_uni_upper(aTHX_ a,b,c) @@ -754,11 +792,11 @@ # define utf8_to_uvchr_buf_helper(a,b,c) Perl_utf8_to_uvchr_buf_helper(aTHX_ a,b,c) # define utf8n_to_uvchr_msgs Perl_utf8n_to_uvchr_msgs # define uvoffuni_to_utf8_flags_msgs(a,b,c,d) Perl_uvoffuni_to_utf8_flags_msgs(aTHX_ a,b,c,d) -# define uvuni_to_utf8(a,b) Perl_uvuni_to_utf8(aTHX_ a,b) # define valid_utf8_to_uvchr Perl_valid_utf8_to_uvchr # define vcmp(a,b) Perl_vcmp(aTHX_ a,b) # define vcroak(a,b) Perl_vcroak(aTHX_ a,b) # define vdeb(a,b) Perl_vdeb(aTHX_ a,b) +# define vfatal_warner(a,b,c) Perl_vfatal_warner(aTHX_ a,b,c) # define vform(a,b) Perl_vform(aTHX_ a,b) # define vload_module(a,b,c,d) Perl_vload_module(aTHX_ a,b,c,d) # define vmess(a,b) Perl_vmess(aTHX_ a,b) @@ -818,13 +856,15 @@ # define warn_nocontext Perl_warn_nocontext # define warner_nocontext Perl_warner_nocontext # endif /* defined(MULTIPLICITY) */ -# if !defined(MULTIPLICITY) || defined(PERL_CORE) +# if !defined(MULTIPLICITY) || defined(PERL_CORE) || \ + defined(PERL_WANT_VARARGS) # define ck_warner(a,...) Perl_ck_warner(aTHX_ a,__VA_ARGS__) # define ck_warner_d(a,...) Perl_ck_warner_d(aTHX_ a,__VA_ARGS__) # define croak(...) Perl_croak(aTHX_ __VA_ARGS__) # define deb(...) Perl_deb(aTHX_ __VA_ARGS__) # define die(...) Perl_die(aTHX_ __VA_ARGS__) # define dump_indent(a,b,...) Perl_dump_indent(aTHX_ a,b,__VA_ARGS__) +# define fatal_warner(a,...) Perl_fatal_warner(aTHX_ a,__VA_ARGS__) # define form(...) Perl_form(aTHX_ __VA_ARGS__) # define load_module(a,b,...) Perl_load_module(aTHX_ a,b,__VA_ARGS__) # define mess(...) Perl_mess(aTHX_ __VA_ARGS__) @@ -835,7 +875,8 @@ # define sv_setpvf_mg(a,...) Perl_sv_setpvf_mg(aTHX_ a,__VA_ARGS__) # define warn(...) Perl_warn(aTHX_ __VA_ARGS__) # define warner(a,...) Perl_warner(aTHX_ a,__VA_ARGS__) -# endif /* !defined(MULTIPLICITY) || defined(PERL_CORE) */ +# endif /* !defined(MULTIPLICITY) || defined(PERL_CORE) || + defined(PERL_WANT_VARARGS) */ # if defined(MYMALLOC) # define dump_mstats(a) Perl_dump_mstats(aTHX_ a) # define get_mstats(a,b,c) Perl_get_mstats(aTHX_ a,b,c) @@ -850,6 +891,7 @@ # define utf8_to_uvchr(a,b) Perl_utf8_to_uvchr(aTHX_ a,b) # define utf8_to_uvuni(a,b) Perl_utf8_to_uvuni(aTHX_ a,b) # define utf8n_to_uvuni(a,b,c,d) Perl_utf8n_to_uvuni(aTHX_ a,b,c,d) +# define uvuni_to_utf8(a,b) Perl_uvuni_to_utf8(aTHX_ a,b) # endif # if defined(PERL_CORE) # define PerlLIO_dup2_cloexec(a,b) Perl_PerlLIO_dup2_cloexec(aTHX_ a,b) @@ -858,7 +900,6 @@ # define PerlLIO_open_cloexec(a,b) Perl_PerlLIO_open_cloexec(aTHX_ a,b) # define Slab_Alloc(a) Perl_Slab_Alloc(aTHX_ a) # define Slab_Free(a) Perl_Slab_Free(aTHX_ a) -# define _warn_problematic_locale Perl__warn_problematic_locale # define abort_execution(a,b) Perl_abort_execution(aTHX_ a,b) # define alloc_LOGOP(a,b,c) Perl_alloc_LOGOP(aTHX_ a,b,c) # define allocmy(a,b,c) Perl_allocmy(aTHX_ a,b,c) @@ -867,6 +908,7 @@ # define apply(a,b,c) Perl_apply(aTHX_ a,b,c) # define av_extend_guts(a,b,c,d,e) Perl_av_extend_guts(aTHX_ a,b,c,d,e) # define av_nonelem(a,b) Perl_av_nonelem(aTHX_ a,b) +# define av_remove_offset(a) Perl_av_remove_offset(aTHX_ a) # define bind_match(a,b,c) Perl_bind_match(aTHX_ a,b,c) # define boot_core_PerlIO() Perl_boot_core_PerlIO(aTHX) # define boot_core_UNIVERSAL() Perl_boot_core_UNIVERSAL(aTHX) @@ -881,9 +923,10 @@ # define cmpchain_start(a,b,c) Perl_cmpchain_start(aTHX_ a,b,c) # define core_prototype(a,b,c,d) Perl_core_prototype(aTHX_ a,b,c,d) # define coresub_op(a,b,c) Perl_coresub_op(aTHX_ a,b,c) -# define create_eval_scope(a,b) Perl_create_eval_scope(aTHX_ a,b) +# define create_eval_scope(a,b,c) Perl_create_eval_scope(aTHX_ a,b,c) # define croak_caller Perl_croak_caller # define croak_no_mem Perl_croak_no_mem +# define croak_no_mem_ext Perl_croak_no_mem_ext # define croak_popstack Perl_croak_popstack # define custom_op_get_field(a,b) Perl_custom_op_get_field(aTHX_ a,b) # define cv_clone_into(a,b) Perl_cv_clone_into(aTHX_ a,b) @@ -919,9 +962,8 @@ # define find_lexical_cv(a) Perl_find_lexical_cv(aTHX_ a) # define find_runcv_where(a,b,c) Perl_find_runcv_where(aTHX_ a,b,c) # define find_script(a,b,c,d) Perl_find_script(aTHX_ a,b,c,d) -# define force_locale_unlock Perl_force_locale_unlock +# define force_locale_unlock() Perl_force_locale_unlock(aTHX) # define free_tied_hv_pool() Perl_free_tied_hv_pool(aTHX) -# define get_extended_os_errno Perl_get_extended_os_errno # define get_hash_seed(a) Perl_get_hash_seed(aTHX_ a) # define get_no_modify() Perl_get_no_modify(aTHX) # define get_opargs() Perl_get_opargs(aTHX) @@ -1062,8 +1104,8 @@ # define scalar(a) Perl_scalar(aTHX_ a) # define scalarvoid(a) Perl_scalarvoid(aTHX_ a) # define set_caret_X() Perl_set_caret_X(aTHX) -# define set_numeric_standard() Perl_set_numeric_standard(aTHX) -# define set_numeric_underlying() Perl_set_numeric_underlying(aTHX) +# define set_numeric_standard(a,b) Perl_set_numeric_standard(aTHX_ a,b) +# define set_numeric_underlying(a,b) Perl_set_numeric_underlying(aTHX_ a,b) # define setfd_cloexec Perl_setfd_cloexec # define setfd_cloexec_for_nonsysfd(a) Perl_setfd_cloexec_for_nonsysfd(aTHX_ a) # define setfd_cloexec_or_inhexec_by_sysfdness(a) Perl_setfd_cloexec_or_inhexec_by_sysfdness(aTHX_ a) @@ -1137,7 +1179,8 @@ # else # define magic_regdatum_set(a,b) Perl_magic_regdatum_set(aTHX_ a,b) # endif -# if !defined(MULTIPLICITY) || defined(PERL_CORE) +# if !defined(MULTIPLICITY) || defined(PERL_CORE) || \ + defined(PERL_WANT_VARARGS) # define tied_method(a,b,c,d,e,...) Perl_tied_method(aTHX_ a,b,c,d,e,__VA_ARGS__) # if defined(PERL_IN_REGCOMP_C) # define re_croak(a,...) S_re_croak(aTHX_ a,__VA_ARGS__) @@ -1156,34 +1199,17 @@ # if defined(PERL_IN_AV_C) # define get_aux_mg(a) S_get_aux_mg(aTHX_ a) # endif -# if defined(PERL_IN_DEB_C) -# define deb_stack_n(a,b,c,d,e) S_deb_stack_n(aTHX_ a,b,c,d,e) -# endif -# if defined(PERL_IN_DOIO_C) -# define argvout_final(a,b,c) S_argvout_final(aTHX_ a,b,c) -# define exec_failed(a,b,c) S_exec_failed(aTHX_ a,b,c) -# define ingroup(a,b) S_ingroup(aTHX_ a,b) -# define openn_cleanup(a,b,c,d,e,f,g,h,i,j,k,l,m) S_openn_cleanup(aTHX_ a,b,c,d,e,f,g,h,i,j,k,l,m) -# define openn_setup(a,b,c,d,e,f) S_openn_setup(aTHX_ a,b,c,d,e,f) -# endif -# if defined(PERL_IN_DOOP_C) -# define do_trans_complex(a,b) S_do_trans_complex(aTHX_ a,b) -# define do_trans_count(a,b) S_do_trans_count(aTHX_ a,b) -# define do_trans_count_invmap(a,b) S_do_trans_count_invmap(aTHX_ a,b) -# define do_trans_invmap(a,b) S_do_trans_invmap(aTHX_ a,b) -# define do_trans_simple(a,b) S_do_trans_simple(aTHX_ a,b) -# endif -# if defined(PERL_IN_DUMP_C) -# define deb_curcv(a) S_deb_curcv(aTHX_ a) -# define debprof(a) S_debprof(aTHX_ a) -# define pm_description(a) S_pm_description(aTHX_ a) -# define sequence_num(a) S_sequence_num(aTHX_ a) +# if defined(PERL_IN_BUILTIN_C) || defined(PERL_IN_OP_C) +# define finish_export_lexical() Perl_finish_export_lexical(aTHX) +# define import_builtin_bundle(a) Perl_import_builtin_bundle(aTHX_ a) +# define prepare_export_lexical() Perl_prepare_export_lexical(aTHX) # endif -# if defined(PERL_IN_GLOBALS_C) || defined(PERL_IN_OP_C) || \ - defined(PERL_IN_PEEP_C) +# if defined(PERL_IN_CLASS_C) || defined(PERL_IN_GLOBALS_C) || \ + defined(PERL_IN_OP_C) || defined(PERL_IN_PEEP_C) # define ck_anoncode(a) Perl_ck_anoncode(aTHX_ a) # define ck_backtick(a) Perl_ck_backtick(aTHX_ a) # define ck_bitop(a) Perl_ck_bitop(aTHX_ a) +# define ck_classname(a) Perl_ck_classname(aTHX_ a) # define ck_cmp(a) Perl_ck_cmp(aTHX_ a) # define ck_concat(a) Perl_ck_concat(aTHX_ a) # define ck_defined(a) Perl_ck_defined(aTHX_ a) @@ -1230,8 +1256,34 @@ # define ck_tell(a) Perl_ck_tell(aTHX_ a) # define ck_trunc(a) Perl_ck_trunc(aTHX_ a) # define ck_trycatch(a) Perl_ck_trycatch(aTHX_ a) -# endif /* defined(PERL_IN_GLOBALS_C) || defined(PERL_IN_OP_C) || - defined(PERL_IN_PEEP_C) */ +# endif /* defined(PERL_IN_CLASS_C) || defined(PERL_IN_GLOBALS_C) || + defined(PERL_IN_OP_C) || defined(PERL_IN_PEEP_C) */ +# if defined(PERL_IN_DEB_C) +# define deb_stack_n(a,b,c,d,e,f) S_deb_stack_n(aTHX_ a,b,c,d,e,f) +# endif +# if defined(PERL_IN_DOIO_C) +# define argvout_final(a,b,c) S_argvout_final(aTHX_ a,b,c) +# define exec_failed(a,b,c) S_exec_failed(aTHX_ a,b,c) +# define is_fork_open S_is_fork_open +# define openn_cleanup(a,b,c,d,e,f,g,h,i,j,k,l,m) S_openn_cleanup(aTHX_ a,b,c,d,e,f,g,h,i,j,k,l,m) +# define openn_setup(a,b,c,d,e,f) S_openn_setup(aTHX_ a,b,c,d,e,f) +# if !defined(DOSISH) +# define ingroup(a,b) S_ingroup(aTHX_ a,b) +# endif +# endif +# if defined(PERL_IN_DOOP_C) +# define do_trans_complex(a,b) S_do_trans_complex(aTHX_ a,b) +# define do_trans_count(a,b) S_do_trans_count(aTHX_ a,b) +# define do_trans_count_invmap(a,b) S_do_trans_count_invmap(aTHX_ a,b) +# define do_trans_invmap(a,b) S_do_trans_invmap(aTHX_ a,b) +# define do_trans_simple(a,b) S_do_trans_simple(aTHX_ a,b) +# endif +# if defined(PERL_IN_DUMP_C) +# define deb_curcv(a) S_deb_curcv(aTHX_ a) +# define debprof(a) S_debprof(aTHX_ a) +# define pm_description(a) S_pm_description(aTHX_ a) +# define sequence_num(a) S_sequence_num(aTHX_ a) +# endif # if defined(PERL_IN_GV_C) # define find_default_stash(a,b,c,d,e,f) S_find_default_stash(aTHX_ a,b,c,d,e,f) # define gv_fetchmeth_internal(a,b,c,d,e,f) S_gv_fetchmeth_internal(aTHX_ a,b,c,d,e,f) @@ -1263,26 +1315,42 @@ # endif /* defined(PERL_IN_HV_C) */ # if defined(PERL_IN_LOCALE_C) # define get_locale_string_utf8ness_i(a,b,c,d) S_get_locale_string_utf8ness_i(aTHX_ a,b,c,d) +# define ints_to_tm(a,b,c,d,e,f,g,h,i,j,k) S_ints_to_tm(aTHX_ a,b,c,d,e,f,g,h,i,j,k) # define is_locale_utf8(a) S_is_locale_utf8(aTHX_ a) -# if defined(HAS_LOCALECONV) -# define my_localeconv(a) S_my_localeconv(aTHX_ a) -# define populate_hash_from_localeconv(a,b,c,d,e) S_populate_hash_from_localeconv(aTHX_ a,b,c,d,e) +# define my_localeconv(a) S_my_localeconv(aTHX_ a) +# define populate_hash_from_C_localeconv(a,b,c,d,e) S_populate_hash_from_C_localeconv(aTHX_ a,b,c,d,e) +# define strftime8(a,b,c,d,e,f,g) S_strftime8(aTHX_ a,b,c,d,e,f,g) +# define strftime_tm(a,b,c,d) S_strftime_tm(aTHX_ a,b,c,d) +# define sv_strftime_common(a,b,c) S_sv_strftime_common(aTHX_ a,b,c) +# if defined(HAS_MISSING_LANGINFO_ITEM_) || !defined(HAS_NL_LANGINFO) +# define emulate_langinfo(a,b,c,d) S_emulate_langinfo(aTHX_ a,b,c,d) # endif # if defined(USE_LOCALE) -# define get_category_index S_get_category_index -# define get_category_index_nowarn S_get_category_index_nowarn +# define calculate_LC_ALL_string(a,b,c,d) S_calculate_LC_ALL_string(aTHX_ a,b,c,d) +# define external_call_langinfo(a,b,c) S_external_call_langinfo(aTHX_ a,b,c) +# define get_category_index_helper(a,b,c) S_get_category_index_helper(aTHX_ a,b,c) # define mortalized_pv_copy(a) S_mortalized_pv_copy(aTHX_ a) +# define native_querylocale_i(a) S_native_querylocale_i(aTHX_ a) # define new_LC_ALL(a,b) S_new_LC_ALL(aTHX_ a,b) -# define save_to_buffer S_save_to_buffer -# define setlocale_failure_panic_i(a,b,c,d,e) S_setlocale_failure_panic_i(aTHX_ a,b,c,d,e) -# define stdize_locale(a,b,c,d,e) S_stdize_locale(aTHX_ a,b,c,d,e) +# define output_check_environment_warning(a,b,c) S_output_check_environment_warning(aTHX_ a,b,c) +# define parse_LC_ALL_string(a,b,c,d,e,f) S_parse_LC_ALL_string(aTHX_ a,b,c,d,e,f) +# define save_to_buffer(a,b,c) S_save_to_buffer(aTHX_ a,b,c) +# define set_save_buffer_min_size(a,b,c) S_set_save_buffer_min_size(aTHX_ a,b,c) +# define setlocale_failure_panic_via_i(a,b,c,d,e,f,g) S_setlocale_failure_panic_via_i(aTHX_ a,b,c,d,e,f,g) # if defined(DEBUGGING) # define my_setlocale_debug_string_i(a,b,c,d) S_my_setlocale_debug_string_i(aTHX_ a,b,c,d) # endif -# if defined(HAS_NL_LANGINFO) || defined(HAS_NL_LANGINFO_L) -# define my_langinfo_i(a,b,c,d,e,f) S_my_langinfo_i(aTHX_ a,b,c,d,e,f) +# if defined(HAS_LOCALECONV) && \ + ( defined(USE_LOCALE_MONETARY) || defined(USE_LOCALE_NUMERIC) ) +# define populate_hash_from_localeconv(a,b,c,d,e) S_populate_hash_from_localeconv(aTHX_ a,b,c,d,e) +# endif +# if defined(HAS_NL_LANGINFO) +# define langinfo_sv_i(a,b,c,d,e) S_langinfo_sv_i(aTHX_ a,b,c,d,e) +# endif +# if defined(LC_ALL) +# define give_perl_locale_control(a,b) S_give_perl_locale_control(aTHX_ a,b) # else -# define my_langinfo_i(a,b,c,d,e,f) S_my_langinfo_i(aTHX_ a,b,c,d,e,f) +# define give_perl_locale_control(a,b) S_give_perl_locale_control(aTHX_ a,b) # endif # if defined(USE_LOCALE_COLLATE) # define new_collate(a,b) S_new_collate(aTHX_ a,b) @@ -1301,42 +1369,30 @@ # define get_LC_ALL_display() S_get_LC_ALL_display(aTHX) # endif # if defined(USE_POSIX_2008_LOCALE) -# define emulate_setlocale_i(a,b,c,d) S_emulate_setlocale_i(aTHX_ a,b,c,d) -# define my_querylocale_i(a) S_my_querylocale_i(aTHX_ a) -# define setlocale_from_aggregate_LC_ALL(a,b) S_setlocale_from_aggregate_LC_ALL(aTHX_ a,b) +# define bool_setlocale_2008_i(a,b,c) S_bool_setlocale_2008_i(aTHX_ a,b,c) +# define querylocale_2008_i(a,b) S_querylocale_2008_i(aTHX_ a,b) # define use_curlocale_scratch() S_use_curlocale_scratch(aTHX) -# if defined(USE_QUERYLOCALE) -# define calculate_LC_ALL(a) S_calculate_LC_ALL(aTHX_ a) -# else +# if !defined(USE_QUERYLOCALE) # define update_PL_curlocales_i(a,b,c) S_update_PL_curlocales_i(aTHX_ a,b,c) # endif -# elif defined(USE_LOCALE_THREADS) && \ - !defined(USE_THREAD_SAFE_LOCALE) && \ - !defined(USE_THREAD_SAFE_LOCALE_EMULATION) /* && - !defined(USE_POSIX_2008_LOCALE) */ +# elif defined(USE_LOCALE_THREADS) && \ + !defined(USE_THREAD_SAFE_LOCALE) && \ + !defined(USE_THREAD_SAFE_LOCALE_EMULATION) +# define less_dicey_bool_setlocale_r(a,b) S_less_dicey_bool_setlocale_r(aTHX_ a,b) # define less_dicey_setlocale_r(a,b) S_less_dicey_setlocale_r(aTHX_ a,b) -# define less_dicey_void_setlocale_i(a,b,c) S_less_dicey_void_setlocale_i(aTHX_ a,b,c) -# if 0 -# define less_dicey_bool_setlocale_r(a,b) S_less_dicey_bool_setlocale_r(aTHX_ a,b) -# endif # endif -# if !( defined(USE_POSIX_2008_LOCALE) && defined(USE_QUERYLOCALE) ) && \ - ( !defined(LC_ALL) || defined(USE_POSIX_2008_LOCALE) || \ - defined(WIN32) ) -# define calculate_LC_ALL(a) S_calculate_LC_ALL(aTHX_ a) -# endif -# if defined(WIN32) +# if defined(WIN32) || defined(WIN32_USE_FAKE_OLD_MINGW_LOCALES) # define Win_byte_string_to_wstring S_Win_byte_string_to_wstring # define Win_wstring_to_byte_string S_Win_wstring_to_byte_string # define win32_setlocale(a,b) S_win32_setlocale(aTHX_ a,b) # define wrap_wsetlocale(a,b) S_wrap_wsetlocale(aTHX_ a,b) # endif -# if defined(WIN32) || \ +# if defined(WIN32) || defined(WIN32_USE_FAKE_OLD_MINGW_LOCALES) || \ ( defined(USE_POSIX_2008_LOCALE) && !defined(USE_QUERYLOCALE) ) # define find_locale_from_environment(a) S_find_locale_from_environment(aTHX_ a) # endif # endif /* defined(USE_LOCALE) */ -# if defined(USE_POSIX_2008_LOCALE) || defined(DEBUGGING) +# if defined(USE_LOCALE) || defined(DEBUGGING) # define get_displayable_string(a,b,c) S_get_displayable_string(aTHX_ a,b,c) # endif # endif /* defined(PERL_IN_LOCALE_C) */ @@ -1378,6 +1434,7 @@ # define gen_constant_list(a) S_gen_constant_list(aTHX_ a) # define inplace_aassign(a) S_inplace_aassign(aTHX_ a) # define is_handle_constructor S_is_handle_constructor +# define is_standard_filehandle_name S_is_standard_filehandle_name # define listkids(a) S_listkids(aTHX_ a) # define looks_like_bool(a) S_looks_like_bool(aTHX_ a) # define modkids(a,b) S_modkids(aTHX_ a,b) @@ -1690,7 +1747,6 @@ # define mg_find_mglob(a) Perl_mg_find_mglob(aTHX_ a) # define multiconcat_stringify(a) Perl_multiconcat_stringify(aTHX_ a) # define multideref_stringify(a,b) Perl_multideref_stringify(aTHX_ a,b) -# define my_strftime8_temp(a,b,c,d,e,f,g,h,i,j,k) Perl_my_strftime8_temp(aTHX_ a,b,c,d,e,f,g,h,i,j,k) # define op_clear(a) Perl_op_clear(aTHX_ a) # define qerror(a) Perl_qerror(aTHX_ a) # define reg_named_buff(a,b,c,d) Perl_reg_named_buff(aTHX_ a,b,c,d) @@ -1708,6 +1764,7 @@ # define skipspace_flags(a,b) Perl_skipspace_flags(aTHX_ a,b) # define sv_magicext_mglob(a) Perl_sv_magicext_mglob(aTHX_ a) # define sv_only_taint_gmagic Perl_sv_only_taint_gmagic +# define sv_strftime_ints(a,b,c,d,e,f,g,h,i,j) Perl_sv_strftime_ints(aTHX_ a,b,c,d,e,f,g,h,i,j) # define utf16_to_utf8_base(a,b,c,d,e,f) Perl_utf16_to_utf8_base(aTHX_ a,b,c,d,e,f) # define utf8_to_utf16_base(a,b,c,d,e,f) Perl_utf8_to_utf16_base(aTHX_ a,b,c,d,e,f) # define validate_proto(a,b,c,d) Perl_validate_proto(aTHX_ a,b,c,d) @@ -1792,14 +1849,12 @@ # define invlist_highest_range_start S_invlist_highest_range_start # define invlist_is_iterating S_invlist_is_iterating # define invlist_lowest S_invlist_lowest -# define is_ssc_worth_it Perl_is_ssc_worth_it # define join_exact(a,b,c,d,e,f,g) Perl_join_exact(aTHX_ a,b,c,d,e,f,g) # define make_trie(a,b,c,d,e,f,g,h) Perl_make_trie(aTHX_ a,b,c,d,e,f,g,h) # define populate_anyof_bitmap_from_invlist(a,b) Perl_populate_anyof_bitmap_from_invlist(aTHX_ a,b) # define reg_add_data Perl_reg_add_data # define scan_commit(a,b,c,d) Perl_scan_commit(aTHX_ a,b,c,d) # define set_ANYOF_arg(a,b,c,d,e) Perl_set_ANYOF_arg(aTHX_ a,b,c,d,e) -# define ssc_finalize(a,b) Perl_ssc_finalize(aTHX_ a,b) # define ssc_init(a,b) Perl_ssc_init(aTHX_ a,b) # define study_chunk(a,b,c,d,e,f,g,h,i,j,k,l) Perl_study_chunk(aTHX_ a,b,c,d,e,f,g,h,i,j,k,l) # if defined(PERL_IN_REGCOMP_TRIE_C) && defined(DEBUGGING) @@ -1826,6 +1881,7 @@ # define handle_possible_posix(a,b,c,d,e) S_handle_possible_posix(aTHX_ a,b,c,d,e) # define handle_regex_sets(a,b,c,d) S_handle_regex_sets(aTHX_ a,b,c,d) # define handle_user_defined_property(a,b,c,d,e,f,g,h,i,j) S_handle_user_defined_property(aTHX_ a,b,c,d,e,f,g,h,i,j) +# define is_ssc_worth_it S_is_ssc_worth_it # define nextchar(a) S_nextchar(aTHX_ a) # define optimize_regclass(a,b,c,d,e,f,g,h,i,j) S_optimize_regclass(aTHX_ a,b,c,d,e,f,g,h,i,j) # define output_posix_warnings(a,b) S_output_posix_warnings(aTHX_ a,b) @@ -1850,6 +1906,7 @@ # define regtail(a,b,c,d) S_regtail(aTHX_ a,b,c,d) # define set_regex_pv(a,b) S_set_regex_pv(aTHX_ a,b) # define skip_to_be_ignored_text(a,b,c) S_skip_to_be_ignored_text(aTHX_ a,b,c) +# define ssc_finalize(a,b) S_ssc_finalize(aTHX_ a,b) # if defined(DEBUGGING) # define regnode_guts_debug(a,b,c) S_regnode_guts_debug(aTHX_ a,b,c) # define regtail_study(a,b,c,d) S_regtail_study(aTHX_ a,b,c,d) @@ -1947,7 +2004,8 @@ # if defined(DEBUGGING) # define debug_start_match(a,b,c,d,e) S_debug_start_match(aTHX_ a,b,c,d,e) # define dump_exec_pos(a,b,c,d,e,f,g) S_dump_exec_pos(aTHX_ a,b,c,d,e,f,g) -# if !defined(MULTIPLICITY) || defined(PERL_CORE) +# if !defined(MULTIPLICITY) || defined(PERL_CORE) || \ + defined(PERL_WANT_VARARGS) # define re_exec_indentf(a,...) Perl_re_exec_indentf(aTHX_ a,__VA_ARGS__) # endif # endif @@ -1982,20 +2040,19 @@ # define check_regnode_after(a,b) Perl_check_regnode_after(aTHX_ a,b) # define regnext(a) Perl_regnext(aTHX_ a) # define regnode_after(a,b) Perl_regnode_after(aTHX_ a,b) -# if defined(DEBUGGING) -# if ( !defined(MULTIPLICITY) || defined(PERL_CORE) ) && \ - ( defined(PERL_CORE) || defined(PERL_EXT) ) +# if defined(DEBUGGING) && ( defined(PERL_CORE) || defined(PERL_EXT) ) +# define debug_peep(a,b,c,d,e) Perl_debug_peep(aTHX_ a,b,c,d,e) +# define debug_show_study_flags(a,b,c) Perl_debug_show_study_flags(aTHX_ a,b,c) +# define debug_studydata(a,b,c,d,e,f,g) Perl_debug_studydata(aTHX_ a,b,c,d,e,f,g) +# define dumpuntil(a,b,c,d,e,f,g,h) Perl_dumpuntil(aTHX_ a,b,c,d,e,f,g,h) +# define regprop(a,b,c,d,e) Perl_regprop(aTHX_ a,b,c,d,e) +# if !defined(MULTIPLICITY) || defined(PERL_CORE) || \ + defined(PERL_WANT_VARARGS) # define re_indentf(a,...) Perl_re_indentf(aTHX_ a,__VA_ARGS__) # define re_printf(...) Perl_re_printf(aTHX_ __VA_ARGS__) # endif -# if defined(PERL_CORE) || defined(PERL_EXT) -# define debug_peep(a,b,c,d,e) Perl_debug_peep(aTHX_ a,b,c,d,e) -# define debug_show_study_flags(a,b,c) Perl_debug_show_study_flags(aTHX_ a,b,c) -# define debug_studydata(a,b,c,d,e,f,g) Perl_debug_studydata(aTHX_ a,b,c,d,e,f,g) -# define dumpuntil(a,b,c,d,e,f,g,h) Perl_dumpuntil(aTHX_ a,b,c,d,e,f,g,h) -# define regprop(a,b,c,d,e) Perl_regprop(aTHX_ a,b,c,d,e) -# endif -# endif /* defined(DEBUGGING) */ +# endif /* defined(DEBUGGING) && + ( defined(PERL_CORE) || defined(PERL_EXT) ) */ # if defined(PERL_EXT_RE_BUILD) # if defined(PERL_CORE) || defined(PERL_EXT) # define get_re_gclass_aux_data(a,b,c,d,e,f) Perl_get_re_gclass_aux_data(aTHX_ a,b,c,d,e,f) @@ -2034,6 +2091,8 @@ # define visit(a,b,c) S_visit(aTHX_ a,b,c) # if defined(DEBUGGING) # define del_sv(a) S_del_sv(aTHX_ a) +# define sv_mark_arenas() Perl_sv_mark_arenas(aTHX) +# define sv_sweep_arenas() Perl_sv_sweep_arenas(aTHX) # endif # if !defined(NV_PRESERVES_UV) # if defined(DEBUGGING) @@ -2082,6 +2141,9 @@ # define cx_topblock(a) Perl_cx_topblock(aTHX_ a) # define gimme_V() Perl_gimme_V(aTHX) # endif /* !defined(PERL_NO_INLINE_FUNCTIONS) */ +# if defined(PERL_RC_STACK) +# define runops_wrap() Perl_runops_wrap(aTHX) +# endif # if defined(PERL_USE_3ARG_SIGHANDLER) # define csighandler Perl_csighandler # else @@ -2152,6 +2214,10 @@ # define PerlIO_unread(a,b,c) Perl_PerlIO_unread(aTHX_ a,b,c) # define PerlIO_write(a,b,c) Perl_PerlIO_write(aTHX_ a,b,c) # endif /* defined(USE_PERLIO) */ +# if defined(USE_THREADS) +# define thread_locale_init() Perl_thread_locale_init(aTHX) +# define thread_locale_term() Perl_thread_locale_term(aTHX) +# endif # if defined(VMS) || defined(WIN32) # define do_aspawn(a,b,c) Perl_do_aspawn(aTHX_ a,b,c) # define do_spawn(a) Perl_do_spawn(aTHX_ a) Index: gnu/usr.bin/perl/embedvar.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/embedvar.h,v diff -u -p -a -u -p -r1.8 embedvar.h --- gnu/usr.bin/perl/embedvar.h 14 May 2024 19:38:53 -0000 1.8 +++ gnu/usr.bin/perl/embedvar.h 22 Jan 2025 00:37:44 -0000 @@ -150,8 +150,7 @@ # define PL_internal_random_state (vTHX->Iinternal_random_state) # define PL_isarev (vTHX->Iisarev) # define PL_known_layers (vTHX->Iknown_layers) -# define PL_langinfo_buf (vTHX->Ilanginfo_buf) -# define PL_langinfo_bufsize (vTHX->Ilanginfo_bufsize) +# define PL_langinfo_sv (vTHX->Ilanginfo_sv) # define PL_last_in_gv (vTHX->Ilast_in_gv) # define PL_lastfd (vTHX->Ilastfd) # define PL_lastgotoprobe (vTHX->Ilastgotoprobe) @@ -159,6 +158,8 @@ # define PL_laststype (vTHX->Ilaststype) # define PL_Latin1 (vTHX->ILatin1) # define PL_LB_invlist (vTHX->ILB_invlist) +# define PL_less_dicey_locale_buf (vTHX->Iless_dicey_locale_buf) +# define PL_less_dicey_locale_bufsize (vTHX->Iless_dicey_locale_bufsize) # define PL_LIO (vTHX->ILIO) # define PL_locale_mutex_depth (vTHX->Ilocale_mutex_depth) # define PL_localizing (vTHX->Ilocalizing) @@ -261,6 +262,7 @@ # define PL_scopestack_ix (vTHX->Iscopestack_ix) # define PL_scopestack_max (vTHX->Iscopestack_max) # define PL_scopestack_name (vTHX->Iscopestack_name) +# define PL_scratch_langinfo (vTHX->Iscratch_langinfo) # define PL_scratch_locale_obj (vTHX->Iscratch_locale_obj) # define PL_SCX_invlist (vTHX->ISCX_invlist) # define PL_secondgv (vTHX->Isecondgv) @@ -297,8 +299,6 @@ # define PL_stderrgv (vTHX->Istderrgv) # define PL_stdingv (vTHX->Istdingv) # define PL_StdIO (vTHX->IStdIO) -# define PL_stdize_locale_buf (vTHX->Istdize_locale_buf) -# define PL_stdize_locale_bufsize (vTHX->Istdize_locale_bufsize) # define PL_strtab (vTHX->Istrtab) # define PL_strxfrm_is_behaved (vTHX->Istrxfrm_is_behaved) # define PL_strxfrm_max_cp (vTHX->Istrxfrm_max_cp) @@ -329,7 +329,6 @@ # define PL_top_env (vTHX->Itop_env) # define PL_toptarget (vTHX->Itoptarget) # define PL_TR_SPECIAL_HANDLING_UTF8 (vTHX->ITR_SPECIAL_HANDLING_UTF8) -# define PL_underlying_numeric_obj (vTHX->Iunderlying_numeric_obj) # define PL_underlying_radix_sv (vTHX->Iunderlying_radix_sv) # define PL_unicode (vTHX->Iunicode) # define PL_unitcheckav (vTHX->Iunitcheckav) Index: gnu/usr.bin/perl/feature.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/feature.h,v diff -u -p -a -u -p -r1.7 feature.h --- gnu/usr.bin/perl/feature.h 14 May 2024 19:38:53 -0000 1.7 +++ gnu/usr.bin/perl/feature.h 22 Jan 2025 00:37:44 -0000 @@ -43,6 +43,7 @@ #define FEATURE_BUNDLE_527 5 #define FEATURE_BUNDLE_535 6 #define FEATURE_BUNDLE_537 7 +#define FEATURE_BUNDLE_539 8 #define FEATURE_BUNDLE_CUSTOM (HINT_FEATURE_MASK >> HINT_FEATURE_SHIFT) /* this is preserved for testing and asserts */ @@ -65,7 +66,7 @@ #define FEATURE_FC_IS_ENABLED \ ( \ (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \ - CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_537) \ + CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_539) \ || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ FEATURE_IS_ENABLED_MASK(FEATURE_FC_BIT)) \ ) @@ -73,7 +74,7 @@ #define FEATURE_ISA_IS_ENABLED \ ( \ (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_535 && \ - CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_537) \ + CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_539) \ || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ FEATURE_IS_ENABLED_MASK(FEATURE_ISA_BIT)) \ ) @@ -81,15 +82,16 @@ #define FEATURE_SAY_IS_ENABLED \ ( \ (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \ - CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_537) \ + CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_539) \ || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ FEATURE_IS_ENABLED_MASK(FEATURE_SAY_BIT)) \ ) #define FEATURE_TRY_IS_ENABLED \ ( \ - CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ - FEATURE_IS_ENABLED_MASK(FEATURE_TRY_BIT) \ + CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_539 \ + || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ + FEATURE_IS_ENABLED_MASK(FEATURE_TRY_BIT)) \ ) #define FEATURE_CLASS_IS_ENABLED \ @@ -107,7 +109,7 @@ #define FEATURE_STATE_IS_ENABLED \ ( \ (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \ - CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_537) \ + CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_539) \ || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ FEATURE_IS_ENABLED_MASK(FEATURE_STATE_BIT)) \ ) @@ -123,7 +125,7 @@ #define FEATURE_BITWISE_IS_ENABLED \ ( \ (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_527 && \ - CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_537) \ + CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_539) \ || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ FEATURE_IS_ENABLED_MASK(FEATURE_BITWISE_BIT)) \ ) @@ -138,7 +140,7 @@ #define FEATURE_EVALBYTES_IS_ENABLED \ ( \ (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \ - CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_537) \ + CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_539) \ || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ FEATURE_IS_ENABLED_MASK(FEATURE_EVALBYTES_BIT)) \ ) @@ -146,7 +148,7 @@ #define FEATURE_SIGNATURES_IS_ENABLED \ ( \ (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_535 && \ - CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_537) \ + CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_539) \ || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ FEATURE_IS_ENABLED_MASK(FEATURE_SIGNATURES_BIT)) \ ) @@ -154,14 +156,15 @@ #define FEATURE___SUB___IS_ENABLED \ ( \ (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \ - CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_537) \ + CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_539) \ || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ FEATURE_IS_ENABLED_MASK(FEATURE___SUB___BIT)) \ ) #define FEATURE_MODULE_TRUE_IS_ENABLED \ ( \ - CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_537 \ + (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_537 && \ + CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_539) \ || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ FEATURE_IS_ENABLED_MASK(FEATURE_MODULE_TRUE_BIT)) \ ) @@ -175,7 +178,7 @@ #define FEATURE_POSTDEREF_QQ_IS_ENABLED \ ( \ (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_523 && \ - CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_537) \ + CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_539) \ || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ FEATURE_IS_ENABLED_MASK(FEATURE_POSTDEREF_QQ_BIT)) \ ) @@ -183,7 +186,7 @@ #define FEATURE_UNIEVAL_IS_ENABLED \ ( \ (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \ - CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_537) \ + CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_539) \ || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ FEATURE_IS_ENABLED_MASK(FEATURE_UNIEVAL_BIT)) \ ) @@ -197,7 +200,7 @@ #define FEATURE_UNICODE_IS_ENABLED \ ( \ (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_511 && \ - CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_537) \ + CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_539) \ || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \ FEATURE_IS_ENABLED_MASK(FEATURE_UNICODE_BIT)) \ ) @@ -227,14 +230,7 @@ #define CLEARFEATUREBITS() (PL_compiling.cop_features = 0) -#define STOREFEATUREBITSHH(hh) \ - (hv_stores((hh), "feature/bits", newSVuv(PL_compiling.cop_features))) - -#define FETCHFEATUREBITSHH(hh) \ - STMT_START { \ - SV **fbsv = hv_fetchs((hh), "feature/bits", FALSE); \ - PL_compiling.cop_features = fbsv ? SvUV(*fbsv) : 0; \ - } STMT_END +#define FETCHFEATUREBITSHH(hh) S_fetch_feature_bits_hh(aTHX_ (hh)) #endif /* PERL_CORE or PERL_EXT */ @@ -245,6 +241,9 @@ S_enable_feature_bundle(pTHX_ SV *ver) SV *comp_ver = sv_newmortal(); PL_hints = (PL_hints &~ HINT_FEATURE_MASK) | ( + (sv_setnv(comp_ver, 5.039), + vcmp(ver, upg_version(comp_ver, FALSE)) >= 0) + ? FEATURE_BUNDLE_539 : (sv_setnv(comp_ver, 5.037), vcmp(ver, upg_version(comp_ver, FALSE)) >= 0) ? FEATURE_BUNDLE_537 : @@ -275,7 +274,7 @@ S_enable_feature_bundle(pTHX_ SV *ver) } #endif /* PERL_IN_OP_C */ -#ifdef PERL_IN_MG_C +#if defined(PERL_IN_MG_C) || defined(PERL_IN_PP_CTL_C) #define magic_sethint_feature(keysv, keypv, keylen, valsv, valbool) \ S_magic_sethint_feature(aTHX_ (keysv), (keypv), (keylen), (valsv), (valbool)) @@ -448,6 +447,167 @@ S_magic_sethint_feature(pTHX_ SV *keysv, } } #endif /* PERL_IN_MG_C */ + +/* subject to change */ +struct perl_feature_bit { + const char *name; + STRLEN namelen; + U32 mask; +}; + +#ifdef PERL_IN_PP_CTL_C + +static const struct perl_feature_bit +PL_feature_bits[] = { + { + /* feature bareword_filehandles */ + "feature_bareword_filehandles", + STRLENs("feature_bareword_filehandles"), + FEATURE_BAREWORD_FILEHANDLES_BIT + }, + { + /* feature bitwise */ + "feature_bitwise", + STRLENs("feature_bitwise"), + FEATURE_BITWISE_BIT + }, + { + /* feature class */ + "feature_class", + STRLENs("feature_class"), + FEATURE_CLASS_BIT + }, + { + /* feature current_sub */ + "feature___SUB__", + STRLENs("feature___SUB__"), + FEATURE___SUB___BIT + }, + { + /* feature declared_refs */ + "feature_myref", + STRLENs("feature_myref"), + FEATURE_MYREF_BIT + }, + { + /* feature defer */ + "feature_defer", + STRLENs("feature_defer"), + FEATURE_DEFER_BIT + }, + { + /* feature evalbytes */ + "feature_evalbytes", + STRLENs("feature_evalbytes"), + FEATURE_EVALBYTES_BIT + }, + { + /* feature extra_paired_delimiters */ + "feature_more_delims", + STRLENs("feature_more_delims"), + FEATURE_MORE_DELIMS_BIT + }, + { + /* feature fc */ + "feature_fc", + STRLENs("feature_fc"), + FEATURE_FC_BIT + }, + { + /* feature indirect */ + "feature_indirect", + STRLENs("feature_indirect"), + FEATURE_INDIRECT_BIT + }, + { + /* feature isa */ + "feature_isa", + STRLENs("feature_isa"), + FEATURE_ISA_BIT + }, + { + /* feature module_true */ + "feature_module_true", + STRLENs("feature_module_true"), + FEATURE_MODULE_TRUE_BIT + }, + { + /* feature multidimensional */ + "feature_multidimensional", + STRLENs("feature_multidimensional"), + FEATURE_MULTIDIMENSIONAL_BIT + }, + { + /* feature postderef_qq */ + "feature_postderef_qq", + STRLENs("feature_postderef_qq"), + FEATURE_POSTDEREF_QQ_BIT + }, + { + /* feature refaliasing */ + "feature_refaliasing", + STRLENs("feature_refaliasing"), + FEATURE_REFALIASING_BIT + }, + { + /* feature say */ + "feature_say", + STRLENs("feature_say"), + FEATURE_SAY_BIT + }, + { + /* feature signatures */ + "feature_signatures", + STRLENs("feature_signatures"), + FEATURE_SIGNATURES_BIT + }, + { + /* feature state */ + "feature_state", + STRLENs("feature_state"), + FEATURE_STATE_BIT + }, + { + /* feature switch */ + "feature_switch", + STRLENs("feature_switch"), + FEATURE_SWITCH_BIT + }, + { + /* feature try */ + "feature_try", + STRLENs("feature_try"), + FEATURE_TRY_BIT + }, + { + /* feature unicode_eval */ + "feature_unieval", + STRLENs("feature_unieval"), + FEATURE_UNIEVAL_BIT + }, + { + /* feature unicode_strings */ + "feature_unicode", + STRLENs("feature_unicode"), + FEATURE_UNICODE_BIT + }, + { NULL, 0, 0U } +}; + +PERL_STATIC_INLINE void +S_fetch_feature_bits_hh(pTHX_ HV *hh) { + PL_compiling.cop_features = 0; + + const struct perl_feature_bit *fb = PL_feature_bits; + while (fb->name) { + SV **svp = hv_fetch(hh, fb->name, (I32)fb->namelen, 0); + if (svp && SvTRUE(*svp)) + PL_compiling.cop_features |= fb->mask; + ++fb; + } +} + +#endif #endif /* PERL_FEATURE_H_ */ Index: gnu/usr.bin/perl/globvar.sym =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/globvar.sym,v diff -u -p -a -u -p -r1.15 globvar.sym --- gnu/usr.bin/perl/globvar.sym 14 May 2024 19:38:53 -0000 1.15 +++ gnu/usr.bin/perl/globvar.sym 22 Jan 2025 00:37:44 -0000 @@ -37,7 +37,6 @@ PL_no_dir_func PL_no_func PL_no_helem_sv PL_no_localize_ref -PL_no_mem PL_no_modify PL_no_myglob PL_no_security Index: gnu/usr.bin/perl/gv.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/gv.c,v diff -u -p -a -u -p -r1.25 gv.c --- gnu/usr.bin/perl/gv.c 14 May 2024 19:38:53 -0000 1.25 +++ gnu/usr.bin/perl/gv.c 22 Jan 2025 00:37:44 -0000 @@ -21,7 +21,7 @@ /* =head1 GV Handling and Stashes -A GV is a structure which corresponds to to a Perl typeglob, ie *foo. +A GV is a structure which corresponds to a Perl typeglob, ie *foo. It is a structure that holds a pointer to a scalar, an array, a hash etc, corresponding to $foo, @foo, %foo. @@ -1212,13 +1212,7 @@ Perl_gv_fetchmethod_pvn_flags(pTHX_ HV * gv = gv_fetchmeth_pvn(stash, name, name_end - name, 0, flags); if (!gv) { - /* This is the special case that exempts Foo->import and - Foo->unimport from being an error even if there's no - import/unimport subroutine */ - if (strEQ(name,"import") || strEQ(name,"unimport")) { - gv = (GV*)sv_2mortal((SV*)newCONSTSUB_flags(NULL, - NULL, 0, 0, NULL)); - } else if (autoload) + if (autoload) gv = gv_autoload_pvn( ostash, name, name_end - name, GV_AUTOLOAD_ISMETHOD|flags ); @@ -2691,10 +2685,14 @@ Perl_gv_fetchpvn_flags(pTHX_ const char gv_init_pvn(gv, stash, name, len, (add & GV_ADDMULTI)|is_utf8); if ( full_len != 0 - && isIDFIRST_lazy_if_safe(name, name + full_len, is_utf8) - && !ckWARN(WARN_ONCE) ) - { - GvMULTI_on(gv) ; + && isIDFIRST_lazy_if_safe(name, name + full_len, is_utf8)) { + if (ckWARN(WARN_ONCE)) { + if (ckDEAD(WARN_ONCE)) + GvONCE_FATAL_on(gv); + } + else { + GvMULTI_on(gv) ; + } } /* set up magic where warranted */ @@ -2825,11 +2823,20 @@ Perl_gv_check(pTHX_ HV *stash) CopFILEGV(PL_curcop) = gv_fetchfile_flags(file, HEK_LEN(GvFILE_HEK(gv)), 0); #endif - Perl_warner(aTHX_ packWARN(WARN_ONCE), - "Name \"%" HEKf "::%" HEKf - "\" used only once: possible typo", - HEKfARG(HvNAME_HEK(stash)), - HEKfARG(GvNAME_HEK(gv))); + if (GvONCE_FATAL(gv)) { + fatal_warner(packWARN(WARN_ONCE), + "Name \"%" HEKf "::%" HEKf + "\" used only once: possible typo", + HEKfARG(HvNAME_HEK(stash)), + HEKfARG(GvNAME_HEK(gv))); + } + else { + warner(packWARN(WARN_ONCE), + "Name \"%" HEKf "::%" HEKf + "\" used only once: possible typo", + HEKfARG(HvNAME_HEK(stash)), + HEKfARG(GvNAME_HEK(gv))); + } } } } @@ -3362,10 +3369,11 @@ Perl_gv_handler(pTHX_ HV *stash, I32 id) */ bool -Perl_try_amagic_un(pTHX_ int method, int flags) { - dSP; +Perl_try_amagic_un(pTHX_ int method, int flags) +{ SV* tmpsv; - SV* const arg = TOPs; + SV* const arg = PL_stack_sp[0]; + bool is_rc = rpp_stack_is_rc(); SvGETMAGIC(arg); @@ -3378,22 +3386,33 @@ Perl_try_amagic_un(pTHX_ int method, int * then assign the returned value to targ and return that; * otherwise return the value directly */ + SV *targ = tmpsv; if ( (PL_opargs[PL_op->op_type] & OA_TARGLEX) && (PL_op->op_private & OPpTARGET_MY)) { - dTARGET; - sv_setsv(TARG, tmpsv); - SETTARG; + targ = PAD_SV(PL_op->op_targ); + sv_setsv(targ, tmpsv); + SvSETMAGIC(targ); + } + if (targ != arg) { + *PL_stack_sp = targ; + if (is_rc) { + SvREFCNT_inc_NN(targ); + SvREFCNT_dec_NN(arg); + } } - else - SETs(tmpsv); - PUTBACK; return TRUE; } - if ((flags & AMGf_numeric) && SvROK(arg)) - *sp = sv_2num(arg); + if ((flags & AMGf_numeric) && SvROK(arg)) { + PL_stack_sp[0] = tmpsv = sv_2num(arg); + if (is_rc) { + SvREFCNT_inc_NN(tmpsv); + SvREFCNT_dec_NN(arg); + } + } + return FALSE; } @@ -3554,10 +3573,11 @@ Perl_amagic_applies(pTHX_ SV *sv, int me */ bool -Perl_try_amagic_bin(pTHX_ int method, int flags) { - dSP; - SV* const left = TOPm1s; - SV* const right = TOPs; +Perl_try_amagic_bin(pTHX_ int method, int flags) +{ + SV* left = PL_stack_sp[-1]; + SV* right = PL_stack_sp[0]; + bool is_rc = rpp_stack_is_rc(); SvGETMAGIC(left); if (left != right) @@ -3572,51 +3592,78 @@ Perl_try_amagic_bin(pTHX_ int method, in (mutator ? AMGf_assign: 0) | (flags & AMGf_numarg)); if (tmpsv) { - (void)POPs; + PL_stack_sp--; + if (is_rc) + SvREFCNT_dec_NN(right); /* where the op is one of the two forms: * $x op= $y * $lex = $x op $y (where the assign is optimised away) * then assign the returned value to targ and return that; * otherwise return the value directly */ + SV *targ = tmpsv;; if ( mutator || ( (PL_opargs[PL_op->op_type] & OA_TARGLEX) && (PL_op->op_private & OPpTARGET_MY))) { - dTARG; - TARG = mutator ? *SP : PAD_SV(PL_op->op_targ); - sv_setsv(TARG, tmpsv); - SETTARG; + targ = mutator ? left : PAD_SV(PL_op->op_targ); + sv_setsv(targ, tmpsv); + SvSETMAGIC(targ); + } + if (targ != left) { + *PL_stack_sp = targ; + if (is_rc) { + SvREFCNT_inc_NN(targ); + SvREFCNT_dec_NN(left); + } } - else - SETs(tmpsv); - PUTBACK; return TRUE; } } - if(left==right && SvGMAGICAL(left)) { - SV * const left = sv_newmortal(); - *(sp-1) = left; + /* if the same magic value appears on both sides, replace the LH one + * with a copy and call get magic on the RH one, so that magic gets + * called twice with possibly two different returned values */ + if (left == right && SvGMAGICAL(left)) { + SV * const tmpsv = is_rc ? newSV_type(SVt_NULL) : sv_newmortal(); /* Print the uninitialized warning now, so it includes the vari- able name. */ if (!SvOK(right)) { - if (ckWARN(WARN_UNINITIALIZED)) report_uninit(right); - sv_setbool(left, FALSE); + if (ckWARN(WARN_UNINITIALIZED)) + report_uninit(right); + sv_setbool(tmpsv, FALSE); } - else sv_setsv_flags(left, right, 0); + else + sv_setsv_flags(tmpsv, right, 0); + if (is_rc) + SvREFCNT_dec_NN(left); + left = PL_stack_sp[-1] = tmpsv; SvGETMAGIC(right); } + if (flags & AMGf_numeric) { - if (SvROK(TOPm1s)) - *(sp-1) = sv_2num(TOPm1s); - if (SvROK(right)) - *sp = sv_2num(right); + SV *tmpsv; + if (SvROK(left)) { + PL_stack_sp[-1] = tmpsv = sv_2num(left); + if (is_rc) { + SvREFCNT_inc_NN(tmpsv); + SvREFCNT_dec_NN(left); + } + } + if (SvROK(right)) { + PL_stack_sp[0] = tmpsv = sv_2num(right); + if (is_rc) { + SvREFCNT_inc_NN(tmpsv); + SvREFCNT_dec_NN(right); + } + } } + return FALSE; } + /* =for apidoc amagic_deref_call @@ -3971,6 +4018,15 @@ Perl_amagic_call(pTHX_ SV *left, SV *rig } } + /* If there's an optimised-away assignment such as $lex = $a + $b, where + * the operator sets the targ lexical directly and skips the sassign, + * treat the op as scalar even if its marked as void */ + if ( PL_op + && (PL_opargs[PL_op->op_type] & OA_TARGLEX) + && (PL_op->op_private & OPpTARGET_MY) + ) + force_scalar = 1; + switch (method) { /* in these cases, we're calling '+' or '-' as a fallback for a ++ or -- * operation. we need this to return a value, so that it can be assigned @@ -4095,7 +4151,7 @@ Perl_amagic_call(pTHX_ SV *left, SV *rig * with the context of individual concats being scalar, * regardless of the overall context of the multiconcat op */ - U8 gimme = (force_scalar || PL_op->op_type == OP_MULTICONCAT) + U8 gimme = (force_scalar || (PL_op && PL_op->op_type == OP_MULTICONCAT)) ? G_SCALAR : GIMME_V; CATCH_SET(TRUE); @@ -4161,6 +4217,13 @@ Perl_amagic_call(pTHX_ SV *left, SV *rig res = newSV_type_mortal(SVt_PVAV); av_extend((AV *)res, nret); while (nret--) + /* Naughtily, we don't increment the ref counts + * of the items we push onto the temporary array. + * So we rely on the caller knowing not to decrement them, + * and to empty the array before there's any chance of + * it being freed. (Probably should either turn off + * AvREAL or actually increment.) + */ av_store((AV *)res, nret, POPs); break; } Index: gnu/usr.bin/perl/gv.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/gv.h,v diff -u -p -a -u -p -r1.18 gv.h --- gnu/usr.bin/perl/gv.h 14 May 2024 19:38:53 -0000 1.18 +++ gnu/usr.bin/perl/gv.h 22 Jan 2025 00:37:44 -0000 @@ -158,6 +158,15 @@ Return the CV from the GV. /* GVf_INTRO is one-shot flag which indicates that the next assignment of a reference to the glob is to be localised; it distinguishes 'local *g = $ref' from '*g = $ref'. + + GVf_MULTI is used to implement the "used only once" warning. It is + always set on a glob when an existing name is referenced, and when + a name is created when the warning is disabled. A post parse scan + in gv_check() then reports any names where this isn't set. + + GVf_ONCE_FATAL is set on a glob when it is created and fatal "used + only once" warnings are enabled, since PL_curcop no longer has the + fatal flag set at the point where the warnings are reported. */ #define GVf_INTRO 0x01 #define GVf_MULTI 0x02 @@ -168,6 +177,7 @@ Return the CV from the GV. #define GVf_IMPORTED_AV 0x20 #define GVf_IMPORTED_HV 0x40 #define GVf_IMPORTED_CV 0x80 +#define GVf_ONCE_FATAL 0x100 #define GvINTRO(gv) (GvFLAGS(gv) & GVf_INTRO) #define GvINTRO_on(gv) (GvFLAGS(gv) |= GVf_INTRO) @@ -200,6 +210,10 @@ Return the CV from the GV. #define GvIMPORTED_CV(gv) (GvFLAGS(gv) & GVf_IMPORTED_CV) #define GvIMPORTED_CV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_CV) #define GvIMPORTED_CV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_CV) + +#define GvONCE_FATAL(gv) (GvFLAGS(gv) & GVf_ONCE_FATAL) +#define GvONCE_FATAL_on(gv) (GvFLAGS(gv) |= GVf_ONCE_FATAL) +#define GvONCE_FATAL_off(gv) (GvFLAGS(gv) &= ~GVf_ONCE_FATAL) #ifndef PERL_CORE # define GvIN_PAD(gv) 0 Index: gnu/usr.bin/perl/handy.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/handy.h,v diff -u -p -a -u -p -r1.23 handy.h --- gnu/usr.bin/perl/handy.h 14 May 2024 19:38:53 -0000 1.23 +++ gnu/usr.bin/perl/handy.h 22 Jan 2025 00:37:44 -0000 @@ -507,8 +507,8 @@ Perl_xxx(aTHX_ ...) form for any API cal #endif #define PERL_JNP_TO_DECIMAL_(maJor,miNor,Patch) \ - /* '10*' leaves room for things like alpha, beta, releases */ \ - (10 * ((maJor) * 1000000) + ((miNor) * 1000) + (Patch)) + /* '10*' leaves room for things like alpha, beta, releases */ \ + (10 * (((maJor) * 1000000) + ((miNor) * 1000) + (Patch))) #define PERL_DECIMAL_VERSION_ \ PERL_JNP_TO_DECIMAL_(PERL_VERSION_MAJOR, PERL_VERSION_MINOR, \ PERL_VERSION_PATCH) @@ -574,13 +574,13 @@ becomes # define PERL_VERSION_LT(j,n,p) /* < '*' effectively means < 0 */ \ (PERL_DECIMAL_VERSION_ < PERL_JNP_TO_DECIMAL_( (j), \ (n), \ - (((p) == '*') ? 0 : p))) + (((p) == '*') ? 0 : (p)))) # define PERL_VERSION_GE(j,n,p) (! PERL_VERSION_LT(j,n,p)) -# define PERL_VERSION_LE(j,n,p) /* <= '*' effectively means < n+1 */ \ - (PERL_DECIMAL_VERSION_ < PERL_JNP_TO_DECIMAL_( (j), \ - (((p) == '*') ? ((n)+1) : (n)), \ - (((p) == '*') ? 0 : p))) +# define PERL_VERSION_LE(j,n,p) /* <= '*' effectively means <= 999 */ \ + (PERL_DECIMAL_VERSION_ <= PERL_JNP_TO_DECIMAL_( (j), \ + (n), \ + (((p) == '*') ? 999 : (p)))) # define PERL_VERSION_GT(j,n,p) (! PERL_VERSION_LE(j,n,p)) /* @@ -2628,7 +2628,7 @@ Memory obtained by this should B b =for apidoc Am|void|Newxz|void* ptr|int nitems|type =for apidoc_item |void*|safecalloc|size_t nitems|size_t item_size -The XSUB-writer's interface to the C C function. The allocated +The XSUB-writer's interface to the C C function. The allocated memory is zeroed with C. See also C>. Memory obtained by this should B be freed with L. @@ -2688,7 +2688,8 @@ optimise. =for apidoc_section $utility =for apidoc Amu|void|StructCopy|type *src|type *dest|type -This is an architecture-independent macro to copy one structure to another. +This is an architecture-independent macro that does a shallow copy of one +structure to another. =for apidoc Am|void|PoisonWith|void* dest|int nitems|type|U8 byte @@ -3110,6 +3111,35 @@ STMT_START { \ (x) ^= ((x) << 26); \ } STMT_END +#ifdef PERL_CORE +/* Convenience macros for dealing with IV_MIN: + In two's complement system, the absolute value of IV_MIN (i.e. -IV_MIN) + cannot be represented in IV. Thus we cannot use simple negation + (like "-iv") if "iv" might be IV_MIN or -IV_MIN. + Note that expressions like "iv = -(UV)iv;" is also not portable + as "-(UV)iv" may not fit in IV range and attempt to convert such value + to IV might get implementation-defined result or raise a signal. */ + +/* Negate IV in the range [IV_MIN, 0) to positive (absolute) UV value. + Written this way to avoid every subexpression never cause signed integer + overflow (even for two's complement), and make it possible to be compiled + into single negation by optimizing compilers. */ +# define NEGATE_2UV(iv) (ASSUME((iv) < 0), (UV)-((iv) + 1) + 1U) + +/* Absolute value of IV_MIN as UV. */ +# define ABS_IV_MIN NEGATE_2UV(IV_MIN) + +/* Negate UV in the range [0, abs(IV_MIN)] to zero or negative IV value + in the range [IV_MIN, 0]. Written this way to avoid casting non-IV value + into IV (which is either the result is implementation-defined or an + implementation-defined signal is raised). Note that "8" below is an + arbitrary value to force both branches of conditional operator to be + non-constant and eventually make it possible to be compiled into + single negation by optimizing compilers. */ +# define NEGATE_2IV(uv) (ASSUME((uv) <= ABS_IV_MIN), \ + (uv) < 8U ? -(IV)(uv) : -(IV)((uv) - 8U) - 8) + +#endif /* PERL_CORE */ #endif /* PERL_HANDY_H_ */ Index: gnu/usr.bin/perl/hv.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/hv.c,v diff -u -p -a -u -p -r1.27 hv.c --- gnu/usr.bin/perl/hv.c 14 May 2024 19:38:53 -0000 1.27 +++ gnu/usr.bin/perl/hv.c 22 Jan 2025 00:37:44 -0000 @@ -337,8 +337,9 @@ dereferenced to get the original C. They differ only in how the hash key is specified. -In C, the key is a C language string literal, enclosed in double -quotes. It is never treated as being in UTF-8. +In C, the key must be a C language string literal, enclosed in +double quotes. It is never treated as being in UTF-8. There is no +length_parameter. In C, C is either NULL or points to the first byte of the string specifying the key, and its length in bytes is given by the absolute value of @@ -397,21 +398,34 @@ See L is the length of the key. If C is -negative the key is assumed to be in UTF-8-encoded Unicode. +These return a boolean indicating whether the specified hash key exists. + +In C, the key must be a C language string literal, enclosed in +double quotes. It is never treated as being in UTF-8. There is no +length_parameter. + +In C, the absolute value of C is the length of the key. If +C is negative the key is assumed to be in UTF-8-encoded Unicode. =for apidoc hv_fetch +=for apidoc_item ||hv_fetchs|HV *hv|"key"|I32 lval -Returns the SV which corresponds to the specified key in the hash. -The absolute value of C is the length of the key. If C is -negative the key is assumed to be in UTF-8-encoded Unicode. If -C is set then the fetch will be part of a store. This means that if -there is no value in the hash associated with the given key, then one is -created and a pointer to it is returned. The C it points to can be -assigned to. But always check that the -return value is non-null before dereferencing it to an C. +These return the SV which corresponds to the specified key in the hash. + +In C, the key must be a C language string literal, enclosed in +double quotes. It is never treated as being in UTF-8. There is no +length_parameter. + +In C, the absolute value of C is the length of the key. If +C is negative the key is assumed to be in UTF-8-encoded Unicode. + +In both, if C is set, then the fetch will be part of a store. This means +that if there is no value in the hash associated with the given key, then one +is created and a pointer to it is returned. The C it points to can be +assigned to. But always check that the return value is non-null before +dereferencing it to an C. See L for more information on how to use this function on tied hashes. @@ -1151,8 +1165,6 @@ Perl_hv_pushkv(pTHX_ HV *hv, U32 flags) || mg_find(MUTABLE_SV(hv), PERL_MAGIC_env) #endif ); - dSP; - PERL_ARGS_ASSERT_HV_PUSHKV; assert(flags); /* must be pushing at least one of keys and values */ @@ -1161,11 +1173,11 @@ Perl_hv_pushkv(pTHX_ HV *hv, U32 flags) if (tied) { SSize_t ext = (flags == 3) ? 2 : 1; while ((entry = hv_iternext(hv))) { - EXTEND(SP, ext); + rpp_extend(ext); if (flags & 1) - PUSHs(hv_iterkeysv(entry)); + rpp_push_1(hv_iterkeysv(entry)); if (flags & 2) - PUSHs(hv_iterval(hv, entry)); + rpp_push_1(hv_iterval(hv, entry)); } } else { @@ -1180,21 +1192,19 @@ Perl_hv_pushkv(pTHX_ HV *hv, U32 flags) ext = nkeys * ((flags == 3) ? 2 : 1); EXTEND_MORTAL(nkeys); - EXTEND(SP, ext); + rpp_extend(ext); while ((entry = hv_iternext(hv))) { if (flags & 1) { SV *keysv = newSVhek(HeKEY_hek(entry)); SvTEMP_on(keysv); PL_tmps_stack[++PL_tmps_ix] = keysv; - PUSHs(keysv); + rpp_push_1(keysv); } if (flags & 2) - PUSHs(HeVAL(entry)); + rpp_push_1(HeVAL(entry)); } } - - PUTBACK; } @@ -1239,13 +1249,21 @@ Perl_hv_bucket_ratio(pTHX_ HV *hv) /* =for apidoc hv_delete +=for apidoc_item ||hv_deletes|HV *hv|"key"|U32 flags + +These delete a key/value pair in the hash. The value's SV is removed from +the hash, made mortal, and returned to the caller. + +In C, the key must be a C language string literal, enclosed in +double quotes. It is never treated as being in UTF-8. There is no +length_parameter. + +In C, the absolute value of C is the length of the key. If +C is negative the key is assumed to be in UTF-8-encoded Unicode. -Deletes a key/value pair in the hash. The value's SV is removed from -the hash, made mortal, and returned to the caller. The absolute -value of C is the length of the key. If C is negative the -key is assumed to be in UTF-8-encoded Unicode. The C value -will normally be zero; if set to C then C will be returned. -C will also be returned if the key is not found. +In both, the C value will normally be zero; if set to C then +C will be returned. C will also be returned if the key is not +found. =for apidoc hv_delete_ent @@ -2245,9 +2263,10 @@ Perl_hv_undef_flags(pTHX_ HV *hv, U32 fl * in sv_clear(), and changes here should be done there too */ if (PL_phase != PERL_PHASE_DESTRUCT && HvHasNAME(hv)) { if (PL_stashcache) { + HEK *hek = HvNAME_HEK(hv); DEBUG_o(Perl_deb(aTHX_ "hv_undef_flags clearing PL_stashcache for '%" - HEKf "'\n", HEKfARG(HvNAME_HEK(hv)))); - (void)hv_deletehek(PL_stashcache, HvNAME_HEK(hv), G_DISCARD); + HEKf "'\n", HEKfARG(hek))); + (void)hv_deletehek(PL_stashcache, hek, G_DISCARD); } hv_name_set(hv, NULL, 0, 0); } Index: gnu/usr.bin/perl/inline.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/inline.h,v diff -u -p -a -u -p -r1.8 inline.h --- gnu/usr.bin/perl/inline.h 14 May 2024 19:38:53 -0000 1.8 +++ gnu/usr.bin/perl/inline.h 22 Jan 2025 00:37:44 -0000 @@ -216,6 +216,24 @@ Perl_av_new_alloc(pTHX_ SSize_t size, bo } +/* remove (AvARRAY(av) - AvALLOC(av)) offset from empty array */ + +PERL_STATIC_INLINE void +Perl_av_remove_offset(pTHX_ AV *av) +{ + PERL_ARGS_ASSERT_AV_REMOVE_OFFSET; + assert(AvFILLp(av) == -1); + SSize_t i = AvARRAY(av) - AvALLOC(av); + if (i) { + AvARRAY(av) = AvALLOC(av); + AvMAX(av) += i; +#ifdef PERL_RC_STACK + Zero(AvALLOC(av), i, SV*); +#endif + } +} + + /* ------------------------------- cv.h ------------------------------- */ /* @@ -359,7 +377,7 @@ S_PadnameIN_SCOPE(const PADNAME * const /* ------------------------------- pp.h ------------------------------- */ -PERL_STATIC_INLINE I32 +PERL_STATIC_INLINE Stack_off_t Perl_TOPMARK(pTHX) { DEBUG_s(DEBUG_v(PerlIO_printf(Perl_debug_log, @@ -369,7 +387,7 @@ Perl_TOPMARK(pTHX) return *PL_markstack_ptr; } -PERL_STATIC_INLINE I32 +PERL_STATIC_INLINE Stack_off_t Perl_POPMARK(pTHX) { DEBUG_s(DEBUG_v(PerlIO_printf(Perl_debug_log, @@ -380,6 +398,804 @@ Perl_POPMARK(pTHX) return *PL_markstack_ptr--; } +/* +=for apidoc_section $rpp + +=for apidoc rpp_extend +Ensures that there is space on the stack to push C items, extending it +if necessary. + +=cut +*/ + +PERL_STATIC_INLINE void +Perl_rpp_extend(pTHX_ SSize_t n) +{ + PERL_ARGS_ASSERT_RPP_EXTEND; + + EXTEND_HWM_SET(PL_stack_sp, n); +#ifndef STRESS_REALLOC + if (UNLIKELY(_EXTEND_NEEDS_GROW(PL_stack_sp, n))) +#endif + { + (void)stack_grow(PL_stack_sp, PL_stack_sp, n); + } +} + + +/* +=for apidoc rpp_popfree_to + +Pop and free all items on the argument stack above C. On return, +C will be equal to C. + +=cut +*/ + +PERL_STATIC_INLINE void +Perl_rpp_popfree_to(pTHX_ SV **sp) +{ + PERL_ARGS_ASSERT_RPP_POPFREE_TO; + + assert(sp <= PL_stack_sp); +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + while (PL_stack_sp > sp) { + SV *sv = *PL_stack_sp--; + SvREFCNT_dec(sv); + } +#else + PL_stack_sp = sp; +#endif +} + + +/* +=for apidoc rpp_popfree_to_NN + +A variant of rpp_popfree_to() which assumes that all the pointers being +popped off the stack are non-NULL. + +=cut +*/ + +PERL_STATIC_INLINE void +Perl_rpp_popfree_to_NN(pTHX_ SV **sp) +{ + PERL_ARGS_ASSERT_RPP_POPFREE_TO_NN; + + assert(sp <= PL_stack_sp); +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + while (PL_stack_sp > sp) { + SV *sv = *PL_stack_sp--; + assert(sv); + SvREFCNT_dec_NN(sv); + } +#else + PL_stack_sp = sp; +#endif +} + + +/* +=for apidoc rpp_popfree_1 + +Pop and free the top item on the argument stack and update C. + +=cut +*/ + +PERL_STATIC_INLINE void +Perl_rpp_popfree_1(pTHX) +{ + PERL_ARGS_ASSERT_RPP_POPFREE_1; + +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + SV *sv = *PL_stack_sp--; + SvREFCNT_dec(sv); +#else + PL_stack_sp--; +#endif +} + + +/* +=for apidoc rpp_popfree_1_NN + +A variant of rpp_popfree_1() which assumes that the pointer being popped +off the stack is non-NULL. + +=cut +*/ + +PERL_STATIC_INLINE void +Perl_rpp_popfree_1_NN(pTHX) +{ + PERL_ARGS_ASSERT_RPP_POPFREE_1_NN; + + assert(*PL_stack_sp); +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + SV *sv = *PL_stack_sp--; + SvREFCNT_dec_NN(sv); +#else + PL_stack_sp--; +#endif +} + + +/* +=for apidoc rpp_popfree_2 + +Pop and free the top two items on the argument stack and update +C. + +=cut +*/ + + +PERL_STATIC_INLINE void +Perl_rpp_popfree_2(pTHX) +{ + PERL_ARGS_ASSERT_RPP_POPFREE_2; + +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + for (int i = 0; i < 2; i++) { + SV *sv = *PL_stack_sp--; + SvREFCNT_dec(sv); + } +#else + PL_stack_sp -= 2; +#endif +} + + +/* +=for apidoc rpp_popfree_2_NN + +A variant of rpp_popfree_2() which assumes that the two pointers being +popped off the stack are non-NULL. + +=cut +*/ + + +PERL_STATIC_INLINE void +Perl_rpp_popfree_2_NN(pTHX) +{ + PERL_ARGS_ASSERT_RPP_POPFREE_2_NN; +#ifdef PERL_RC_STACK + SV *sv2 = *PL_stack_sp--; + assert(sv2); + SV *sv1 = *PL_stack_sp; + assert(sv1); + + assert(rpp_stack_is_rc()); + U32 rc1 = SvREFCNT(sv1); + U32 rc2 = SvREFCNT(sv2); + /* This expression is intended to be true if either of rc1 or rc2 has + * the value 0 or 1, but using only a single branch test, rather + * than the two branches that a compiler would plant for a boolean + * expression. We are working on the assumption that, most of the + * time, neither of the args to a binary function will need to be + * freed - they're likely to lex vars, or PADTMPs or whatever. + * So give the CPU a single branch that is rarely taken. */ + if (UNLIKELY( !(rc1>>1) + !(rc2>>1) )) + /* at least one of the old SVs needs freeing. Do it the long way */ + Perl_rpp_free_2_(aTHX_ sv1, sv2, rc1, rc2); + else { + SvREFCNT(sv1) = rc1 - 1; + SvREFCNT(sv2) = rc2 - 1; + } + PL_stack_sp--; +#else + PL_stack_sp -= 2; +#endif +} + + +/* +=for apidoc rpp_pop_1_norc + +Pop and return the top item off the argument stack and update +C. It's similar to rpp_popfree_1(), except that it actually +returns a value, and it I decrement the SV's reference count. +On non-C builds it actually increments the SV's reference +count. + +This is useful in cases where the popped value is immediately embedded +somewhere e.g. via av_store(), allowing you skip decrementing and then +immediately incrementing the reference count again (and risk prematurely +freeing the SV if it had a RC of 1). On non-RC builds, the reference count +bookkeeping still works too, which is why it should be used rather than +a simple C<*PL_stack_sp-->. + +=cut +*/ + +PERL_STATIC_INLINE SV* +Perl_rpp_pop_1_norc(pTHX) +{ + PERL_ARGS_ASSERT_RPP_POP_1_NORC + + SV *sv = *PL_stack_sp--; + +#ifndef PERL_RC_STACK + SvREFCNT_inc(sv); +#else + assert(rpp_stack_is_rc()); +#endif + return sv; +} + + + +/* +=for apidoc rpp_push_1 +=for apidoc_item rpp_push_IMM +=for apidoc_item rpp_push_2 +=for apidoc_item rpp_xpush_1 +=for apidoc_item rpp_xpush_IMM +=for apidoc_item rpp_xpush_2 + +Push one or two SVs onto the stack, incrementing their reference counts +and updating C. With the C variants, it extends the stack +first. The C variants assume that the single argument is an immortal +such as <&PL_sv_undef> and, for efficiency, will skip incrementing its +reference count. + +=cut +*/ + +PERL_STATIC_INLINE void +Perl_rpp_push_1(pTHX_ SV *sv) +{ + PERL_ARGS_ASSERT_RPP_PUSH_1; + + *++PL_stack_sp = sv; +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + SvREFCNT_inc_simple_void_NN(sv); +#endif +} + +PERL_STATIC_INLINE void +Perl_rpp_push_IMM(pTHX_ SV *sv) +{ + PERL_ARGS_ASSERT_RPP_PUSH_IMM; + + assert(SvIMMORTAL(sv)); + *++PL_stack_sp = sv; +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); +#endif +} + +PERL_STATIC_INLINE void +Perl_rpp_push_2(pTHX_ SV *sv1, SV *sv2) +{ + PERL_ARGS_ASSERT_RPP_PUSH_2; + + *++PL_stack_sp = sv1; + *++PL_stack_sp = sv2; +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + SvREFCNT_inc_simple_void_NN(sv1); + SvREFCNT_inc_simple_void_NN(sv2); +#endif +} + +PERL_STATIC_INLINE void +Perl_rpp_xpush_1(pTHX_ SV *sv) +{ + PERL_ARGS_ASSERT_RPP_XPUSH_1; + + rpp_extend(1); + rpp_push_1(sv); +} + +PERL_STATIC_INLINE void +Perl_rpp_xpush_IMM(pTHX_ SV *sv) +{ + PERL_ARGS_ASSERT_RPP_XPUSH_IMM; + + rpp_extend(1); + rpp_push_IMM(sv); +} + +PERL_STATIC_INLINE void +Perl_rpp_xpush_2(pTHX_ SV *sv1, SV *sv2) +{ + PERL_ARGS_ASSERT_RPP_XPUSH_2; + + rpp_extend(2); + rpp_push_2(sv1, sv2); +} + + +/* +=for apidoc rpp_push_1_norc + +Push C onto the stack without incrementing its reference count, and +update C. On non-PERL_RC_STACK builds, mortalise too. + +This is most useful where an SV has just been created and already has a +reference count of 1, but has not yet been anchored anywhere. + +=cut +*/ + +PERL_STATIC_INLINE void +Perl_rpp_push_1_norc(pTHX_ SV *sv) +{ + PERL_ARGS_ASSERT_RPP_PUSH_1; + + *++PL_stack_sp = sv; +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); +#else + sv_2mortal(sv); +#endif +} + + +/* +=for apidoc rpp_replace_1_1 +=for apidoc_item rpp_replace_1_1_NN +=for apidoc_item rpp_replace_1_IMM_NN + +Replace the current top stack item with C, while suitably adjusting +reference counts. Equivalent to rpp_popfree_1(); rpp_push_1(sv), but +is more efficient and handles both SVs being the same. + +The C<_NN> variant assumes that the pointer on the stack to the SV being +freed is non-NULL. + +The C variant is like the C<_NN> variant, but in addition, assumes +that the single argument is an immortal such as <&PL_sv_undef> and, for +efficiency, will skip incrementing its reference count. + +=cut +*/ + +PERL_STATIC_INLINE void +Perl_rpp_replace_1_1(pTHX_ SV *sv) +{ + PERL_ARGS_ASSERT_RPP_REPLACE_1_1; + + assert(sv); +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + SV *oldsv = *PL_stack_sp; + *PL_stack_sp = sv; + SvREFCNT_inc_simple_void_NN(sv); + SvREFCNT_dec(oldsv); +#else + *PL_stack_sp = sv; +#endif +} + + +PERL_STATIC_INLINE void +Perl_rpp_replace_1_1_NN(pTHX_ SV *sv) +{ + PERL_ARGS_ASSERT_RPP_REPLACE_1_1_NN; + + assert(sv); + assert(*PL_stack_sp); +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + SV *oldsv = *PL_stack_sp; + *PL_stack_sp = sv; + SvREFCNT_inc_simple_void_NN(sv); + SvREFCNT_dec_NN(oldsv); +#else + *PL_stack_sp = sv; +#endif +} + + +PERL_STATIC_INLINE void +Perl_rpp_replace_1_IMM_NN(pTHX_ SV *sv) +{ + PERL_ARGS_ASSERT_RPP_REPLACE_1_IMM_NN; + + assert(sv); + assert(SvIMMORTAL(sv)); + assert(*PL_stack_sp); +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + SV *oldsv = *PL_stack_sp; + *PL_stack_sp = sv; + SvREFCNT_dec_NN(oldsv); +#else + *PL_stack_sp = sv; +#endif +} + + +/* +=for apidoc rpp_replace_2_1 +=for apidoc_item rpp_replace_2_1_NN +=for apidoc_item rpp_replace_2_IMM_NN + +Replace the current top to stacks item with C, while suitably +adjusting reference counts. Equivalent to rpp_popfree_2(); rpp_push_1(sv), +but is more efficient and handles SVs being the same. + +The C<_NN> variant assumes that the pointers on the stack to the SVs being +freed are non-NULL. + +The C variant is like the C<_NN> variant, but in addition, assumes +that the single argument is an immortal such as <&PL_sv_undef> and, for +efficiency, will skip incrementing its reference count. +=cut +*/ + +PERL_STATIC_INLINE void +Perl_rpp_replace_2_1(pTHX_ SV *sv) +{ + PERL_ARGS_ASSERT_RPP_REPLACE_2_1; + +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + /* replace PL_stack_sp[-1] first; leave PL_stack_sp[0] in place while + * we free [-1], so if an exception occurs, [0] will still be freed. + */ + SV *oldsv = PL_stack_sp[-1]; + PL_stack_sp[-1] = sv; + SvREFCNT_inc_simple_void_NN(sv); + SvREFCNT_dec(oldsv); + oldsv = *PL_stack_sp--; + SvREFCNT_dec(oldsv); +#else + *--PL_stack_sp = sv; +#endif +} + + +/* Private helper function for _NN and _IMM_NN variants. + * Assumes sv has already had its ref count incremented, + * ready for being put on the stack. + * Intended to be small and fast, since it's inlined into many hot parts of + * code. + */ + +PERL_STATIC_INLINE void +Perl_rpp_replace_2_1_COMMON(pTHX_ SV *sv) +{ + + assert(sv); +#ifdef PERL_RC_STACK + SV *sv2 = *PL_stack_sp--; + assert(sv2); + SV *sv1 = *PL_stack_sp; + assert(sv1); + + *PL_stack_sp = sv; + assert(rpp_stack_is_rc()); + U32 rc1 = SvREFCNT(sv1); + U32 rc2 = SvREFCNT(sv2); + /* This expression is intended to be true if either of rc1 or rc2 has + * the value 0 or 1, but using only a single branch test, rather + * than the two branches that a compiler would plant for a boolean + * expression. We are working on the assumption that, most of the + * time, neither of the args to a binary function will need to be + * freed - they're likely to lex vars, or PADTMPs or whatever. + * So give the CPU a single branch that is rarely taken. */ + if (UNLIKELY( !(rc1>>1) + !(rc2>>1) )) + /* at least one of the old SVs needs freeing. Do it the long way */ + Perl_rpp_free_2_(aTHX_ sv1, sv2, rc1, rc2); + else { + SvREFCNT(sv1) = rc1 - 1; + SvREFCNT(sv2) = rc2 - 1; + } +#else + *--PL_stack_sp = sv; +#endif +} + + +PERL_STATIC_INLINE void +Perl_rpp_replace_2_1_NN(pTHX_ SV *sv) +{ + PERL_ARGS_ASSERT_RPP_REPLACE_2_1_NN; + + assert(sv); +#ifdef PERL_RC_STACK + SvREFCNT_inc_simple_void_NN(sv); +#endif + rpp_replace_2_1_COMMON(sv); +} + + +PERL_STATIC_INLINE void +Perl_rpp_replace_2_IMM_NN(pTHX_ SV *sv) +{ + PERL_ARGS_ASSERT_RPP_REPLACE_2_IMM_NN; + + assert(sv); + assert(SvIMMORTAL(sv)); + rpp_replace_2_1_COMMON(sv); +} + + +/* +=for apidoc rpp_replace_at + +Replace the SV at address sp within the stack with C, while suitably +adjusting reference counts. Equivalent to C<*sp = sv>, except with proper +reference count handling. + +=cut +*/ + +PERL_STATIC_INLINE void +Perl_rpp_replace_at(pTHX_ SV **sp, SV *sv) +{ + PERL_ARGS_ASSERT_RPP_REPLACE_AT; + +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + SV *oldsv = *sp; + *sp = sv; + SvREFCNT_inc_simple_void_NN(sv); + SvREFCNT_dec(oldsv); +#else + *sp = sv; +#endif +} + + +/* +=for apidoc rpp_replace_at_NN + +A variant of rpp_replace_at() which assumes that the SV pointer on the +stack is non-NULL. + +=cut +*/ + +PERL_STATIC_INLINE void +Perl_rpp_replace_at_NN(pTHX_ SV **sp, SV *sv) +{ + PERL_ARGS_ASSERT_RPP_REPLACE_AT_NN; + + assert(sv); + assert(*sp); +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + SV *oldsv = *sp; + *sp = sv; + SvREFCNT_inc_simple_void_NN(sv); + SvREFCNT_dec_NN(oldsv); +#else + *sp = sv; +#endif +} + + +/* +=for apidoc rpp_replace_at_norc + +Replace the SV at address sp within the stack with C, while suitably +adjusting the reference count of the old SV. Equivalent to C<*sp = sv>, +except with proper reference count handling. + +C's reference count doesn't get incremented. On non-C +builds, it gets mortalised too. + +This is most useful where an SV has just been created and already has a +reference count of 1, but has not yet been anchored anywhere. + +=cut +*/ + +PERL_STATIC_INLINE void +Perl_rpp_replace_at_norc(pTHX_ SV **sp, SV *sv) +{ + PERL_ARGS_ASSERT_RPP_REPLACE_AT_NORC; + +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + SV *oldsv = *sp; + *sp = sv; + SvREFCNT_dec(oldsv); +#else + *sp = sv; + sv_2mortal(sv); +#endif +} + + +/* +=for apidoc rpp_replace_at_norc_NN + +A variant of rpp_replace_at_norc() which assumes that the SV pointer on the +stack is non-NULL. + +=cut +*/ + +PERL_STATIC_INLINE void +Perl_rpp_replace_at_norc_NN(pTHX_ SV **sp, SV *sv) +{ + PERL_ARGS_ASSERT_RPP_REPLACE_AT_NORC_NN; + + assert(*sp); +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); + SV *oldsv = *sp; + *sp = sv; + SvREFCNT_dec_NN(oldsv); +#else + *sp = sv; + sv_2mortal(sv); +#endif +} + + +/* +=for apidoc rpp_context + +Impose void, scalar or list context on the stack. +First, pop C items off the stack, then when C is: +C: return as-is. +C: pop everything back to C +C: move the top stack item (or C<&PL_sv_undef> if none) to +C and free everything above it. + +=cut +*/ + +PERL_STATIC_INLINE void +Perl_rpp_context(pTHX_ SV **mark, U8 gimme, SSize_t extra) +{ + PERL_ARGS_ASSERT_RPP_CONTEXT; + assert(extra >= 0); + assert(mark <= PL_stack_sp - extra); + + if (gimme == G_LIST) + mark = PL_stack_sp - extra; + else if (gimme == G_SCALAR) { + SV **svp = PL_stack_sp - extra; + mark++; + if (mark > svp) { + /* empty list (plus extra) */ + rpp_popfree_to(svp); + rpp_extend(1); + *++PL_stack_sp = &PL_sv_undef; + return; + } + /* swap top and bottom list items */ + SV *top = *svp; + *svp = *mark; + *mark = top; + } + rpp_popfree_to(mark); +} + + + + +/* +=for apidoc rpp_try_AMAGIC_1 +=for apidoc_item rpp_try_AMAGIC_2 + +Check whether either of the one or two SVs at the top of the stack is +magical or a ref, and in either case handle it specially: invoke get +magic, call an overload method, or replace a ref with a temporary numeric +value, as appropriate. If this function returns true, it indicates that +the correct return value is already on the stack. Intended to be used at +the beginning of the PP function for unary or binary ops. + +=cut +*/ + +PERL_STATIC_INLINE bool +Perl_rpp_try_AMAGIC_1(pTHX_ int method, int flags) +{ + return UNLIKELY((SvFLAGS(*PL_stack_sp) & (SVf_ROK|SVs_GMG))) + && Perl_try_amagic_un(aTHX_ method, flags); +} + +PERL_STATIC_INLINE bool +Perl_rpp_try_AMAGIC_2(pTHX_ int method, int flags) +{ + return UNLIKELY(((SvFLAGS(PL_stack_sp[-1])|SvFLAGS(PL_stack_sp[0])) + & (SVf_ROK|SVs_GMG))) + && Perl_try_amagic_bin(aTHX_ method, flags); +} + + +/* +=for apidoc rpp_stack_is_rc + +Returns a boolean value indicating whether the stack is currently +reference-counted. Note that if the stack is split (bottom half RC, top +half non-RC), this function returns false, even if the top half currently +contains zero items. + +=cut +*/ + +PERL_STATIC_INLINE bool +Perl_rpp_stack_is_rc(pTHX) +{ +#ifdef PERL_RC_STACK + return AvREAL(PL_curstack) && !PL_curstackinfo->si_stack_nonrc_base; +#else + return 0; +#endif + +} + + +/* +=for apidoc rpp_is_lone + +Indicates whether the stacked SV C (assumed to be not yet popped off +the stack) is only kept alive due to a single reference from the argument +stack and/or and the temps stack. + +This can used for example to decide whether the copying of return values +in rvalue context can be skipped, or whether it shouldn't be assigned to +in lvalue context. + +=cut +*/ + + +PERL_STATIC_INLINE bool +Perl_rpp_is_lone(pTHX_ SV *sv) +{ +#ifdef PERL_RC_STACK + /* note that rpp_is_lone() can be used in wrapped pp functions, + * where technically the stack is no longer ref-counted; but because + * the args are non-RC copies of RC args further down the stack, we + * can't be in a *completely* non-ref stack. + */ + assert(AvREAL(PL_curstack)); +#endif + + return SvREFCNT(sv) <= cBOOL(SvTEMP(sv)) +#ifdef PERL_RC_STACK + + 1 + && !SvIMMORTAL(sv) /* PL_sv_undef etc are never stealable */ +#endif + ; +} + + +/* +=for apidoc rpp_invoke_xs + +Call the XS function associated with C. Wraps the call if necessary to +handle XS functions which are not aware of reference-counted stacks. + +=cut +*/ + + +PERL_STATIC_INLINE void +Perl_rpp_invoke_xs(pTHX_ CV *cv) +{ + PERL_ARGS_ASSERT_RPP_INVOKE_XS; + +#ifdef PERL_RC_STACK + if (!CvXS_RCSTACK(cv)) + Perl_xs_wrap(aTHX_ CvXSUB(cv), cv); + else +#endif + CvXSUB(cv)(aTHX_ cv); +} + + + + /* ----------------------------- regexp.h ----------------------------- */ /* PVLVs need to act as a superset of all scalar types - they are basically @@ -686,13 +1502,16 @@ Perl_is_utf8_invariant_string_loc(const # endif #endif -#if defined(_MSC_VER) +#if defined(WIN32) # include -# pragma intrinsic(_BitScanForward) -# pragma intrinsic(_BitScanReverse) -# ifdef _WIN64 -# pragma intrinsic(_BitScanForward64) -# pragma intrinsic(_BitScanReverse64) + /* MinGW warns that it ignores "pragma intrinsic". */ +# if defined(_MSC_VER) +# pragma intrinsic(_BitScanForward) +# pragma intrinsic(_BitScanReverse) +# if defined(_WIN64) +# pragma intrinsic(_BitScanForward64) +# pragma intrinsic(_BitScanReverse64) +# endif # endif #endif @@ -728,7 +1547,7 @@ Perl_lsbit_pos64(U64 word) return (unsigned) PERL_CTZ_64(word); -# elif U64SIZE == 8 && defined(_WIN64) && defined(_MSC_VER) +# elif U64SIZE == 8 && defined(_WIN64) # define PERL_HAS_FAST_GET_LSB_POS64 { @@ -782,7 +1601,7 @@ Perl_lsbit_pos32(U32 word) return (unsigned) PERL_CTZ_32(word); -#elif U32SIZE == 4 && defined(_MSC_VER) +#elif U32SIZE == 4 && defined(WIN32) # define PERL_HAS_FAST_GET_LSB_POS32 { @@ -791,6 +1610,14 @@ Perl_lsbit_pos32(U32 word) return (unsigned)index; } +#elif defined(PERL_HAS_FAST_GET_LSB_POS64) +# define PERL_HAS_FAST_GET_LSB_POS32 + + /* Unlikely, but possible for the platform to have a wider fast operation + * but not a narrower one. But easy enough to handle the case by widening + * the parameter size. */ + return lsbit_pos64(word); + #else return single_1bit_pos32(word & (~word + 1)); @@ -828,7 +1655,7 @@ Perl_msbit_pos64(U64 word) return (unsigned) LZC_TO_MSBIT_POS_(U64, PERL_CLZ_64(word)); -# elif U64SIZE == 8 && defined(_WIN64) && defined(_MSC_VER) +# elif U64SIZE == 8 && defined(_WIN64) # define PERL_HAS_FAST_GET_MSB_POS64 { @@ -884,8 +1711,7 @@ Perl_msbit_pos32(U32 word) # define PERL_HAS_FAST_GET_MSB_POS32 return (unsigned) LZC_TO_MSBIT_POS_(U32, PERL_CLZ_32(word)); - -#elif U32SIZE == 4 && defined(_MSC_VER) +#elif U32SIZE == 4 && defined(WIN32) # define PERL_HAS_FAST_GET_MSB_POS32 { @@ -894,6 +1720,11 @@ Perl_msbit_pos32(U32 word) return (unsigned)index; } +#elif defined(PERL_HAS_FAST_GET_MSB_POS64) +# define PERL_HAS_FAST_GET_MSB_POS32 + + return msbit_pos64(word); /* Let compiler widen parameter */ + #else word |= (word >> 1); @@ -908,6 +1739,13 @@ Perl_msbit_pos32(U32 word) } +/* Note that if you are working through all the 1 bits in a word, and don't + * care which order you process them in, it is better to use lsbit_pos. This + * is because some platforms have a fast way to find the msb but not the lsb, + * and others vice versa. The code above falls back to use the single + * available fast method when the desired one is missing, and it is cheaper to + * fall back from lsb to msb than the other way around */ + #if UVSIZE == U64SIZE # define msbit_pos(word) msbit_pos64(word) # define lsbit_pos(word) lsbit_pos64(word) @@ -976,18 +1814,6 @@ Perl_single_1bit_pos32(U32 word) return lsbit_pos32(word); -/* Unlikely, but possible for the platform to have a wider fast operation but - * not a narrower one. But easy enough to handle the case by widening the - * parameter size. (Going the other way, emulating 64 bit by two 32 bit ops - * would be slower than the deBruijn method.) */ -#elif defined(PERL_HAS_FAST_GET_MSB_POS64) - - return msbit_pos64(word); - -#elif defined(PERL_HAS_FAST_GET_LSB_POS64) - - return lsbit_pos64(word); - #else return PL_deBruijn_bitpos_tab32[(word * PERL_deBruijnMagic32_) @@ -1924,10 +2750,6 @@ Perl_is_utf8_string_loclen_flags(const U assert(0 == (flags & ~(UTF8_DISALLOW_ILLEGAL_INTERCHANGE |UTF8_DISALLOW_PERL_EXTENDED))); - if (len == 0) { - len = strlen((const char *) s); - } - if (flags == 0) { return is_utf8_string_loclen(s, len, ep, el); } @@ -1944,6 +2766,10 @@ Perl_is_utf8_string_loclen_flags(const U return is_c9strict_utf8_string_loclen(s, len, ep, el); } + if (len == 0) { + len = strlen((const char *) s); + } + if (is_utf8_invariant_string_loc(s, len, &first_variant)) { if (el) *el = len; @@ -2150,7 +2976,7 @@ Perl_utf8_hop_back(const U8 *s, SSize_t while (off++ && s > start) { do { s--; - } while (UTF8_IS_CONTINUATION(*s) && s > start); + } while (s > start && UTF8_IS_CONTINUATION(*s)); } GCC_DIAG_IGNORE(-Wcast-qual) @@ -2481,7 +3307,7 @@ Perl_utf8n_to_uvchr_msgs(const U8 *s, UV state = PL_strict_utf8_dfa_tab[256 + type]; uv = (0xff >> type) & NATIVE_UTF8_TO_I8(*s); - while (++s < send) { + while (LIKELY(state != 1) && ++s < send) { type = PL_strict_utf8_dfa_tab[*s]; state = PL_strict_utf8_dfa_tab[256 + state + type]; @@ -2493,10 +3319,6 @@ Perl_utf8n_to_uvchr_msgs(const U8 *s, #endif goto success; } - - if (UNLIKELY(state == 1)) { - break; - } } /* Here is potentially problematic. Use the full mechanism */ @@ -2640,18 +3462,27 @@ S_lossless_NV_to_IV(const NV nv, IV *ivp } # endif +# ifndef NV_PRESERVES_UV + STATIC_ASSERT_STMT(((UV)1 << NV_PRESERVES_UV_BITS) - 1 <= (UV)IV_MAX); +# endif + /* Written this way so that with an always-false NaN comparison we * return false */ - if (!(LIKELY(nv >= (NV) IV_MIN) && LIKELY(nv < IV_MAX_P1))) { - return FALSE; - } - - if ((IV) nv != nv) { - return FALSE; + if ( +# ifdef NV_PRESERVES_UV + LIKELY(nv >= (NV) IV_MIN) && LIKELY(nv < IV_MAX_P1) && +# else + /* If the condition below is not satisfied, lower bits of nv's + * integral part is already lost and accurate conversion to integer + * is impossible. + * Note this should be consistent with S_sv_2iuv_common in sv.c. */ + Perl_fabs(nv) < (NV) ((UV)1 << NV_PRESERVES_UV_BITS) && +# endif + (IV) nv == nv) { + *ivp = (IV) nv; + return TRUE; } - - *ivp = (IV) nv; - return TRUE; + return FALSE; } #endif @@ -2748,7 +3579,10 @@ Perl_cx_pushblock(pTHX_ U8 type, U8 gimm cx->cx_type = type; cx->blk_gimme = gimme; cx->blk_oldsaveix = saveix; - cx->blk_oldsp = (I32)(sp - PL_stack_base); + cx->blk_oldsp = (Stack_off_t)(sp - PL_stack_base); + assert(cxstack_ix <= 0 + || CxTYPE(cx-1) == CXt_SUBST + || cx->blk_oldsp >= (cx-1)->blk_oldsp); cx->blk_oldcop = PL_curcop; cx->blk_oldmarksp = (I32)(PL_markstack_ptr - PL_markstack); cx->blk_oldscopesp = PL_scopestack_ix; @@ -2798,8 +3632,7 @@ Perl_cx_topblock(pTHX_ PERL_CONTEXT *cx) PL_markstack_ptr = PL_markstack + cx->blk_oldmarksp; PL_scopestack_ix = cx->blk_oldscopesp; PL_curpm = cx->blk_oldpm; - - PL_stack_sp = PL_stack_base + cx->blk_oldsp; + Perl_rpp_popfree_to(aTHX_ PL_stack_base + cx->blk_oldsp); } @@ -2812,7 +3645,7 @@ Perl_cx_pushsub(pTHX_ PERL_CONTEXT *cx, PERL_DTRACE_PROBE_ENTRY(cv); cx->blk_sub.old_cxsubix = PL_curstackinfo->si_cxsubix; - PL_curstackinfo->si_cxsubix = cx - PL_curstackinfo->si_cxstack; + PL_curstackinfo->si_cxsubix = (I32)(cx - PL_curstackinfo->si_cxstack); cx->blk_sub.cv = cv; cx->blk_sub.olddepth = CvDEPTH(cv); cx->blk_sub.prevcomppad = PL_comppad; @@ -2834,7 +3667,7 @@ Perl_cx_popsub_common(pTHX_ PERL_CONTEXT assert(CxTYPE(cx) == CXt_SUB); PL_comppad = cx->blk_sub.prevcomppad; - PL_curpad = LIKELY(PL_comppad) ? AvARRAY(PL_comppad) : NULL; + PL_curpad = LIKELY(PL_comppad != NULL) ? AvARRAY(PL_comppad) : NULL; cv = cx->blk_sub.cv; CvDEPTH(cv) = cx->blk_sub.olddepth; cx->blk_sub.cv = NULL; @@ -2858,12 +3691,15 @@ Perl_cx_popsub_args(pTHX_ PERL_CONTEXT * CX_POP_SAVEARRAY(cx); av = MUTABLE_AV(PAD_SVl(0)); - if (UNLIKELY(AvREAL(av))) + if (!SvMAGICAL(av) && SvREFCNT(av) == 1 +#ifndef PERL_RC_STACK + && !AvREAL(av) +#endif + ) + clear_defarray_simple(av); + else /* abandon @_ if it got reified */ clear_defarray(av, 0); - else { - CLEAR_ARGARRAY(av); - } } @@ -2887,7 +3723,7 @@ Perl_cx_pushformat(pTHX_ PERL_CONTEXT *c PERL_ARGS_ASSERT_CX_PUSHFORMAT; cx->blk_format.old_cxsubix = PL_curstackinfo->si_cxsubix; - PL_curstackinfo->si_cxsubix= cx - PL_curstackinfo->si_cxstack; + PL_curstackinfo->si_cxsubix= (I32)(cx - PL_curstackinfo->si_cxstack); cx->blk_format.cv = cv; cx->blk_format.retop = retop; cx->blk_format.gv = gv; @@ -2916,7 +3752,7 @@ Perl_cx_popformat(pTHX_ PERL_CONTEXT *cx SvREFCNT_dec_NN(dfout); PL_comppad = cx->blk_format.prevcomppad; - PL_curpad = LIKELY(PL_comppad) ? AvARRAY(PL_comppad) : NULL; + PL_curpad = LIKELY(PL_comppad != NULL) ? AvARRAY(PL_comppad) : NULL; cv = cx->blk_format.cv; cx->blk_format.cv = NULL; --CvDEPTH(cv); @@ -2948,7 +3784,7 @@ Perl_cx_pusheval(pTHX_ PERL_CONTEXT *cx, Perl_push_evalortry_common(aTHX_ cx, retop, namesv); cx->blk_eval.old_cxsubix = PL_curstackinfo->si_cxsubix; - PL_curstackinfo->si_cxsubix = cx - PL_curstackinfo->si_cxstack; + PL_curstackinfo->si_cxsubix = (I32)(cx - PL_curstackinfo->si_cxstack); } PERL_STATIC_INLINE void @@ -3107,6 +3943,129 @@ Perl_cx_popgiven(pTHX_ PERL_CONTEXT *cx) SvREFCNT_dec(sv); } + +/* Make @_ empty in-place in simple cases: a cheap av_clear(). + * See Perl_clear_defarray() for non-simple cases */ + + +PERL_STATIC_INLINE void +Perl_clear_defarray_simple(pTHX_ AV *av) +{ + PERL_ARGS_ASSERT_CLEAR_DEFARRAY_SIMPLE; + + assert(SvTYPE(av) == SVt_PVAV); + assert(!SvREADONLY(av)); + assert(!SvMAGICAL(av)); + assert(SvREFCNT(av) == 1); + +#ifdef PERL_RC_STACK + assert(AvREAL(av)); + /* this code assumes that destructors called here can't free av + * itself, because pad[0] and/or CX pointers will keep it alive */ + SSize_t i = AvFILLp(av); + while (i >= 0) { + SV *sv = AvARRAY(av)[i]; + AvARRAY(av)[i--] = NULL; + SvREFCNT_dec(sv); + } +#else + assert(!AvREAL(av)); +#endif + AvFILLp(av) = -1; + Perl_av_remove_offset(aTHX_ av); +} + +/* Switch to a different argument stack. + * + * Note that it doesn't update PL_curstackinfo->si_stack_nonrc_base, + * so this should only be used as part of a general switching between + * stackinfos. + */ + +PERL_STATIC_INLINE void +Perl_switch_argstack(pTHX_ AV *to) +{ + PERL_ARGS_ASSERT_SWITCH_ARGSTACK; + + AvFILLp(PL_curstack) = PL_stack_sp - PL_stack_base; + PL_stack_base = AvARRAY(to); + PL_stack_max = PL_stack_base + AvMAX(to); + PL_stack_sp = PL_stack_base + AvFILLp(to); + PL_curstack = to; +} + + +/* Push, and switch to a new stackinfo, allocating one if none are spare, + * to get a fresh set of stacks. + * Update all the interpreter variables like PL_curstackinfo, + * PL_stack_sp, etc. + * current flag meanings: + * 1 make the new arg stack AvREAL + */ + + +PERL_STATIC_INLINE void +Perl_push_stackinfo(pTHX_ I32 type, UV flags) +{ + PERL_ARGS_ASSERT_PUSH_STACKINFO; + + PERL_SI *next = PL_curstackinfo->si_next; + DEBUG_l({ + int i = 0; PERL_SI *p = PL_curstackinfo; + while (p) { i++; p = p->si_prev; } + Perl_deb(aTHX_ "push STACKINFO %d in %s at %s:%d\n", + i, SAFE_FUNCTION__, __FILE__, __LINE__); + }) + + if (!next) { + next = new_stackinfo_flags(32, 2048/sizeof(PERL_CONTEXT) - 1, flags); + next->si_prev = PL_curstackinfo; + PL_curstackinfo->si_next = next; + } + next->si_type = type; + next->si_cxix = -1; + next->si_cxsubix = -1; + PUSHSTACK_INIT_HWM(next); +#ifdef PERL_RC_STACK + next->si_stack_nonrc_base = 0; +#endif + if (flags & 1) + AvREAL_on(next->si_stack); + else + AvREAL_off(next->si_stack); + AvFILLp(next->si_stack) = 0; + switch_argstack(next->si_stack); + PL_curstackinfo = next; + SET_MARK_OFFSET; +} + + +/* Pop, then switch to the previous stackinfo and set of stacks. + * Update all the interpreter variables like PL_curstackinfo, + * PL_stack_sp, etc. */ + +PERL_STATIC_INLINE void +Perl_pop_stackinfo(pTHX) +{ + PERL_ARGS_ASSERT_POP_STACKINFO; + + PERL_SI * const prev = PL_curstackinfo->si_prev; + DEBUG_l({ + int i = -1; PERL_SI *p = PL_curstackinfo; + while (p) { i++; p = p->si_prev; } + Perl_deb(aTHX_ "pop STACKINFO %d in %s at %s:%d\n", + i, SAFE_FUNCTION__, __FILE__, __LINE__);}) + if (!prev) { + Perl_croak_popstack(); + } + + switch_argstack(prev->si_stack); + /* don't free prev here, free them all at the END{} */ + PL_curstackinfo = prev; +} + + + /* =for apidoc newPADxVOP @@ -3156,6 +4115,8 @@ range bytes match only themselves. PERL_STATIC_INLINE I32 Perl_foldEQ(pTHX_ const char *s1, const char *s2, I32 len) { + PERL_UNUSED_CONTEXT; + const U8 *a = (const U8 *)s1; const U8 *b = (const U8 *)s2; @@ -3179,6 +4140,8 @@ Perl_foldEQ_latin1(pTHX_ const char *s1, * does not check for this. Nor does it check that the strings each have * at least 'len' characters. */ + PERL_UNUSED_CONTEXT; + const U8 *a = (const U8 *)s1; const U8 *b = (const U8 *)s2; @@ -3236,8 +4199,8 @@ Perl_foldEQ_locale(pTHX_ const char *s1, The C library C if available, or a Perl implementation of it. C computes the length of the string, up to C -characters. It will never attempt to address more than C -characters, making it suitable for use with strings that are not +bytes. It will never attempt to address more than C +bytes, making it suitable for use with strings that are not guaranteed to be NUL-terminated. =cut @@ -3487,6 +4450,7 @@ Perl_mortal_getenv(const char * str) PERL_STATIC_INLINE bool Perl_sv_isbool(pTHX_ const SV *sv) { + PERL_UNUSED_CONTEXT; return SvBoolFlagsOK(sv) && BOOL_INTERNALS_sv_isbool(sv); } @@ -3693,7 +4657,7 @@ The C library C if available, o This operates on C C-terminated strings. C appends string C to the end of C. It will append at -most S> characters. It will then C-terminate, +most S> bytes. It will then C-terminate, unless C is 0 or the original C string was longer than C (in practice this should not happen as it means that either C is incorrect or that C is not a proper C-terminated string). @@ -3734,7 +4698,7 @@ Perl_my_strlcat(char *dst, const char *s The C library C if available, or a Perl implementation of it. This operates on C C-terminated strings. -C copies up to S> characters from the string C +C copies up to S> bytes from the string C to C, C-terminating the result if C is not 0. The return value is the total length C would be if the copy completely Index: gnu/usr.bin/perl/intrpvar.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/intrpvar.h,v diff -u -p -a -u -p -r1.8 intrpvar.h --- gnu/usr.bin/perl/intrpvar.h 14 May 2024 19:38:53 -0000 1.8 +++ gnu/usr.bin/perl/intrpvar.h 22 Jan 2025 00:37:44 -0000 @@ -49,10 +49,10 @@ PERLVARI(I, tmps_ix, SSize_t, -1) PERLVARI(I, tmps_floor, SSize_t, -1) PERLVAR(I, tmps_max, SSize_t) /* first unalloced slot in tmps stack */ -PERLVAR(I, markstack, I32 *) /* stack_sp locations we're +PERLVAR(I, markstack, Stack_off_t *) /* stack_sp locations we're remembering */ -PERLVAR(I, markstack_ptr, I32 *) -PERLVAR(I, markstack_max, I32 *) +PERLVAR(I, markstack_ptr, Stack_off_t *) +PERLVAR(I, markstack_max, Stack_off_t *) PERLVARI(I, sub_generation, U32, 1) /* incr to invalidate method cache */ @@ -395,8 +395,8 @@ PERLVARI(I, locale_mutex_depth, int, 0) #ifdef USE_LOCALE_CTYPE PERLVAR(I, warn_locale, SV *) -PERLVAR(I, in_utf8_CTYPE_locale, bool) -PERLVAR(I, in_utf8_turkic_locale, bool) +PERLVARI(I, in_utf8_CTYPE_locale, bool, false) +PERLVARI(I, in_utf8_turkic_locale, bool, false) #endif PERLVARA(I, colors,6, char *) /* values from PERL_RE_COLORS env var */ @@ -746,23 +746,25 @@ PERLVAR(I, constpadix, PADOFFSET) /* low PERLVAR(I, padix_floor, PADOFFSET) /* how low may inner block reset padix */ #if defined(USE_POSIX_2008_LOCALE) && defined(MULTIPLICITY) -PERLVARI(I, cur_locale_obj, locale_t, NULL) +PERLVARI(I, cur_locale_obj, locale_t, LC_GLOBAL_LOCALE) #endif #ifdef USE_PL_CURLOCALES -/* This is the most number of categories we've encountered so far on any - * platform, doesn't include LC_ALL */ -PERLVARA(I, curlocales, 12, const char *) +/* Some configurations do not allow perl to query libc to find out what the + * locale for a given category is. On such platforms this array contains that + * information, indexed by the perl-defined category index. + * Note that this array keeps the actual locale for each category. LC_NUMERIC + * is almost always toggled into the C locale, and the locale it nominally is + * is stored as PL_numeric_name. */ +PERLVARA(I, curlocales, LOCALE_CATEGORIES_COUNT_ + 1, const char *) #endif #ifdef USE_PL_CUR_LC_ALL - PERLVARI(I, cur_LC_ALL, const char *, NULL) - #endif #ifdef USE_LOCALE_COLLATE -/* The emory needed to store the collxfrm transformation of a string with +/* The memory needed to store the collxfrm transformation of a string with * length 'x' is predicted by the linear equation mx+b; m=mult, b=base */ PERLVARI(I, collxfrm_mult,Size_t, 0) /* Expansion factor in *xfrm(); 0 => unknown or bad, depending on @@ -772,7 +774,7 @@ PERLVAR(I, collxfrm_base, Size_t) /* Bas mult == 0, base != 0 => ill-formed; */ PERLVAR(I, collation_name, char *) /* Name of current collation */ -PERLVARI(I, collation_ix, U32, 0) /* Collation generation index */ +PERLVARI(I, collation_ix, PERL_UINTMAX_T, 0) /* Collation generation index */ PERLVARI(I, strxfrm_NUL_replacement, U8, 0) /* Code point to replace NULs */ PERLVARI(I, strxfrm_is_behaved, bool, TRUE) /* Assume until proven otherwise that it works */ @@ -782,12 +784,15 @@ PERLVARI(I, collation_standard, bool, TR PERLVAR(I, in_utf8_COLLATE_locale, bool) #endif /* USE_LOCALE_COLLATE */ -PERLVARI(I, langinfo_buf, const char *, NULL) -PERLVARI(I, langinfo_bufsize, Size_t, 0) -PERLVARI(I, setlocale_buf, const char *, NULL) +PERLVARI(I, langinfo_sv, SV *, NULL) /* For Perl_langinfo8? */ +PERLVARI(I, scratch_langinfo, SV *, NULL) /* For internal use */ +PERLVARI(I, setlocale_buf, char *, NULL) PERLVARI(I, setlocale_bufsize, Size_t, 0) -PERLVARI(I, stdize_locale_buf, const char *, NULL) -PERLVARI(I, stdize_locale_bufsize, Size_t, 0) + +#if defined(USE_LOCALE_THREADS) && ! defined(USE_THREAD_SAFE_LOCALE) +PERLVARI(I, less_dicey_locale_buf, char *, NULL) +PERLVARI(I, less_dicey_locale_bufsize, Size_t, 0) +#endif #ifdef PERL_SAWAMPERSAND PERLVAR(I, sawampersand, U8) /* must save all match strings */ @@ -850,11 +855,6 @@ PERLVAR(I, numeric_name, char *) /* PERLVAR(I, numeric_radix_sv, SV *) /* The radix separator */ PERLVAR(I, underlying_radix_sv, SV *) /* The radix in the program's current underlying locale */ -#if defined(USE_LOCALE_NUMERIC) && defined(USE_POSIX_2008_LOCALE) - -PERLVARI(I, underlying_numeric_obj, locale_t, NULL) - -#endif #ifdef USE_POSIX_2008_LOCALE PERLVARI(I, scratch_locale_obj, locale_t, 0) #endif @@ -952,9 +952,7 @@ PERLVARI(I, threadhook, thrhook_proc_t, /* Can shared object be destroyed */ PERLVARI(I, destroyhook, destroyable_proc_t, Perl_sv_destroyable) -#ifndef PERL_MICRO PERLVARI(I, signalhook, despatch_signals_proc_t, Perl_despatch_signals) -#endif PERLVARI(I, isarev, HV *, NULL) /* Reverse map of @ISA dependencies */ Index: gnu/usr.bin/perl/keywords.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/keywords.c,v diff -u -p -a -u -p -r1.6 keywords.c --- gnu/usr.bin/perl/keywords.c 14 May 2024 19:38:53 -0000 1.6 +++ gnu/usr.bin/perl/keywords.c 22 Jan 2025 00:37:44 -0000 @@ -1,4 +1,4 @@ -/* -*- buffer-read-only: t -*- +/* -*- mode: C; buffer-read-only: t -*- * !!!!!!! DO NOT EDIT THIS FILE !!!!!!! * This file is built by regen/keywords.pl from its data. * Any changes made here will be lost! @@ -2879,7 +2879,7 @@ Perl_keyword (pTHX_ const char *name, I3 goto unknown; } - case 9: /* 10 tokens of length 9 */ + case 9: /* 11 tokens of length 9 */ switch (name[0]) { case 'U': @@ -2897,6 +2897,21 @@ Perl_keyword (pTHX_ const char *name, I3 goto unknown; + case '_': + if (name[1] == '_' && + name[2] == 'C' && + name[3] == 'L' && + name[4] == 'A' && + name[5] == 'S' && + name[6] == 'S' && + name[7] == '_' && + name[8] == '_') + { /* __CLASS__ */ + return (all_keywords || FEATURE_CLASS_IS_ENABLED ? -KEY___CLASS__ : 0); + } + + goto unknown; + case 'e': switch (name[1]) { @@ -3558,5 +3573,5 @@ unknown: } /* Generated from: - * eb67e851da14ede1aad67aec4a387fa250c1345407fad0a02988d2d8d3cc27f2 regen/keywords.pl - * ex: set ro: */ + * c8b75109fa56ce3ea3f30503a3b398f02e49036dc60d5fb36ea5ba9ffd6c596e regen/keywords.pl + * ex: set ro ft=c: */ Index: gnu/usr.bin/perl/keywords.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/keywords.h,v diff -u -p -a -u -p -r1.15 keywords.h --- gnu/usr.bin/perl/keywords.h 14 May 2024 19:38:53 -0000 1.15 +++ gnu/usr.bin/perl/keywords.h 22 Jan 2025 00:37:44 -0000 @@ -1,4 +1,4 @@ -/* -*- buffer-read-only: t -*- +/* -*- mode: C; buffer-read-only: t -*- * * keywords.h * @@ -17,267 +17,268 @@ #define KEY___FILE__ 1 #define KEY___LINE__ 2 #define KEY___PACKAGE__ 3 -#define KEY___DATA__ 4 -#define KEY___END__ 5 -#define KEY___SUB__ 6 -#define KEY_ADJUST 7 -#define KEY_AUTOLOAD 8 -#define KEY_BEGIN 9 -#define KEY_UNITCHECK 10 -#define KEY_DESTROY 11 -#define KEY_END 12 -#define KEY_INIT 13 -#define KEY_CHECK 14 -#define KEY_abs 15 -#define KEY_accept 16 -#define KEY_alarm 17 -#define KEY_and 18 -#define KEY_atan2 19 -#define KEY_bind 20 -#define KEY_binmode 21 -#define KEY_bless 22 -#define KEY_break 23 -#define KEY_caller 24 -#define KEY_catch 25 -#define KEY_chdir 26 -#define KEY_chmod 27 -#define KEY_chomp 28 -#define KEY_chop 29 -#define KEY_chown 30 -#define KEY_chr 31 -#define KEY_chroot 32 -#define KEY_class 33 -#define KEY_close 34 -#define KEY_closedir 35 -#define KEY_cmp 36 -#define KEY_connect 37 -#define KEY_continue 38 -#define KEY_cos 39 -#define KEY_crypt 40 -#define KEY_dbmclose 41 -#define KEY_dbmopen 42 -#define KEY_default 43 -#define KEY_defer 44 -#define KEY_defined 45 -#define KEY_delete 46 -#define KEY_die 47 -#define KEY_do 48 -#define KEY_dump 49 -#define KEY_each 50 -#define KEY_else 51 -#define KEY_elsif 52 -#define KEY_endgrent 53 -#define KEY_endhostent 54 -#define KEY_endnetent 55 -#define KEY_endprotoent 56 -#define KEY_endpwent 57 -#define KEY_endservent 58 -#define KEY_eof 59 -#define KEY_eq 60 -#define KEY_eval 61 -#define KEY_evalbytes 62 -#define KEY_exec 63 -#define KEY_exists 64 -#define KEY_exit 65 -#define KEY_exp 66 -#define KEY_fc 67 -#define KEY_fcntl 68 -#define KEY_field 69 -#define KEY_fileno 70 -#define KEY_finally 71 -#define KEY_flock 72 -#define KEY_for 73 -#define KEY_foreach 74 -#define KEY_fork 75 -#define KEY_format 76 -#define KEY_formline 77 -#define KEY_ge 78 -#define KEY_getc 79 -#define KEY_getgrent 80 -#define KEY_getgrgid 81 -#define KEY_getgrnam 82 -#define KEY_gethostbyaddr 83 -#define KEY_gethostbyname 84 -#define KEY_gethostent 85 -#define KEY_getlogin 86 -#define KEY_getnetbyaddr 87 -#define KEY_getnetbyname 88 -#define KEY_getnetent 89 -#define KEY_getpeername 90 -#define KEY_getpgrp 91 -#define KEY_getppid 92 -#define KEY_getpriority 93 -#define KEY_getprotobyname 94 -#define KEY_getprotobynumber 95 -#define KEY_getprotoent 96 -#define KEY_getpwent 97 -#define KEY_getpwnam 98 -#define KEY_getpwuid 99 -#define KEY_getservbyname 100 -#define KEY_getservbyport 101 -#define KEY_getservent 102 -#define KEY_getsockname 103 -#define KEY_getsockopt 104 -#define KEY_given 105 -#define KEY_glob 106 -#define KEY_gmtime 107 -#define KEY_goto 108 -#define KEY_grep 109 -#define KEY_gt 110 -#define KEY_hex 111 -#define KEY_if 112 -#define KEY_index 113 -#define KEY_int 114 -#define KEY_ioctl 115 -#define KEY_isa 116 -#define KEY_join 117 -#define KEY_keys 118 -#define KEY_kill 119 -#define KEY_last 120 -#define KEY_lc 121 -#define KEY_lcfirst 122 -#define KEY_le 123 -#define KEY_length 124 -#define KEY_link 125 -#define KEY_listen 126 -#define KEY_local 127 -#define KEY_localtime 128 -#define KEY_lock 129 -#define KEY_log 130 -#define KEY_lstat 131 -#define KEY_lt 132 -#define KEY_m 133 -#define KEY_map 134 -#define KEY_method 135 -#define KEY_mkdir 136 -#define KEY_msgctl 137 -#define KEY_msgget 138 -#define KEY_msgrcv 139 -#define KEY_msgsnd 140 -#define KEY_my 141 -#define KEY_ne 142 -#define KEY_next 143 -#define KEY_no 144 -#define KEY_not 145 -#define KEY_oct 146 -#define KEY_open 147 -#define KEY_opendir 148 -#define KEY_or 149 -#define KEY_ord 150 -#define KEY_our 151 -#define KEY_pack 152 -#define KEY_package 153 -#define KEY_pipe 154 -#define KEY_pop 155 -#define KEY_pos 156 -#define KEY_print 157 -#define KEY_printf 158 -#define KEY_prototype 159 -#define KEY_push 160 -#define KEY_q 161 -#define KEY_qq 162 -#define KEY_qr 163 -#define KEY_quotemeta 164 -#define KEY_qw 165 -#define KEY_qx 166 -#define KEY_rand 167 -#define KEY_read 168 -#define KEY_readdir 169 -#define KEY_readline 170 -#define KEY_readlink 171 -#define KEY_readpipe 172 -#define KEY_recv 173 -#define KEY_redo 174 -#define KEY_ref 175 -#define KEY_rename 176 -#define KEY_require 177 -#define KEY_reset 178 -#define KEY_return 179 -#define KEY_reverse 180 -#define KEY_rewinddir 181 -#define KEY_rindex 182 -#define KEY_rmdir 183 -#define KEY_s 184 -#define KEY_say 185 -#define KEY_scalar 186 -#define KEY_seek 187 -#define KEY_seekdir 188 -#define KEY_select 189 -#define KEY_semctl 190 -#define KEY_semget 191 -#define KEY_semop 192 -#define KEY_send 193 -#define KEY_setgrent 194 -#define KEY_sethostent 195 -#define KEY_setnetent 196 -#define KEY_setpgrp 197 -#define KEY_setpriority 198 -#define KEY_setprotoent 199 -#define KEY_setpwent 200 -#define KEY_setservent 201 -#define KEY_setsockopt 202 -#define KEY_shift 203 -#define KEY_shmctl 204 -#define KEY_shmget 205 -#define KEY_shmread 206 -#define KEY_shmwrite 207 -#define KEY_shutdown 208 -#define KEY_sin 209 -#define KEY_sleep 210 -#define KEY_socket 211 -#define KEY_socketpair 212 -#define KEY_sort 213 -#define KEY_splice 214 -#define KEY_split 215 -#define KEY_sprintf 216 -#define KEY_sqrt 217 -#define KEY_srand 218 -#define KEY_stat 219 -#define KEY_state 220 -#define KEY_study 221 -#define KEY_sub 222 -#define KEY_substr 223 -#define KEY_symlink 224 -#define KEY_syscall 225 -#define KEY_sysopen 226 -#define KEY_sysread 227 -#define KEY_sysseek 228 -#define KEY_system 229 -#define KEY_syswrite 230 -#define KEY_tell 231 -#define KEY_telldir 232 -#define KEY_tie 233 -#define KEY_tied 234 -#define KEY_time 235 -#define KEY_times 236 -#define KEY_tr 237 -#define KEY_try 238 -#define KEY_truncate 239 -#define KEY_uc 240 -#define KEY_ucfirst 241 -#define KEY_umask 242 -#define KEY_undef 243 -#define KEY_unless 244 -#define KEY_unlink 245 -#define KEY_unpack 246 -#define KEY_unshift 247 -#define KEY_untie 248 -#define KEY_until 249 -#define KEY_use 250 -#define KEY_utime 251 -#define KEY_values 252 -#define KEY_vec 253 -#define KEY_wait 254 -#define KEY_waitpid 255 -#define KEY_wantarray 256 -#define KEY_warn 257 -#define KEY_when 258 -#define KEY_while 259 -#define KEY_write 260 -#define KEY_x 261 -#define KEY_xor 262 -#define KEY_y 263 +#define KEY___CLASS__ 4 +#define KEY___DATA__ 5 +#define KEY___END__ 6 +#define KEY___SUB__ 7 +#define KEY_ADJUST 8 +#define KEY_AUTOLOAD 9 +#define KEY_BEGIN 10 +#define KEY_UNITCHECK 11 +#define KEY_DESTROY 12 +#define KEY_END 13 +#define KEY_INIT 14 +#define KEY_CHECK 15 +#define KEY_abs 16 +#define KEY_accept 17 +#define KEY_alarm 18 +#define KEY_and 19 +#define KEY_atan2 20 +#define KEY_bind 21 +#define KEY_binmode 22 +#define KEY_bless 23 +#define KEY_break 24 +#define KEY_caller 25 +#define KEY_catch 26 +#define KEY_chdir 27 +#define KEY_chmod 28 +#define KEY_chomp 29 +#define KEY_chop 30 +#define KEY_chown 31 +#define KEY_chr 32 +#define KEY_chroot 33 +#define KEY_class 34 +#define KEY_close 35 +#define KEY_closedir 36 +#define KEY_cmp 37 +#define KEY_connect 38 +#define KEY_continue 39 +#define KEY_cos 40 +#define KEY_crypt 41 +#define KEY_dbmclose 42 +#define KEY_dbmopen 43 +#define KEY_default 44 +#define KEY_defer 45 +#define KEY_defined 46 +#define KEY_delete 47 +#define KEY_die 48 +#define KEY_do 49 +#define KEY_dump 50 +#define KEY_each 51 +#define KEY_else 52 +#define KEY_elsif 53 +#define KEY_endgrent 54 +#define KEY_endhostent 55 +#define KEY_endnetent 56 +#define KEY_endprotoent 57 +#define KEY_endpwent 58 +#define KEY_endservent 59 +#define KEY_eof 60 +#define KEY_eq 61 +#define KEY_eval 62 +#define KEY_evalbytes 63 +#define KEY_exec 64 +#define KEY_exists 65 +#define KEY_exit 66 +#define KEY_exp 67 +#define KEY_fc 68 +#define KEY_fcntl 69 +#define KEY_field 70 +#define KEY_fileno 71 +#define KEY_finally 72 +#define KEY_flock 73 +#define KEY_for 74 +#define KEY_foreach 75 +#define KEY_fork 76 +#define KEY_format 77 +#define KEY_formline 78 +#define KEY_ge 79 +#define KEY_getc 80 +#define KEY_getgrent 81 +#define KEY_getgrgid 82 +#define KEY_getgrnam 83 +#define KEY_gethostbyaddr 84 +#define KEY_gethostbyname 85 +#define KEY_gethostent 86 +#define KEY_getlogin 87 +#define KEY_getnetbyaddr 88 +#define KEY_getnetbyname 89 +#define KEY_getnetent 90 +#define KEY_getpeername 91 +#define KEY_getpgrp 92 +#define KEY_getppid 93 +#define KEY_getpriority 94 +#define KEY_getprotobyname 95 +#define KEY_getprotobynumber 96 +#define KEY_getprotoent 97 +#define KEY_getpwent 98 +#define KEY_getpwnam 99 +#define KEY_getpwuid 100 +#define KEY_getservbyname 101 +#define KEY_getservbyport 102 +#define KEY_getservent 103 +#define KEY_getsockname 104 +#define KEY_getsockopt 105 +#define KEY_given 106 +#define KEY_glob 107 +#define KEY_gmtime 108 +#define KEY_goto 109 +#define KEY_grep 110 +#define KEY_gt 111 +#define KEY_hex 112 +#define KEY_if 113 +#define KEY_index 114 +#define KEY_int 115 +#define KEY_ioctl 116 +#define KEY_isa 117 +#define KEY_join 118 +#define KEY_keys 119 +#define KEY_kill 120 +#define KEY_last 121 +#define KEY_lc 122 +#define KEY_lcfirst 123 +#define KEY_le 124 +#define KEY_length 125 +#define KEY_link 126 +#define KEY_listen 127 +#define KEY_local 128 +#define KEY_localtime 129 +#define KEY_lock 130 +#define KEY_log 131 +#define KEY_lstat 132 +#define KEY_lt 133 +#define KEY_m 134 +#define KEY_map 135 +#define KEY_method 136 +#define KEY_mkdir 137 +#define KEY_msgctl 138 +#define KEY_msgget 139 +#define KEY_msgrcv 140 +#define KEY_msgsnd 141 +#define KEY_my 142 +#define KEY_ne 143 +#define KEY_next 144 +#define KEY_no 145 +#define KEY_not 146 +#define KEY_oct 147 +#define KEY_open 148 +#define KEY_opendir 149 +#define KEY_or 150 +#define KEY_ord 151 +#define KEY_our 152 +#define KEY_pack 153 +#define KEY_package 154 +#define KEY_pipe 155 +#define KEY_pop 156 +#define KEY_pos 157 +#define KEY_print 158 +#define KEY_printf 159 +#define KEY_prototype 160 +#define KEY_push 161 +#define KEY_q 162 +#define KEY_qq 163 +#define KEY_qr 164 +#define KEY_quotemeta 165 +#define KEY_qw 166 +#define KEY_qx 167 +#define KEY_rand 168 +#define KEY_read 169 +#define KEY_readdir 170 +#define KEY_readline 171 +#define KEY_readlink 172 +#define KEY_readpipe 173 +#define KEY_recv 174 +#define KEY_redo 175 +#define KEY_ref 176 +#define KEY_rename 177 +#define KEY_require 178 +#define KEY_reset 179 +#define KEY_return 180 +#define KEY_reverse 181 +#define KEY_rewinddir 182 +#define KEY_rindex 183 +#define KEY_rmdir 184 +#define KEY_s 185 +#define KEY_say 186 +#define KEY_scalar 187 +#define KEY_seek 188 +#define KEY_seekdir 189 +#define KEY_select 190 +#define KEY_semctl 191 +#define KEY_semget 192 +#define KEY_semop 193 +#define KEY_send 194 +#define KEY_setgrent 195 +#define KEY_sethostent 196 +#define KEY_setnetent 197 +#define KEY_setpgrp 198 +#define KEY_setpriority 199 +#define KEY_setprotoent 200 +#define KEY_setpwent 201 +#define KEY_setservent 202 +#define KEY_setsockopt 203 +#define KEY_shift 204 +#define KEY_shmctl 205 +#define KEY_shmget 206 +#define KEY_shmread 207 +#define KEY_shmwrite 208 +#define KEY_shutdown 209 +#define KEY_sin 210 +#define KEY_sleep 211 +#define KEY_socket 212 +#define KEY_socketpair 213 +#define KEY_sort 214 +#define KEY_splice 215 +#define KEY_split 216 +#define KEY_sprintf 217 +#define KEY_sqrt 218 +#define KEY_srand 219 +#define KEY_stat 220 +#define KEY_state 221 +#define KEY_study 222 +#define KEY_sub 223 +#define KEY_substr 224 +#define KEY_symlink 225 +#define KEY_syscall 226 +#define KEY_sysopen 227 +#define KEY_sysread 228 +#define KEY_sysseek 229 +#define KEY_system 230 +#define KEY_syswrite 231 +#define KEY_tell 232 +#define KEY_telldir 233 +#define KEY_tie 234 +#define KEY_tied 235 +#define KEY_time 236 +#define KEY_times 237 +#define KEY_tr 238 +#define KEY_try 239 +#define KEY_truncate 240 +#define KEY_uc 241 +#define KEY_ucfirst 242 +#define KEY_umask 243 +#define KEY_undef 244 +#define KEY_unless 245 +#define KEY_unlink 246 +#define KEY_unpack 247 +#define KEY_unshift 248 +#define KEY_untie 249 +#define KEY_until 250 +#define KEY_use 251 +#define KEY_utime 252 +#define KEY_values 253 +#define KEY_vec 254 +#define KEY_wait 255 +#define KEY_waitpid 256 +#define KEY_wantarray 257 +#define KEY_warn 258 +#define KEY_when 259 +#define KEY_while 260 +#define KEY_write 261 +#define KEY_x 262 +#define KEY_xor 263 +#define KEY_y 264 /* Generated from: - * eb67e851da14ede1aad67aec4a387fa250c1345407fad0a02988d2d8d3cc27f2 regen/keywords.pl - * ex: set ro: */ + * c8b75109fa56ce3ea3f30503a3b398f02e49036dc60d5fb36ea5ba9ffd6c596e regen/keywords.pl + * ex: set ro ft=c: */ Index: gnu/usr.bin/perl/locale.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/locale.c,v diff -u -p -a -u -p -r1.11 locale.c --- gnu/usr.bin/perl/locale.c 17 May 2024 18:11:58 -0000 1.11 +++ gnu/usr.bin/perl/locale.c 22 Jan 2025 00:37:44 -0000 @@ -33,6 +33,13 @@ * switched to the C locale for outputting the message unless within the scope * of 'use locale'. * + * There is more than the typical amount of variation between platforms with + * regard to locale handling. At the end of these introductory comments, are + * listed various relevent Configuration options, including some that can be + * used to pretend to some extent that this is being developed on a different + * platform than it actually is. This allows you to make changes and catch + * some errors without having access to those other platforms. + * * This code now has multi-thread-safe locale handling on systems that support * that. This is completely transparent to most XS code. On earlier systems, * it would be possible to emulate thread-safe locales, but this likely would @@ -46,30 +53,18 @@ * to table lookup. Instead we have created our own equivalent values which * are all small contiguous non-negative integers, and translation functions * between the two sets. For category 'LC_foo', the name of our index is - * LC_foo_INDEX_. Various parallel tables, indexed by these, are used. - * - * Many of the macros and functions in this file have one of the suffixes '_c', - * '_r', or '_i'. khw found these useful in remembering what type of locale - * category to use as their parameter. '_r' takes an int category number as - * passed to setlocale(), like LC_ALL, LC_CTYPE, etc. The 'r' indicates that - * the value isn't known until runtime. '_c' also indicates such a category - * number, but its value is known at compile time. These are both converted - * into unsigned indexes into various tables of category information, where the - * real work is generally done. The tables are generated at compile-time based - * on platform characteristics and Configure options. They hide from the code - * many of the vagaries of the different locale implementations out there. You - * may have already guessed that '_i' indicates the parameter is such an - * unsigned index. Converting from '_r' to '_i' requires run-time lookup. - * '_c' is used to get cpp to do this at compile time. To avoid the runtime - * expense, the code is structured to use '_r' at the API level, and once - * converted, everything possible is done using the table indexes. + * LC_foo_INDEX_. Various parallel tables, indexed by these, are used for the + * translation. The tables are generated at compile-time based on platform + * characteristics and Configure options. They hide from the code many of the + * vagaries of the different locale implementations out there. * * On unthreaded perls, most operations expand out to just the basic - * setlocale() calls. The same is true on threaded perls on modern Windows + * setlocale() calls. That sort of is true on threaded perls on modern Windows * systems where the same API, after set up, is used for thread-safe locale - * handling. On other systems, there is a completely different API, specified - * in POSIX 2008, to do thread-safe locales. On these systems, our - * emulate_setlocale_i() function is used to hide the different API from the + * handling. (But there are complications on Windows due to internal character + * set issues.) On other systems, there is a completely different API, + * specified in POSIX 2008, to do thread-safe locales. On these systems, our + * bool_setlocale_2008_i() function is used to hide the different API from the * outside. This makes it completely transparent to most XS code. * * A huge complicating factor is that the LC_NUMERIC category is normally held @@ -85,23 +80,45 @@ * There are 3.5 major implementations here; which one chosen depends on what * the platform has available, and Configuration options. * - * 1) Raw my_setlocale(). Here the layer adds nothing. This is used for - * unthreaded perls, and when the API for safe locale threading is identical - * to the unsafe API (Windows, currently). + * 1) Raw posix_setlocale(). This implementation is basically the libc + * setlocale(), with possibly minor tweaks. This is used for startup, and + * always for unthreaded perls, and when the API for safe locale threading + * is identical to the unsafe API (Windows, currently). * - * 2) A minimal layer that makes my_setlocale() uninterruptible and returns a + * This implementation is composed of two layers: + * a) posix_setlocale() implements the libc setlocale(). In most cases, + * it is just an alias for the libc version. But Windows doesn't + * fully conform to the POSIX standard, and this is a layer on top of + * libc to bring it more into conformance. And in Configurations + * where perl is to ignore some locale categories that the libc + * setlocale() knows about, there is a layer to cope with that. + * b) stdized_setlocale() is a layer above a) that fixes some vagaries in + * the return value of the libc setlocale(). On most platforms this + * layer is empty; in order to be activated, it requires perl to be + * Configured with a parameter indicating the platform's defect. The + * current ones are listed at the definition of the macro. + * + * 2) An implementation that adds a minimal layer above implementation 1), + * making that implementation uninterruptible and returning a * per-thread/per-category value. * - * 3a and 3b) A layer that implements POSIX 2008 thread-safe locale handling, - * mapping the setlocale() API to them. This automatically makes almost all - * code thread-safe without need for changes. This layer is chosen on - * threaded perls when the platform supports the POSIX 2008 functions, and - * when there is no manual override in Configure. + * 3a and 3b) An implementation of POSIX 2008 thread-safe locale handling, + * hiding from the programmer the completely different API for this. + * This automatically makes almost all code thread-safe without need for + * changes. This implementation is chosen on threaded perls when the + * platform properly supports the POSIX 2008 functions, and when there is no + * manual override to the contrary passed to Configure. * - * 3a) is when the platform has a reliable querylocale() function or - * equivalent that is selected to be used. + * 3a) is when the platform has a documented reliable querylocale() function + * or equivalent that is selected to be used. * 3b) is when we have to emulate that functionality. * + * Unfortunately, it seems that some platforms that claim to support these + * are buggy, in one way or another. There are workarounds encoded here, + * where feasible, for platforms where the bugs are amenable to that + * (glibc, for example). But other platforms instead don't use this + * implementation. + * * z/OS (os390) is an outlier. Locales really don't work under threads when * either the radix character isn't a dot, or attempts are made to change * locales after the first thread is created. The reason is that IBM has made @@ -111,29 +128,247 @@ * its locale information before the first fork, and be stable thereafter. But * perl toggles LC_NUMERIC if the locale's radix character isn't a dot, as do * the other toggles, which are less common. + * + * Associated with each implementation are three sets of macros that translate + * a consistent API into what that implementation needs. Each set consists of + * three macros with the suffixes: + * _c Means the argument is a locale category number known at compile time. + * An example would be LC_TIME. This token is a compile-time constant + * and can be passed to a '_c' macro. + * _r Means the argument is a locale category number whose value might not be + * known until runtime + * _i Means the argument is our internal index of a locale category + * + * The three sets are: ('_X' means one of '_c', '_r', '_i') + * 1) bool_setlocale_X() + * This calls the appropriate setlocale()-equivalent for the + * implementation, with the category and new locale. The input locale is + * not necessarily valid, so the return is true or false depending on + * whether or not the setlocale() succeeded. This is not used for + * querying the locale, so the input locale must not be NULL. + * + * This macro is suitable for toggling the locale back and forth during an + * operation. For example, the names of days and months under LC_TIME are + * strings that are also subject to LC_CTYPE. If the locales of these two + * categories differ, mojibake can result on many platforms. The code + * here will toggle LC_CTYPE into the locale of LC_TIME temporarily to + * avoid this. + * + * Several categories require extra work when their locale is changed. + * LC_CTYPE, for example, requires the calculation of the table of which + * characters fold to which others under /i pattern matching or fc(), as + * folding is not a concept in POSIX. This table isn't needed when the + * LC_CTYPE locale gets toggled during an operation, and will be toggled + * back before return to the caller. To save work that would be + * discarded, the bool_setlocale_X() implementations don't do this extra + * work. Instead, there is a separate function for just this purpose to + * be done before control is transferred back to the external caller. All + * categories that have such requirements have such a function. The + * update_functions[] array contains pointers to them (or NULL for + * categories which don't need a function). + * + * Care must be taken to remember to call the separate function before + * returning to an external caller, and to not use things it updates + * before its call. An alternative approach would be to have + * bool_setlocale_X() always call the update, which would return + * immediately if a flag wasn't set indicating it was time to actually + * perform it. + * + * 2) void_setlocale_X() + * This is like bool_setlocale_X(), but it is used only when it is + * expected that the call must succeed, or something is seriously wrong. + * A panic is issued if it fails. The caller uses this form when it just + * wants to assume things worked. + * + * 3) querylocale_X() + * This returns a string that specifies the current locale for the given + * category given by the input argument. The string is safe from other + * threads zapping it, and the caller need not worry about freeing it, but + * it may be mortalized, so must be copied if you need to preserve it + * across calls, or long term. This returns the actual current locale, + * not the nominal. These differ, for example, when LC_NUMERIC is + * supposed to be a locale whose decimal radix character is a comma. As + * mentioned above, Perl actually keeps this category set to C in such + * circumstances so that XS code can just assume a dot radix character. + * querylocale_X() returns the locale that libc has stored at this moment, + * so most of the time will return a locale whose radix character is a + * dot. The macro query_nominal_locale_i() can be used to get the nominal + * locale that an external caller would expect, for all categories except + * LC_ALL. For that, you can use the function + * S_calculate_LC_ALL_string(). Or S_native_querylocale_i() will operate + * on any category. + * + * The underlying C API that this implements uses category numbers, hence the + * code is structured to use '_r' at the API level to convert to indexes, which + * are then used internally with the '_i' forms. + * + * The splitting apart into setting vs querying means that the return value of + * the bool macros is not subject to potential clashes with other threads, + * eliminating any need for the calling code to worry about that and get it + * wrong. Whereas, you do have to think about thread interactions when using a + * query. + * + * Additionally, for the implementations where there aren't any complications, + * a setlocale_i() is defined that is like plain setlocale(), returning the new + * locale. Thus it combines a bool_setlocale_X() with a querylocale_X(). It + * is used only for performance on implementations that allow it, such as + * non-threaded perls. + * + * There are also a few other macros herein that use this naming convention to + * describe their category parameter. + * + * Relevant Configure options + * + * -Accflags=-DNO_LOCALE + * This compiles perl to always use the C locale, ignoring any + * attempts to change it. This could be useful on platforms with a + * crippled locale implementation. + * + * -Accflags=-DNO_THREAD_SAFE_LOCALE + * Even if thread-safe operations are available on this platform and + * would otherwise be used (because this is a perl with multiplicity), + * perl is compiled to not use them. This could be useful on + * platforms where the libc is buggy. + * + * -Accflags=-DNO_POSIX_2008_LOCALE + * Even if the libc locale operations specified by the Posix 2008 + * Standard are available on this platform and would otherwise be used + * (because this is a threaded perl), perl is compiled to not use + * them. This could be useful on platforms where the libc is buggy. + * This is like NO_THREAD_SAFE_LOCALE, but has no effect on platforms + * that don't have these functions. + * + * -Accflags=-DUSE_POSIX_2008_LOCALE + * Normally, setlocale() is used for locale operations on perls + * compiled without threads. This option causes the locale operations + * defined by the Posix 2008 Standard to always be used instead. This + * could be useful on platforms where the libc setlocale() is buggy. + * + * -Accflags=-DNO_THREAD_SAFE_QUERYLOCALE + * This applies only to platforms that have a querylocale() libc + * function. perl assumes that that function is thread-safe, unless + * overridden by this, typically in a hints file. When overridden, + * querylocale() is called only while the locale mutex is locked, and + * the result is copied to a per-thread place before unlocking. + * + * -Accflags=-DNO_USE_NL_LOCALE_NAME + * glibc has an undocumented equivalent function to querylocale(), + * which our experience indicates is reliable. But you can forbid its + * use by specifying this Configure option (with no effect on systems + * lacking it). When this is function is enabled, it removes the need + * for perl to keep its own records, hence is more efficient and + * guaranteed to be accurate. + * + * -Accflags=-DNO_LOCALE_CTYPE + * -Accflags=-DNO_LOCALE_NUMERIC + * etc. + * + * If the named category(ies) does(do) not exist on this platform, + * these have no effect. Otherwise they cause perl to be compiled to + * always keep the named category(ies) in the C locale. + * + * -Accflags=-DHAS_BROKEN_SETLOCALE_QUERY_LC_ALL + * This would be set in a hints file to tell perl that doing a libc + * setlocale(LC_ALL, NULL) + * can give erroneous results, and perl will compensate to get the + * correct results. This is known to be a problem in earlier AIX + * versions + * + * -Accflags=-DHAS_LF_IN_SETLOCALE_RETURN + * This would be set in a hints file to tell perl that a libc + * setlocale() can return results containing \n characters that need + * to be stripped off. khw believes there aren't any such platforms + * still in existence. + * + * -Accflags=-DLIBC_HANDLES_MISMATCHED_CTYPE + * Consider the name of a month in some language, Chinese for example. + * If LC_TIME has been set to a Chinese locale, strftime() can be used + * to generate the Chinese month name for any given date, by using the + * %B format. But also suppose that LC_CTYPE is set to, say, "C". + * The return from strftime() on many platforms will be mojibake given + * that no Chinese month name is composed of just ASCII characters. + * Perl handles this for you by automatically toggling LC_CTYPE to + * whatever LC_TIME is during the execution of strftime(), and + * afterwards restoring it to its prior value. But the strftime() + * (and similar functions) in some libc implementations already do + * this toggle, meaning perl's action is redundant. You can tell perl + * that a libc does this by setting this Configure option, and it will + * skip its syncing LC_CTYPE and whatever the other locale is. + * Currently, perl ignores this Configuration option and syncs anyway + * for LC_COLLATE-related operations, due to perl's internal needs. + * + * -Accflags=USE_FAKE_LC_ALL_POSITIONAL_NOTATION + * This is used when developing Perl on a platform that uses + * 'name=value;' notation to represent LC_ALL when not all categories + * are the same. When so compiled, much of the code gets compiled + * and exercised that applies to platforms that instead use positional + * notation. This allows for finding many bugs in that portion of the + * implementation, without having to access such a platform. + * + * -Accflags=-DWIN32_USE_FAKE_OLD_MINGW_LOCALES + * This is used when developing Perl on a non-Windows platform to + * compile and exercise much of the locale-related code that instead + * applies to MingW platforms that don't use the more modern UCRT + * library. This allows for finding many bugs in that portion of the + * implementation, without having to access such a platform. */ /* If the environment says to, we can output debugging information during * initialization. This is done before option parsing, and before any thread * creation, so can be a file-level static. (Must come before #including * perl.h) */ +#include "config.h" + +/* Returns the Unix errno portion; ignoring any others. This is a macro here + * instead of putting it into perl.h, because unclear to khw what should be + * done generally. */ +#define GET_ERRNO saved_errno + #ifdef DEBUGGING static int debug_initialization = 0; # define DEBUG_INITIALIZATION_set(v) (debug_initialization = v) # define DEBUG_LOCALE_INITIALIZATION_ debug_initialization -/* C standards seem to say that __LINE__ is merely "an integer constant", - * which means it might be either int, long (with L suffix), or long long - * (or their corresponding unsigned type). So, we have to explicitly cast - * __LINE__ to a particular integer type to pass it reliably to variadic - * functions like (PerlIO_)printf, as below: */ -# ifdef USE_LOCALE_THREADS -# define DEBUG_PRE_STMTS \ - dSAVE_ERRNO; dTHX; PerlIO_printf(Perl_debug_log,"\n%s: %" LINE_Tf ": %p: ",\ - __FILE__, (line_t)__LINE__, aTHX); -# else -# define DEBUG_PRE_STMTS \ - dSAVE_ERRNO; dTHX; PerlIO_printf(Perl_debug_log, "\n%s: %" LINE_Tf ": ", \ - __FILE__, (line_t)__LINE__); + +# ifdef HAS_EXTENDED_OS_ERRNO + /* Output the non-zero errno and/or the non-zero extended errno */ +# define DEBUG_ERRNO \ + dSAVE_ERRNO; dTHX; \ + int extended = get_extended_os_errno(); \ + const char * errno_string; \ + if (GET_ERRNO == 0) { /* Skip output if both errno types are 0 */ \ + if (LIKELY(extended == 0)) errno_string = ""; \ + else errno_string = Perl_form(aTHX_ "; $^E=%d", extended); \ + } \ + else if (LIKELY(extended == GET_ERRNO)) \ + errno_string = Perl_form(aTHX_ "; $!=%d", GET_ERRNO); \ + else errno_string = Perl_form(aTHX_ "; $!=%d, $^E=%d", \ + GET_ERRNO, extended); +# else + /* Output the errno, if non-zero */ +# define DEBUG_ERRNO \ + dSAVE_ERRNO; \ + const char * errno_string = ""; \ + if (GET_ERRNO != 0) { \ + dTHX; \ + errno_string = Perl_form(aTHX_ "; $!=%d", GET_ERRNO); \ + } +# endif + +/* Automatically include the caller's file, and line number in debugging output; + * and the errno (and/or extended errno) if non-zero. On threaded perls add + * the aTHX too. */ +# if defined(MULTIPLICITY) && ! defined(NO_LOCALE_THREADS) +# define DEBUG_PRE_STMTS \ + DEBUG_ERRNO; \ + PerlIO_printf(Perl_debug_log, "\n%s: %" LINE_Tf ": 0x%p%s: ", \ + __FILE__, (line_t)__LINE__, aTHX_ \ + errno_string); +# else +# define DEBUG_PRE_STMTS \ + DEBUG_ERRNO; \ + PerlIO_printf(Perl_debug_log, "\n%s: %" LINE_Tf "%s: ", \ + __FILE__, (line_t)__LINE__, \ + errno_string); # endif # define DEBUG_POST_STMTS RESTORE_ERRNO; #else @@ -147,6 +382,224 @@ static int debug_initialization = 0; #define PERL_IN_LOCALE_C #include "perl.h" +/* Some platforms require LC_CTYPE to be congruent with the category we are + * looking for. XXX This still presumes that we have to match COLLATE and + * CTYPE even on platforms that apparently handle this. */ +#if defined(USE_LOCALE_CTYPE) && ! defined(LIBC_HANDLES_MISMATCHED_CTYPE) +# define WE_MUST_DEAL_WITH_MISMATCHED_CTYPE /* no longer used; kept for + possible future use */ +# define start_DEALING_WITH_MISMATCHED_CTYPE(locale) \ + const char * orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, locale) +# define end_DEALING_WITH_MISMATCHED_CTYPE(locale) \ + restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale); +#else +# define start_DEALING_WITH_MISMATCHED_CTYPE(locale) +# define end_DEALING_WITH_MISMATCHED_CTYPE(locale) +#endif + +#ifdef WIN32_USE_FAKE_OLD_MINGW_LOCALES + + /* Use -Accflags=-DWIN32_USE_FAKE_OLD_MINGW_LOCALES on a POSIX or *nix box + * to get a semblance of pretending the locale handling is that of a MingW + * that doesn't use UCRT (hence 'OLD' in the name). This exercizes code + * paths that are not compiled on non-Windows boxes, and allows for ASAN + * and PERL_MEMLOG. This is thus a way to see if locale.c on Windows is + * likely going to compile, without having to use a real Win32 box. And + * running the test suite will verify to a large extent our logic and memory + * allocation handling for such boxes. Of course the underlying calls are + * to the POSIX libc, so any differences in implementation between those and + * the Windows versions will not be caught by this. */ + +# define WIN32 +# undef P_CS_PRECEDES +# undef CURRENCY_SYMBOL +# define CP_UTF8 -1 +# undef _configthreadlocale +# define _configthreadlocale(arg) NOOP + +# define MultiByteToWideChar(cp, flags, byte_string, m1, wstring, req_size) \ + (PERL_UNUSED_ARG(cp), \ + mbsrtowcs(wstring, &(byte_string), req_size, NULL) + 1) +# define WideCharToMultiByte(cp, flags, wstring, m1, byte_string, \ + req_size, default_char, found_default_char) \ + (PERL_UNUSED_ARG(cp), \ + wcsrtombs(byte_string, &(wstring), req_size, NULL) + 1) + +# ifdef USE_LOCALE + +static const wchar_t * wsetlocale_buf = NULL; +static Size_t wsetlocale_buf_size = 0; + +# ifdef MULTIPLICITY + +static PerlInterpreter * wsetlocale_buf_aTHX = NULL; + +# endif + +STATIC +const wchar_t * +S_wsetlocale(const int category, const wchar_t * wlocale) +{ + /* Windows uses a setlocale that takes a wchar_t* locale. Other boxes + * don't have this, so this Windows replacement converts the wchar_t input + * to plain 'char*', calls plain setlocale(), and converts the result back + * to 'wchar_t*' */ + + const char * byte_locale = NULL; + if (wlocale) { + byte_locale = Win_wstring_to_byte_string(CP_UTF8, wlocale); + } + + const char * byte_result = setlocale(category, byte_locale); + Safefree(byte_locale); + if (byte_result == NULL) { + return NULL; + } + + const wchar_t * wresult = Win_byte_string_to_wstring(CP_UTF8, byte_result); + + if (! wresult) { + return NULL; + } + + /* Emulate a global static memory return from wsetlocale(). This currently + * leaks at process end; would require changing LOCALE_TERM to fix that */ + Size_t string_size = wcslen(wresult) + 1; + + if (wsetlocale_buf_size == 0) { + Newx(wsetlocale_buf, string_size, wchar_t); + wsetlocale_buf_size = string_size; + +# ifdef MULTIPLICITY + + dTHX; + wsetlocale_buf_aTHX = aTHX; + +# endif + + } + else if (string_size > wsetlocale_buf_size) { + Renew(wsetlocale_buf, string_size, wchar_t); + wsetlocale_buf_size = string_size; + } + + Copy(wresult, wsetlocale_buf, string_size, wchar_t); + Safefree(wresult); + + return wsetlocale_buf; +} + +# define _wsetlocale(category, wlocale) S_wsetlocale(category, wlocale) +# endif +#endif /* WIN32_USE_FAKE_OLD_MINGW_LOCALES */ + +/* 'for' loop headers to hide the necessary casts */ +#define for_category_indexes_between(i, m, n) \ + for (locale_category_index i = (locale_category_index) (m); \ + i <= (locale_category_index) (n); \ + i = (locale_category_index) ((int) i + 1)) +#define for_all_individual_category_indexes(i) \ + for_category_indexes_between(i, 0, LC_ALL_INDEX_ - 1) +#define for_all_but_0th_individual_category_indexes(i) \ + for_category_indexes_between(i, 1, LC_ALL_INDEX_ - 1) +#define for_all_category_indexes(i) \ + for_category_indexes_between(i, 0, LC_ALL_INDEX_) + +#ifdef USE_LOCALE +# if defined(USE_FAKE_LC_ALL_POSITIONAL_NOTATION) && defined(LC_ALL) + +/* This simulates an underlying positional notation for LC_ALL when compiled on + * a system that uses name=value notation. Use this to develop on Linux and + * make a quick check that things have some chance of working on a positional + * box. Enable by adding to the Congfigure parameters: + * -Accflags=USE_FAKE_LC_ALL_POSITIONAL_NOTATION + * + * NOTE it redefines setlocale() and usequerylocale() + * */ + +STATIC const char * +S_positional_name_value_xlation(const char * locale, bool direction) +{ /* direction == 1 is from name=value to positional + direction == 0 is from positional to name=value */ + assert(locale); + + dTHX; + const char * individ_locales[LC_ALL_INDEX_] = { NULL }; + + /* This parses either notation */ + switch (parse_LC_ALL_string(locale, + (const char **) &individ_locales, + no_override, /* Handled by other code */ + false, /* Return only [0] if suffices */ + false, /* Don't panic on error */ + __LINE__)) + { + default: /* Some compilers don't realize that below is the complete + list of the available enum values */ + case invalid: + return NULL; + + case no_array: + return locale; + case only_element_0: + SAVEFREEPV(individ_locales[0]); + return individ_locales[0]; + case full_array: + { + calc_LC_ALL_format format = (direction) + ? EXTERNAL_FORMAT_FOR_SET + : INTERNAL_FORMAT; + const char * retval = calculate_LC_ALL_string(individ_locales, + format, + WANT_TEMP_PV, + __LINE__); + + for_all_individual_category_indexes(i) { + Safefree(individ_locales[i]); + } + + return retval; + } + } +} + +STATIC const char * +S_positional_setlocale(int cat, const char * locale) +{ + if (cat != LC_ALL) return setlocale(cat, locale); + + if (locale && strNE(locale, "")) { + locale = S_positional_name_value_xlation(locale, 0); + if (! locale) return NULL; + } + + locale = setlocale(cat, locale); + if (locale == NULL) return NULL; + return S_positional_name_value_xlation(locale, 1); +} + +# undef setlocale +# define setlocale(a,b) S_positional_setlocale(a,b) +# ifdef USE_POSIX_2008_LOCALE + +STATIC locale_t +S_positional_newlocale(int mask, const char * locale, locale_t base) +{ + assert(locale); + + if (mask != LC_ALL_MASK) return newlocale(mask, locale, base); + + if (strNE(locale, "")) locale = S_positional_name_value_xlation(locale, 0); + if (locale == NULL) return NULL; + return newlocale(LC_ALL_MASK, locale, base); +} + +# undef newlocale +# define newlocale(a,b,c) S_positional_newlocale(a,b,c) +# endif +# endif +#endif /* End of fake positional notation */ + #include "reentr.h" #ifdef I_WCHAR @@ -163,17 +616,55 @@ static int debug_initialization = 0; # define SET_EINVAL #endif -/* If we have any of these library functions, we can reliably determine is a - * locale is a UTF-8 one or not. And if we aren't using locales at all, we act - * as if everything is the C locale, so the answer there is always "No, it - * isn't UTF-8"; this too is reliably accurate */ -#if defined(HAS_SOME_LANGINFO) || defined(HAS_MBTOWC) || defined(HAS_MBRTOWC) \ - || ! defined(USE_LOCALE) -# define HAS_RELIABLE_UTF8NESS_DETERMINATION +/* This is a starting guess as to when this is true. It definititely isn't + * true on *BSD where positional LC_ALL notation is used. Likely this will end + * up being defined in hints files. */ +#ifdef PERL_LC_ALL_USES_NAME_VALUE_PAIRS +# define NEWLOCALE_HANDLES_DISPARATE_LC_ALL #endif +/* But regardless, we have to look at individual categories if some are + * ignored. */ +#ifdef HAS_IGNORED_LOCALE_CATEGORIES_ +# undef NEWLOCALE_HANDLES_DISPARATE_LC_ALL +#endif #ifdef USE_LOCALE +/* Not all categories need be set to the same locale. This macro determines if + * 'name' which represents LC_ALL is uniform or disparate. There are two + * situations: 1) the platform uses unordered name=value pairs; 2) the platform + * uses ordered positional values, with a separator string between them */ +# ifdef PERL_LC_ALL_SEPARATOR /* positional */ +# define is_disparate_LC_ALL(name) cBOOL(instr(name, PERL_LC_ALL_SEPARATOR)) +# else /* name=value */ + + /* In the, hopefully never occurring, event that the platform doesn't use + * either mechanism for disparate LC_ALL's, assume the name=value pairs + * form, rather than taking the extreme step of refusing to compile. Many + * programs won't have disparate locales, so will generally work */ +# define PERL_LC_ALL_SEPARATOR ";" +# define is_disparate_LC_ALL(name) cBOOL( strchr(name, ';') \ + && strchr(name, '=')) +# endif + +/* It is possible to compile perl to always keep any individual category in the + * C locale. This would be done where the implementation on a platform is + * flawed or incomplete. At the time of this writing, for example, OpenBSD has + * not implemented LC_COLLATE beyond the C locale. The 'category_available[]' + * table is a bool that says whether a category is changeable, or must be kept + * in C. This macro substitutes C for the locale appropriately, expanding to + * nothing on the more typical case where all possible categories present on + * the platform are handled. */ +# if defined(HAS_IGNORED_LOCALE_CATEGORIES_) \ + || defined(HAS_MISSING_LANGINFO_ITEM_) +# define need_to_override_category(i) (! category_available[i]) +# define override_ignored_category(i, new_locale) \ + ((need_to_override_category(i)) ? "C" : (new_locale)) +# else +# define need_to_override_category(i) 0 +# define override_ignored_category(i, new_locale) (new_locale) +# endif + PERL_STATIC_INLINE const char * S_mortalized_pv_copy(pTHX_ const char * const pv) { @@ -193,321 +684,348 @@ S_mortalized_pv_copy(pTHX_ const char * #endif -/* Returns the Unix errno portion; ignoring any others. This is a macro here - * instead of putting it into perl.h, because unclear to khw what should be - * done generally. */ -#define GET_ERRNO saved_errno - /* Default values come from the C locale */ #define C_codeset "ANSI_X3.4-1968" /* Only in some Configurations, and usually a single instance, so is a #define */ static const char C_decimal_point[] = "."; + +#if defined(HAS_NL_LANGINFO_L) || defined(HAS_NL_LANGINFO) +# define HAS_SOME_LANGINFO +#endif + +#if (defined(USE_LOCALE_NUMERIC) && ! defined(TS_W32_BROKEN_LOCALECONV)) \ + || ! ( defined(USE_LOCALE_NUMERIC) \ + && (defined(HAS_SOME_LANGINFO) || defined(HAS_LOCALECONV))) static const char C_thousands_sep[] = ""; +#endif /* Is the C string input 'name' "C" or "POSIX"? If so, and 'name' is the * return of setlocale(), then this is extremely likely to be the C or POSIX * locale. However, the output of setlocale() is documented to be opaque, but * the odds are extremely small that it would return these two strings for some - * other locale. Note that VMS in these two locales includes many non-ASCII - * characters as controls and punctuation (below are hex bytes): + * other locale. Note that VMS includes many non-ASCII characters in these two + * locales as controls and punctuation (below are hex bytes): * cntrl: 84-97 9B-9F * punct: A1-A3 A5 A7-AB B0-B3 B5-B7 B9-BD BF-CF D1-DD DF-EF F1-FD * Oddly, none there are listed as alphas, though some represent alphabetics - * http://www.nntp.perl.org/group/perl.perl5.porters/2013/02/msg198753.html */ + * https://www.nntp.perl.org/group/perl.perl5.porters/2013/02/msg198753.html */ #define isNAME_C_OR_POSIX(name) \ ( (name) != NULL \ && (( *(name) == 'C' && (*(name + 1)) == '\0') \ || strEQ((name), "POSIX"))) -#if defined(HAS_NL_LANGINFO_L) || defined(HAS_NL_LANGINFO) -# define HAS_SOME_LANGINFO -#endif +/* If this interface to nl_langinfo() isn't defined by embed.fnc, it means it + * isn't available on this platform, so instead emulate it */ +#ifndef langinfo_sv_i +# define langinfo_sv_i(i, c, l, s, u) \ + (PERL_UNUSED_VAR(c), emulate_langinfo(i, l, s, u)) +#endif + +/* In either case, create a version that takes things like 'LC_NUMERIC' as a + * parameter */ +#define langinfo_sv_c(item, category, locale, sv, utf8ness) \ + langinfo_sv_i(item, category##_INDEX_, locale, sv, utf8ness) + +/* The normal method for interfacing with nl_langinfo() in this file is to use + * a scratch buffer (whose existence is hidden from the caller by these + * macros). */ +#define langinfo_i(item, index, locale, utf8ness) \ + langinfo_sv_i(item, index, locale, PL_scratch_langinfo, utf8ness) -#define my_langinfo_c(item, category, locale, retbufp, retbuf_sizep, utf8ness) \ - my_langinfo_i(item, category##_INDEX_, locale, retbufp, \ - retbuf_sizep, utf8ness) +#define langinfo_c(item, category, locale, utf8ness) \ + langinfo_i(item, category##_INDEX_, locale, utf8ness) -#ifdef USE_LOCALE +#ifndef USE_LOCALE /* A no-op unless locales are enabled */ +# define toggle_locale_i(index, locale) \ + ((const char *) (PERL_UNUSED_VAR(locale), NULL)) +# define restore_toggled_locale_i(index, locale) PERL_UNUSED_VAR(locale) +#else +# define toggle_locale_i(index, locale) \ + S_toggle_locale_i(aTHX_ index, locale, __LINE__) +# define restore_toggled_locale_i(index, locale) \ + S_restore_toggled_locale_i(aTHX_ index, locale, __LINE__) +#endif +# define toggle_locale_c(cat, locale) toggle_locale_i(cat##_INDEX_, locale) +# define restore_toggled_locale_c(cat, locale) \ + restore_toggled_locale_i(cat##_INDEX_, locale) +#ifdef USE_LOCALE # ifdef DEBUGGING # define setlocale_debug_string_i(index, locale, result) \ my_setlocale_debug_string_i(index, locale, result, __LINE__) # define setlocale_debug_string_c(category, locale, result) \ setlocale_debug_string_i(category##_INDEX_, locale, result) # define setlocale_debug_string_r(category, locale, result) \ - setlocale_debug_string_i(get_category_index(category, locale), \ + setlocale_debug_string_i(get_category_index(category), \ locale, result) # endif -# define toggle_locale_i(index, locale) \ - S_toggle_locale_i(aTHX_ index, locale, __LINE__) -# define toggle_locale_c(cat, locale) toggle_locale_i(cat##_INDEX_, locale) -# define restore_toggled_locale_i(index, locale) \ - S_restore_toggled_locale_i(aTHX_ index, locale, __LINE__) -# define restore_toggled_locale_c(cat, locale) \ - restore_toggled_locale_i(cat##_INDEX_, locale) - -/* Two parallel arrays indexed by our mapping of category numbers into small - * non-negative indexes; first the locale categories Perl uses on this system, - * used to do the inverse mapping. The second array is their names. These - * arrays are in mostly arbitrary order. */ +/* On systems without LC_ALL, pretending it exists anyway simplifies things. + * Choose a value for it that is very unlikely to clash with any actual + * category */ +# define FAKE_LC_ALL PERL_INT_MIN + +/* Below are parallel arrays for locale information indexed by our mapping of + * category numbers into small non-negative indexes. locale_table.h contains + * an entry like this for each individual category used on this system: + * PERL_LOCALE_TABLE_ENTRY(CTYPE, S_new_ctype) + * + * Each array redefines PERL_LOCALE_TABLE_ENTRY to generate the information + * needed for that array, and #includes locale_table.h to get the valid + * categories. + * + * An entry for the conglomerate category LC_ALL is added here, immediately + * following the individual categories. (The treatment for it varies, so can't + * be in locale_table.h.) + * + * Following this, each array ends with an entry for illegal categories. All + * category numbers unknown to perl get mapped to this entry. This is likely + * to be a parameter error from the calling program; but it could be that this + * platform has a category we don't know about, in which case it needs to be + * added, using the paradigm of one of the existing categories. */ +/* The first array is the locale categories perl uses on this system, used to + * map our index back to the system's category number. */ STATIC const int categories[] = { -# ifdef USE_LOCALE_CTYPE - LC_CTYPE, -# endif -# ifdef USE_LOCALE_NUMERIC - LC_NUMERIC, +# undef PERL_LOCALE_TABLE_ENTRY +# define PERL_LOCALE_TABLE_ENTRY(name, call_back) LC_ ## name, +# include "locale_table.h" + +# ifdef LC_ALL + LC_ALL, +# else + FAKE_LC_ALL, # endif -# ifdef USE_LOCALE_COLLATE - LC_COLLATE, -# endif -# ifdef USE_LOCALE_TIME - LC_TIME, -# endif -# ifdef USE_LOCALE_MESSAGES - LC_MESSAGES, -# endif -# ifdef USE_LOCALE_MONETARY - LC_MONETARY, -# endif -# ifdef USE_LOCALE_ADDRESS - LC_ADDRESS, -# endif -# ifdef USE_LOCALE_IDENTIFICATION - LC_IDENTIFICATION, -# endif -# ifdef USE_LOCALE_MEASUREMENT - LC_MEASUREMENT, -# endif -# ifdef USE_LOCALE_PAPER - LC_PAPER, -# endif -# ifdef USE_LOCALE_TELEPHONE - LC_TELEPHONE, -# endif -# ifdef USE_LOCALE_NAME - LC_NAME, -# endif -# ifdef USE_LOCALE_SYNTAX - LC_SYNTAX, -# endif -# ifdef USE_LOCALE_TOD - LC_TOD, -# endif -# ifdef LC_ALL - LC_ALL, -# endif - /* Placeholder as a precaution if code fails to check the return of - * get_category_index(), which returns this element to indicate an error */ - -1 + (FAKE_LC_ALL + 1) /* Entry for unknown category; this number is unlikely + to clash with a real category */ }; -/* The top-most real element is LC_ALL */ +# define GET_NAME_AS_STRING(token) # token +# define GET_LC_NAME_AS_STRING(token) GET_NAME_AS_STRING(LC_ ## token) +/* The second array is the category names. */ STATIC const char * const category_names[] = { -# ifdef USE_LOCALE_CTYPE - "LC_CTYPE", -# endif -# ifdef USE_LOCALE_NUMERIC - "LC_NUMERIC", +# undef PERL_LOCALE_TABLE_ENTRY +# define PERL_LOCALE_TABLE_ENTRY(name, call_back) GET_LC_NAME_AS_STRING(name), +# include "locale_table.h" + +# ifdef LC_ALL +# define LC_ALL_STRING "LC_ALL" +# else +# define LC_ALL_STRING "If you see this, it is a bug in perl;" \ + " please report it via perlbug" # endif -# ifdef USE_LOCALE_COLLATE - "LC_COLLATE", -# endif -# ifdef USE_LOCALE_TIME - "LC_TIME", -# endif -# ifdef USE_LOCALE_MESSAGES - "LC_MESSAGES", -# endif -# ifdef USE_LOCALE_MONETARY - "LC_MONETARY", -# endif -# ifdef USE_LOCALE_ADDRESS - "LC_ADDRESS", -# endif -# ifdef USE_LOCALE_IDENTIFICATION - "LC_IDENTIFICATION", -# endif -# ifdef USE_LOCALE_MEASUREMENT - "LC_MEASUREMENT", -# endif -# ifdef USE_LOCALE_PAPER - "LC_PAPER", -# endif -# ifdef USE_LOCALE_TELEPHONE - "LC_TELEPHONE", -# endif -# ifdef USE_LOCALE_NAME - "LC_NAME", -# endif -# ifdef USE_LOCALE_SYNTAX - "LC_SYNTAX", -# endif -# ifdef USE_LOCALE_TOD - "LC_TOD", -# endif -# ifdef LC_ALL - "LC_ALL", -# endif - /* Placeholder as a precaution if code fails to check the return of - * get_category_index(), which returns this element to indicate an error */ - NULL + LC_ALL_STRING, + +# define LC_UNKNOWN_STRING "Locale category unknown to Perl; if you see" \ + " this, it is a bug in perl; please report it" \ + " via perlbug" + LC_UNKNOWN_STRING }; -/* A few categories require additional setup when they are changed. This table - * points to the functions that do that setup */ -STATIC void (*update_functions[]) (pTHX_ const char *, bool force) = { -# ifdef USE_LOCALE_CTYPE - S_new_ctype, -# endif -# ifdef USE_LOCALE_NUMERIC - S_new_numeric, -# endif -# ifdef USE_LOCALE_COLLATE - S_new_collate, -# endif -# ifdef USE_LOCALE_TIME - NULL, -# endif -# ifdef USE_LOCALE_MESSAGES - NULL, -# endif -# ifdef USE_LOCALE_MONETARY - NULL, -# endif -# ifdef USE_LOCALE_ADDRESS - NULL, -# endif -# ifdef USE_LOCALE_IDENTIFICATION - NULL, -# endif -# ifdef USE_LOCALE_MEASUREMENT - NULL, -# endif -# ifdef USE_LOCALE_PAPER - NULL, -# endif -# ifdef USE_LOCALE_TELEPHONE - NULL, -# endif -# ifdef USE_LOCALE_NAME - NULL, -# endif -# ifdef USE_LOCALE_SYNTAX - NULL, -# endif -# ifdef USE_LOCALE_TOD - NULL, -# endif - /* No harm done to have this even without an LC_ALL */ - S_new_LC_ALL, +STATIC const Size_t category_name_lengths[] = { + +# undef PERL_LOCALE_TABLE_ENTRY +# define PERL_LOCALE_TABLE_ENTRY(name, call_back) \ + STRLENs(GET_LC_NAME_AS_STRING(name)), +# include "locale_table.h" - /* Placeholder as a precaution if code fails to check the return of - * get_category_index(), which returns this element to indicate an error */ - NULL + STRLENs(LC_ALL_STRING), + STRLENs(LC_UNKNOWN_STRING) }; -# ifdef LC_ALL +/* Each entry includes space for the '=' and ';' */ +# undef PERL_LOCALE_TABLE_ENTRY +# define PERL_LOCALE_TABLE_ENTRY(name, call_back) \ + + STRLENs(GET_LC_NAME_AS_STRING(name)) + 2 + +STATIC const Size_t lc_all_boiler_plate_length = 1 /* space for trailing NUL */ +# include "locale_table.h" +; - /* On systems with LC_ALL, it is kept in the highest index position. (-2 - * to account for the final unused placeholder element.) */ -# define NOMINAL_LC_ALL_INDEX (C_ARRAY_LENGTH(categories) - 2) -# else - - /* On systems without LC_ALL, we pretend it is there, one beyond the real - * top element, hence in the unused placeholder element. */ -# define NOMINAL_LC_ALL_INDEX (C_ARRAY_LENGTH(categories) - 1) -# endif - -/* Pretending there is an LC_ALL element just above allows us to avoid most - * special cases. Most loops through these arrays in the code below are - * written like 'for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++)'. They will work - * on either type of system. But the code must be written to not access the - * element at 'LC_ALL_INDEX_' except on platforms that have it. This can be - * checked for at compile time by using the #define LC_ALL_INDEX_ which is only - * defined if we do have LC_ALL. */ +/* A few categories require additional setup when they are changed. This table + * points to the functions that do that setup */ +STATIC void (*update_functions[]) (pTHX_ const char *, bool force) = { -STATIC int -S_get_category_index_nowarn(const int category) -{ - /* Given a category, return the equivalent internal index we generally use - * instead, or negative if not found. - * - * Some sort of hash could be used instead of this loop, but the number of - * elements is so far at most 12 */ +# undef PERL_LOCALE_TABLE_ENTRY +# define PERL_LOCALE_TABLE_ENTRY(name, call_back) call_back, +# include "locale_table.h" + + S_new_LC_ALL, + NULL, /* No update for unknown category */ +}; - unsigned int i; +# if defined(HAS_IGNORED_LOCALE_CATEGORIES_) \ + || defined(HAS_MISSING_LANGINFO_ITEM_) - PERL_ARGS_ASSERT_GET_CATEGORY_INDEX; +/* Indicates if each category on this platform is available to use not in + * the C locale */ +STATIC const bool category_available[] = { + +# undef PERL_LOCALE_TABLE_ENTRY +# define PERL_LOCALE_TABLE_ENTRY(name, call_back) LC_ ## name ## _AVAIL_, +# include "locale_table.h" # ifdef LC_ALL - for (i = 0; i <= LC_ALL_INDEX_; i++) + true, # else - for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) + false, # endif - { - if (category == categories[i]) { - dTHX_DEBUGGING; - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "index of category %d (%s) is %d\n", - category, category_names[i], i)); - return i; - } - } - return -1; -} + false /* LC_UNKNOWN_AVAIL_ */ +}; -STATIC unsigned int -S_get_category_index(const int category, const char * locale) -{ - /* Given a category, return the equivalent internal index we generally use - * instead. - * - * 'locale' is for use in any generated diagnostics, and may be NULL - */ +# endif +# if defined(USE_POSIX_2008_LOCALE) - const char * conditional_warn_text = "; can't set it to "; - const int index = get_category_index_nowarn(category); +STATIC const int category_masks[] = { - if (index >= 0) { - return index; +# undef PERL_LOCALE_TABLE_ENTRY +# define PERL_LOCALE_TABLE_ENTRY(name, call_back) LC_ ## name ## _MASK, +# include "locale_table.h" + + LC_ALL_MASK, /* Will rightly refuse to compile unless this is defined */ + 0 /* Empty mask for unknown category */ +}; + +# endif +# if ! defined(PERL_LC_ALL_USES_NAME_VALUE_PAIRS) + +/* On platforms that use positional notation for expressing LC_ALL, this maps + * the position of each category to our corresponding internal index for it. + * This is initialized at run time if needed. LC_ALL_INDEX_ is not legal for + * an individual locale, hence marks the elements here as not actually + * initialized. */ +STATIC +unsigned int +map_LC_ALL_position_to_index[LC_ALL_INDEX_] = { LC_ALL_INDEX_ }; + +# endif +#endif +#if defined(USE_LOCALE) || defined(DEBUGGING) + +STATIC const char * +S_get_displayable_string(pTHX_ + const char * const s, + const char * const e, + const bool is_utf8) +{ + PERL_ARGS_ASSERT_GET_DISPLAYABLE_STRING; + + if (e <= s) { + return ""; } - /* Here, we don't know about this category, so can't handle it. */ + const char * t = s; + bool prev_was_printable = TRUE; + bool first_time = TRUE; + char * ret; + + /* Worst case scenario: All are non-printable so have a blank between each. + * If UTF-8, all are the largest possible code point; otherwise all are a + * single byte. '(2 + 1)' is from each byte takes 2 characters to + * display, and a blank (or NUL for the final one) after it */ + const Size_t size = (e - s) * (2 + 1) * ((is_utf8) ? UVSIZE : 1); + Newxz(ret, size, char); + SAVEFREEPV(ret); + + while (t < e) { + UV cp = (is_utf8) + ? utf8_to_uvchr_buf((U8 *) t, e, NULL) + : * (U8 *) t; + if (isPRINT(cp)) { + if (! prev_was_printable) { + my_strlcat(ret, " ", size); + } - if (! locale) { - locale = ""; - conditional_warn_text = ""; + /* Escape these to avoid any ambiguity */ + if (cp == ' ' || cp == '\\') { + my_strlcat(ret, "\\", size); + } + my_strlcat(ret, Perl_form(aTHX_ "%c", (U8) cp), size); + prev_was_printable = TRUE; + } + else { + if (! first_time) { + my_strlcat(ret, " ", size); + } + my_strlcat(ret, Perl_form(aTHX_ "%02" UVXf, cp), size); + prev_was_printable = FALSE; + } + t += (is_utf8) ? UTF8SKIP(t) : 1; + first_time = FALSE; } - /* diag_listed_as: Unknown locale category %d; can't set it to %s */ - Perl_warner_nocontext(packWARN(WARN_LOCALE), - "Unknown locale category %d%s%s", - category, conditional_warn_text, locale); + return ret; +} + +#endif +#ifdef USE_LOCALE - SET_EINVAL; +# define get_category_index(cat) get_category_index_helper(cat, NULL, __LINE__) + +STATIC locale_category_index +S_get_category_index_helper(pTHX_ const int category, bool * succeeded, + const line_t caller_line) +{ + PERL_ARGS_ASSERT_GET_CATEGORY_INDEX_HELPER; + + /* Given a category, return the equivalent internal index we generally use + * instead, warn or panic if not found. */ + + locale_category_index i; + +# undef PERL_LOCALE_TABLE_ENTRY +# define PERL_LOCALE_TABLE_ENTRY(name, call_back) \ + case LC_ ## name: i = LC_ ## name ## _INDEX_; break; + + switch (category) { + +# include "locale_table.h" +# ifdef LC_ALL + case LC_ALL: i = LC_ALL_INDEX_; break; +# endif + + default: goto unknown_locale; + } + + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "index of category %d (%s) is %d;" + " called from %" LINE_Tf "\n", + category, category_names[i], i, caller_line)); + + if (succeeded) { + *succeeded = true; + } - /* Return an out-of-bounds value */ - return NOMINAL_LC_ALL_INDEX + 1; + return i; + + unknown_locale: + + if (succeeded) { + *succeeded = false; + return LC_ALL_INDEX_; /* Arbitrary */ + } + + locale_panic_via_(Perl_form(aTHX_ "Unknown locale category %d", category), + __FILE__, caller_line); + NOT_REACHED; /* NOTREACHED */ } #endif /* ifdef USE_LOCALE */ void -Perl_force_locale_unlock() +Perl_force_locale_unlock(pTHX) { + /* Remove any locale mutex, in preperation for an inglorious termination, + * typically a panic */ #if defined(USE_LOCALE_THREADS) - dTHX; - /* If recursively locked, clear all at once */ if (PL_locale_mutex_depth > 1) { PL_locale_mutex_depth = 1; @@ -550,13 +1068,13 @@ S_use_curlocale_scratch(pTHX) void Perl_locale_panic(const char * msg, - const char * file_name, - const line_t line, - const int errnum) + const line_t immediate_caller_line, + const char * const higher_caller_file, + const line_t higher_caller_line) { - dTHX; - PERL_ARGS_ASSERT_LOCALE_PANIC; + dTHX; + dSAVE_ERRNO; force_locale_unlock(); @@ -564,4327 +1082,7270 @@ Perl_locale_panic(const char * msg, dump_c_backtrace(Perl_debug_log, 20, 1); #endif - /* diag_listed_as: panic: %s */ - Perl_croak(aTHX_ "%s: %" LINE_Tf ": panic: %s; errno=%d\n", - file_name, line, msg, errnum); -} + const char * called_by = ""; + if ( strNE(__FILE__, higher_caller_file) + || immediate_caller_line != higher_caller_line) + { + called_by = Perl_form(aTHX_ "\nCalled by %s: %" LINE_Tf "\n", + higher_caller_file, higher_caller_line); + } -#define setlocale_failure_panic_c( \ - cat, current, failed, caller_0_line, caller_1_line) \ - setlocale_failure_panic_i(cat##_INDEX_, current, failed, \ - caller_0_line, caller_1_line) - -/* posix_setlocale() presents a consistent POSIX-compliant interface to - * setlocale(). Windows requres a customized base-level setlocale(). Any - * necessary mutex locking needs to be done at a higher level */ -#ifdef WIN32 -# define posix_setlocale(cat, locale) win32_setlocale(cat, locale) -#else -# define posix_setlocale(cat, locale) ((const char *) setlocale(cat, locale)) -#endif + RESTORE_ERRNO; -/* The next layer up is to catch vagaries and bugs in the libc setlocale return - * value. Again, any necessary mutex locking needs to be done at a higher - * level */ -#ifdef stdize_locale -# define stdized_setlocale(cat, locale) \ - stdize_locale(cat, posix_setlocale(cat, locale), \ - &PL_stdize_locale_buf, &PL_stdize_locale_bufsize, __LINE__) -#else -# define stdized_setlocale(cat, locale) posix_setlocale(cat, locale) -#endif + const char * errno_text; -/* The next many lines form a layer above the close-to-the-metal 'posix' - * and 'stdized' macros. They are used to present a uniform API to the rest of - * the code in this file in spite of the disparate underlying implementations. - * */ +#ifdef HAS_EXTENDED_OS_ERRNO -#if (! defined(USE_LOCALE_THREADS) && ! defined(USE_POSIX_2008_LOCALE)) \ - || ( defined(WIN32) && defined(USE_THREAD_SAFE_LOCALE)) + const int extended_errnum = get_extended_os_errno(); + if (errno != extended_errnum) { + errno_text = Perl_form(aTHX_ "; errno=%d, $^E=%d", + errno, extended_errnum); + } + else -/* For non-threaded perls, the added layer just expands to the base-level - * functions, except if we are supposed to use the POSIX 2008 interface anyway. - * On perls where threading is invisible to us, the base-level functions are - * used regardless of threading. Currently this is only on later Windows - * versions. - * - * See the introductory comments in this file for the meaning of the suffixes - * '_c', '_r', '_i'. */ - -# define setlocale_r(cat, locale) stdized_setlocale(cat, locale) -# define setlocale_i(i, locale) setlocale_r(categories[i], locale) -# define setlocale_c(cat, locale) setlocale_r(cat, locale) +#endif -# define void_setlocale_i(i, locale) \ - STMT_START { \ - if (! posix_setlocale(categories[i], locale)) { \ - setlocale_failure_panic_i(i, NULL, locale, __LINE__, 0); \ - NOT_REACHED; /* NOTREACHED */ \ - } \ - } STMT_END -# define void_setlocale_c(cat, locale) \ - void_setlocale_i(cat##_INDEX_, locale) -# define void_setlocale_r(cat, locale) \ - void_setlocale_i(get_category_index(cat, locale), locale) + { + errno_text = Perl_form(aTHX_ "; errno=%d", errno); + } -# define bool_setlocale_r(cat, locale) cBOOL(posix_setlocale(cat, locale)) -# define bool_setlocale_i(i, locale) \ - bool_setlocale_c(categories[i], locale) -# define bool_setlocale_c(cat, locale) bool_setlocale_r(cat, locale) + /* diag_listed_as: panic: %s */ + Perl_croak(aTHX_ "%s: %" LINE_Tf ": panic: %s%s%s\n", + __FILE__, immediate_caller_line, + msg, errno_text, called_by); +} + +/* Macros to report and croak on an unexpected failure to set the locale. The + * via version has more stack trace information */ +#define setlocale_failure_panic_i(i, cur, fail, line, higher_line) \ + setlocale_failure_panic_via_i(i, cur, fail, __LINE__, line, \ + __FILE__, higher_line) + +#define setlocale_failure_panic_c(cat, cur, fail, line, higher_line) \ + setlocale_failure_panic_i(cat##_INDEX_, cur, fail, line, higher_line) + +#if defined(USE_LOCALE) + +/* Expands to the code to + * result = savepvn(s, len) + * if the category whose internal index is 'i' doesn't need to be kept in the C + * locale on this system, or if 'action is 'no_override'. Otherwise it expands + * to + * result = savepv("C") + * unless 'action' isn't 'check_that_overridden', in which case if the string + * 's' isn't already "C" it panics */ +# ifndef HAS_IGNORED_LOCALE_CATEGORIES_ +# define OVERRIDE_AND_SAVEPV(s, len, result, i, action) \ + result = savepvn(s, len) +# else +# define OVERRIDE_AND_SAVEPV(s, len, result, i, action) \ + STMT_START { \ + if (LIKELY( ! need_to_override_category(i) \ + || action == no_override)) { \ + result = savepvn(s, len); \ + } \ + else { \ + const char * temp = savepvn(s, len); \ + result = savepv(override_ignored_category(i, temp)); \ + if (action == check_that_overridden && strNE(result, temp)) { \ + locale_panic_(Perl_form(aTHX_ \ + "%s expected to be '%s', instead is '%s'", \ + category_names[i], result, temp)); \ + } \ + Safefree(temp); \ + } \ + } STMT_END +# endif -/* All the querylocale...() forms return a mortalized copy. If you need - * something stable across calls, you need to savepv() the result yourself */ +STATIC parse_LC_ALL_string_return +S_parse_LC_ALL_string(pTHX_ const char * string, + const char ** output, + const parse_LC_ALL_STRING_action override, + bool always_use_full_array, + const bool panic_on_error, + const line_t caller_line) +{ + /* This function parses the value of the input 'string' which is expected + * to be the representation of an LC_ALL locale, and splits the result into + * the values for the individual component categories, returning those in + * the 'output' array. Each array value will be a savepv() copy that is + * the responsibility of the caller to make sure gets freed + * + * The locale for each category is independent of the other categories. + * Often, they are all the same, but certainly not always. Perl, in fact, + * usually keeps LC_NUMERIC in the C locale, regardless of the underlying + * locale. LC_ALL has to be able to represent the case of when not all + * categories have the same locale. Platforms have differing ways of + * representing this. Internally, this file uses the 'name=value;' + * representation found on some platforms, so this function always looks + * for and parses that. Other platforms use a positional notation. On + * those platforms, this function also parses that form. It examines the + * input to see which form is being parsed. + * + * Often, all categories will have the same locale. This is special cased + * if 'always_use_full_array' is false on input: + * 1) If the input 'string' is a single value, this function doesn't + * store anything into 'output', and returns 'no_array' + * 2) Some platforms will return multiple occurrences of the same + * value rather than coalescing them down to a single one. HP-UX + * is such a one. This function will do that collapsing for you, + * returning 'only_element_0' and saving the single value in + * output[0], which the caller will need to arrange to be freed. + * The rest of output[] is undefined, and does not need to be + * freed. + * + * Otherwise, the input 'string' may not be valid. This function looks + * mainly for syntactic errors, and if found, returns 'invalid'. 'output' + * will not be filled in in that case, but the input state of it isn't + * necessarily preserved. Turning on -DL debugging will give details as to + * the error. If 'panic_on_error' is 'true', the function panics instead + * of returning on error, with a message giving the details. + * + * Otherwise, output[] will be filled with the individual locale names for + * all categories on the system, 'full_array' will be returned, and the + * caller needs to arrange for each to be freed. This means that either at + * least one category differed from the others, or 'always_use_full_array' was + * true on input. + * + * perl may be configured to ignore changes to a category's locale to + * non-C. The parameter 'override' tells this function what to do when + * encountering such an illegal combination: + * + * no_override indicates to take no special action + * override_if_ignored, indicates to return 'C' instead of what the + * input string actually says. + * check_that_overridden indicates to panic if the string says the + * category is not 'C'. This is used when + * non-C is very unexpected behavior. + * */ -# define querylocale_r(cat) mortalized_pv_copy(setlocale_r(cat, NULL)) -# define querylocale_c(cat) querylocale_r(cat) -# define querylocale_i(i) querylocale_c(categories[i]) + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "Entering parse_LC_ALL_string; called from %" \ + LINE_Tf "\nnew='%s'\n", caller_line, string)); -#elif defined(USE_LOCALE_THREADS) \ - && ! defined(USE_THREAD_SAFE_LOCALE) +# ifdef PERL_LC_ALL_USES_NAME_VALUE_PAIRS - /* Here, there are threads, and there is no support for thread-safe - * operation. This is a dangerous situation, which perl is documented as - * not supporting, but it arises in practice. We can do a modicum of - * automatic mitigation by making sure there is a per-thread return from - * setlocale(), and that a mutex protects it from races */ -STATIC const char * -S_less_dicey_setlocale_r(pTHX_ const int category, const char * locale) -{ - const char * retval; + const char separator[] = ";"; + const Size_t separator_len = 1; + const bool single_component = (strchr(string, ';') == NULL); - PERL_ARGS_ASSERT_LESS_DICEY_SETLOCALE_R; +# else - POSIX_SETLOCALE_LOCK; + /* It's possible (but quite unlikely) that the separator string is an '=' + * or a ';'. Requiring both to be present for using the 'name=value;' form + * properly handles those possibilities */ + const bool name_value = strchr(string, '=') && strchr(string, ';'); + const char * separator; + Size_t separator_len; + bool single_component; + if (name_value) { + separator = ";"; + separator_len = 1; + single_component = false; /* Since has both [;=], must be multi */ + } + else { + separator = PERL_LC_ALL_SEPARATOR; + separator_len = STRLENs(PERL_LC_ALL_SEPARATOR); + single_component = instr(string, separator) == NULL; + } - retval = stdized_setlocale(category, locale); + Size_t component_number = 0; /* Position in the parsing loop below */ - /* We reuse PL_stdize_locale_buf as it doesn't conflict, but the call may - * already have used it, in which case we don't have to do anything further - * */ - retval = save_to_buffer(retval, - &PL_stdize_locale_buf, &PL_stdize_locale_bufsize); +# endif +# ifndef HAS_IGNORED_LOCALE_CATEGORIES_ + PERL_UNUSED_ARG(override); +# else - POSIX_SETLOCALE_UNLOCK; + /* Any ignored categories are to be set to "C", so if this single-component + * LC_ALL isn't to C, it has both "C" and non-C, so isn't really a single + * component. All the non-ignored categories are set to the input + * component, but the ignored ones are overridden to be C. + * + * This incidentally handles the case where the string is "". The return + * will be C for each ignored category and "" for the others. Then the + * caller can individually set each category, and get the right answer. */ + if (single_component && ! isNAME_C_OR_POSIX(string)) { + for_all_individual_category_indexes(i) { + OVERRIDE_AND_SAVEPV(string, strlen(string), output[i], i, override); + } - return retval; -} + return full_array; + } -# define setlocale_r(cat, locale) less_dicey_setlocale_r(cat, locale) -# define setlocale_c(cat, locale) setlocale_r(cat, locale) -# define setlocale_i(i, locale) setlocale_r(categories[i], locale) - -# define querylocale_r(cat) mortalized_pv_copy(setlocale_r(cat, NULL)) -# define querylocale_c(cat) querylocale_r(cat) -# define querylocale_i(i) querylocale_r(categories[i]) +# endif -STATIC void -S_less_dicey_void_setlocale_i(pTHX_ const unsigned cat_index, - const char * locale, - const line_t line) -{ - PERL_ARGS_ASSERT_LESS_DICEY_VOID_SETLOCALE_I; + if (single_component) { + if (! always_use_full_array) { + return no_array; + } - POSIX_SETLOCALE_LOCK; - if (! posix_setlocale(categories[cat_index], locale)) { - POSIX_SETLOCALE_UNLOCK; - setlocale_failure_panic_i(cat_index, NULL, locale, __LINE__, line); + for_all_individual_category_indexes(i) { + output[i] = savepv(string); + } + + return full_array; } - POSIX_SETLOCALE_UNLOCK; -} -# define void_setlocale_i(i, locale) \ - less_dicey_void_setlocale_i(i, locale, __LINE__) -# define void_setlocale_c(cat, locale) \ - void_setlocale_i(cat##_INDEX_, locale) -# define void_setlocale_r(cat, locale) \ - void_setlocale_i(get_category_index(cat, locale), locale) + /* Here the input is multiple components. Parse through them. (It is + * possible that these components are all the same, so we check, and if so, + * return just the 0th component (unless 'always_use_full_array' is true) + * + * This enum notes the possible errors findable in parsing */ + enum { + incomplete, + no_equals, + unknown_category, + contains_LC_ALL_element + } error; -# if 0 /* Not currently used */ + /* Keep track of the categories we have encountered so far */ + bool seen[LC_ALL_INDEX_] = { false }; -STATIC bool -S_less_dicey_bool_setlocale_r(pTHX_ const int cat, const char * locale) -{ - bool retval; + Size_t index; /* Our internal index for the current category */ + const char * s = string; + const char * e = s + strlen(string); + const char * category_end = NULL; + const char * saved_first = NULL; - PERL_ARGS_ASSERT_LESS_DICEY_BOOL_SETLOCALE_R; + /* Parse the input locale string */ + while (s < e) { - POSIX_SETLOCALE_LOCK; - retval = cBOOL(posix_setlocale(cat, locale)); - POSIX_SETLOCALE_UNLOCK; + /* 'separator' has been set up to delimit the components */ + const char * next_sep = instr(s, separator); + if (! next_sep) { /* At the end of the input */ + next_sep = e; + } - return retval; -} +# ifndef PERL_LC_ALL_USES_NAME_VALUE_PAIRS + + if (! name_value) { + /* Get the index of the category in this position */ + index = map_LC_ALL_position_to_index[component_number++]; + } + else # endif -# define bool_setlocale_r(cat, locale) \ - less_dicey_bool_setlocale_r(cat, locale) -# define bool_setlocale_i(i, locale) \ - bool_setlocale_r(categories[i], locale) -# define bool_setlocale_c(cat, locale) bool_setlocale_r(cat, locale) -#else -/* Here, there is a completely different API to get thread-safe locales. We - * emulate the setlocale() API with our own function(s). setlocale categories, - * like LC_NUMERIC, are not valid here for the POSIX 2008 API. Instead, there - * are equivalents, like LC_NUMERIC_MASK, which we use instead, converting to - * by using get_category_index() followed by table lookup. */ + { /* Get the category part when each component is the + * 'category=locale' form */ -# define emulate_setlocale_c(cat, locale, recalc_LC_ALL, line) \ - emulate_setlocale_i(cat##_INDEX_, locale, recalc_LC_ALL, line) + category_end = strchr(s, '='); - /* A wrapper for the macros below. */ -# define common_emulate_setlocale(i, locale) \ - emulate_setlocale_i(i, locale, YES_RECALC_LC_ALL, __LINE__) - -# define setlocale_i(i, locale) \ - save_to_buffer(common_emulate_setlocale(i, locale), \ - &PL_stdize_locale_buf, \ - &PL_stdize_locale_bufsize) -# define setlocale_c(cat, locale) setlocale_i(cat##_INDEX_, locale) -# define setlocale_r(cat, locale) \ - setlocale_i(get_category_index(cat, locale), locale) + /* The '=' terminates the category name. If no '=', is improper + * form */ + if (! category_end) { + error = no_equals; + goto failure; + } -# define void_setlocale_i(i, locale) \ - ((void) common_emulate_setlocale(i, locale)) -# define void_setlocale_c(cat, locale) \ - void_setlocale_i(cat##_INDEX_, locale) -# define void_setlocale_r(cat, locale) ((void) setlocale_r(cat, locale)) + /* Find our internal index of the category name; uses a linear + * search. (XXX This could be avoided by various means, but the + * maximum likely search is 6 items, and khw doesn't think the + * added complexity would save very much at all.) */ + const unsigned int name_len = (unsigned int) (category_end - s); + for (index = 0; index < C_ARRAY_LENGTH(category_names); index++) { + if ( name_len == category_name_lengths[index] + && memEQ(s, category_names[index], name_len)) + { + goto found_category; + } + } -# define bool_setlocale_i(i, locale) \ - cBOOL(common_emulate_setlocale(i, locale)) -# define bool_setlocale_c(cat, locale) \ - bool_setlocale_i(cat##_INDEX_, locale) -# define bool_setlocale_r(cat, locale) cBOOL(setlocale_r(cat, locale)) + /* Here, the category is not in our list. */ + error = unknown_category; + goto failure; -# define querylocale_i(i) mortalized_pv_copy(my_querylocale_i(i)) -# define querylocale_c(cat) querylocale_i(cat##_INDEX_) -# define querylocale_r(cat) querylocale_i(get_category_index(cat,NULL)) + found_category: /* The system knows about this category. */ -# ifdef USE_QUERYLOCALE -# define isSINGLE_BIT_SET(mask) isPOWER_OF_2(mask) + if (index == LC_ALL_INDEX_) { + error = contains_LC_ALL_element; + goto failure; + } - /* This code used to think querylocale() was valid on LC_ALL. Make sure - * all instances of that have been removed */ -# define QUERYLOCALE_ASSERT(index) \ - __ASSERT_(isSINGLE_BIT_SET(category_masks[index])) -# if ! defined(HAS_QUERYLOCALE) && ( defined(_NL_LOCALE_NAME) \ - && defined(HAS_NL_LANGINFO_L)) -# define querylocale_l(index, locale_obj) \ - (QUERYLOCALE_ASSERT(index) \ - mortalized_pv_copy(nl_langinfo_l( \ - _NL_LOCALE_NAME(categories[index]), locale_obj))) -# else -# define querylocale_l(index, locale_obj) \ - (QUERYLOCALE_ASSERT(index) \ - mortalized_pv_copy(querylocale(category_masks[index], locale_obj))) -# endif -# endif -# if defined(__GLIBC__) && defined(USE_LOCALE_MESSAGES) -# define HAS_GLIBC_LC_MESSAGES_BUG -# include -# endif + /* The locale name starts just beyond the '=' */ + s = category_end + 1; -/* A fourth array, parallel to the ones above to map from category to its - * equivalent mask */ -STATIC const int category_masks[] = { -# ifdef USE_LOCALE_CTYPE - LC_CTYPE_MASK, -# endif -# ifdef USE_LOCALE_NUMERIC - LC_NUMERIC_MASK, -# endif -# ifdef USE_LOCALE_COLLATE - LC_COLLATE_MASK, -# endif -# ifdef USE_LOCALE_TIME - LC_TIME_MASK, -# endif -# ifdef USE_LOCALE_MESSAGES - LC_MESSAGES_MASK, -# endif -# ifdef USE_LOCALE_MONETARY - LC_MONETARY_MASK, -# endif -# ifdef USE_LOCALE_ADDRESS - LC_ADDRESS_MASK, -# endif -# ifdef USE_LOCALE_IDENTIFICATION - LC_IDENTIFICATION_MASK, -# endif -# ifdef USE_LOCALE_MEASUREMENT - LC_MEASUREMENT_MASK, -# endif -# ifdef USE_LOCALE_PAPER - LC_PAPER_MASK, -# endif -# ifdef USE_LOCALE_TELEPHONE - LC_TELEPHONE_MASK, -# endif -# ifdef USE_LOCALE_NAME - LC_NAME_MASK, -# endif -# ifdef USE_LOCALE_SYNTAX - LC_SYNTAX_MASK, -# endif -# ifdef USE_LOCALE_TOD - LC_TOD_MASK, -# endif - /* LC_ALL can't be turned off by a Configure - * option, and in Posix 2008, should always be - * here, so compile it in unconditionally. - * This could catch some glitches at compile - * time */ - LC_ALL_MASK, - - /* Placeholder as a precaution if code fails to check the return of - * get_category_index(), which returns this element to indicate an error */ - 0 -}; + /* Linux (and maybe others) doesn't treat a duplicate category in + * the string as an error. Instead it uses the final occurrence as + * the intended value. So if this is a duplicate, free the former + * value before setting the new one */ + if (seen[index]) { + Safefree(output[index]); + } + else { + seen[index] = true; + } + } -# define my_querylocale_c(cat) my_querylocale_i(cat##_INDEX_) + /* Here, 'index' contains our internal index number for the current + * category, and 's' points to the beginning of the locale name for + * that category. */ + OVERRIDE_AND_SAVEPV(s, next_sep - s, output[index], index, override); -STATIC const char * -S_my_querylocale_i(pTHX_ const unsigned int index) -{ - /* This function returns the name of the locale category given by the input - * index into our parallel tables of them. + if (! always_use_full_array) { + if (! saved_first) { + saved_first = output[index]; + } + else { + if (strNE(saved_first, output[index])) { + always_use_full_array = true; + } + } + } + + /* Next time start from the new position */ + s = next_sep + separator_len; + } + + /* Finished looping through all the categories * - * POSIX 2008, for some sick reason, chose not to provide a method to find - * the category name of a locale, discarding a basic linguistic tenet that - * for any object, people will create a name for it. Some vendors have - * created a querylocale() function to do just that. This function is a - * lot simpler to implement on systems that have this. Otherwise, we have - * to keep track of what the locale has been set to, so that we can return - * its name so as to emulate setlocale(). It's also possible for C code in - * some library to change the locale without us knowing it, though as of - * September 2017, there are no occurrences in CPAN of uselocale(). Some - * libraries do use setlocale(), but that changes the global locale, and - * threads using per-thread locales will just ignore those changes. */ + * Check if the input was incomplete. */ - int category; - const locale_t cur_obj = uselocale((locale_t) 0); - const char * retval; +# ifndef PERL_LC_ALL_USES_NAME_VALUE_PAIRS + + if (! name_value) { /* Positional notation */ + if (component_number != LC_ALL_INDEX_) { + error = incomplete; + goto failure; + } + } + else - PERL_ARGS_ASSERT_MY_QUERYLOCALE_I; - assert(index <= NOMINAL_LC_ALL_INDEX); +# endif - category = categories[index]; + { /* Here is the name=value notation */ + for_all_individual_category_indexes(i) { + if (! seen[i]) { + error = incomplete; + goto failure; + } + } + } - DEBUG_Lv(PerlIO_printf(Perl_debug_log, "my_querylocale_i(%s) on %p\n", - category_names[index], cur_obj)); - if (cur_obj == LC_GLOBAL_LOCALE) { - POSIX_SETLOCALE_LOCK; - retval = posix_setlocale(category, NULL); - POSIX_SETLOCALE_UNLOCK; + /* In the loop above, we changed 'always_use_full_array' to true iff not all + * categories have the same locale. Hence, if it is still 'false', all of + * them are the same. */ + if (always_use_full_array) { + return full_array; } - else { -# ifdef USE_QUERYLOCALE + /* Free the dangling ones */ + for_all_but_0th_individual_category_indexes(i) { + Safefree(output[i]); + output[i] = NULL; + } - /* We don't currently keep records when there is querylocale(), so have - * to get it anew each time */ - retval = (index == LC_ALL_INDEX_) - ? calculate_LC_ALL(cur_obj) - : querylocale_l(index, cur_obj); + return only_element_0; -# else + failure: - /* But we do have up-to-date values when we keep our own records - * (except some times in initialization, where we get the value from - * the system. */ - const char ** which = (index == LC_ALL_INDEX_) - ? &PL_cur_LC_ALL - : &PL_curlocales[index]; - if (*which == NULL) { - retval = stdized_setlocale(category, NULL); - *which = savepv(retval); - } - else { - retval = *which; + /* Don't leave memory dangling that we allocated before the failure */ + for_all_individual_category_indexes(i) { + if (seen[i]) { + Safefree(output[i]); + output[i] = NULL; } + } -# endif + const char * msg; + const char * display_start = s; + const char * display_end = e; + switch (error) { + case incomplete: + msg = "doesn't list every locale category"; + display_start = string; + break; + case no_equals: + msg = "needs an '=' to split name=value"; + break; + case unknown_category: + msg = "is an unknown category"; + display_end = (category_end && category_end > display_start) + ? category_end + : e; + break; + case contains_LC_ALL_element: + msg = "has LC_ALL, which is illegal here"; + break; } - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "my_querylocale_i(%s) returning '%s'\n", - category_names[index], retval)); - assert(strNE(retval, "")); - return retval; -} - -# ifdef USE_PL_CURLOCALES - -STATIC const char * -S_update_PL_curlocales_i(pTHX_ - const unsigned int index, - const char * new_locale, - recalc_lc_all_t recalc_LC_ALL) -{ - /* This is a helper function for emulate_setlocale_i(), mostly used to - * make that function easier to read. */ - - PERL_ARGS_ASSERT_UPDATE_PL_CURLOCALES_I; - assert(index <= NOMINAL_LC_ALL_INDEX); - - if (index == LC_ALL_INDEX_) { - unsigned int i; - - /* For LC_ALL, we change all individual categories to correspond */ - /* PL_curlocales is a parallel array, so has same - * length as 'categories' */ - for (i = 0; i < LC_ALL_INDEX_; i++) { - Safefree(PL_curlocales[i]); - PL_curlocales[i] = savepv(new_locale); - } + msg = Perl_form(aTHX_ "'%.*s' %s\n", + (int) (display_end - display_start), + display_start, msg); - Safefree(PL_cur_LC_ALL); - PL_cur_LC_ALL = savepv(calculate_LC_ALL(PL_curlocales)); - return PL_cur_LC_ALL; - } + DEBUG_L(PerlIO_printf(Perl_debug_log, "%s", msg)); - /* Update the single category's record */ - Safefree(PL_curlocales[index]); - PL_curlocales[index] = savepv(new_locale); - - /* And also LC_ALL if the input says to, including if this is the final - * iteration of a loop updating all sub-categories */ - if ( recalc_LC_ALL == YES_RECALC_LC_ALL - || ( recalc_LC_ALL == RECALCULATE_LC_ALL_ON_FINAL_INTERATION - && index == NOMINAL_LC_ALL_INDEX - 1)) - { - Safefree(PL_cur_LC_ALL); - PL_cur_LC_ALL = savepv(calculate_LC_ALL(PL_curlocales)); + if (panic_on_error) { + locale_panic_via_(msg, __FILE__, caller_line); } - return PL_curlocales[index]; + return invalid; } -# endif /* Need PL_curlocales[] */ +# undef OVERRIDE_AND_SAVEPV +#endif + +/*========================================================================== + * Here starts the code that gives a uniform interface to its callers, hiding + * the differences between platforms. + * + * base_posix_setlocale_() presents a consistent POSIX-compliant interface to + * setlocale(). Windows requres a customized base-level setlocale(). This + * layer should only be used by the next level up: the plain posix_setlocale + * layer. Any necessary mutex locking needs to be done at a higher level. The + * return may be overwritten by the next call to this function */ +#ifdef WIN32 +# define base_posix_setlocale_(cat, locale) win32_setlocale(cat, locale) +#else +# define base_posix_setlocale_(cat, locale) \ + ((const char *) setlocale(cat, locale)) +#endif + +/*========================================================================== + * Here is the main posix layer. It is the same as the base one unless the + * system is lacking LC_ALL, or there are categories that we ignore, but that + * the system libc knows about */ + +#if ! defined(USE_LOCALE) \ + || (defined(LC_ALL) && ! defined(HAS_IGNORED_LOCALE_CATEGORIES_)) +# define posix_setlocale(cat, locale) base_posix_setlocale_(cat, locale) +#else +# define posix_setlocale(cat, locale) \ + S_posix_setlocale_with_complications(aTHX_ cat, locale, __LINE__) STATIC const char * -S_setlocale_from_aggregate_LC_ALL(pTHX_ const char * locale, const line_t line) -{ - /* This function parses the value of the LC_ALL locale, assuming glibc - * syntax, and sets each individual category on the system to the proper - * value. - * - * This is likely to only ever be called from one place, so exists to make - * the calling function easier to read by moving this ancillary code out of - * the main line. - * - * The locale for each category is independent of the other categories. - * Often, they are all the same, but certainly not always. Perl, in fact, - * usually keeps LC_NUMERIC in the C locale, regardless of the underlying - * locale. LC_ALL has to be able to represent the case of when there are - * varying locales. Platforms have differing ways of representing this. - * Because of this, the code in this file goes to lengths to avoid the - * issue, generally looping over the component categories instead of - * referring to them in the aggregate, wherever possible. However, there - * are cases where we have to parse our own constructed aggregates, which use - * the glibc syntax. */ - - const char * locale_on_entry = querylocale_c(LC_ALL); - - PERL_ARGS_ASSERT_SETLOCALE_FROM_AGGREGATE_LC_ALL; - - /* If the string that gives what to set doesn't include all categories, - * the omitted ones get set to "C". To get this behavior, first set - * all the individual categories to "C", and override the furnished - * ones below. FALSE => No need to recalculate LC_ALL, as this is a - * temporary state */ - if (! emulate_setlocale_c(LC_ALL, "C", DONT_RECALC_LC_ALL, line)) { - setlocale_failure_panic_c(LC_ALL, locale_on_entry, - "C", __LINE__, line); - NOT_REACHED; /* NOTREACHED */ +S_posix_setlocale_with_complications(pTHX_ const int cat, + const char * new_locale, + const line_t caller_line) +{ + /* This implements the posix layer above the base posix layer. + * It is needed to reconcile our internal records that reflect only a + * proper subset of the categories known by the system. */ + + /* Querying the current locale returns the real value */ + if (new_locale == NULL) { + new_locale = base_posix_setlocale_(cat, NULL); + assert(new_locale); + return new_locale; } - const char * s = locale; - const char * e = locale + strlen(locale); - while (s < e) { - const char * p = s; + const char * locale_on_entry = NULL; - /* Parse through the category */ - while (isWORDCHAR(*p)) { - p++; + /* If setting from the environment, actually do the set to get the system's + * idea of what that means; we may have to override later. */ + if (strEQ(new_locale, "")) { + locale_on_entry = base_posix_setlocale_(cat, NULL); + assert(locale_on_entry); + new_locale = base_posix_setlocale_(cat, ""); + if (! new_locale) { + SET_EINVAL; + return NULL; } + } - const char * category_end = p; - - if (*p++ != '=') { - locale_panic_(Perl_form(aTHX_ - "Unexpected character in locale category name '%s" - "<-- HERE", - get_displayable_string(s, p - 1, 0))); - } +# ifdef LC_ALL - /* Parse through the locale name */ - const char * name_start = p; - while (p < e && *p != ';') { - p++; - } - if (UNLIKELY( p < e && *p != ';')) { - locale_panic_(Perl_form(aTHX_ - "Unexpected character in locale name '%s<-- HERE", - get_displayable_string(s, p, 0))); - } + const char * new_locales[LC_ALL_INDEX_] = { NULL }; - const char * name_end = p; + if (cat == LC_ALL) { + switch (parse_LC_ALL_string(new_locale, + (const char **) &new_locales, + override_if_ignored, /* Override any + ignored + categories */ + false, /* Return only [0] if suffices */ + false, /* Don't panic on error */ + caller_line)) + { + case invalid: + SET_EINVAL; + return NULL; - /* Space past the semi-colon */ - if (p < e) { - p++; - } + case no_array: + break; - /* Find the index of the category name in our lists */ - for (PERL_UINT_FAST8_T i = 0; i < LC_ALL_INDEX_; i++) { + case only_element_0: + new_locale = new_locales[0]; + SAVEFREEPV(new_locale); + break; - /* Keep going if this index doesn't point to the category being - * parsed. The strnNE() avoids a Perl_form(), but would fail if - * ever a category name could be a substring of another one, e.g., - * if there were a "LC_TIME_DATE" */ - if strnNE(s, category_names[i], category_end - s) { - continue; - } + case full_array: - /* Here i points to the category being parsed. Now isolate the - * locale it is being changed to */ - const char * individ_locale = Perl_form(aTHX_ "%.*s", - (int) (name_end - name_start), name_start); - - /* And do the change. Don't recalculate LC_ALL; we'll do it - * ourselves after the loop */ - if (! emulate_setlocale_i(i, individ_locale, - DONT_RECALC_LC_ALL, line)) - { + /* Turn the array into a string that the libc setlocale() should + * understand. (Another option would be to loop, setting the + * individual locales, and then return base(cat, NULL) */ + new_locale = calculate_LC_ALL_string(new_locales, + EXTERNAL_FORMAT_FOR_SET, + WANT_TEMP_PV, + caller_line); - /* But if we have to back out, do fix up LC_ALL */ - if (! emulate_setlocale_c(LC_ALL, locale_on_entry, - YES_RECALC_LC_ALL, line)) - { - setlocale_failure_panic_i(i, individ_locale, - locale, __LINE__, line); - NOT_REACHED; /* NOTREACHED */ - } + for_all_individual_category_indexes(i) { + Safefree(new_locales[i]); + } - /* Reverting to the entry value succeeded, but the operation - * failed to go to the requested locale. */ - return NULL; + /* And call the libc setlocale. We could avoid this call if + * locale_on_entry is set and eq the new_locale. But that would be + * only for the relatively rare case of the desired locale being + * "", and the time spent in doing the string compare might be more + * than that of just setting it unconditionally */ + new_locale = base_posix_setlocale_(cat, new_locale); + if (! new_locale) { + goto failure; } - /* Found and handled the desired category. Quit the inner loop to - * try the next category */ - break; + return new_locale; } - - /* Finished with this category; iterate to the next one in the input */ - s = p; } -# ifdef USE_PL_CURLOCALES +# endif - /* Here we have set all the individual categories. Update the LC_ALL entry - * as well. We can't just use the input 'locale' as the value may omit - * categories whose locale is 'C'. khw thinks it's better to store a - * complete LC_ALL. So calculate it. */ - const char * retval = savepv(calculate_LC_ALL(PL_curlocales)); - Safefree(PL_cur_LC_ALL); - PL_cur_LC_ALL = retval; + /* Here, 'new_locale' is a single value, not an aggregation. Just set it. + * */ + new_locale = + base_posix_setlocale_(cat, + override_ignored_category( + get_category_index(cat), new_locale)); + if (! new_locale) { + goto failure; + } -# else + return new_locale; - const char * retval = querylocale_c(LC_ALL); + failure: -# endif + /* 'locale_on_entry' being set indicates there has likely been a change in + * locale which needs to be restored */ + if (locale_on_entry) { + if (! base_posix_setlocale_(cat, locale_on_entry)) { + setlocale_failure_panic_i(get_category_index(cat), + NULL, locale_on_entry, + __LINE__, caller_line); + } + } - return retval; + SET_EINVAL; + return NULL; } -STATIC const char * -S_emulate_setlocale_i(pTHX_ - - /* Our internal index of the 'category' setlocale is called with */ - const unsigned int index, +#endif - const char * new_locale, /* The locale to set the category to */ - const recalc_lc_all_t recalc_LC_ALL, /* Explained below */ - const line_t line /* Called from this line number */ - ) -{ - PERL_ARGS_ASSERT_EMULATE_SETLOCALE_I; - assert(index <= NOMINAL_LC_ALL_INDEX); +/* End of posix layer + *========================================================================== + * + * The next layer up is to catch vagaries and bugs in the libc setlocale return + * value. The return is not guaranteed to be stable. + * + * Any necessary mutex locking needs to be done at a higher level. + * + * On most platforms this layer is empty, expanding to just the layer + * below. To enable it, call Configure with either or both: + * -Accflags=-DHAS_LF_IN_SETLOCALE_RETURN + * to indicate that extraneous \n characters can be returned + * by setlocale() + * -Accflags=-DHAS_BROKEN_SETLOCALE_QUERY_LC_ALL + * to indicate that setlocale(LC_ALL, NULL) cannot be relied + * on + */ - /* Otherwise could have undefined behavior, as the return of this function - * may be copied to this buffer, which this function could change in the - * middle of its work */ - assert(new_locale != PL_stdize_locale_buf); +#define STDIZED_SETLOCALE_LOCK POSIX_SETLOCALE_LOCK +#define STDIZED_SETLOCALE_UNLOCK POSIX_SETLOCALE_UNLOCK +#if ! defined(USE_LOCALE) \ + || ! ( defined(HAS_LF_IN_SETLOCALE_RETURN) \ + || defined(HAS_BROKEN_SETLOCALE_QUERY_LC_ALL)) +# define stdized_setlocale(cat, locale) posix_setlocale(cat, locale) +# define stdize_locale(cat, locale) (locale) +#else +# define stdized_setlocale(cat, locale) \ + S_stdize_locale(aTHX_ cat, posix_setlocale(cat, locale), __LINE__) - /* This function effectively performs a setlocale() on just the current - * thread; thus it is thread-safe. It does this by using the POSIX 2008 - * locale functions to emulate the behavior of setlocale(). Similar to - * regular setlocale(), the return from this function points to memory that - * can be overwritten by other system calls, so needs to be copied - * immediately if you need to retain it. The difference here is that - * system calls besides another setlocale() can overwrite it. - * - * By doing this, most locale-sensitive functions become thread-safe. The - * exceptions are mostly those that return a pointer to static memory. - * - * This function may be called in a tight loop that iterates over all - * categories. Because LC_ALL is not a "real" category, but merely the sum - * of all the other ones, such loops don't include LC_ALL. On systems that - * have querylocale() or similar, the current LC_ALL value is immediately - * retrievable; on systems lacking that feature, we have to keep track of - * LC_ALL ourselves. We could do that on each iteration, only to throw it - * away on the next, but the calculation is more than a trivial amount of - * work. Instead, the 'recalc_LC_ALL' parameter is set to - * RECALCULATE_LC_ALL_ON_FINAL_INTERATION to only do the calculation once. - * This function calls itself recursively in such a loop. +STATIC const char * +S_stdize_locale(pTHX_ const int category, + const char *input_locale, + const line_t caller_line) +{ + /* The return value of setlocale() is opaque, but is required to be usable + * as input to a future setlocale() to create the same state. + * Unfortunately not all systems are compliant. This function brings those + * outliers into conformance. It is based on what problems have arisen in + * the field. + * + * This has similar constraints as the posix layer. You need to lock + * around it until its return is safely copied or no longer needed. (The + * return may point to a global static buffer or may be mortalized.) + * + * The current things this corrects are: + * 1) A new-line. This function chops any \n characters + * 2) A broken 'setlocale(LC_ALL, foo)' This constructs a proper returned + * string from the constituent categories * - * When not in such a loop, the parameter is set to the other enum values - * DONT_RECALC_LC_ALL or YES_RECALC_LC_ALL. */ - - int mask = category_masks[index]; - const locale_t entry_obj = uselocale((locale_t) 0); - const char * locale_on_entry = querylocale_i(index); + * If no changes were made, the input is returned as-is */ DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "emulate_setlocale_i input=%d (%s), mask=0x%x," - " new locale=\"%s\", current locale=\"%s\"," - "index=%d, object=%p\n", - categories[index], category_names[index], mask, - ((new_locale == NULL) ? "(nil)" : new_locale), - locale_on_entry, index, entry_obj)); + "Entering stdize_locale(%d, '%s');" + " called from %" LINE_Tf "\n", + category, input_locale, caller_line)); - /* Return the already-calculated info if just querying what the existing - * locale is */ - if (new_locale == NULL) { - return locale_on_entry; + if (input_locale == NULL) { + SET_EINVAL; + return NULL; } - /* Here, trying to change the locale, but it is a no-op if the new boss is - * the same as the old boss. Except this routine is called when converting - * from the global locale, so in that case we will create a per-thread - * locale below (with the current values). It also seemed that newlocale() - * could free up the basis locale memory if we called it with the new and - * old being the same, but khw now thinks that this was due to some other - * bug, since fixed, as there are other places where newlocale() gets - * similarly called without problems. */ - if ( entry_obj != LC_GLOBAL_LOCALE - && locale_on_entry - && strEQ(new_locale, locale_on_entry)) - { - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "(%" LINE_Tf "): emulate_setlocale_i" - " no-op to change to what it already was\n", - line)); + char * retval = (char *) input_locale; -# ifdef USE_PL_CURLOCALES +# if defined(LC_ALL) && defined(HAS_BROKEN_SETLOCALE_QUERY_LC_ALL) - /* On the final iteration of a loop that needs to recalculate LC_ALL, do - * so. If no iteration changed anything, LC_ALL also doesn't change, - * but khw believes the complexity needed to keep track of that isn't - * worth it. */ - if (UNLIKELY( recalc_LC_ALL == RECALCULATE_LC_ALL_ON_FINAL_INTERATION - && index == NOMINAL_LC_ALL_INDEX - 1)) - { - Safefree(PL_cur_LC_ALL); - PL_cur_LC_ALL = savepv(calculate_LC_ALL(PL_curlocales)); - } + /* If setlocale(LC_ALL, NULL) is broken, compute what the system + * actually thinks it should be from its individual components */ + if (category == LC_ALL) { + retval = (char *) calculate_LC_ALL_string( + NULL, /* query each individ locale */ + EXTERNAL_FORMAT_FOR_SET, + WANT_TEMP_PV, + caller_line); + } # endif +# ifdef HAS_NL_IN_SETLOCALE_RETURN - return locale_on_entry; - } + char * first_bad = NULL; -# ifndef USE_QUERYLOCALE +# ifndef LC_ALL - /* Without a querylocale() mechanism, we have to figure out ourselves what - * happens with setting a locale to "" */ - if (strEQ(new_locale, "")) { - new_locale = find_locale_from_environment(index); - } + PERL_UNUSED_ARG(category); + PERL_UNUSED_ARG(caller_line); -# endif +# define INPUT_LOCALE retval +# define MARK_CHANGED +# else - /* So far, it has worked that a semi-colon in the locale name means that - * the category is LC_ALL and it subsumes categories which don't all have - * the same locale. This is the glibc syntax. */ - if (strchr(new_locale, ';')) { - assert(index == LC_ALL_INDEX_); - return setlocale_from_aggregate_LC_ALL(new_locale, line); + char * individ_locales[LC_ALL_INDEX_] = { NULL }; + bool made_changes = false; + Size_t upper; + if (category != LC_ALL) { + individ_locales[0] = retval; + upper = 0; } + else { -# ifdef HAS_GLIBC_LC_MESSAGES_BUG + /* And parse the locale string, splitting into its individual + * components. */ + switch (parse_LC_ALL_string(retval, + (const char **) &individ_locales, + check_that_overridden, /* ignored + categories should + already have been + overridden */ + false, /* Return only [0] if suffices */ + false, /* Don't panic on error */ + caller_line)) + { + case invalid: + SET_EINVAL; + return NULL; - /* For this bug, if the LC_MESSAGES locale changes, we have to do an - * expensive workaround. Save the current value so we can later determine - * if it changed. */ - const char * old_messages_locale = NULL; - if ( (index == LC_MESSAGES_INDEX_ || index == LC_ALL_INDEX_) - && LIKELY(PL_phase != PERL_PHASE_CONSTRUCT)) - { - old_messages_locale = querylocale_c(LC_MESSAGES); + case full_array: /* Loop below through all the component categories. + */ + upper = LC_ALL_INDEX_ - 1; + break; + + case no_array: + /* All categories here are set to the same locale, and the parse + * didn't fill in any of 'individ_locales'. Set the 0th element to + * that locale. */ + individ_locales[0] = retval; + /* FALLTHROUGH */ + + case only_element_0: /* Element 0 is the only element we need to look + at */ + upper = 0; + break; + } } -# endif + for (unsigned int i = 0; i <= upper; i++) - assert(PL_C_locale_obj); +# define INPUT_LOCALE individ_locales[i] +# define MARK_CHANGED made_changes = true; +# endif /* Has LC_ALL */ - /* Now ready to switch to the input 'new_locale' */ + { + first_bad = (char *) strchr(INPUT_LOCALE, '\n'); - /* Switching locales generally entails freeing the current one's space (at - * the C library's discretion), hence we can't be using that locale at the - * time of the switch (this wasn't obvious to khw from the man pages). So - * switch to a known locale object that we don't otherwise mess with. */ - if (! uselocale(PL_C_locale_obj)) { + /* Most likely, there isn't a problem with the input */ + if (UNLIKELY(first_bad)) { - /* Not being able to change to the C locale is severe; don't keep - * going. */ - setlocale_failure_panic_i(index, locale_on_entry, "C", __LINE__, line); - NOT_REACHED; /* NOTREACHED */ - } + /* This element will need to be adjusted. Create a modifiable + * copy. */ + MARK_CHANGED + retval = savepv(INPUT_LOCALE); + SAVEFREEPV(retval); + + /* Translate the found position into terms of the copy */ + first_bad = retval + (first_bad - INPUT_LOCALE); + + /* Get rid of the \n and what follows. (Originally, only a + * trailing \n was stripped. Unsure what to do if not trailing) */ + *((char *) first_bad) = '\0'; + } /* End of needs adjusting */ + } /* End of looking for problems */ - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "(%" LINE_Tf "): emulate_setlocale_i now using C" - " object=%p\n", line, PL_C_locale_obj)); +# ifdef LC_ALL - locale_t new_obj; + /* If we had multiple elements, extra work is required */ + if (upper != 0) { - /* We created a (never changing) object at start-up for LC_ALL being in the - * C locale. If this call is to switch to LC_ALL=>C, simply use that - * object. But in fact, we already have switched to it just above, in - * preparation for the general case. Since we're already there, no need to - * do further switching. */ - if (mask == LC_ALL_MASK && isNAME_C_OR_POSIX(new_locale)) { - DEBUG_Lv(PerlIO_printf(Perl_debug_log, "(%" LINE_Tf "):" - " emulate_setlocale_i will stay" - " in C object\n", line)); - new_obj = PL_C_locale_obj; + /* If no changes were made to the input, 'retval' already contains it + * */ + if (made_changes) { - /* And free the old object if it isn't a special one */ - if (entry_obj != LC_GLOBAL_LOCALE && entry_obj != PL_C_locale_obj) { - freelocale(entry_obj); + /* But if did make changes, need to calculate the new value */ + retval = (char *) calculate_LC_ALL_string( + (const char **) &individ_locales, + EXTERNAL_FORMAT_FOR_SET, + WANT_TEMP_PV, + caller_line); } - } - else { /* Here is the general case, not to LC_ALL=>C */ - locale_t basis_obj = entry_obj; - - /* Specially handle two objects */ - if (basis_obj == LC_GLOBAL_LOCALE || basis_obj == PL_C_locale_obj) { - - /* For these two objects, we make duplicates to hand to newlocale() - * below. For LC_GLOBAL_LOCALE, this is because newlocale() - * doesn't necessarily accept it as input (the results are - * undefined). For PL_C_locale_obj, it is so that it never gets - * modified, as otherwise newlocale() is free to do so */ - basis_obj = duplocale(basis_obj); - if (! basis_obj) { - locale_panic_(Perl_form(aTHX_ "(%" LINE_Tf "): duplocale failed", - line)); - NOT_REACHED; /* NOTREACHED */ - } - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "(%" LINE_Tf "): emulate_setlocale_i" - " created %p by duping the input\n", - line, basis_obj)); + /* And free the no-longer needed memory */ + for (unsigned int i = 0; i <= upper; i++) { + Safefree(individ_locales[i]); } + } - /* Ready to create a new locale by modification of the existing one. - * - * NOTE: This code may incorrectly show up as a leak under the address - * sanitizer. We do not free this object under normal teardown, however - * you can set PERL_DESTRUCT_LEVEL=2 to cause it to be freed. - */ - new_obj = newlocale(mask, new_locale, basis_obj); +# endif +# undef INPUT_LOCALE +# undef MARK_CHANGED +# endif /* HAS_NL_IN_SETLOCALE_RETURN */ - if (! new_obj) { - DEBUG_L(PerlIO_printf(Perl_debug_log, - " (%" LINE_Tf "): emulate_setlocale_i" - " creating new object from %p failed:" - " errno=%d\n", - line, basis_obj, GET_ERRNO)); - - /* Failed. Likely this is because the proposed new locale isn't - * valid on this system. But we earlier switched to the LC_ALL=>C - * locale in anticipation of it succeeding, Now have to switch - * back to the state upon entry */ - if (! uselocale(entry_obj)) { - setlocale_failure_panic_i(index, "switching back to", - locale_on_entry, __LINE__, line); - NOT_REACHED; /* NOTREACHED */ - } + return (const char *) retval; +} -# ifdef USE_PL_CURLOCALES +#endif /* USE_LOCALE */ - if (entry_obj == LC_GLOBAL_LOCALE) { +/* End of stdize_locale layer + * + * ========================================================================== + * + * The next many lines form several implementations of a layer above the + * close-to-the-metal 'posix' and 'stdized' macros. They are used to present a + * uniform API to the rest of the code in this file in spite of the disparate + * underlying implementations. Which implementation gets compiled depends on + * the platform capabilities (and some user choice) as determined by Configure. + * + * As more fully described in the introductory comments in this file, the + * API of each implementation consists of three sets of macros. Each set has + * three variants with suffixes '_c', '_r', and '_i'. In the list below '_X' + * is to be replaced by any of these suffixes. + * + * 1) bool_setlocale_X attempts to set the given category's locale to the + * given value, returning if it worked or not. + * 2) void_setlocale_X is like the corresponding bool_setlocale, but used when + * success is the only sane outcome, so failure causes it + * to panic. + * 3) querylocale_X to see what the given category's locale is + * + * 4) setlocale_i() is defined only in those implementations where the bool + * and query forms are essentially the same, and can be + * combined to save CPU time. + * + * Each implementation is fundamentally defined by just two macros: a + * bool_setlocale_X() and a querylocale_X(). The other macros are all + * derivable from these. Each fundamental macro is either a '_i' suffix one or + * an '_r' suffix one, depending on what is the most efficient in getting to an + * input form that the underlying libc functions want. The derived macro + * definitions are deferred in this file to after the code for all the + * implementations. This makes each implementation shorter and clearer, and + * removes duplication. + * + * Each implementation below is separated by ==== lines, and includes bool, + * void, and query macros. The query macros are first, followed by any + * functions needed to implement them. Then come the bool, again followed by + * any implementing functions Then are the void macros; next is setlocale_i if + * present on this implementation. Finally are any helper functions. The sets + * in each implementation are separated by ---- lines. + * + * The returned strings from all the querylocale...() forms in all + * implementations are thread-safe, and the caller should not free them, + * but each may be a mortalized copy. If you need something stable across + * calls, you need to savepv() the result yourself. + * + *===========================================================================*/ - /* Here, we are back in the global locale. We may never have - * set PL_curlocales. If the locale change had succeeded, the - * code would have then set them up, but since it didn't, do so - * here. khw isn't sure if this prevents some issues or not, - * This will calculate LC_ALL's entry only on the final - * iteration */ - POSIX_SETLOCALE_LOCK; - for (PERL_UINT_FAST8_T i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { - update_PL_curlocales_i(i, - posix_setlocale(categories[i], NULL), - RECALCULATE_LC_ALL_ON_FINAL_INTERATION); - } - POSIX_SETLOCALE_UNLOCK; - } -# endif +#if (! defined(USE_LOCALE_THREADS) && ! defined(USE_POSIX_2008_LOCALE)) \ + || ( defined(WIN32) && defined(USE_THREAD_SAFE_LOCALE)) - return NULL; - } +/* For non-threaded perls, the implementation just expands to the base-level + * functions (except if we are Configured to nonetheless use the POSIX 2008 + * interface) This implementation is also used on threaded perls where + * threading is invisible to us. Currently this is only on later Windows + * versions. */ - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "(%" LINE_Tf "): emulate_setlocale_i created %p" - " while freeing %p\n", line, new_obj, basis_obj)); +# define querylocale_r(cat) mortalized_pv_copy(stdized_setlocale(cat, NULL)) +# define bool_setlocale_r(cat, locale) cBOOL(posix_setlocale(cat, locale)) - /* Here, successfully created an object representing the desired - * locale; now switch into it */ - if (! uselocale(new_obj)) { - freelocale(new_obj); - locale_panic_(Perl_form(aTHX_ "(%" LINE_Tf "): emulate_setlocale_i" - " switching into new locale failed", - line)); - } - } +/*---------------------------------------------------------------------------*/ - /* Here, we are using 'new_obj' which matches the input 'new_locale'. */ - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "(%" LINE_Tf "): emulate_setlocale_i now using %p\n", - line, new_obj)); +/* setlocale_i is only defined for Configurations where the libc setlocale() + * doesn't need any tweaking. It allows for some shortcuts */ +# ifndef USE_LOCALE_THREADS +# define setlocale_i(i, locale) stdized_setlocale(categories[i], locale) -#ifdef MULTIPLICITY - PL_cur_locale_obj = new_obj; -#endif +# elif defined(WIN32) && defined(USE_THREAD_SAFE_LOCALE) - /* We are done, except for updating our records (if the system doesn't keep - * them) and in the case of locale "", we don't actually know what the - * locale that got switched to is, as it came from the environment. So - * have to find it */ +/* On Windows, we don't know at compile time if we are in thread-safe mode or + * not. If we are, we can just return the result of the layer below us. If we + * are in unsafe mode, we need to first copy that result to a safe place while + * in a critical section */ -# ifdef USE_QUERYLOCALE +# define setlocale_i(i, locale) S_setlocale_i(aTHX_ categories[i], locale) - if (strEQ(new_locale, "")) { - new_locale = querylocale_i(index); +STATIC const char * +S_setlocale_i(pTHX_ const int category, const char * locale) +{ + if (LIKELY(_configthreadlocale(0) == _ENABLE_PER_THREAD_LOCALE)) { + return stdized_setlocale(category, locale); } - PERL_UNUSED_ARG(recalc_LC_ALL); - -# else + gwLOCALE_LOCK; + const char * retval = save_to_buffer(stdized_setlocale(category, locale), + &PL_setlocale_buf, + &PL_setlocale_bufsize); + gwLOCALE_UNLOCK; - new_locale = update_PL_curlocales_i(index, new_locale, recalc_LC_ALL); + return retval; +} # endif -# ifdef HAS_GLIBC_LC_MESSAGES_BUG - /* Invalidate the glibc cache of loaded translations if the locale has - * changed, see [perl #134264] */ - if (old_messages_locale) { - if (strNE(old_messages_locale, my_querylocale_c(LC_MESSAGES))) { - textdomain(textdomain(NULL)); - } - } +/*===========================================================================*/ +#elif defined(USE_LOCALE_THREADS) \ + && ! defined(USE_THREAD_SAFE_LOCALE) -# endif + /* Here, there are threads, and there is no support for thread-safe + * operation. This is a dangerous situation, which perl is documented as + * not supporting, but it arises in practice. We can do a modicum of + * automatic mitigation by making sure there is a per-thread return from + * setlocale(), and that a mutex protects it from races */ - return new_locale; -} - -#endif /* End of the various implementations of the setlocale and - querylocale macros used in the remainder of this program */ - -#ifdef USE_LOCALE - -/* So far, the locale strings returned by modern 2008-compliant systems have - * been fine */ +# define querylocale_r(cat) \ + mortalized_pv_copy(less_dicey_setlocale_r(cat, NULL)) STATIC const char * -S_stdize_locale(pTHX_ const int category, - const char *input_locale, - const char **buf, - Size_t *buf_size, - const line_t caller_line) +S_less_dicey_setlocale_r(pTHX_ const int category, const char * locale) { - /* The return value of setlocale() is opaque, but is required to be usable - * as input to a future setlocale() to create the same state. - * Unfortunately not all systems are compliant. But most often they are of - * a very restricted set of forms that this file has been coded to expect. - * - * There are some outliers, though, that this function tries to tame: - * - * 1) A new-line. This function chomps any \n characters - * 2) foo=bar. 'bar' is what is generally meant, and the foo= part is - * stripped. This form is legal for LC_ALL. When found in - * that category group, the function calls itself - * recursively on each possible component category to make - * sure the individual categories are ok. - * - * If no changes to the input were made, it is returned; otherwise the - * changed version is stored into memory at *buf, with *buf_size set to its - * new value, and *buf is returned. - */ - - const char * first_bad; const char * retval; - PERL_ARGS_ASSERT_STDIZE_LOCALE; - - if (input_locale == NULL) { - return NULL; - } - - first_bad = strpbrk(input_locale, "=\n"); - - /* Most likely, there isn't a problem with the input */ - if (LIKELY(! first_bad)) { - return input_locale; - } - -# ifdef LC_ALL + PERL_ARGS_ASSERT_LESS_DICEY_SETLOCALE_R; - /* But if there is, and the category is LC_ALL, we have to look at each - * component category */ - if (category == LC_ALL) { - const char * individ_locales[LC_ALL_INDEX_]; - bool made_changes = FALSE; - unsigned int i; - - for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { - Size_t this_size = 0; - individ_locales[i] = stdize_locale(categories[i], - posix_setlocale(categories[i], - NULL), - &individ_locales[i], - &this_size, - caller_line); - - /* If the size didn't change, it means this category did not have - * to be adjusted, and individ_locales[i] points to the buffer - * returned by posix_setlocale(); we have to copy that before - * it's called again in the next iteration */ - if (this_size == 0) { - individ_locales[i] = savepv(individ_locales[i]); - } - else { - made_changes = TRUE; - } - } + STDIZED_SETLOCALE_LOCK; - /* If all the individual categories were ok as-is, this was a false - * alarm. We must have seen an '=' which was a legal occurrence in - * this combination locale */ - if (! made_changes) { - retval = input_locale; /* The input can be returned unchanged */ - } - else { - retval = save_to_buffer(querylocale_c(LC_ALL), buf, buf_size); - } + retval = save_to_buffer(stdized_setlocale(category, locale), + &PL_less_dicey_locale_buf, + &PL_less_dicey_locale_bufsize); - for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { - Safefree(individ_locales[i]); - } + STDIZED_SETLOCALE_UNLOCK; - return retval; - } + return retval; +} -# else /* else no LC_ALL */ +/*---------------------------------------------------------------------------*/ - PERL_UNUSED_ARG(category); - PERL_UNUSED_ARG(caller_line); +# define bool_setlocale_r(cat, locale) \ + less_dicey_bool_setlocale_r(cat, locale) -# endif +STATIC bool +S_less_dicey_bool_setlocale_r(pTHX_ const int cat, const char * locale) +{ + bool retval; - /* Here, there was a problem in an individual category. This means that at - * least one adjustment will be necessary. Create a modifiable copy */ - retval = save_to_buffer(input_locale, buf, buf_size); + PERL_ARGS_ASSERT_LESS_DICEY_BOOL_SETLOCALE_R; - if (*first_bad != '=') { + /* Unlikely, but potentially possible that another thread could zap the + * buffer from true to false or vice-versa, so need to lock here */ + POSIX_SETLOCALE_LOCK; + retval = cBOOL(posix_setlocale(cat, locale)); + POSIX_SETLOCALE_UNLOCK; - /* Translate the found position into terms of the copy */ - first_bad = retval + (first_bad - input_locale); - } - else { /* An '=' */ + return retval; +} - /* It is unlikely that the return is so screwed-up that it contains - * multiple equals signs, but handle that case by stripping all of - * them. */ - const char * final_equals = strrchr(retval, '='); +/*---------------------------------------------------------------------------*/ - /* The length passed here causes the move to include the terminating - * NUL */ - Move(final_equals + 1, retval, strlen(final_equals), char); +/* setlocale_i is only defined for Configurations where the libc setlocale() + * suffices for both querying and setting the locale. It allows for some + * shortcuts */ +# define setlocale_i(i, locale) less_dicey_setlocale_r(categories[i], locale) + +/* The code in this file may change the locale briefly during certain + * operations. This should be a critical section when that could interfere + * with other instances executing at the same time. */ +# define TOGGLE_LOCK(i) POSIX_SETLOCALE_LOCK +# define TOGGLE_UNLOCK(i) POSIX_SETLOCALE_UNLOCK + +/*===========================================================================*/ + +#elif defined(USE_POSIX_2008_LOCALE) +# ifndef LC_ALL +# error This code assumes that LC_ALL is available on a system modern enough to have POSIX 2008 +# endif - /* See if there are additional problems; if not, we're good to return. - * */ - first_bad = strpbrk(retval, "\n"); +/* Here, there is a completely different API to get thread-safe locales. We + * emulate the setlocale() API with our own function(s). setlocale categories, + * like LC_NUMERIC, are not valid here for the POSIX 2008 API. Instead, there + * are equivalents, like LC_NUMERIC_MASK, which we use instead, which we find + * by table lookup. */ - if (! first_bad) { - return retval; - } - } +# if defined(__GLIBC__) && defined(USE_LOCALE_MESSAGES) + /* https://sourceware.org/bugzilla/show_bug.cgi?id=24936 */ +# define HAS_GLIBC_LC_MESSAGES_BUG +# include +# endif - /* Here, the problem must be a \n. Get rid of it and what follows. - * (Originally, only a trailing \n was stripped. Unsure what to do if not - * trailing) */ - *((char *) first_bad) = '\0'; - return retval; -} +# define querylocale_i(i) querylocale_2008_i(i, __LINE__) -#if defined(WIN32) || ( defined(USE_POSIX_2008_LOCALE) \ - && ! defined(USE_QUERYLOCALE)) + /* We need to define this derivative macro here, as it is needed in + * the implementing function (for recursive calls). It also gets defined + * where all the other derivative macros are defined, and the compiler + * will complain if the definition gets out of sync */ +# define querylocale_c(cat) querylocale_i(cat##_INDEX_) STATIC const char * -S_find_locale_from_environment(pTHX_ const unsigned int index) +S_querylocale_2008_i(pTHX_ const locale_category_index index, + const line_t caller_line) { - /* NB: This function may actually change the locale on Windows. - * - * On Windows systems, the concept of the POSIX ordering of environment - * variables is missing. To increase portability of programs across - * platforms, the POSIX ordering is emulated on Windows. - * - * And on POSIX 2008 systems without querylocale(), it is problematic - * getting the results of the POSIX 2008 equivalent of - * setlocale(category, "") - * (which gets the locale from the environment). - * - * To ensure that we know exactly what those values are, we do the setting - * ourselves, using the documented algorithm (assuming the documentation is - * correct) rather than use "" as the locale. This will lead to results - * that differ from native behavior if the native behavior differs from the - * standard documented value, but khw believes it is better to know what's - * going on, even if different from native, than to just guess. - * - * Another option for the POSIX 2008 case would be, in a critical section, - * to save the global locale's current value, and do a straight - * setlocale(LC_ALL, ""). That would return our desired values, destroying - * the global locale's, which we would then restore. But that could cause - * races with any other thread that is using the global locale and isn't - * using the mutex. And, the only reason someone would have done that is - * because they are calling a library function, like in gtk, that calls - * setlocale(), and which can't be changed to use the mutex. That wouldn't - * be a problem if this were to be done before any threads had switched, - * say during perl construction time. But this code would still be needed - * for the general case. + PERL_ARGS_ASSERT_QUERYLOCALE_2008_I; + + /* This function returns the name of the locale category given by the input + * 'index' into our parallel tables of them. * - * The Windows and POSIX 2008 differ in that the ultimate fallback is "C" - * in POSIX, and is the system default locale in Windows. To get that - * system default value, we actually have to call setlocale() on Windows. + * POSIX 2008, for some sick reason, chose not to provide a method to find + * the category name of a locale, disregarding a basic linguistic tenet + * that for any object, people will create a name for it. (The next + * version of the POSIX standard is proposed to fix this.) Some vendors + * have created a querylocale() function to do this in the meantime. On + * systems without querylocale(), we have to keep track of what the locale + * has been set to, so that we can return its name so as to emulate + * setlocale(). There are potential problems with this: + * + * 1) We don't know what calling newlocale() with the locale argument "" + * actually does. It gets its values from the program's environment. + * find_locale_from_environment() is used to work around this. But it + * isn't fool-proof. See the comments for that function for details. + * 2) It's possible for C code in some library to change the locale + * without us knowing it, and thus our records become wrong; + * querylocale() would catch this. But as of September 2017, there + * are no occurrences in CPAN of uselocale(). Some libraries do use + * setlocale(), but that changes the global locale, and threads using + * per-thread locales will just ignore those changes. + * 3) Many systems have multiple names for the same locale. Generally, + * there is an underlying base name, with aliases that evaluate to it. + * On some systems, if you set the locale to an alias, and then + * retrieve the name, you get the alias as expected; but on others you + * get the base name, not the alias you used. And sometimes the + * charade is incomplete. See + * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269375. + * + * The code is structured so that the returned locale name when the + * locale is changed is whatever the result of querylocale() on the + * new locale is. This effectively gives the result the system + * expects. Without querylocale, the name returned is always the + * input name. Theoretically this could cause problems, but khw knows + * of none so far, but mentions it here in case you are trying to + * debug something. (This could be worked around by messing with the + * global locale temporarily, using setlocale() to get the base name; + * but that could cause a race. The comments for + * find_locale_from_environment() give details on the potential race.) */ - /* We rely on PerlEnv_getenv() returning a mortalized copy */ - const char * const lc_all = PerlEnv_getenv("LC_ALL"); + const locale_t cur_obj = uselocale((locale_t) 0); + const char * retval; - /* Use any "LC_ALL" environment variable, as it overrides everything - * else. */ - if (lc_all && strNE(lc_all, "")) { - return lc_all; + DEBUG_Lv(PerlIO_printf(Perl_debug_log, "querylocale_2008_i(%s) on %p;" + " called from %" LINE_Tf "\n", + category_names[index], cur_obj, + caller_line)); + + if (UNLIKELY(cur_obj == LC_GLOBAL_LOCALE)) { + + /* Even on platforms that have querylocale(), it is unclear if they + * work in the global locale, and we have the means to get the correct + * answer anyway. khw is unsure this situation even comes up these + * days, hence the branch prediction */ + POSIX_SETLOCALE_LOCK; + retval = mortalized_pv_copy(posix_setlocale(categories[index], NULL)); + POSIX_SETLOCALE_UNLOCK; } - /* If setting an individual category, use its corresponding value found in - * the environment, if any */ - if (index != LC_ALL_INDEX_) { - const char * const new_value = PerlEnv_getenv(category_names[index]); + /* Here we have handled the case of the current locale being the global + * one. Below is the 'else' case of that. There are two different + * implementations, depending on USE_PL_CURLOCALES */ - if (new_value && strNE(new_value, "")) { - return new_value; - } +# ifdef USE_PL_CURLOCALES + + else { - /* If no corresponding environment variable, see if LANG exists. If - * so, use it. */ - const char * default_name = PerlEnv_getenv("LANG"); - if (default_name && strNE(default_name, "")) { - return default_name; + /* PL_curlocales[] is kept up-to-date for all categories except LC_ALL, + * which may have been invalidated by setting it to NULL, and if so, + * should now be calculated. (The called function updates that + * element.) */ + if (index == LC_ALL_INDEX_ && PL_curlocales[LC_ALL_INDEX_] == NULL) { + calculate_LC_ALL_string((const char **) &PL_curlocales, + INTERNAL_FORMAT, + WANT_VOID, + caller_line); + } + + if (cur_obj == PL_C_locale_obj) { + + /* If the current locale object is the C object, then the answer is + * "C" or POSIX, regardless of the category. Handling this + * reasonably likely case specially shortcuts extra effort, and + * hides some bugs from us in OS's that alias other locales to C, + * but do so incompletely. If our records say it is POSIX, use + * that; otherwise use C. See + * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269375 */ + retval = (strEQ(PL_curlocales[index], "POSIX")) + ? "POSIX" + : "C"; + } + else { + retval = mortalized_pv_copy(PL_curlocales[index]); } + } - /* If no LANG, use "C" on POSIX 2008, the system default on Windows */ -# ifndef WIN32 - return "C"; # else - return wrap_wsetlocale(categories[index], ""); -# endif - } + /* Below is the implementation of the 'else' clause which handles the case + * of the current locale not being the global one on platforms where + * USE_PL_CURLOCALES is NOT in effect. That means the system must have + * some form of querylocale. But these have varying characteristics, so + * first create some #defines to make the actual 'else' clause uniform. + * + * First, glibc has a function that implements querylocale(), but is called + * something else, and takes the category number; the others take the mask. + * */ +# if defined(USE_QUERYLOCALE) && ( defined(_NL_LOCALE_NAME) \ + && defined(HAS_NL_LANGINFO_L)) +# define my_querylocale(index, cur_obj) \ + nl_langinfo_l(_NL_LOCALE_NAME(categories[index]), cur_obj) + + /* Experience so far shows it is thread-safe, as well as glibc's + * nl_langinfo_l(), so unless overridden, mark it so */ +# ifdef NO_THREAD_SAFE_QUERYLOCALE +# undef HAS_THREAD_SAFE_QUERYLOCALE +# else +# define HAS_THREAD_SAFE_QUERYLOCALE +# endif +# else /* below, ! glibc */ - /* Here is LC_ALL, and no LC_ALL environment variable. LANG is used as a - * default, but overridden for individual categories that have - * corresponding environment variables. If no LANG exists, the default is - * "C" on POSIX 2008, or the system default for the category on Windows. */ - const char * default_name = PerlEnv_getenv("LANG"); + /* Otherwise, use the system's querylocale(). */ +# define my_querylocale(index, cur_obj) \ + querylocale(category_masks[index], cur_obj) + + /* There is no standard for this function, and khw has never seen + * anything beyond minimal vendor documentation, lacking important + * details. Experience has shown that some implementations have race + * condiions, and their returns may not be thread safe. It would be + * unreliable to test for complete thread safety in Configure. What we + * do instead is to assume that it is thread-safe, unless overriden by, + * say, a hints file specifying + * -Accflags='-DNO_THREAD_SAFE_QUERYLOCALE */ +# ifdef NO_THREAD_SAFE_QUERYLOCALE +# undef HAS_THREAD_SAFE_QUERYLOCALE +# else +# define HAS_THREAD_SAFE_QUERYLOCALE +# endif +# endif - /* Convert "" to NULL to save conditionals in the loop below */ - if (default_name != NULL && strEQ(default_name, "")) { - default_name = NULL; - } + /* Here, we have set up enough information to know if this querylocale() + * is thread-safe, or needs to use a mutex */ +# ifdef HAS_THREAD_SAFE_QUERYLOCALE +# define QUERYLOCALE_LOCK +# define QUERYLOCALE_UNLOCK +# else +# define QUERYLOCALE_LOCK gwLOCALE_LOCK +# define QUERYLOCALE_UNLOCK gwLOCALE_UNLOCK +# endif - /* Loop through all the individual categories, setting each to any - * corresponding environment variable; or to the default if none exists for - * the category */ - const char * locale_names[LC_ALL_INDEX_]; - for (unsigned i = 0; i < LC_ALL_INDEX_; i++) { - const char * const env_override = PerlEnv_getenv(category_names[i]); + /* Finally, everything is ready, so here is the 'else' clause to implement + * the case of the current locale not being the global one on systems that + * have some form of querylocale(). (POSIX will presumably eventually + * publish their next version in their pipeline, which will define a + * precisely specified querylocale equivalent, and there can be a new + * #ifdef to use it without having to guess at its characteristics) */ - if (env_override && strNE(env_override, "")) { - locale_names[i] = env_override; - } - else if (default_name) { - locale_names[i] = default_name; + else { + /* We don't keep records when there is querylocale(), so as to avoid the + * pitfalls mentioned at the beginning of this function. + * + * That means LC_ALL has to be calculated from all its constituent + * categories each time, since the querylocale() forms on many (if not + * all) platforms only work on individual categories */ + if (index == LC_ALL_INDEX_) { + retval = calculate_LC_ALL_string(NULL, INTERNAL_FORMAT, + WANT_TEMP_PV, + caller_line); } else { -# ifndef WIN32 - locale_names[i] = "C"; -# else - locale_names[i] = wrap_wsetlocale(categories[index], ""); -# endif + QUERYLOCALE_LOCK; + retval = my_querylocale(index, cur_obj); + /* querylocale() may conflate the C locale with something that + * isn't exactly the same. See for example + * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=269375 + * We know that if the locale object is the C one, we + * are in the C locale, which may go by the name POSIX, as both, by + * definition, are equivalent. But we consider any other name + * spurious, so override with "C". As in the PL_CURLOCALES case + * above, this hides those glitches, for the most part, from the + * rest of our code. (The code is ordered this way so that if the + * system distinugishes "C" from "POSIX", we do too.) */ + if (cur_obj == PL_C_locale_obj && ! isNAME_C_OR_POSIX(retval)) { + QUERYLOCALE_UNLOCK; + retval = "C"; + } + else { + retval = savepv(retval); + QUERYLOCALE_UNLOCK; + SAVEFREEPV(retval); + } } - - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "find_locale_from_environment i=%d, name=%s, locale=%s\n", - i, category_names[i], locale_names[i])); } - return calculate_LC_ALL(locale_names); +# undef QUERYLOCALE_LOCK +# undef QUERYLOCALE_UNLOCK +# endif + + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "querylocale_2008_i(%s) returning '%s'\n", + category_names[index], retval)); + assert(strNE(retval, "")); + return retval; } -#endif -#if defined(WIN32) || defined(USE_POSIX_2008_LOCALE) || ! defined(LC_ALL) +/*---------------------------------------------------------------------------*/ -STATIC -const char * +# define bool_setlocale_i(i, locale) \ + bool_setlocale_2008_i(i, locale, __LINE__) -# ifdef USE_QUERYLOCALE -S_calculate_LC_ALL(pTHX_ const locale_t cur_obj) -# else -S_calculate_LC_ALL(pTHX_ const char ** individ_locales) +/* If this doesn't exist on this platform, make it a no-op (to save #ifdefs) */ +# ifndef update_PL_curlocales_i +# define update_PL_curlocales_i(index, new_locale, caller_line) # endif +STATIC bool +S_bool_setlocale_2008_i(pTHX_ + + /* Our internal index of the 'category' setlocale is called with */ + const locale_category_index index, + const char * new_locale, /* The locale to set the category to */ + const line_t caller_line /* Called from this line number */ + ) { - /* For POSIX 2008, we have to figure out LC_ALL ourselves when needed. - * querylocale(), on systems that have it, doesn't tend to work for LC_ALL. - * So we have to construct the answer ourselves based on the passed in - * data, which is either a locale_t object, for systems with querylocale(), - * or an array we keep updated to the proper values, otherwise. - * - * For Windows, we also may need to construct an LC_ALL when setting the - * locale to the system default. - * - * This function returns a mortalized string containing the locale name(s) - * of LC_ALL. - * - * If all individual categories are the same locale, we can just set LC_ALL - * to that locale. But if not, we have to create an aggregation of all the - * categories on the system. Platforms differ as to the syntax they use - * for these non-uniform locales for LC_ALL. Some use a '/' or other - * delimiter of the locales with a predetermined order of categories; a - * Configure probe would be needed to tell us how to decipher those. glibc - * and Windows use a series of name=value pairs, like - * LC_NUMERIC=C;LC_TIME=en_US.UTF-8;... - * This function returns that syntax, which is suitable for input to the - * Windows setlocale(). It could also be suitable for glibc, but because - * the non-Windows code is common to systems that use a different syntax, - * we don't depend on it for glibc. Instead we take care not to use the - * native setlocale() function on whatever non-Windows style is chosen. - * But, it would be possible for someone to call Perl_setlocale() using a - * native style we don't understand. So far no one has complained. + PERL_ARGS_ASSERT_BOOL_SETLOCALE_2008_I; + + /* This function effectively performs a setlocale() on just the current + * thread; thus it is thread-safe. It does this by using the POSIX 2008 + * locale functions to emulate the behavior of setlocale(). Similar to + * regular setlocale(), the return from this function points to memory that + * can be overwritten by other system calls, so needs to be copied + * immediately if you need to retain it. The difference here is that + * system calls besides another setlocale() can overwrite it. * - * For systems that have categories we don't know about, the algorithm - * below won't know about those missing categories, leading to potential - * bugs for code that looks at them. If there is an environment variable - * that sets that category, we won't know to look for it, and so our use of - * LANG or "C" improperly overrides it. On the other hand, if we don't do - * what is done here, and there is no environment variable, the category's - * locale should be set to LANG or "C". So there is no good solution. khw - * thinks the best is to make sure we have a complete list of possible - * categories, adding new ones as they show up on obscure platforms. + * By doing this, most locale-sensitive functions become thread-safe. The + * exceptions are mostly those that return a pointer to static memory. */ - unsigned int i; - Size_t names_len = 0; - bool are_all_categories_the_same_locale = TRUE; - char * aggregate_locale; - char * previous_start = NULL; - char * this_start = NULL; - Size_t entry_len = 0; - - PERL_ARGS_ASSERT_CALCULATE_LC_ALL; - - /* First calculate the needed size for the string listing the categories - * and their locales. */ - for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { + int mask = category_masks[index]; + const locale_t entry_obj = uselocale((locale_t) 0); + const char * locale_on_entry = querylocale_i(index); -# ifdef USE_QUERYLOCALE - const char * entry = querylocale_l(i, cur_obj); -# else - const char * entry = individ_locales[i]; -# endif + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "bool_setlocale_2008_i: input=%d (%s), mask=0x%x," + " new locale=\"%s\", current locale=\"%s\"," + " index=%d, entry object=%p;" + " called from %" LINE_Tf "\n", + categories[index], category_names[index], mask, + ((new_locale == NULL) ? "(nil)" : new_locale), + locale_on_entry, index, entry_obj, caller_line)); - names_len += strlen(category_names[i]) - + 1 /* '=' */ - + strlen(entry) - + 1; /* ';' */ + /* Here, trying to change the locale, but it is a no-op if the new boss is + * the same as the old boss. Except this routine is called when converting + * from the global locale, so in that case we will create a per-thread + * locale below (with the current values). It also seemed that newlocale() + * could free up the basis locale memory if we called it with the new and + * old being the same, but khw now thinks that this was due to some other + * bug, since fixed, as there are other places where newlocale() gets + * similarly called without problems. */ + if ( entry_obj != LC_GLOBAL_LOCALE + && locale_on_entry + && strEQ(new_locale, locale_on_entry)) + { + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "bool_setlocale_2008_i: no-op to change to" + " what it already was\n")); + return true; } - names_len++; /* Trailing '\0' */ +# ifndef USE_QUERYLOCALE - /* Allocate enough space for the aggregated string */ - Newxz(aggregate_locale, names_len, char); - SAVEFREEPV(aggregate_locale); + /* Without a querylocale() mechanism, we have to figure out ourselves what + * happens with setting a locale to "" */ - /* Then fill it in */ - for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { - Size_t new_len; + if (strEQ(new_locale, "")) { + new_locale = find_locale_from_environment(index); + if (! new_locale) { + SET_EINVAL; + return false; + } + } -# ifdef USE_QUERYLOCALE - const char * entry = querylocale_l(i, cur_obj); -# else - const char * entry = individ_locales[i]; # endif +# ifdef NEWLOCALE_HANDLES_DISPARATE_LC_ALL - new_len = my_strlcat(aggregate_locale, category_names[i], names_len); - assert(new_len <= names_len); - new_len = my_strlcat(aggregate_locale, "=", names_len); - assert(new_len <= names_len); + const bool need_loop = false; - this_start = aggregate_locale + strlen(aggregate_locale); - entry_len = strlen(entry); +# else - new_len = my_strlcat(aggregate_locale, entry, names_len); - assert(new_len <= names_len); - new_len = my_strlcat(aggregate_locale, ";", names_len); - assert(new_len <= names_len); - PERL_UNUSED_VAR(new_len); /* Only used in DEBUGGING */ + bool need_loop = false; + const char * new_locales[LC_ALL_INDEX_] = { NULL }; - if ( i > 0 - && are_all_categories_the_same_locale - && memNE(previous_start, this_start, entry_len + 1)) + /* If we're going to have to parse the LC_ALL string, might as well do it + * now before we have made changes that we would have to back out of if the + * parse fails */ + if (index == LC_ALL_INDEX_) { + switch (parse_LC_ALL_string(new_locale, + (const char **) &new_locales, + override_if_ignored, + false, /* Return only [0] if suffices */ + false, /* Don't panic on error */ + caller_line)) { - are_all_categories_the_same_locale = FALSE; - } - else { - previous_start = this_start; - } - } + case invalid: + SET_EINVAL; + return false; - /* If they are all the same, just return any one of them */ - if (are_all_categories_the_same_locale) { - aggregate_locale = this_start; - aggregate_locale[entry_len] = '\0'; - } + case no_array: + need_loop = false; + break; - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "calculate_LC_ALL returning '%s'\n", - aggregate_locale)); + case only_element_0: + SAVEFREEPV(new_locales[0]); + new_locale = new_locales[0]; + need_loop = false; + break; - return aggregate_locale; -} + case full_array: + need_loop = true; + break; + } + } -#endif -#if defined(USE_LOCALE) && ( defined(DEBUGGING) \ - || defined(USE_PERL_SWITCH_LOCALE_CONTEXT)) +# endif +# ifdef HAS_GLIBC_LC_MESSAGES_BUG -STATIC const char * -S_get_LC_ALL_display(pTHX) -{ + /* For this bug, if the LC_MESSAGES locale changes, we have to do an + * expensive workaround. Save the current value so we can later determine + * if it changed. */ + const char * old_messages_locale = NULL; + if ( (index == LC_MESSAGES_INDEX_ || index == LC_ALL_INDEX_) + && LIKELY(PL_phase != PERL_PHASE_CONSTRUCT)) + { + old_messages_locale = querylocale_c(LC_MESSAGES); + } -# ifdef LC_ALL +# endif - return querylocale_c(LC_ALL); + assert(PL_C_locale_obj); -# else + /* Now ready to switch to the input 'new_locale' */ - const char * curlocales[NOMINAL_LC_ALL_INDEX]; + /* Switching locales generally entails freeing the current one's space (at + * the C library's discretion), hence we can't be using that locale at the + * time of the switch (this wasn't obvious to khw from the man pages). So + * switch to a known locale object that we don't otherwise mess with. */ + if (! uselocale(PL_C_locale_obj)) { - for (unsigned i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { - curlocales[i] = querylocale_i(i); + /* Not being able to change to the C locale is severe; don't keep + * going. */ + setlocale_failure_panic_i(index, locale_on_entry, "C", + __LINE__, caller_line); + NOT_REACHED; /* NOTREACHED */ } - return calculate_LC_ALL(curlocales); - -# endif - -} + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "bool_setlocale_2008_i: now using C" + " object=%p\n", PL_C_locale_obj)); -#endif + /* These two objects are special: + * LC_GLOBAL_LOCALE because it is undefined behavior to call + * newlocale() with it as a parameter. + * PL_C_locale_obj because newlocale() generally destroys its locale + * object parameter when it succeeds; and we don't + * want that happening to this immutable object. + * Copies will be made for them to use instead if we get so far as to call + * newlocale(). */ + bool entry_obj_is_special = ( entry_obj == LC_GLOBAL_LOCALE + || entry_obj == PL_C_locale_obj); + locale_t new_obj; -STATIC void -S_setlocale_failure_panic_i(pTHX_ - const unsigned int cat_index, - const char * current, - const char * failed, - const line_t caller_0_line, - const line_t caller_1_line) -{ - dSAVE_ERRNO; - const int cat = categories[cat_index]; - const char * name = category_names[cat_index]; + /* PL_C_locale_obj is LC_ALL set to the C locale. If this call is to + * switch to LC_ALL => C, simply use that object. But in fact, we already + * have switched to it just above, in preparation for the general case. + * Since we're already there, no need to do further switching. */ + if (mask == LC_ALL_MASK && isNAME_C_OR_POSIX(new_locale)) { + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "bool_setlocale_2008_i: will stay in C" + " object\n")); + new_obj = PL_C_locale_obj; - PERL_ARGS_ASSERT_SETLOCALE_FAILURE_PANIC_I; + /* 'entry_obj' is now dangling, of no further use to anyone (unless it + * is one of the special ones). Free it to avoid a leak */ + if (! entry_obj_is_special) { + freelocale(entry_obj); + } - if (current == NULL) { - current = querylocale_i(cat_index); + update_PL_curlocales_i(index, new_locale, caller_line); } + else { /* Here is the general case, not to LC_ALL => C */ - Perl_locale_panic(Perl_form(aTHX_ "(%" LINE_Tf - "): Can't change locale for %s(%d)" - " from '%s' to '%s'", - caller_1_line, name, cat, - current, failed), - __FILE__, caller_0_line, GET_ERRNO); - NOT_REACHED; /* NOTREACHED */ -} - -/* Any of these will allow us to find the RADIX */ -# if defined(USE_LOCALE_NUMERIC) && ( defined(HAS_SOME_LANGINFO) \ - || defined(HAS_LOCALECONV) \ - || defined(HAS_SNPRINTF)) -# define CAN_CALCULATE_RADIX -# endif -# ifdef USE_LOCALE_NUMERIC + /* The newlocale() call(s) below take a basis object to build upon to + * create the changed locale, trashing it iff successful. + * + * For the objects that are not to be modified by this function, we + * create a duplicate that gets trashed instead. + * + * Also if we will have to loop doing multiple newlocale()s, there is a + * chance we will succeed for the first few, and then fail, having to + * back out. We need to duplicate 'entry_obj' in this case as well, so + * it remains valid as something to back out to. */ + locale_t basis_obj = entry_obj; -STATIC void -S_new_numeric(pTHX_ const char *newnum, bool force) -{ - PERL_ARGS_ASSERT_NEW_NUMERIC; + if (entry_obj_is_special || need_loop) { + basis_obj = duplocale(basis_obj); + if (! basis_obj) { + locale_panic_via_("duplocale failed", __FILE__, caller_line); + NOT_REACHED; /* NOTREACHED */ + } - /* Called after each libc setlocale() call affecting LC_NUMERIC, to tell - * core Perl this and that 'newnum' is the name of the new locale, and we - * are switched into it. It installs this locale as the current underlying - * default, and then switches to the C locale, if necessary, so that the - * code that has traditionally expected the radix character to be a dot may - * continue to do so. - * - * The default locale and the C locale can be toggled between by use of the - * set_numeric_underlying() and set_numeric_standard() functions, which - * should probably not be called directly, but only via macros like - * SET_NUMERIC_STANDARD() in perl.h. - * - * The toggling is necessary mainly so that a non-dot radix decimal point - * character can be input and output, while allowing internal calculations - * to use a dot. - * - * This sets several interpreter-level variables: - * PL_numeric_name The underlying locale's name: a copy of 'newnum' - * PL_numeric_underlying A boolean indicating if the toggled state is such - * that the current locale is the program's underlying - * locale - * PL_numeric_standard An int indicating if the toggled state is such - * that the current locale is the C locale or - * indistinguishable from the C locale. If non-zero, it - * is in C; if > 1, it means it may not be toggled away - * from C. - * PL_numeric_underlying_is_standard A bool kept by this function - * indicating that the underlying locale and the standard - * C locale are indistinguishable for the purposes of - * LC_NUMERIC. This happens when both of the above two - * variables are true at the same time. (Toggling is a - * no-op under these circumstances.) This variable is - * used to avoid having to recalculate. - * PL_numeric_radix_sv Contains the string that code should use for the - * decimal point. It is set to either a dot or the - * program's underlying locale's radix character string, - * depending on the situation. - * PL_underlying_radix_sv Contains the program's underlying locale's radix - * character string. This is copied into - * PL_numeric_radix_sv when the situation warrants. It - * exists to avoid having to recalculate it when toggling. - * PL_underlying_numeric_obj = (only on POSIX 2008 platforms) An object - * with everything set up properly so as to avoid work on - * such platforms. - */ + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "bool_setlocale_2008_i created %p by" + " duping the input\n", basis_obj)); + } - DEBUG_L( PerlIO_printf(Perl_debug_log, - "Called new_numeric with %s, PL_numeric_name=%s\n", - newnum, PL_numeric_name)); +# define DEBUG_NEW_OBJECT_CREATED(category, locale, new, old, caller_line) \ + DEBUG_Lv(PerlIO_printf(Perl_debug_log, \ + "bool_setlocale_2008_i(%s, %s): created %p" \ + " while freeing %p; called from %" LINE_Tf \ + " via %" LINE_Tf "\n", \ + category, locale, new, old, \ + caller_line, (line_t)__LINE__)) +# define DEBUG_NEW_OBJECT_FAILED(category, locale, basis_obj) \ + DEBUG_L(PerlIO_printf(Perl_debug_log, \ + "bool_setlocale_2008_i: creating new object" \ + " for (%s '%s') from %p failed; called from %" \ + LINE_Tf " via %" LINE_Tf "\n", \ + category, locale, basis_obj, \ + caller_line, (line_t)__LINE__)); - /* If not forcing this procedure, and there isn't actually a change from - * our records, do nothing. (Our records can be wrong when sync'ing to the - * locale set up by an external library, hence the 'force' parameter) */ - if (! force && strEQ(PL_numeric_name, newnum)) { - return; - } + /* Ready to create a new locale by modification of the existing one. + * + * NOTE: This code may incorrectly show up as a leak under the address + * sanitizer. We do not free this object under normal teardown, however + * you can set PERL_DESTRUCT_LEVEL=2 to cause it to be freed. + */ - Safefree(PL_numeric_name); - PL_numeric_name = savepv(newnum); +# ifdef NEWLOCALE_HANDLES_DISPARATE_LC_ALL - /* Handle the trivial case. Since this is called at process - * initialization, be aware that this bit can't rely on much being - * available. */ - if (isNAME_C_OR_POSIX(PL_numeric_name)) { - PL_numeric_standard = TRUE; - PL_numeric_underlying_is_standard = TRUE; - PL_numeric_underlying = TRUE; - sv_setpv(PL_numeric_radix_sv, C_decimal_point); - sv_setpv(PL_underlying_radix_sv, C_decimal_point); - return; - } + /* Some platforms have a newlocale() that can handle disparate LC_ALL + * input, so on these a single call to newlocale() always works */ +# else - /* We are in the underlying locale until changed at the end of this - * function */ - PL_numeric_underlying = TRUE; + /* If a single call to newlocale() will do */ + if (! need_loop) -# ifdef USE_POSIX_2008_LOCALE +# endif - /* We keep a special object for easy switching to. - * - * NOTE: This code may incorrectly show up as a leak under the address - * sanitizer. We do not free this object under normal teardown, however - * you can set PERL_DESTRUCT_LEVEL=2 to cause it to be freed. - */ - PL_underlying_numeric_obj = newlocale(LC_NUMERIC_MASK, - PL_numeric_name, - PL_underlying_numeric_obj); + { + new_obj = newlocale(mask, + override_ignored_category(index, new_locale), + basis_obj); + if (! new_obj) { + DEBUG_NEW_OBJECT_FAILED(category_names[index], new_locale, + basis_obj); -# endif + /* Since the call failed, it didn't trash 'basis_obj', which is + * a dup for these objects, and hence would leak if we don't + * free it. XXX However, something is seriously wrong if we + * can't switch to C or the global locale, so maybe should + * panic instead */ + if (entry_obj_is_special) { + freelocale(basis_obj); + } - const char * radix = NULL; - utf8ness_t utf8ness = UTF8NESS_IMMATERIAL; + goto must_restore_state; + } - /* Find and save this locale's radix character. */ - my_langinfo_c(RADIXCHAR, LC_NUMERIC, PL_numeric_name, - &radix, NULL, &utf8ness); - sv_setpv(PL_underlying_radix_sv, radix); + DEBUG_NEW_OBJECT_CREATED(category_names[index], new_locale, + new_obj, basis_obj, caller_line); - if (utf8ness == UTF8NESS_YES) { - SvUTF8_on(PL_underlying_radix_sv); - } + update_PL_curlocales_i(index, new_locale, caller_line); + } - DEBUG_L(PerlIO_printf(Perl_debug_log, - "Locale radix is '%s', ?UTF-8=%d\n", - SvPVX(PL_underlying_radix_sv), - cBOOL(SvUTF8(PL_underlying_radix_sv)))); +# ifndef NEWLOCALE_HANDLES_DISPARATE_LC_ALL - /* This locale is indistinguishable from C (for numeric purposes) if both - * the radix character and the thousands separator are the same as C's. - * Start with the radix. */ - PL_numeric_underlying_is_standard = strEQ(C_decimal_point, radix); - Safefree(radix); + else { /* Need multiple newlocale() calls */ -# ifndef TS_W32_BROKEN_LOCALECONV + /* Loop through the individual categories, setting the locale of + * each to the corresponding name previously populated into + * newlocales[]. Each iteration builds on the previous one, adding + * its category to what's already been calculated, and taking as a + * basis for what's been calculated 'basis_obj', which is updated + * each iteration to be the result of the previous one. Upon + * success, newlocale() trashes the 'basis_obj' parameter to it. + * If any iteration fails, we immediately give up, restore the + * locale to what it was at the time this function was called + * (saved in 'entry_obj'), and return failure. */ - /* If the radix isn't the same as C's, we know it is distinguishable from - * C; otherwise check the thousands separator too. Only if both are the - * same as C's is the locale indistinguishable from C. - * - * But on earlier Windows versions, there is a potential race. This code - * knows that localeconv() (elsewhere in this file) will be used to extract - * the needed value, and localeconv() was buggy for quite a while, and that - * code in this file hence uses a workaround. And that workaround may have - * an (unlikely) race. Gathering the radix uses a different workaround on - * Windows that doesn't involve a race. It might be possible to do the - * same for this (patches welcome). - * - * Until then khw doesn't think it's worth even the small risk of a race to - * get this value, which doesn't appear to be used in any of the Microsoft - * library routines anyway. */ + /* Loop, using the previous iteration's result as the basis for the + * next one. (The first time we effectively use the locale in + * force upon entry to this function.) */ + for_all_individual_category_indexes(i) { + new_obj = newlocale(category_masks[i], + new_locales[i], + basis_obj); + if (new_obj) { + DEBUG_NEW_OBJECT_CREATED(category_names[i], + new_locales[i], + new_obj, basis_obj, + caller_line); + basis_obj = new_obj; + continue; + } - const char * scratch_buffer = NULL; - if (PL_numeric_underlying_is_standard) { - PL_numeric_underlying_is_standard = strEQ(C_thousands_sep, - my_langinfo_c(THOUSEP, LC_NUMERIC, - PL_numeric_name, - &scratch_buffer, - NULL, NULL)); - } - Safefree(scratch_buffer); + /* Failed. Likely this is because the proposed new locale + * isn't valid on this system. */ -# else - PERL_UNUSED_VAR(C_thousands_sep); -# endif + DEBUG_NEW_OBJECT_FAILED(category_names[i], + new_locales[i], + basis_obj); - PL_numeric_standard = PL_numeric_underlying_is_standard; + /* newlocale() didn't trash this, since the function call + * failed */ + freelocale(basis_obj); - /* Keep LC_NUMERIC so that it has the C locale radix and thousands - * separator. This is for XS modules, so they don't have to worry about - * the radix being a non-dot. (Core operations that need the underlying - * locale change to it temporarily). */ - if (! PL_numeric_standard) { - set_numeric_standard(); - } + for_all_individual_category_indexes(j) { + Safefree(new_locales[j]); + } -} + goto must_restore_state; + } -# endif + /* Success for all categories. */ + for_all_individual_category_indexes(i) { + update_PL_curlocales_i(i, new_locales[i], caller_line); + Safefree(new_locales[i]); + } -void -Perl_set_numeric_standard(pTHX) -{ + /* We dup'd entry_obj in case we had to fall back to it. The + * newlocale() above destroyed the dup when it first succeeded, but + * entry_obj itself is left dangling, so free it */ + if (! entry_obj_is_special) { + freelocale(entry_obj); + } + } -# ifdef USE_LOCALE_NUMERIC +# endif /* End of newlocale can't handle disparate LC_ALL input */ - /* Unconditionally toggle the LC_NUMERIC locale to the C locale - * - * Most code should use the macro SET_NUMERIC_STANDARD() in perl.h - * instead of calling this directly. The macro avoids calling this routine - * if toggling isn't necessary according to our records (which could be - * wrong if some XS code has changed the locale behind our back) */ + } - DEBUG_L(PerlIO_printf(Perl_debug_log, - "Setting LC_NUMERIC locale to standard C\n")); +# undef DEBUG_NEW_OBJECT_CREATED +# undef DEBUG_NEW_OBJECT_FAILED - void_setlocale_c(LC_NUMERIC, "C"); - PL_numeric_standard = TRUE; - sv_setpv(PL_numeric_radix_sv, C_decimal_point); + /* Here, successfully created an object representing the desired locale; + * now switch into it */ + if (! uselocale(new_obj)) { + freelocale(new_obj); + locale_panic_(Perl_form(aTHX_ "(called from %" LINE_Tf "):" + " bool_setlocale_2008_i: switching" + " into new locale failed", + caller_line)); + } - PL_numeric_underlying = PL_numeric_underlying_is_standard; + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "bool_setlocale_2008_i: now using %p\n", new_obj)); -# endif /* USE_LOCALE_NUMERIC */ +# ifdef MULTIPLICITY /* Unlikely, but POSIX 2008 functions could be + Configured to be used on unthreaded perls, in which + case this object doesn't exist */ -} + if (DEBUG_Lv_TEST) { + if (PL_cur_locale_obj != new_obj) { + PerlIO_printf(Perl_debug_log, + "bool_setlocale_2008_i: PL_cur_locale_obj" + " was %p, now is %p\n", + PL_cur_locale_obj, new_obj); + } + } -void -Perl_set_numeric_underlying(pTHX) -{ + /* Update the current object */ + PL_cur_locale_obj = new_obj; -# ifdef USE_LOCALE_NUMERIC +# endif +# ifdef HAS_GLIBC_LC_MESSAGES_BUG - /* Unconditionally toggle the LC_NUMERIC locale to the current underlying - * default. - * - * Most code should use the macro SET_NUMERIC_UNDERLYING() in perl.h - * instead of calling this directly. The macro avoids calling this routine - * if toggling isn't necessary according to our records (which could be - * wrong if some XS code has changed the locale behind our back) */ + /* Invalidate the glibc cache of loaded translations if the locale has + * changed, see [perl #134264] and + * https://sourceware.org/bugzilla/show_bug.cgi?id=24936 */ + if (old_messages_locale) { + if (strNE(old_messages_locale, querylocale_c(LC_MESSAGES))) { + textdomain(textdomain(NULL)); + } + } - DEBUG_L(PerlIO_printf(Perl_debug_log, "Setting LC_NUMERIC locale to %s\n", - PL_numeric_name)); +# endif - void_setlocale_c(LC_NUMERIC, PL_numeric_name); - PL_numeric_underlying = TRUE; - sv_setsv_nomg(PL_numeric_radix_sv, PL_underlying_radix_sv); + return true; - PL_numeric_standard = PL_numeric_underlying_is_standard; + must_restore_state: -# endif /* USE_LOCALE_NUMERIC */ + /* We earlier switched to the LC_ALL => C locale in anticipation of it + * succeeding, Now have to switch back to the state upon entry. */ + if (! uselocale(entry_obj)) { + setlocale_failure_panic_i(index, "switching back to", + locale_on_entry, __LINE__, caller_line); + } + return false; } -# ifdef USE_LOCALE_CTYPE - -STATIC void -S_new_ctype(pTHX_ const char *newctype, bool force) -{ - PERL_ARGS_ASSERT_NEW_CTYPE; - PERL_UNUSED_ARG(force); +/*===========================================================================*/ - /* Called after each libc setlocale() call affecting LC_CTYPE, to tell - * core Perl this and that 'newctype' is the name of the new locale. - * - * This function sets up the folding arrays for all 256 bytes, assuming - * that tofold() is tolc() since fold case is not a concept in POSIX, - */ +#else +# error Unexpected Configuration +#endif /* End of the various implementations of the setlocale and + querylocale macros used in the remainder of this program */ - DEBUG_L(PerlIO_printf(Perl_debug_log, "Entering new_ctype(%s)\n", newctype)); +/*===========================================================================*/ - /* No change means no-op */ - if (strEQ(PL_ctype_name, newctype)) { - return; - } +/* Each implementation above is based on two fundamental macros #defined above: + * 1) either a querylocale_r or a querylocale_i + * 2) either a bool_setlocale_r or a bool_setlocale_i + * + * (Which one of each got #defined is based on which is most efficient in + * interacting with the underlying libc functions called.) + * + * To complete the implementation, macros for the missing two suffixes must be + * #defined, as well as all the void_setlocale_X() forms. These all can be + * mechanically derived from the fundamental ones. */ + +#ifdef querylocale_r +# define querylocale_c(cat) querylocale_r(cat) +# define querylocale_i(i) querylocale_r(categories[i]) +#elif defined(querylocale_i) +# define querylocale_c(cat) querylocale_i(cat##_INDEX_) +# define querylocale_r(cat) querylocale_i(get_category_index(cat)) +#else +# error No querylocale() form defined +#endif - /* We will replace any bad locale warning with 1) nothing if the new one is - * ok; or 2) a new warning for the bad new locale */ - if (PL_warn_locale) { - SvREFCNT_dec_NN(PL_warn_locale); - PL_warn_locale = NULL; - } +#ifdef bool_setlocale_r +# define bool_setlocale_i(i, l) bool_setlocale_r(categories[i], l) +# define bool_setlocale_c(cat, l) bool_setlocale_r(cat, l) + +# define void_setlocale_r_with_caller(cat, locale, file, line) \ + STMT_START { \ + if (! bool_setlocale_r(cat, locale)) \ + setlocale_failure_panic_via_i(get_category_index(cat), \ + NULL, locale, __LINE__, 0, \ + file, line); \ + } STMT_END - /* Clear cache */ - Safefree(PL_ctype_name); - PL_ctype_name = ""; +# define void_setlocale_c_with_caller(cat, locale, file, line) \ + void_setlocale_r_with_caller(cat, locale, file, line) - PL_in_utf8_turkic_locale = FALSE; +# define void_setlocale_i_with_caller(i, locale, file, line) \ + void_setlocale_r_with_caller(categories[i], locale, file, line) - /* For the C locale, just use the standard folds, and we know there are no - * glitches possible, so return early. Since this is called at process - * initialization, be aware that this bit can't rely on much being - * available. */ - if (isNAME_C_OR_POSIX(newctype)) { - Copy(PL_fold, PL_fold_locale, 256, U8); - PL_ctype_name = savepv(newctype); - PL_in_utf8_CTYPE_locale = FALSE; - return; - } +# define void_setlocale_r(cat, locale) \ + void_setlocale_r_with_caller(cat, locale, __FILE__, __LINE__) +# define void_setlocale_c(cat, locale) \ + void_setlocale_r(cat, locale) +# define void_setlocale_i(i, locale) \ + void_setlocale_r(categories[i], locale) - /* The cache being cleared signals this function to compute a new value */ - PL_in_utf8_CTYPE_locale = is_locale_utf8(newctype); +#elif defined(bool_setlocale_i) +# define bool_setlocale_c(cat, loc) bool_setlocale_i(cat##_INDEX_, loc) +# define bool_setlocale_r(c, loc) bool_setlocale_i(get_category_index(c), l) + +# define void_setlocale_i_with_caller(i, locale, file, line) \ + STMT_START { \ + if (! bool_setlocale_i(i, locale)) \ + setlocale_failure_panic_via_i(i, NULL, locale, __LINE__, 0, \ + file, line); \ + } STMT_END + +# define void_setlocale_r_with_caller(cat, locale, file, line) \ + void_setlocale_i_with_caller(get_category_index(cat), locale, \ + file, line) - PL_ctype_name = savepv(newctype); - bool maybe_utf8_turkic = FALSE; +# define void_setlocale_c_with_caller(cat, locale, file, line) \ + void_setlocale_i_with_caller(cat##_INDEX_, locale, file, line) - /* Don't check for problems if we are suppressing the warnings */ - bool check_for_problems = ckWARN_d(WARN_LOCALE) || UNLIKELY(DEBUG_L_TEST); +# define void_setlocale_i(i, locale) \ + void_setlocale_i_with_caller(i, locale, __FILE__, __LINE__) +# define void_setlocale_c(cat, locale) \ + void_setlocale_i(cat##_INDEX_, locale) +# define void_setlocale_r(cat, locale) \ + void_setlocale_i(get_category_index(cat), locale) - if (PL_in_utf8_CTYPE_locale) { +#else +# error No bool_setlocale() form defined +#endif - /* A UTF-8 locale gets standard rules. But note that code still has to - * handle this specially because of the three problematic code points - * */ - Copy(PL_fold_latin1, PL_fold_locale, 256, U8); +/*===========================================================================*/ - /* UTF-8 locales can have special handling for 'I' and 'i' if they are - * Turkic. Make sure these two are the only anomalies. (We don't - * require towupper and towlower because they aren't in C89.) */ +/* Most of the cases in this file just toggle the locale briefly; but there are + * a few instances where a longer toggled interval, over multiple operations, + * is desirable, since toggling and untoggling have a cost. But on platforms + * where toggling must be done in a critical section, it is even more desirable + * to minimize the length of time in an uninterruptable state. + * + * The macros below try to balance these competing interests. When the + * toggling is to be brief, simply use the plain "toggle_locale" macros. But + * in addition, in the places where an over-arching toggle would be nice, add + * calls to the macros below that have the "_locking" suffix. These are no-ops + * except on systems where the toggling doesn't force a critical section. But + * otherwise these toggle to the over-arching locale. When the individual + * toggles are executed, they will check and find that the locale is already in + * the right state, and return without doing anything. */ +#if TOGGLING_LOCKS +# define toggle_locale_c_unless_locking(cat, locale) NULL +# define toggle_locale_c_if_locking( cat, locale) \ + toggle_locale_i(cat##_INDEX_, locale) + +# define restore_toggled_locale_c_unless_locking(cat, locale) \ + PERL_UNUSED_ARG(locale) +# define restore_toggled_locale_c_if_locking( cat, locale) \ + restore_toggled_locale_i( cat##_INDEX_, locale) +#else +# define toggle_locale_c_unless_locking(cat, locale) \ + toggle_locale_i(cat##_INDEX_, locale) +# define toggle_locale_c_if_locking( cat, locale) NULL + +# define restore_toggled_locale_c_unless_locking(cat, locale) \ + restore_toggled_locale_i(cat##_INDEX_, locale) +# define restore_toggled_locale_c_if_locking( cat, locale) \ + PERL_UNUSED_ARG(locale) +#endif + +/* query_nominal_locale_i() is used when the caller needs the locale that an + * external caller would be expecting, and not what we're secretly using + * behind the scenes. It deliberately doesn't handle LC_ALL; use + * calculate_LC_ALL_string() for that. */ +#ifdef USE_LOCALE_NUMERIC +# define query_nominal_locale_i(i) \ + (__ASSERT_(i != LC_ALL_INDEX_) \ + ((i == LC_NUMERIC_INDEX_) ? PL_numeric_name : querylocale_i(i))) +#elif defined(USE_LOCALE) +# define query_nominal_locale_i(i) \ + (__ASSERT_(i != LC_ALL_INDEX_) querylocale_i(i)) +#else +# define query_nominal_locale_i(i) "C" +#endif -# if defined(HAS_TOWUPPER) && defined (HAS_TOWLOWER) +#ifdef USE_PL_CURLOCALES - if (towupper('i') == 0x130 && towlower('I') == 0x131) +STATIC void +S_update_PL_curlocales_i(pTHX_ + const locale_category_index index, + const char * new_locale, + const line_t caller_line) +{ + /* Update PL_curlocales[], which is parallel to the other ones indexed by + * our mapping of libc category number to our internal equivalents. */ -# else + PERL_ARGS_ASSERT_UPDATE_PL_CURLOCALES_I; - if (toU8_UPPER_LC('i') == 'i' && toU8_LOWER_LC('I') == 'I') + if (index == LC_ALL_INDEX_) { -# endif + /* For LC_ALL, we change all individual categories to correspond, + * including the LC_ALL element */ + for (unsigned int i = 0; i <= LC_ALL_INDEX_; i++) { + Safefree(PL_curlocales[i]); + PL_curlocales[i] = NULL; + } + switch (parse_LC_ALL_string(new_locale, + (const char **) &PL_curlocales, + check_that_overridden, /* things should + have already + been overridden + */ + true, /* Always fill array */ + true, /* Panic if fails, as to get here + it earlier had to have succeeded + */ + caller_line)) { - /* This is how we determine it really is Turkic */ - check_for_problems = TRUE; - maybe_utf8_turkic = TRUE; - } + case invalid: + case no_array: + case only_element_0: + locale_panic_via_("Unexpected return from parse_LC_ALL_string", + __FILE__, caller_line); + + case full_array: + /* parse_LC_ALL_string() has already filled PL_curlocales properly, + * except for the LC_ALL element, which should be set to + * 'new_locale'. */ + PL_curlocales[LC_ALL_INDEX_] = savepv(new_locale); + } + } + else { /* Not LC_ALL */ + + /* Update the single category's record */ + Safefree(PL_curlocales[index]); + PL_curlocales[index] = savepv(new_locale); + + /* Invalidate LC_ALL */ + Safefree(PL_curlocales[LC_ALL_INDEX_]); + PL_curlocales[LC_ALL_INDEX_] = NULL; } - else { /* Not a canned locale we know the values for. Compute them */ +} -# ifdef DEBUGGING +# endif /* Need PL_curlocales[] */ - bool has_non_ascii_fold = FALSE; - bool found_unexpected = FALSE; +/*===========================================================================*/ - /* Under -DLv, see if there are any folds outside the ASCII range. - * This factoid is used below */ - if (DEBUG_Lv_TEST) { - for (unsigned i = 128; i < 256; i++) { - int j = LATIN1_TO_NATIVE(i); - if (toU8_LOWER_LC(j) != j || toU8_UPPER_LC(j) != j) { - has_non_ascii_fold = TRUE; - break; - } +#if defined(USE_LOCALE) + +/* This paradigm is needed in several places in the function below. We have to + * substitute the nominal locale for LC_NUMERIC when returning a value for + * external consumption */ +# ifndef USE_LOCALE_NUMERIC +# define ENTRY(i, array, format) array[i] +# else +# define ENTRY(i, array, format) \ + (UNLIKELY( format == EXTERNAL_FORMAT_FOR_QUERY \ + && i == LC_NUMERIC_INDEX_) \ + ? PL_numeric_name \ + : array[i]) +# endif + +STATIC +const char * +S_calculate_LC_ALL_string(pTHX_ const char ** category_locales_list, + const calc_LC_ALL_format format, + const calc_LC_ALL_return returning, + const line_t caller_line) +{ + PERL_ARGS_ASSERT_CALCULATE_LC_ALL_STRING; + + /* NOTE: On Configurations that have PL_curlocales[], this function has the + * side effect of updating the LC_ALL_INDEX_ element with its result. + * + * This function calculates a string that defines the locale(s) LC_ALL is + * set to, in either: + * 1) Our internal format if 'format' is set to INTERNAL_FORMAT. + * 2) The external format returned by Perl_setlocale() if 'format' is set + * to EXTERNAL_FORMAT_FOR_QUERY or EXTERNAL_FORMAT_FOR_SET. + * + * These two are distinguished by: + * a) EXTERNAL_FORMAT_FOR_SET returns the actual locale currently in + * effect. + * b) EXTERNAL_FORMAT_FOR_QUERY returns the nominal locale. + * Currently this can differ only from the actual locale in the + * LC_NUMERIC category when it is set to a locale whose radix is + * not a dot. (The actual locale is kept as a dot to accommodate + * the large corpus of XS code that expects it to be that; + * switched to a non-dot temporarily during certain operations + * that require the actual radix.) + * + * In both 1) and 2), LC_ALL's values are passed to this function by + * 'category_locales_list' which is either: + * 1) a pointer to an array of strings with up-to-date values of all the + * individual categories; or + * 2) NULL, to indicate to use querylocale_i() to get each individual + * value. + * + * The caller sets 'returning' to + * WANT_TEMP_PV the function returns the calculated string + * as a mortalized temporary, so the caller + * doesn't have to worry about it being + * per-thread, nor needs to arrange for its + * clean-up. + * WANT_PL_setlocale_buf the function stores the calculated string + * into the per-thread buffer PL_setlocale_buf + * and returns a pointer to that. The buffer + * is cleaned up automatically in process + * destruction. This return method avoids + * extra copies in some circumstances. + * WANT_VOID NULL is returned. This is used when the + * function is being called only for its side + * effect of updating + * PL_curlocales[LC_ALL_INDEX_] + * + * querylocale(), on systems that have it, doesn't tend to work for LC_ALL. + * So we have to construct the answer ourselves based on the passed in + * data. + * + * If all individual categories are the same locale, we can just set LC_ALL + * to that locale. But if not, we have to create an aggregation of all the + * categories on the system. Platforms differ as to the syntax they use + * for these non-uniform locales for LC_ALL. Some, like glibc and Windows, + * use an unordered series of name=value pairs, like + * LC_NUMERIC=C;LC_TIME=en_US.UTF-8;... + * to specify LC_ALL; others, like *BSD, use a positional notation with a + * delimitter, typically a single '/' character: + * C/en_UK.UTF-8/... + * + * When the external format is desired, this function returns whatever the + * system expects. The internal format is always name=value pairs. + * + * For systems that have categories we don't know about, the algorithm + * below won't know about those missing categories, leading to potential + * bugs for code that looks at them. If there is an environment variable + * that sets that category, we won't know to look for it, and so our use of + * LANG or "C" improperly overrides it. On the other hand, if we don't do + * what is done here, and there is no environment variable, the category's + * locale should be set to LANG or "C". So there is no good solution. khw + * thinks the best is to make sure we have a complete list of possible + * categories, adding new ones as they show up on obscure platforms. + */ + + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "Entering calculate_LC_ALL_string(%s);" + " called from %" LINE_Tf "\n", + ((format == EXTERNAL_FORMAT_FOR_QUERY) + ? "EXTERNAL_FORMAT_FOR_QUERY" + : ((format == EXTERNAL_FORMAT_FOR_SET) + ? "EXTERNAL_FORMAT_FOR_SET" + : "INTERNAL_FORMAT")), + caller_line)); + + bool input_list_was_NULL = (category_locales_list == NULL); + + /* If there was no input category list, construct a temporary one + * ourselves. */ + const char * my_category_locales_list[LC_ALL_INDEX_]; + const char ** locales_list = category_locales_list; + if (locales_list == NULL) { + locales_list = my_category_locales_list; + + if (format == EXTERNAL_FORMAT_FOR_QUERY) { + for_all_individual_category_indexes(i) { + locales_list[i] = query_nominal_locale_i(i); + } + } + else { + for_all_individual_category_indexes(i) { + locales_list[i] = querylocale_i(i); } } + } + + /* While we are calculating LC_ALL, we see if every category's locale is + * the same as every other's or not. */ +# ifndef HAS_IGNORED_LOCALE_CATEGORIES_ + + /* When we pay attention to all categories, we assume they are all the same + * until proven different */ + bool disparate = false; + +# else + + /* But if there are ignored categories, those will be set to "C", so try an + * arbitrary category, and if it isn't C, we know immediately that the + * locales are disparate. (The #if conditionals are to handle the case + * where LC_NUMERIC_INDEX_ is 0. We don't want to use LC_NUMERIC to + * compare, as that may be different between external and internal forms.) + * */ +# if ! defined(USE_LOCALE_NUMERIC) + + bool disparate = ! isNAME_C_OR_POSIX(locales_list[0]); + +# elif LC_NUMERIC_INDEX_ != 0 + + bool disparate = ! isNAME_C_OR_POSIX(locales_list[0]); + +# else + + /* Would need revision to handle the very unlikely case where only a single + * category, LC_NUMERIC, is defined */ + assert(LOCALE_CATEGORIES_COUNT_ > 0); + + bool disparate = ! isNAME_C_OR_POSIX(locales_list[1]); # endif +# endif - for (unsigned i = 0; i < 256; i++) { - if (isU8_UPPER_LC(i)) - PL_fold_locale[i] = (U8) toU8_LOWER_LC(i); - else if (isU8_LOWER_LC(i)) - PL_fold_locale[i] = (U8) toU8_UPPER_LC(i); - else - PL_fold_locale[i] = (U8) i; + /* Calculate the needed size for the string listing the individual locales. + * Initialize with values known at compile time. */ + Size_t total_len; + const char *separator; -# ifdef DEBUGGING +# ifdef PERL_LC_ALL_USES_NAME_VALUE_PAIRS /* Positional formatted LC_ALL */ + PERL_UNUSED_ARG(format); +# else - /* Most locales these days are supersets of ASCII. When debugging - * with -DLv, it is helpful to know what the exceptions to that are - * in this locale */ - if (DEBUG_Lv_TEST) { - bool unexpected = FALSE; + if (format != INTERNAL_FORMAT) { - if (isUPPER_L1(i)) { - if (isUPPER_A(i)) { - if (PL_fold_locale[i] != toLOWER_A(i)) { - unexpected = TRUE; - } - } - else if (has_non_ascii_fold) { - if (PL_fold_locale[i] != toLOWER_L1(i)) { - unexpected = TRUE; - } - } - else if (PL_fold_locale[i] != i) { - unexpected = TRUE; - } - } - else if ( isLOWER_L1(i) - && i != LATIN_SMALL_LETTER_SHARP_S - && i != MICRO_SIGN) - { - if (isLOWER_A(i)) { - if (PL_fold_locale[i] != toUPPER_A(i)) { - unexpected = TRUE; - } - } - else if (has_non_ascii_fold) { - if (PL_fold_locale[i] != toUPPER_LATIN1_MOD(i)) { - unexpected = TRUE; - } - } - else if (PL_fold_locale[i] != i) { - unexpected = TRUE; - } - } - else if (PL_fold_locale[i] != i) { - unexpected = TRUE; - } + /* Here, we will be using positional notation. it includes n-1 + * separators */ + total_len = ( LOCALE_CATEGORIES_COUNT_ - 1) + * STRLENs(PERL_LC_ALL_SEPARATOR) + + 1; /* And a trailing NUL */ + separator = PERL_LC_ALL_SEPARATOR; + } + else - if (unexpected) { - found_unexpected = TRUE; - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "For %s, fold of %02x is %02x\n", - newctype, i, PL_fold_locale[i])); - } - } +# endif + + { + /* name=value output is always used in internal format, and when + * positional isn't available on the platform. */ + total_len = lc_all_boiler_plate_length; + separator = ";"; + } + + /* The total length then is just the sum of the above boiler-plate plus the + * total strlen()s of the locale name of each individual category. */ + for_all_individual_category_indexes(i) { + const char * entry = ENTRY(i, locales_list, format); + + total_len += strlen(entry); + if (! disparate && strNE(entry, locales_list[0])) { + disparate = true; } + } - if (found_unexpected) { - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "All bytes not mentioned above either fold to" - " themselves or are the expected ASCII or" - " Latin1 ones\n")); + bool free_if_void_return = false; + const char * retval; + + /* If all categories have the same locale, we already know the answer */ + if (! disparate) { + if (returning == WANT_PL_setlocale_buf) { + save_to_buffer(locales_list[0], + &PL_setlocale_buf, + &PL_setlocale_bufsize); + retval = PL_setlocale_buf; } else { - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "No nonstandard folds were found\n")); -# endif + retval = locales_list[0]; + + /* If a temporary is wanted for the return, and we had to create + * the input list ourselves, we created it into such a temporary, + * so no further work is needed; but otherwise, make a mortal copy + * of this passed-in list element */ + if (returning == WANT_TEMP_PV && ! input_list_was_NULL) { + retval = savepv(retval); + SAVEFREEPV(retval); + } + + /* In all cases here, there's nothing we create that needs to be + * freed, so leave 'free_if_void_return' set to the default + * 'false'. */ } } + else { /* Here, not all categories have the same locale */ -# ifdef MB_CUR_MAX + char * constructed; - /* We only handle single-byte locales (outside of UTF-8 ones); so if this - * locale requires more than one byte, there are going to be BIG problems. - * */ + /* If returning to PL_setlocale_buf, set up to write directly to it, + * being sure it is resized to be large enough */ + if (returning == WANT_PL_setlocale_buf) { + set_save_buffer_min_size(total_len, + &PL_setlocale_buf, + &PL_setlocale_bufsize); + constructed = PL_setlocale_buf; + } + else { /* Otherwise we need new memory to hold the calculated value. */ - if (MB_CUR_MAX > 1 && ! PL_in_utf8_CTYPE_locale + Newx(constructed, total_len, char); - /* Some platforms return MB_CUR_MAX > 1 for even the "C" locale. - * Just assume that the implementation for them (plus for POSIX) is - * correct and the > 1 value is spurious. (Since these are - * specially handled to never be considered UTF-8 locales, as long - * as this is the only problem, everything should work fine */ - && ! isNAME_C_OR_POSIX(newctype)) - { - DEBUG_L(PerlIO_printf(Perl_debug_log, - "Unsupported, MB_CUR_MAX=%d\n", (int) MB_CUR_MAX)); + /* If returning the new memory, it must be set up to be freed + * later; otherwise at the end of this function */ + if (returning == WANT_TEMP_PV) { + SAVEFREEPV(constructed); + } + else { + free_if_void_return = true; + } + } + + constructed[0] = '\0'; + + /* Loop through all the categories */ + for_all_individual_category_indexes(j) { + + /* Add a separator, except before the first one */ + if (j != 0) { + my_strlcat(constructed, separator, total_len); + } + + const char * entry; + Size_t needed_len; + unsigned int i = j; + +# ifndef PERL_LC_ALL_USES_NAME_VALUE_PAIRS + + if (UNLIKELY(format != INTERNAL_FORMAT)) { + + /* In positional notation 'j' means the position, and we have + * to convert to the index 'i' */ + i = map_LC_ALL_position_to_index[j]; + + entry = ENTRY(i, locales_list, format); + needed_len = my_strlcat(constructed, entry, total_len); + } + else + +# endif + { + /* Below, we are to use name=value notation, either because + * that's what the platform uses, or because this is the + * internal format, which uses that notation regardless of the + * external form */ + + entry = ENTRY(i, locales_list, format); + + /* "name=locale;" */ + my_strlcat(constructed, category_names[i], total_len); + my_strlcat(constructed, "=", total_len); + needed_len = my_strlcat(constructed, entry, total_len); + } + + if (LIKELY(needed_len <= total_len)) { + continue; + } - Perl_ck_warner_d(aTHX_ packWARN(WARN_LOCALE), - "Locale '%s' is unsupported, and may crash the" - " interpreter.\n", - newctype); + /* If would have overflowed, panic */ + locale_panic_via_(Perl_form(aTHX_ + "Internal length calculation wrong.\n" + "\"%s\" was not entirely added to" + " \"%.*s\"; needed=%zu, had=%zu", + entry, (int) total_len, + constructed, + needed_len, total_len), + __FILE__, + caller_line); + } /* End of loop through the categories */ + + retval = constructed; + } /* End of the categories' locales are displarate */ + +# if defined(USE_PL_CURLOCALES) && defined(LC_ALL) + + if (format == INTERNAL_FORMAT) { + + /* PL_curlocales[LC_ALL_INDEX_] is updated as a side-effect of this + * function for internal format. */ + Safefree(PL_curlocales[LC_ALL_INDEX_]); + PL_curlocales[LC_ALL_INDEX_] = savepv(retval); } -# endif +# endif - DEBUG_Lv(PerlIO_printf(Perl_debug_log, "check_for_problems=%d\n", - check_for_problems)); + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "calculate_LC_ALL_string calculated '%s'\n", + retval)); - /* We don't populate the other lists if a UTF-8 locale, but do check that - * everything works as expected, unless checking turned off */ - if (check_for_problems) { - /* Assume enough space for every character being bad. 4 spaces each - * for the 94 printable characters that are output like "'x' "; and 5 - * spaces each for "'\\' ", "'\t' ", and "'\n' "; plus a terminating - * NUL */ - char bad_chars_list[ (94 * 4) + (3 * 5) + 1 ] = { '\0' }; - unsigned int bad_count = 0; /* Count of bad characters */ + if (returning == WANT_VOID) { + if (free_if_void_return) { + Safefree(retval); + } - for (unsigned i = 0; i < 256; i++) { + return NULL; + } - /* If checking for locale problems, see if the native ASCII-range - * printables plus \n and \t are in their expected categories in - * the new locale. If not, this could mean big trouble, upending - * Perl's and most programs' assumptions, like having a - * metacharacter with special meaning become a \w. Fortunately, - * it's very rare to find locales that aren't supersets of ASCII - * nowadays. It isn't a problem for most controls to be changed - * into something else; we check only \n and \t, though perhaps \r - * could be an issue as well. */ - if (isGRAPH_A(i) || isBLANK_A(i) || i == '\n') { - bool is_bad = FALSE; - char name[4] = { '\0' }; + return retval; +} - /* Convert the name into a string */ - if (isGRAPH_A(i)) { - name[0] = i; - name[1] = '\0'; - } - else if (i == '\n') { - my_strlcpy(name, "\\n", sizeof(name)); - } - else if (i == '\t') { - my_strlcpy(name, "\\t", sizeof(name)); - } - else { - assert(i == ' '); - my_strlcpy(name, "' '", sizeof(name)); +# if defined(WIN32) || ( defined(USE_POSIX_2008_LOCALE) \ + && ! defined(USE_QUERYLOCALE)) + +STATIC const char * +S_find_locale_from_environment(pTHX_ const locale_category_index index) +{ + /* NB: This function may actually change the locale on Windows. It + * currently is designed to be called only from setting the locale on + * Windows, and POSIX 2008 + * + * This function returns the locale specified by the program's environment + * for the category specified by our internal index number 'index'. It + * therefore simulates: + * setlocale(cat, "") + * but, except for some cases in Windows, doesn't actually change the + * locale; merely returns it. + * + * The return need not be freed by the caller. This + * promise relies on PerlEnv_getenv() returning a mortalized copy to us. + * + * The simulation is needed only on certain platforms; otherwise, libc is + * called with "" to get the actual value(s). The simulation is needed + * for: + * + * 1) On Windows systems, the concept of the POSIX ordering of + * environment variables is missing. To increase portability of + * programs across platforms, the POSIX ordering is emulated on + * Windows. + * + * 2) On POSIX 2008 systems without querylocale(), it is problematic + * getting the results of the POSIX 2008 equivalent of + * + * setlocale(category, "") + * + * To ensure that we know exactly what those values are, we do the + * setting ourselves, using the documented algorithm specified by the + * POSIX standard (assuming the platform follows the Standard) rather + * than use "" as the locale. This will lead to results that differ + * from native behavior if the native behavior differs from the + * Standard's documented value, but khw believes it is better to know + * what's going on, even if different from native, than to just guess. + * + * glibc systems differ from this standard in having a LANGUAGE + * environment variable used for just LC_MESSAGES. This function does + * NOT handle that. + * + * Another option for the POSIX 2008 case would be, in a critical + * section, to save the global locale's current value, and do a + * straight setlocale(LC_ALL, ""). That would return our desired + * values, destroying the global locale's, which we would then + * restore. But that could cause races with any other thread that is + * using the global locale and isn't using the mutex. And, the only + * reason someone would have done that is because they are calling a + * library function, like in gtk, that calls setlocale(), and which + * can't be changed to use the mutex. That wouldn't be a problem if + * this were to be done before any threads had switched, say during + * perl construction time. But this code would still be needed for + * the general case. + * + * The Windows and POSIX 2008 differ in that the ultimate fallback is "C" + * in POSIX, and is the system default locale in Windows. To get that + * system default value, we actually have to call setlocale() on Windows. + */ + + const char * const lc_all = PerlEnv_getenv("LC_ALL"); + const char * locale_names[LC_ALL_INDEX_] = { NULL }; + + /* Use any "LC_ALL" environment variable, as it overrides everything else. + * */ + if (lc_all && strNE(lc_all, "")) { + return lc_all; + } + + /* Here, no usable LC_ALL environment variable. We have to handle each + * category separately. If all categories are desired, we loop through + * them all. If only an individual category is desired, to avoid + * duplicating logic, we use the same loop, but set up the limits so it is + * only executed once, for that particular category. */ + locale_category_index lower, upper, offset; + if (index == LC_ALL_INDEX_) { + lower = (locale_category_index) 0; + upper = (locale_category_index) ((int) LC_ALL_INDEX_ - 1); + offset = (locale_category_index) 0; + } + else { + lower = index; + upper = index; + + /* 'offset' is used so that the result of the single loop iteration is + * stored into output[0] */ + offset = lower; + } + + /* When no LC_ALL environment variable, LANG is used as a default, but + * overridden for individual categories that have corresponding environment + * variables. If no LANG exists, the default is "C" on POSIX 2008, or the + * system default for the category on Windows. */ + const char * env_lang = NULL; + + /* For each desired category, use any corresponding environment variable; + * or the default if none such exists. */ + bool is_disparate = false; /* Assume is uniform until proven otherwise */ + for_category_indexes_between(i, lower, upper) { + const char * const env_override = PerlEnv_getenv(category_names[i]); + locale_category_index j = (locale_category_index) (i - offset); + + if (env_override && strNE(env_override, "")) { + locale_names[j] = env_override; + } + else { /* Here, no corresponding environment variable, see if LANG + exists and is usable. Done this way to avoid fetching LANG + unless it is actually needed */ + if (env_lang == NULL) { + env_lang = PerlEnv_getenv("LANG"); + + /* If not usable, set it to a non-NULL illegal value so won't + * try to use it below */ + if (env_lang == NULL || strEQ(env_lang, "")) { + env_lang = (const char *) 1; } + } - /* Check each possibe class */ - if (UNLIKELY(cBOOL(isU8_ALPHANUMERIC_LC(i)) != - cBOOL(isALPHANUMERIC_A(i)))) - { - is_bad = TRUE; - DEBUG_L(PerlIO_printf(Perl_debug_log, - "isalnum('%s') unexpectedly is %x\n", - name, cBOOL(isU8_ALPHANUMERIC_LC(i)))); + /* If a usable LANG exists, use it. */ + if (env_lang != NULL && env_lang != (const char *) 1) { + locale_names[j] = env_lang; + } + else { + +# ifdef WIN32 + /* If no LANG, use the system default on Windows. */ + locale_names[j] = wrap_wsetlocale(categories[i], ".ACP"); + if (locale_names[j]) { + SAVEFREEPV(locale_names[j]); } - if (UNLIKELY(cBOOL(isU8_ALPHA_LC(i)) != cBOOL(isALPHA_A(i)))) { - is_bad = TRUE; - DEBUG_L(PerlIO_printf(Perl_debug_log, - "isalpha('%s') unexpectedly is %x\n", - name, cBOOL(isU8_ALPHA_LC(i)))); - } - if (UNLIKELY(cBOOL(isU8_DIGIT_LC(i)) != cBOOL(isDIGIT_A(i)))) { - is_bad = TRUE; - DEBUG_L(PerlIO_printf(Perl_debug_log, - "isdigit('%s') unexpectedly is %x\n", - name, cBOOL(isU8_DIGIT_LC(i)))); - } - if (UNLIKELY(cBOOL(isU8_GRAPH_LC(i)) != cBOOL(isGRAPH_A(i)))) { - is_bad = TRUE; - DEBUG_L(PerlIO_printf(Perl_debug_log, - "isgraph('%s') unexpectedly is %x\n", - name, cBOOL(isU8_GRAPH_LC(i)))); - } - if (UNLIKELY(cBOOL(isU8_LOWER_LC(i)) != cBOOL(isLOWER_A(i)))) { - is_bad = TRUE; - DEBUG_L(PerlIO_printf(Perl_debug_log, - "islower('%s') unexpectedly is %x\n", - name, cBOOL(isU8_LOWER_LC(i)))); - } - if (UNLIKELY(cBOOL(isU8_PRINT_LC(i)) != cBOOL(isPRINT_A(i)))) { - is_bad = TRUE; - DEBUG_L(PerlIO_printf(Perl_debug_log, - "isprint('%s') unexpectedly is %x\n", - name, cBOOL(isU8_PRINT_LC(i)))); - } - if (UNLIKELY(cBOOL(isU8_PUNCT_LC(i)) != cBOOL(isPUNCT_A(i)))) { - is_bad = TRUE; - DEBUG_L(PerlIO_printf(Perl_debug_log, - "ispunct('%s') unexpectedly is %x\n", - name, cBOOL(isU8_PUNCT_LC(i)))); - } - if (UNLIKELY(cBOOL(isU8_SPACE_LC(i)) != cBOOL(isSPACE_A(i)))) { - is_bad = TRUE; - DEBUG_L(PerlIO_printf(Perl_debug_log, - "isspace('%s') unexpectedly is %x\n", - name, cBOOL(isU8_SPACE_LC(i)))); - } - if (UNLIKELY(cBOOL(isU8_UPPER_LC(i)) != cBOOL(isUPPER_A(i)))) { - is_bad = TRUE; - DEBUG_L(PerlIO_printf(Perl_debug_log, - "isupper('%s') unexpectedly is %x\n", - name, cBOOL(isU8_UPPER_LC(i)))); - } - if (UNLIKELY(cBOOL(isU8_XDIGIT_LC(i))!= cBOOL(isXDIGIT_A(i)))) { - is_bad = TRUE; - DEBUG_L(PerlIO_printf(Perl_debug_log, - "isxdigit('%s') unexpectedly is %x\n", - name, cBOOL(isU8_XDIGIT_LC(i)))); - } - if (UNLIKELY(toU8_LOWER_LC(i) != (int) toLOWER_A(i))) { - is_bad = TRUE; - DEBUG_L(PerlIO_printf(Perl_debug_log, - "tolower('%s')=0x%x instead of the expected 0x%x\n", - name, toU8_LOWER_LC(i), (int) toLOWER_A(i))); - } - if (UNLIKELY(toU8_UPPER_LC(i) != (int) toUPPER_A(i))) { - is_bad = TRUE; - DEBUG_L(PerlIO_printf(Perl_debug_log, - "toupper('%s')=0x%x instead of the expected 0x%x\n", - name, toU8_UPPER_LC(i), (int) toUPPER_A(i))); - } - if (UNLIKELY((i == '\n' && ! isCNTRL_LC(i)))) { - is_bad = TRUE; - DEBUG_L(PerlIO_printf(Perl_debug_log, - "'\\n' (=%02X) is not a control\n", (int) i)); - } - - /* Add to the list; Separate multiple entries with a blank */ - if (is_bad) { - if (bad_count) { - my_strlcat(bad_chars_list, " ", sizeof(bad_chars_list)); - } - my_strlcat(bad_chars_list, name, sizeof(bad_chars_list)); - bad_count++; + else +# endif + { /* If nothing was found or worked, use C */ + locale_names[j] = "C"; } } } - if (bad_count == 2 && maybe_utf8_turkic) { - bad_count = 0; - *bad_chars_list = '\0'; - - /* The casts are because otherwise some compilers warn: - gcc.gnu.org/bugzilla/show_bug.cgi?id=99950 - gcc.gnu.org/bugzilla/show_bug.cgi?id=94182 - */ - PL_fold_locale[ (U8) 'I' ] = 'I'; - PL_fold_locale[ (U8) 'i' ] = 'i'; - PL_in_utf8_turkic_locale = TRUE; - DEBUG_L(PerlIO_printf(Perl_debug_log, "%s is turkic\n", newctype)); + if (j > 0 && ! is_disparate && strNE(locale_names[0], locale_names[j])) + { + is_disparate = true; } - /* If we found problems and we want them output, do so */ - if ( (UNLIKELY(bad_count)) - && (LIKELY(ckWARN_d(WARN_LOCALE)) || UNLIKELY(DEBUG_L_TEST))) - { - /* WARNING. If you change the wording of these; be sure to update - * t/loc_tools.pl correspondingly */ + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "find_locale_from_environment i=%u, j=%u, name=%s," + " locale=%s, locale of 0th category=%s, disparate=%d\n", + i, j, category_names[i], + locale_names[j], locale_names[0], is_disparate)); + } - if (PL_in_utf8_CTYPE_locale) { - PL_warn_locale = Perl_newSVpvf(aTHX_ - "Locale '%s' contains (at least) the following characters" - " which have\nunexpected meanings: %s\nThe Perl program" - " will use the expected meanings", - newctype, bad_chars_list); - } - else { - PL_warn_locale = - Perl_newSVpvf(aTHX_ - "\nThe following characters (and maybe" - " others) may not have the same meaning as" - " the Perl program expects: %s\n", - bad_chars_list - ); - } + if (! is_disparate) { + return locale_names[0]; + } -# ifdef HAS_SOME_LANGINFO + return calculate_LC_ALL_string(locale_names, INTERNAL_FORMAT, + WANT_TEMP_PV, + __LINE__); +} - const char * scratch_buffer = NULL; - Perl_sv_catpvf(aTHX_ PL_warn_locale, "; codeset=%s", - my_langinfo_c(CODESET, LC_CTYPE, - newctype, - &scratch_buffer, NULL, - NULL)); - Safefree(scratch_buffer); +# endif +# if defined(DEBUGGING) || defined(USE_PERL_SWITCH_LOCALE_CONTEXT) + +STATIC const char * +S_get_LC_ALL_display(pTHX) +{ + return calculate_LC_ALL_string(NULL, INTERNAL_FORMAT, + WANT_TEMP_PV, + __LINE__); +} # endif - Perl_sv_catpvf(aTHX_ PL_warn_locale, "\n"); +STATIC void +S_setlocale_failure_panic_via_i(pTHX_ + const locale_category_index cat_index, + const char * current, + const char * failed, + const line_t proxy_caller_line, + const line_t immediate_caller_line, + const char * const higher_caller_file, + const line_t higher_caller_line) +{ + PERL_ARGS_ASSERT_SETLOCALE_FAILURE_PANIC_VIA_I; + + /* Called to panic when a setlocale form unexpectedly failed for the + * category determined by 'cat_index', and the locale that was in effect + * (and likely still is) is 'current'. 'current' may be NULL, which causes + * this function to query what it is. + * + * The extra caller information is used for when a function acts as a + * stand-in for another function, which a typical reader would more likely + * think would be the caller + * + * If a line number is 0, its stack (sort-of) frame is omitted; same if + * it's the same line number as the next higher caller. */ - /* If we are actually in the scope of the locale or are debugging, - * output the message now. If not in that scope, we save the - * message to be output at the first operation using this locale, - * if that actually happens. Most programs don't use locales, so - * they are immune to bad ones. */ - if (IN_LC(LC_CTYPE) || UNLIKELY(DEBUG_L_TEST)) { + const int cat = categories[cat_index]; + const char * name = category_names[cat_index]; - /* The '0' below suppresses a bogus gcc compiler warning */ - Perl_warner(aTHX_ packWARN(WARN_LOCALE), SvPVX(PL_warn_locale), - 0); + dSAVE_ERRNO; - if (IN_LC(LC_CTYPE)) { - SvREFCNT_dec_NN(PL_warn_locale); - PL_warn_locale = NULL; - } - } - } + if (current == NULL) { + current = querylocale_i(cat_index); + } + + const char * proxy_text = ""; + if (proxy_caller_line != 0 && proxy_caller_line != immediate_caller_line) + { + proxy_text = Perl_form(aTHX_ "\nCalled via %s: %" LINE_Tf, + __FILE__, proxy_caller_line); } + if ( strNE(__FILE__, higher_caller_file) + || ( immediate_caller_line != 0 + && immediate_caller_line != higher_caller_line)) + { + proxy_text = Perl_form(aTHX_ "%s\nCalled via %s: %" LINE_Tf, + proxy_text, __FILE__, + immediate_caller_line); + } + + /* 'false' in the get_displayable_string() calls makes it not think the + * locale is UTF-8, so just dumps bytes. Actually figuring it out can be + * too complicated for a panic situation. */ + const char * msg = Perl_form(aTHX_ + "Can't change locale for %s (%d) from '%s' to '%s'" + " %s", + name, cat, + get_displayable_string(current, + current + strlen(current), + false), + get_displayable_string(failed, + failed + strlen(failed), + false), + proxy_text); + RESTORE_ERRNO; + + Perl_locale_panic(msg, __LINE__, higher_caller_file, higher_caller_line); + NOT_REACHED; /* NOTREACHED */ } -# endif /* USE_LOCALE_CTYPE */ +# ifdef USE_LOCALE_NUMERIC -void -Perl__warn_problematic_locale() +STATIC void +S_new_numeric(pTHX_ const char *newnum, bool force) { + PERL_ARGS_ASSERT_NEW_NUMERIC; -# ifdef USE_LOCALE_CTYPE + /* Called after each libc setlocale() or uselocale() call affecting + * LC_NUMERIC, to tell core Perl this and that 'newnum' is the name of the + * new locale, and we are switched into it. It installs this locale as the + * current underlying default, and then switches to the C locale, if + * necessary, so that the code that has traditionally expected the radix + * character to be a dot may continue to do so. + * + * The default locale and the C locale can be toggled between by use of the + * set_numeric_underlying() and set_numeric_standard() functions, which + * should probably not be called directly, but only via macros like + * SET_NUMERIC_STANDARD() in perl.h. + * + * The toggling is necessary mainly so that a non-dot radix decimal point + * character can be input and output, while allowing internal calculations + * to use a dot. + * + * This sets several interpreter-level variables: + * PL_numeric_name The underlying locale's name: a copy of 'newnum' + * PL_numeric_underlying A boolean indicating if the toggled state is + * such that the current locale is the program's + * underlying locale + * PL_numeric_standard An int indicating if the toggled state is such + * that the current locale is the C locale or + * indistinguishable from the C locale. If non-zero, it + * is in C; if > 1, it means it may not be toggled away + * from C. + * PL_numeric_underlying_is_standard A bool kept by this function + * indicating that the underlying locale and the standard + * C locale are indistinguishable for the purposes of + * LC_NUMERIC. This happens when both of the above two + * variables are true at the same time. (Toggling is a + * no-op under these circumstances.) This variable is + * used to avoid having to recalculate. + * PL_numeric_radix_sv Contains the string that code should use for the + * decimal point. It is set to either a dot or the + * program's underlying locale's radix character string, + * depending on the situation. + * PL_underlying_radix_sv Contains the program's underlying locale's + * radix character string. This is copied into + * PL_numeric_radix_sv when the situation warrants. It + * exists to avoid having to recalculate it when toggling. + */ - dTHX; + DEBUG_L( PerlIO_printf(Perl_debug_log, + "Called new_numeric with %s, PL_numeric_name=%s\n", + newnum, PL_numeric_name)); - /* Internal-to-core function that outputs the message in PL_warn_locale, - * and then NULLS it. Should be called only through the macro - * CHECK_AND_WARN_PROBLEMATIC_LOCALE_ */ + /* We keep records comparing the characteristics of the LC_NUMERIC catetory + * of the current locale vs the standard C locale. If the new locale that + * has just been changed to is the same as the one our records are for, + * they are still valid, and we don't have to recalculate them. 'force' is + * true if the caller suspects that the records are out-of-date, so do go + * ahead and recalculate them. (This can happen when an external library + * has had control and now perl is reestablishing control; we have to + * assume that that library changed the locale in unknown ways.) + * + * Even if our records are valid, the new locale will likely have been + * switched to before this function gets called, and we must toggle into + * one indistinguishable from the C locale with regards to LC_NUMERIC + * handling, so that all the libc functions that are affected by LC_NUMERIC + * will work as expected. This can be skipped if we already know that the + * locale is indistinguishable from the C locale. */ + if (! force && strEQ(PL_numeric_name, newnum)) { + if (! PL_numeric_underlying_is_standard) { + set_numeric_standard(__FILE__, __LINE__); + } - if (PL_warn_locale) { - Perl_ck_warner(aTHX_ packWARN(WARN_LOCALE), - SvPVX(PL_warn_locale), - 0 /* dummy to avoid compiler warning */ ); - SvREFCNT_dec_NN(PL_warn_locale); - PL_warn_locale = NULL; + return; } -# endif + Safefree(PL_numeric_name); + PL_numeric_name = savepv(newnum); -} + /* Handle the trivial case. Since this is called at process + * initialization, be aware that this bit can't rely on much being + * available. */ + if (isNAME_C_OR_POSIX(PL_numeric_name)) { + PL_numeric_standard = TRUE; + PL_numeric_underlying_is_standard = TRUE; + PL_numeric_underlying = TRUE; + sv_setpv(PL_numeric_radix_sv, C_decimal_point); + SvUTF8_off(PL_numeric_radix_sv); + sv_setpv(PL_underlying_radix_sv, C_decimal_point); + SvUTF8_off(PL_underlying_radix_sv); + return; + } -STATIC void -S_new_LC_ALL(pTHX_ const char *unused, bool force) -{ - PERL_ARGS_ASSERT_NEW_LC_ALL; - PERL_UNUSED_ARG(unused); + /* We are in the underlying locale until changed at the end of this + * function */ + PL_numeric_underlying = TRUE; - /* LC_ALL updates all the things we care about. */ + /* Passing a non-NULL causes the function call just below to + automatically set the UTF-8 flag on PL_underlying_radix_sv */ + utf8ness_t dummy; - for (unsigned int i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { - if (update_functions[i]) { - const char * this_locale = querylocale_i(i); - update_functions[i](aTHX_ this_locale, force); - } - } -} + /* Find and save this locale's radix character. */ + langinfo_sv_c(RADIXCHAR, LC_NUMERIC, PL_numeric_name, + PL_underlying_radix_sv, &dummy); + DEBUG_L(PerlIO_printf(Perl_debug_log, + "Locale radix is '%s', ?UTF-8=%d\n", + SvPVX(PL_underlying_radix_sv), + cBOOL(SvUTF8(PL_underlying_radix_sv)))); -# ifdef USE_LOCALE_COLLATE + /* This locale is indistinguishable from C (for numeric purposes) if both + * the radix character and the thousands separator are the same as C's. + * Start with the radix. */ + PL_numeric_underlying_is_standard = strEQ(C_decimal_point, + SvPVX(PL_underlying_radix_sv)); -STATIC void -S_new_collate(pTHX_ const char *newcoll, bool force) -{ - PERL_ARGS_ASSERT_NEW_COLLATE; - PERL_UNUSED_ARG(force); +# ifndef TS_W32_BROKEN_LOCALECONV - /* Called after each libc setlocale() call affecting LC_COLLATE, to tell - * core Perl this and that 'newcoll' is the name of the new locale. + /* If the radix isn't the same as C's, we know it is distinguishable from + * C; otherwise check the thousands separator too. Only if both are the + * same as C's is the locale indistinguishable from C. * - * The design of locale collation is that every locale change is given an - * index 'PL_collation_ix'. The first time a string participates in an - * operation that requires collation while locale collation is active, it - * is given PERL_MAGIC_collxfrm magic (via sv_collxfrm_flags()). That - * magic includes the collation index, and the transformation of the string - * by strxfrm(), q.v. That transformation is used when doing comparisons, - * instead of the string itself. If a string changes, the magic is - * cleared. The next time the locale changes, the index is incremented, - * and so we know during a comparison that the transformation is not - * necessarily still valid, and so is recomputed. Note that if the locale - * changes enough times, the index could wrap (a U32), and it is possible - * that a transformation would improperly be considered valid, leading to - * an unlikely bug */ + * But on earlier Windows versions, there is a potential race. This code + * knows that localeconv() (elsewhere in this file) will be used to extract + * the needed value, and localeconv() was buggy for quite a while, and that + * code in this file hence uses a workaround. And that workaround may have + * an (unlikely) race. Gathering the radix uses a different workaround on + * Windows that doesn't involve a race. It might be possible to do the + * same for this (patches welcome). + * + * Until then khw doesn't think it's worth even the small risk of a race to + * get this value, which doesn't appear to be used in any of the Microsoft + * library routines anyway. */ + + if (PL_numeric_underlying_is_standard) { + PL_numeric_underlying_is_standard = strEQ(C_thousands_sep, + langinfo_c(THOUSEP, + LC_NUMERIC, + PL_numeric_name, + NULL)); + } + +# endif + + PL_numeric_standard = PL_numeric_underlying_is_standard; + + /* Keep LC_NUMERIC so that it has the C locale radix and thousands + * separator. This is for XS modules, so they don't have to worry about + * the radix being a non-dot. (Core operations that need the underlying + * locale change to it temporarily). */ + if (! PL_numeric_standard) { + set_numeric_standard(__FILE__, __LINE__); + } +} + +# endif + +void +Perl_set_numeric_standard(pTHX_ const char * const file, const line_t line) +{ + PERL_ARGS_ASSERT_SET_NUMERIC_STANDARD; + PERL_UNUSED_ARG(file); /* Some Configurations ignore these */ + PERL_UNUSED_ARG(line); + +# ifdef USE_LOCALE_NUMERIC + + /* Unconditionally toggle the LC_NUMERIC locale to the C locale + * + * Most code should use the macro SET_NUMERIC_STANDARD() in perl.h + * instead of calling this directly. The macro avoids calling this routine + * if toggling isn't necessary according to our records (which could be + * wrong if some XS code has changed the locale behind our back) */ + + DEBUG_L(PerlIO_printf(Perl_debug_log, "Setting LC_NUMERIC locale to" + " standard C; called from %s: %" + LINE_Tf "\n", file, line)); + + void_setlocale_c_with_caller(LC_NUMERIC, "C", file, line); + PL_numeric_standard = TRUE; + sv_setpv(PL_numeric_radix_sv, C_decimal_point); + SvUTF8_off(PL_numeric_radix_sv); + + PL_numeric_underlying = PL_numeric_underlying_is_standard; + +# endif /* USE_LOCALE_NUMERIC */ + +} + +void +Perl_set_numeric_underlying(pTHX_ const char * const file, const line_t line) +{ + PERL_ARGS_ASSERT_SET_NUMERIC_UNDERLYING; + PERL_UNUSED_ARG(file); /* Some Configurations ignore these */ + PERL_UNUSED_ARG(line); + +# ifdef USE_LOCALE_NUMERIC + + /* Unconditionally toggle the LC_NUMERIC locale to the current underlying + * default. + * + * Most code should use the macro SET_NUMERIC_UNDERLYING() in perl.h + * instead of calling this directly. The macro avoids calling this routine + * if toggling isn't necessary according to our records (which could be + * wrong if some XS code has changed the locale behind our back) */ + + DEBUG_L(PerlIO_printf(Perl_debug_log, "Setting LC_NUMERIC locale to %s;" + " called from %s: %" LINE_Tf "\n", + PL_numeric_name, file, line)); + /* Maybe not in init? assert(PL_locale_mutex_depth > 0);*/ + + void_setlocale_c_with_caller(LC_NUMERIC, PL_numeric_name, file, line); + PL_numeric_underlying = TRUE; + sv_setsv_nomg(PL_numeric_radix_sv, PL_underlying_radix_sv); + + PL_numeric_standard = PL_numeric_underlying_is_standard; + +# endif /* USE_LOCALE_NUMERIC */ + +} + +# ifdef USE_LOCALE_CTYPE + +STATIC void +S_new_ctype(pTHX_ const char *newctype, bool force) +{ + PERL_ARGS_ASSERT_NEW_CTYPE; + PERL_UNUSED_ARG(force); + + /* Called after each libc setlocale() call affecting LC_CTYPE, to tell + * core Perl this and that 'newctype' is the name of the new locale. + * + * This function sets up the folding arrays for all 256 bytes, assuming + * that tofold() is tolc() since fold case is not a concept in POSIX, + */ + + DEBUG_L(PerlIO_printf(Perl_debug_log, "Entering new_ctype(%s)\n", + newctype)); + + /* No change means no-op */ + if (strEQ(PL_ctype_name, newctype)) { + return; + } + + /* We will replace any bad locale warning with + * 1) nothing if the new one is ok; or + * 2) a new warning for the bad new locale */ + if (PL_warn_locale) { + SvREFCNT_dec_NN(PL_warn_locale); + PL_warn_locale = NULL; + } + + /* Clear cache */ + Safefree(PL_ctype_name); + PL_ctype_name = ""; + + PL_in_utf8_turkic_locale = FALSE; + + /* For the C locale, just use the standard folds, and we know there are no + * glitches possible, so return early. Since this is called at process + * initialization, be aware that this bit can't rely on much being + * available. */ + if (isNAME_C_OR_POSIX(newctype)) { + Copy(PL_fold, PL_fold_locale, 256, U8); + PL_ctype_name = savepv(newctype); + PL_in_utf8_CTYPE_locale = FALSE; + return; + } + + /* The cache being cleared signals the called function to compute a new + * value */ + PL_in_utf8_CTYPE_locale = is_locale_utf8(newctype); + + PL_ctype_name = savepv(newctype); + bool maybe_utf8_turkic = FALSE; + + /* Don't check for problems if we are suppressing the warnings */ + bool check_for_problems = ckWARN_d(WARN_LOCALE) || UNLIKELY(DEBUG_L_TEST); + + if (PL_in_utf8_CTYPE_locale) { + + /* A UTF-8 locale gets standard rules. But note that code still has to + * handle this specially because of the three problematic code points + * */ + Copy(PL_fold_latin1, PL_fold_locale, 256, U8); + + /* UTF-8 locales can have special handling for 'I' and 'i' if they are + * Turkic. Make sure these two are the only anomalies. (We don't + * require towupper and towlower because they aren't in C89.) */ + +# if defined(HAS_TOWUPPER) && defined (HAS_TOWLOWER) + + if (towupper('i') == 0x130 && towlower('I') == 0x131) + +# else + + if (toU8_UPPER_LC('i') == 'i' && toU8_LOWER_LC('I') == 'I') + +# endif + + { + /* This is how we determine it really is Turkic */ + check_for_problems = TRUE; + maybe_utf8_turkic = TRUE; + } + } + else { /* Not a canned locale we know the values for. Compute them */ + +# ifdef DEBUGGING + + bool has_non_ascii_fold = FALSE; + bool found_unexpected = FALSE; + + /* Under -DLv, see if there are any folds outside the ASCII range. + * This factoid is used below */ + if (DEBUG_Lv_TEST) { + for (unsigned i = 128; i < 256; i++) { + int j = LATIN1_TO_NATIVE(i); + if (toU8_LOWER_LC(j) != j || toU8_UPPER_LC(j) != j) { + has_non_ascii_fold = TRUE; + break; + } + } + } + +# endif + + for (unsigned i = 0; i < 256; i++) { + if (isU8_UPPER_LC(i)) + PL_fold_locale[i] = (U8) toU8_LOWER_LC(i); + else if (isU8_LOWER_LC(i)) + PL_fold_locale[i] = (U8) toU8_UPPER_LC(i); + else + PL_fold_locale[i] = (U8) i; + +# ifdef DEBUGGING + + /* Most locales these days are supersets of ASCII. When debugging, + * it is helpful to know what the exceptions to that are in this + * locale */ + if (DEBUG_L_TEST) { + bool unexpected = FALSE; + + if (isUPPER_L1(i)) { + if (isUPPER_A(i)) { + if (PL_fold_locale[i] != toLOWER_A(i)) { + unexpected = TRUE; + } + } + else if (has_non_ascii_fold) { + if (PL_fold_locale[i] != toLOWER_L1(i)) { + unexpected = TRUE; + } + } + else if (PL_fold_locale[i] != i) { + unexpected = TRUE; + } + } + else if ( isLOWER_L1(i) + && i != LATIN_SMALL_LETTER_SHARP_S + && i != MICRO_SIGN) + { + if (isLOWER_A(i)) { + if (PL_fold_locale[i] != toUPPER_A(i)) { + unexpected = TRUE; + } + } + else if (has_non_ascii_fold) { + if (PL_fold_locale[i] != toUPPER_LATIN1_MOD(i)) { + unexpected = TRUE; + } + } + else if (PL_fold_locale[i] != i) { + unexpected = TRUE; + } + } + else if (PL_fold_locale[i] != i) { + unexpected = TRUE; + } + + if (unexpected) { + found_unexpected = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, + "For %s, fold of %02x is %02x\n", + newctype, i, PL_fold_locale[i])); + } + } + } + + if (found_unexpected) { + DEBUG_L(PerlIO_printf(Perl_debug_log, + "All bytes not mentioned above either fold to" + " themselves or are the expected ASCII or" + " Latin1 ones\n")); + } + else { + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "No nonstandard folds were found\n")); +# endif + + } + } + +# ifdef MB_CUR_MAX + + /* We only handle single-byte locales (outside of UTF-8 ones); so if this + * locale requires more than one byte, there are going to be BIG problems. + * */ + + const int mb_cur_max = MB_CUR_MAX; + + if (mb_cur_max > 1 && ! PL_in_utf8_CTYPE_locale + + /* Some platforms return MB_CUR_MAX > 1 for even the "C" locale. + * Just assume that the implementation for them (plus for POSIX) is + * correct and the > 1 value is spurious. (Since these are + * specially handled to never be considered UTF-8 locales, as long + * as this is the only problem, everything should work fine */ + && ! isNAME_C_OR_POSIX(newctype)) + { + DEBUG_L(PerlIO_printf(Perl_debug_log, + "Unsupported, MB_CUR_MAX=%d\n", mb_cur_max)); + + if (! IN_LC(LC_CTYPE) || ckWARN_d(WARN_LOCALE)) { + char * msg = Perl_form(aTHX_ + "Locale '%s' is unsupported, and may hang" + " or crash the interpreter", + newctype); + if (IN_LC(LC_CTYPE)) { + Perl_warner(aTHX_ packWARN(WARN_LOCALE), "%s", msg); + } + else { + PL_warn_locale = newSV(0); + sv_setpvn(PL_warn_locale, msg, strlen(msg)); + } + } + } + +# endif + + DEBUG_Lv(PerlIO_printf(Perl_debug_log, "check_for_problems=%d\n", + check_for_problems)); + + /* We don't populate the other lists if a UTF-8 locale, but do check that + * everything works as expected, unless checking turned off */ + if (check_for_problems) { + /* Assume enough space for every character being bad. 4 spaces each + * for the 94 printable characters that are output like "'x' "; and 5 + * spaces each for "'\\' ", "'\t' ", and "'\n' "; plus a terminating + * NUL */ + char bad_chars_list[ (94 * 4) + (3 * 5) + 1 ] = { '\0' }; + unsigned int bad_count = 0; /* Count of bad characters */ + + for (unsigned i = 0; i < 256; i++) { + + /* If checking for locale problems, see if the native ASCII-range + * printables plus \n and \t are in their expected categories in + * the new locale. If not, this could mean big trouble, upending + * Perl's and most programs' assumptions, like having a + * metacharacter with special meaning become a \w. Fortunately, + * it's very rare to find locales that aren't supersets of ASCII + * nowadays. It isn't a problem for most controls to be changed + * into something else; we check only \n and \t, though perhaps \r + * could be an issue as well. */ + if (isGRAPH_A(i) || isBLANK_A(i) || i == '\n') { + bool is_bad = FALSE; + char name[4] = { '\0' }; + + /* Convert the name into a string */ + if (isGRAPH_A(i)) { + name[0] = i; + name[1] = '\0'; + } + else if (i == '\n') { + my_strlcpy(name, "\\n", sizeof(name)); + } + else if (i == '\t') { + my_strlcpy(name, "\\t", sizeof(name)); + } + else { + assert(i == ' '); + my_strlcpy(name, "' '", sizeof(name)); + } + + /* Check each possibe class */ + if (UNLIKELY(cBOOL(isU8_ALPHANUMERIC_LC(i)) != + cBOOL(isALPHANUMERIC_A(i)))) + { + is_bad = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, + "isalnum('%s') unexpectedly is %x\n", + name, cBOOL(isU8_ALPHANUMERIC_LC(i)))); + } + if (UNLIKELY(cBOOL(isU8_ALPHA_LC(i)) != cBOOL(isALPHA_A(i)))) { + is_bad = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, + "isalpha('%s') unexpectedly is %x\n", + name, cBOOL(isU8_ALPHA_LC(i)))); + } + if (UNLIKELY(cBOOL(isU8_DIGIT_LC(i)) != cBOOL(isDIGIT_A(i)))) { + is_bad = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, + "isdigit('%s') unexpectedly is %x\n", + name, cBOOL(isU8_DIGIT_LC(i)))); + } + if (UNLIKELY(cBOOL(isU8_GRAPH_LC(i)) != cBOOL(isGRAPH_A(i)))) { + is_bad = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, + "isgraph('%s') unexpectedly is %x\n", + name, cBOOL(isU8_GRAPH_LC(i)))); + } + if (UNLIKELY(cBOOL(isU8_LOWER_LC(i)) != cBOOL(isLOWER_A(i)))) { + is_bad = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, + "islower('%s') unexpectedly is %x\n", + name, cBOOL(isU8_LOWER_LC(i)))); + } + if (UNLIKELY(cBOOL(isU8_PRINT_LC(i)) != cBOOL(isPRINT_A(i)))) { + is_bad = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, + "isprint('%s') unexpectedly is %x\n", + name, cBOOL(isU8_PRINT_LC(i)))); + } + if (UNLIKELY(cBOOL(isU8_PUNCT_LC(i)) != cBOOL(isPUNCT_A(i)))) { + is_bad = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, + "ispunct('%s') unexpectedly is %x\n", + name, cBOOL(isU8_PUNCT_LC(i)))); + } + if (UNLIKELY(cBOOL(isU8_SPACE_LC(i)) != cBOOL(isSPACE_A(i)))) { + is_bad = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, + "isspace('%s') unexpectedly is %x\n", + name, cBOOL(isU8_SPACE_LC(i)))); + } + if (UNLIKELY(cBOOL(isU8_UPPER_LC(i)) != cBOOL(isUPPER_A(i)))) { + is_bad = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, + "isupper('%s') unexpectedly is %x\n", + name, cBOOL(isU8_UPPER_LC(i)))); + } + if (UNLIKELY(cBOOL(isU8_XDIGIT_LC(i))!= cBOOL(isXDIGIT_A(i)))) { + is_bad = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, + "isxdigit('%s') unexpectedly is %x\n", + name, cBOOL(isU8_XDIGIT_LC(i)))); + } + if (UNLIKELY(toU8_LOWER_LC(i) != (int) toLOWER_A(i))) { + is_bad = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, + "tolower('%s')=0x%x instead of the expected 0x%x\n", + name, toU8_LOWER_LC(i), (int) toLOWER_A(i))); + } + if (UNLIKELY(toU8_UPPER_LC(i) != (int) toUPPER_A(i))) { + is_bad = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, + "toupper('%s')=0x%x instead of the expected 0x%x\n", + name, toU8_UPPER_LC(i), (int) toUPPER_A(i))); + } + if (UNLIKELY((i == '\n' && ! isCNTRL_LC(i)))) { + is_bad = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, + "'\\n' (=%02X) is not a control\n", (int) i)); + } + + /* Add to the list; Separate multiple entries with a blank */ + if (is_bad) { + if (bad_count) { + my_strlcat(bad_chars_list, " ", sizeof(bad_chars_list)); + } + my_strlcat(bad_chars_list, name, sizeof(bad_chars_list)); + bad_count++; + } + } + } + + if (bad_count == 2 && maybe_utf8_turkic) { + bad_count = 0; + *bad_chars_list = '\0'; + + /* The casts are because otherwise some compilers warn: + gcc.gnu.org/bugzilla/show_bug.cgi?id=99950 + gcc.gnu.org/bugzilla/show_bug.cgi?id=94182 + */ + PL_fold_locale[ (U8) 'I' ] = 'I'; + PL_fold_locale[ (U8) 'i' ] = 'i'; + PL_in_utf8_turkic_locale = TRUE; + DEBUG_L(PerlIO_printf(Perl_debug_log, "%s is turkic\n", newctype)); + } + + /* If we found problems and we want them output, do so */ + if ( (UNLIKELY(bad_count)) + && (LIKELY(ckWARN_d(WARN_LOCALE)) || UNLIKELY(DEBUG_L_TEST))) + { + /* WARNING. If you change the wording of these; be sure to update + * t/loc_tools.pl correspondingly */ + + if (PL_warn_locale) { + sv_catpvs(PL_warn_locale, "\n"); + } + else { + PL_warn_locale = newSVpvs(""); + } + + if (PL_in_utf8_CTYPE_locale) { + Perl_sv_catpvf(aTHX_ PL_warn_locale, + "Locale '%s' contains (at least) the following characters" + " which have\nunexpected meanings: %s\nThe Perl program" + " will use the expected meanings", + newctype, bad_chars_list); + } + else { + Perl_sv_catpvf(aTHX_ PL_warn_locale, + "\nThe following characters (and maybe" + " others) may not have the same meaning as" + " the Perl program expects: %s\n", + bad_chars_list + ); + } + +# if defined(HAS_SOME_LANGINFO) || defined(WIN32) + + Perl_sv_catpvf(aTHX_ PL_warn_locale, "; codeset=%s", + langinfo_c(CODESET, LC_CTYPE, newctype, NULL)); + +# endif + + Perl_sv_catpvf(aTHX_ PL_warn_locale, "\n"); + + /* If we are actually in the scope of the locale or are debugging, + * output the message now. If not in that scope, we save the + * message to be output at the first operation using this locale, + * if that actually happens. Most programs don't use locales, so + * they are immune to bad ones. */ + if (IN_LC(LC_CTYPE) || UNLIKELY(DEBUG_L_TEST)) { + + /* The '0' below suppresses a bogus gcc compiler warning */ + Perl_warner(aTHX_ packWARN(WARN_LOCALE), SvPVX(PL_warn_locale), + 0); + if (IN_LC(LC_CTYPE)) { + SvREFCNT_dec_NN(PL_warn_locale); + PL_warn_locale = NULL; + } + } + } + } +} + +void +Perl_warn_problematic_locale() +{ + dTHX; + + /* Core-only function that outputs the message in PL_warn_locale, + * and then NULLS it. Should be called only through the macro + * CHECK_AND_WARN_PROBLEMATIC_LOCALE_ */ + + if (PL_warn_locale) { + Perl_ck_warner(aTHX_ packWARN(WARN_LOCALE), + SvPVX(PL_warn_locale), + 0 /* dummy to avoid compiler warning */ ); + SvREFCNT_dec_NN(PL_warn_locale); + PL_warn_locale = NULL; + } +} + +# endif /* USE_LOCALE_CTYPE */ + +STATIC void +S_new_LC_ALL(pTHX_ const char *lc_all, bool force) +{ + PERL_ARGS_ASSERT_NEW_LC_ALL; + + /* new_LC_ALL() updates all the things we care about. Note that this is + * called just after a change, so uses the actual underlying locale just + * set, and not the nominal one (should they differ, as they may in + * LC_NUMERIC). */ + + const char * individ_locales[LC_ALL_INDEX_] = { NULL }; + + switch (parse_LC_ALL_string(lc_all, + individ_locales, + override_if_ignored, /* Override any ignored + categories */ + true, /* Always fill array */ + true, /* Panic if fails, as to get here it + earlier had to have succeeded */ + __LINE__)) + { + case invalid: + case no_array: + case only_element_0: + locale_panic_("Unexpected return from parse_LC_ALL_string"); + + case full_array: + break; + } + + for_all_individual_category_indexes(i) { + if (update_functions[i]) { + const char * this_locale = individ_locales[i]; + update_functions[i](aTHX_ this_locale, force); + } + + Safefree(individ_locales[i]); + } +} + +# ifdef USE_LOCALE_COLLATE + +STATIC void +S_new_collate(pTHX_ const char *newcoll, bool force) +{ + PERL_ARGS_ASSERT_NEW_COLLATE; + PERL_UNUSED_ARG(force); + + /* Called after each libc setlocale() call affecting LC_COLLATE, to tell + * core Perl this and that 'newcoll' is the name of the new locale. + * + * The design of locale collation is that every locale change is given an + * index 'PL_collation_ix'. The first time a string participates in an + * operation that requires collation while locale collation is active, it + * is given PERL_MAGIC_collxfrm magic (via sv_collxfrm_flags()). That + * magic includes the collation index, and the transformation of the string + * by strxfrm(), q.v. That transformation is used when doing comparisons, + * instead of the string itself. If a string changes, the magic is + * cleared. The next time the locale changes, the index is incremented, + * and so we know during a comparison that the transformation is not + * necessarily still valid, and so is recomputed. Note that if the locale + * changes enough times, the index could wrap, and it is possible that a + * transformation would improperly be considered valid, leading to an + * unlikely bug. The value is declared to the widest possible type on this + * platform. */ + + /* Return if the locale isn't changing */ + if (strEQ(PL_collation_name, newcoll)) { + return; + } + + Safefree(PL_collation_name); + PL_collation_name = savepv(newcoll); + ++PL_collation_ix; + + /* Set the new one up if trivial. Since this is called at process + * initialization, be aware that this bit can't rely on much being + * available. */ + PL_collation_standard = isNAME_C_OR_POSIX(newcoll); + if (PL_collation_standard) { + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "Setting PL_collation name='%s'\n", + PL_collation_name)); + PL_collxfrm_base = 0; + PL_collxfrm_mult = 2; + PL_in_utf8_COLLATE_locale = FALSE; + PL_strxfrm_NUL_replacement = '\0'; + PL_strxfrm_max_cp = 0; + return; + } + + /* Flag that the remainder of the set up is being deferred until first + * need. */ + PL_collxfrm_mult = 0; + PL_collxfrm_base = 0; + +} + +# endif /* USE_LOCALE_COLLATE */ + +# ifdef WIN32 + +STATIC wchar_t * +S_Win_byte_string_to_wstring(const UINT code_page, const char * byte_string) +{ + /* Caller must arrange to free the returned string */ + + int req_size = MultiByteToWideChar(code_page, 0, byte_string, -1, NULL, 0); + if (! req_size) { + SET_EINVAL; + return NULL; + } + + wchar_t *wstring; + Newx(wstring, req_size, wchar_t); + + if (! MultiByteToWideChar(code_page, 0, byte_string, -1, wstring, req_size)) + { + Safefree(wstring); + SET_EINVAL; + return NULL; + } + + return wstring; +} + +# define Win_utf8_string_to_wstring(s) \ + Win_byte_string_to_wstring(CP_UTF8, (s)) + +STATIC char * +S_Win_wstring_to_byte_string(const UINT code_page, const wchar_t * wstring) +{ + /* Caller must arrange to free the returned string */ + + int req_size = + WideCharToMultiByte(code_page, 0, wstring, -1, NULL, 0, NULL, NULL); + + char *byte_string; + Newx(byte_string, req_size, char); + + if (! WideCharToMultiByte(code_page, 0, wstring, -1, byte_string, + req_size, NULL, NULL)) + { + Safefree(byte_string); + SET_EINVAL; + return NULL; + } + + return byte_string; +} + +# define Win_wstring_to_utf8_string(ws) \ + Win_wstring_to_byte_string(CP_UTF8, (ws)) + +STATIC const char * +S_wrap_wsetlocale(pTHX_ const int category, const char *locale) +{ + PERL_ARGS_ASSERT_WRAP_WSETLOCALE; + + /* Calls _wsetlocale(), converting the parameters/return to/from + * Perl-expected forms as if plain setlocale() were being called instead. + * + * Caller must arrange for the returned PV to be freed. + */ + + const wchar_t * wlocale = NULL; + + if (locale) { + wlocale = Win_utf8_string_to_wstring(locale); + if (! wlocale) { + return NULL; + } + } + + WSETLOCALE_LOCK; + const wchar_t * wresult = _wsetlocale(category, wlocale); + + if (! wresult) { + WSETLOCALE_UNLOCK; + Safefree(wlocale); + return NULL; + } + + const char * result = Win_wstring_to_utf8_string(wresult); + WSETLOCALE_UNLOCK; + + Safefree(wlocale); + return result; +} + +STATIC const char * +S_win32_setlocale(pTHX_ int category, const char* locale) +{ + /* This, for Windows, emulates POSIX setlocale() behavior. There is no + * difference between the two unless the input locale is "", which normally + * means on Windows to get the machine default, which is set via the + * computer's "Regional and Language Options" (or its current equivalent). + * In POSIX, it instead means to find the locale from the user's + * environment. This routine changes the Windows behavior to try the POSIX + * behavior first. Further details are in the called function + * find_locale_from_environment(). + */ + + if (locale != NULL && strEQ(locale, "")) { + /* Note this function may change the locale, but that's ok because we + * are about to change it anyway */ + locale = find_locale_from_environment(get_category_index(category)); + if (locale == NULL) { + SET_EINVAL; + return NULL; + } + } + + const char * result = wrap_wsetlocale(category, locale); + DEBUG_L(PerlIO_printf(Perl_debug_log, "%s\n", + setlocale_debug_string_r(category, locale, result))); + + if (! result) { + SET_EINVAL; + return NULL; + } + + save_to_buffer(result, &PL_setlocale_buf, &PL_setlocale_bufsize); + +# ifndef USE_PL_CUR_LC_ALL + + Safefree(result); + +# else + + /* Here, we need to keep track of LC_ALL, so store the new value. but if + * the input locale is NULL, we were just querying, so the original value + * hasn't changed */ + if (locale == NULL) { + Safefree(result); + } + else { + + /* If we set LC_ALL directly above, we already know its new value; but + * if we changed just an individual category, find the new LC_ALL */ + if (category != LC_ALL) { + Safefree(result); + result = wrap_wsetlocale(LC_ALL, NULL); + } + + Safefree(PL_cur_LC_ALL); + PL_cur_LC_ALL = result; + } + + DEBUG_L(PerlIO_printf(Perl_debug_log, "new PL_cur_LC_ALL=%s\n", + PL_cur_LC_ALL)); +# endif + + return PL_setlocale_buf; +} + +# endif + +STATIC const char * +S_native_querylocale_i(pTHX_ const locale_category_index cat_index) +{ + /* Determine the current locale and return it in the form the platform's + * native locale handling understands. This is different only from our + * internal form for the LC_ALL category, as platforms differ in how they + * represent that. + * + * This is only called from Perl_setlocale(). As such it returns in + * PL_setlocale_buf */ + +# ifdef USE_LOCALE_NUMERIC + + /* We have the LC_NUMERIC name saved, because we are normally switched into + * the C locale (or equivalent) for it. */ + if (cat_index == LC_NUMERIC_INDEX_) { + + /* We don't have to copy this return value, as it is a per-thread + * variable, and won't change until a future setlocale */ + return PL_numeric_name; + } + +# endif +# ifdef LC_ALL + + if (cat_index != LC_ALL_INDEX_) + +# endif + + { + /* Here, not LC_ALL, and not LC_NUMERIC: the actual and native values + * match */ + +# ifdef setlocale_i /* Can shortcut if this is defined */ + + return setlocale_i(cat_index, NULL); + +# else + + return save_to_buffer(querylocale_i(cat_index), + &PL_setlocale_buf, &PL_setlocale_bufsize); +# endif + + } + + /* Below, querying LC_ALL */ + +# ifdef LC_ALL +# ifdef USE_PL_CURLOCALES +# define LC_ALL_ARG PL_curlocales +# else +# define LC_ALL_ARG NULL /* Causes calculate_LC_ALL_string() to find the + locale using a querylocale function */ +# endif + + return calculate_LC_ALL_string(LC_ALL_ARG, EXTERNAL_FORMAT_FOR_QUERY, + WANT_PL_setlocale_buf, + __LINE__); +# undef LC_ALL_ARG +# endif /* has LC_ALL */ + +} + +#endif /* USE_LOCALE */ + +/* +=for apidoc Perl_setlocale + +This is an (almost) drop-in replacement for the system L>, +taking the same parameters, and returning the same information, except that it +returns the correct underlying C locale. Regular C will +instead return C if the underlying locale has a non-dot decimal point +character, or a non-empty thousands separator for displaying floating point +numbers. This is because perl keeps that locale category such that it has a +dot and empty separator, changing the locale briefly during the operations +where the underlying one is required. C knows about this, and +compensates; regular C doesn't. + +Another reason it isn't completely a drop-in replacement is that it is +declared to return S>, whereas the system setlocale omits the +C (presumably because its API was specified long ago, and can't be +updated; it is illegal to change the information C returns; doing +so leads to segfaults.) + +Finally, C works under all circumstances, whereas plain +C can be completely ineffective on some platforms under some +configurations. + +Changing the locale is not a good idea when more than one thread is running, +except on systems where the predefined variable C<${^SAFE_LOCALES}> is +non-zero. This is because on such systems the locale is global to the whole +process and not local to just the thread calling the function. So changing it +in one thread instantaneously changes it in all. On some such systems, the +system C is ineffective, returning the wrong information, and +failing to actually change the locale. z/OS refuses to try to change the +locale once a second thread is created. C, should give you +accurate results of what actually happened on these problematic platforms, +returning NULL if the system forbade the locale change. + +The return points to a per-thread static buffer, which is overwritten the next +time C is called from the same thread. + +=cut + +*/ + +const char * +Perl_setlocale(const int category, const char * locale) +{ + /* This wraps POSIX::setlocale() */ + +#ifndef USE_LOCALE + + PERL_UNUSED_ARG(category); + PERL_UNUSED_ARG(locale); + + return "C"; + +#else + + dTHX; + + DEBUG_L(PerlIO_printf(Perl_debug_log, + "Entering Perl_setlocale(%d, \"%s\")\n", + category, locale)); + + bool valid_category; + locale_category_index cat_index = get_category_index_helper(category, + &valid_category, + __LINE__); + if (! valid_category) { + if (ckWARN(WARN_LOCALE)) { + const char * conditional_warn_text; + if (locale == NULL) { + conditional_warn_text = ""; + locale = ""; + } + else { + conditional_warn_text = "; can't set it to "; + } + + /* diag_listed_as: Unknown locale category %d; can't set it to %s */ + Perl_warner(aTHX_ + packWARN(WARN_LOCALE), + "Unknown locale category %d%s%s", + category, conditional_warn_text, locale); + } + + SET_EINVAL; + return NULL; + } + +# ifdef setlocale_i + + /* setlocale_i() gets defined only on Configurations that use setlocale() + * in a simple manner that adequately handles all cases. If this category + * doesn't have any perl complications, just do that. */ + if (! update_functions[cat_index]) { + return setlocale_i(cat_index, locale); + } + +# endif + + /* Get current locale */ + const char * current_locale = native_querylocale_i(cat_index); + + /* A NULL locale means only query what the current one is. */ + if (locale == NULL) { + return current_locale; + } + + if (strEQ(current_locale, locale)) { + DEBUG_L(PerlIO_printf(Perl_debug_log, + "Already in requested locale: no action taken\n")); + return current_locale; + } + + /* Here, an actual change is being requested. Do it */ + if (! bool_setlocale_i(cat_index, locale)) { + DEBUG_L(PerlIO_printf(Perl_debug_log, "%s\n", + setlocale_debug_string_i(cat_index, locale, "NULL"))); + return NULL; + } + + /* At this point, the locale has been changed based on the requested value, + * and the querylocale_i() will return the actual new value that the system + * has for the category. That may not be the same as the input, as libc + * may have returned a synonymous locale name instead of the input one; or, + * if there are locale categories that we are compiled to ignore, any + * attempt to change them away from "C" is overruled */ + current_locale = querylocale_i(cat_index); + + /* But certain categories need further work. For example we may need to + * calculate new folding or collation rules. And for LC_NUMERIC, we have + * to switch into a locale that has a dot radix. */ + if (update_functions[cat_index]) { + update_functions[cat_index](aTHX_ current_locale, + /* No need to force recalculation, as + * aren't coming from a situation + * where Perl hasn't been controlling + * the locale, so has accurate + * records. */ + false); + } + + /* Make sure the result is in a stable buffer for the caller's use, and is + * in the expected format */ + current_locale = native_querylocale_i(cat_index); + + DEBUG_L(PerlIO_printf(Perl_debug_log, "returning '%s'\n", current_locale)); + + return current_locale; + +#endif + +} + +#ifdef USE_LOCALE +# ifdef DEBUGGING + +STATIC char * +S_my_setlocale_debug_string_i(pTHX_ + const locale_category_index cat_index, + const char* locale, /* Optional locale name */ + + /* return value from setlocale() when attempting + * to set 'category' to 'locale' */ + const char* retval, + + const line_t line) +{ + /* Returns a pointer to a NUL-terminated string in static storage with + * added text about the info passed in. This is not thread safe and will + * be overwritten by the next call, so this should be used just to + * formulate a string to immediately print or savepv() on. */ + + const char * locale_quote; + const char * retval_quote; + + if (locale == NULL) { + locale_quote = ""; + locale = "NULL"; + } + else { + locale_quote = "\""; + } + + if (retval == NULL) { + retval_quote = ""; + retval = "NULL"; + } + else { + retval_quote = "\""; + } + +# ifdef MULTIPLICITY +# define THREAD_FORMAT "%p:" +# define THREAD_ARGUMENT aTHX_ +# else +# define THREAD_FORMAT +# define THREAD_ARGUMENT +# endif + + return Perl_form(aTHX_ + "%s:%" LINE_Tf ": " THREAD_FORMAT + " setlocale(%s[%d], %s%s%s) returned %s%s%s\n", + + __FILE__, line, THREAD_ARGUMENT + category_names[cat_index], categories[cat_index], + locale_quote, locale, locale_quote, + retval_quote, retval, retval_quote); +} + +# endif + +/* If this implementation hasn't defined these macros, they aren't needed */ +# ifndef TOGGLE_LOCK +# define TOGGLE_LOCK(i) +# define TOGGLE_UNLOCK(i) +# endif + +STATIC const char * +S_toggle_locale_i(pTHX_ const locale_category_index cat_index, + const char * new_locale, + const line_t caller_line) +{ + PERL_ARGS_ASSERT_TOGGLE_LOCALE_I; + + /* Changes the locale for the category specified by 'index' to 'new_locale, + * if they aren't already the same. EVERY CALL to this function MUST HAVE + * a corresponding call to restore_toggled_locale_i() + * + * Returns a copy of the name of the original locale for 'cat_index' + * so can be switched back to with the companion function + * restore_toggled_locale_i(), (NULL if no restoral is necessary.) */ + + /* Find the original locale of the category we may need to change, so that + * it can be restored to later */ + const char * locale_to_restore_to = querylocale_i(cat_index); + + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "Entering toggle_locale_i: index=%d(%s)," \ + " wanted=%s, actual=%s; called from %" LINE_Tf \ + "\n", cat_index, category_names[cat_index], + new_locale, locale_to_restore_to ? locale_to_restore_to : "(null)", + caller_line)); + + if (! locale_to_restore_to) { + locale_panic_via_(Perl_form(aTHX_ + "Could not find current %s locale", + category_names[cat_index]), + __FILE__, caller_line); + } + + /* Begin a critical section on platforms that need it. We do this even if + * we don't have to change here, so as to prevent other instances from + * changing the locale out from under us. */ + TOGGLE_LOCK(cat_index); + + /* If the locales are the same, there's nothing to do */ + if (strEQ(locale_to_restore_to, new_locale)) { + DEBUG_Lv(PerlIO_printf(Perl_debug_log, "%s locale unchanged as %s\n", + category_names[cat_index], + new_locale)); + return NULL; + } + + /* Finally, change the locale to the new one */ + void_setlocale_i_with_caller(cat_index, new_locale, __FILE__, caller_line); + + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "%s locale switched to %s\n", + category_names[cat_index], new_locale)); + + return locale_to_restore_to; + +# ifndef DEBUGGING + PERL_UNUSED_ARG(caller_line); +# endif + +} + +STATIC void +S_restore_toggled_locale_i(pTHX_ const locale_category_index cat_index, + const char * restore_locale, + const line_t caller_line) +{ + /* Restores the locale for LC_category corresponding to cat_index to + * 'restore_locale' (which is a copy that will be freed by this function), + * or do nothing if the latter parameter is NULL */ + + PERL_ARGS_ASSERT_RESTORE_TOGGLED_LOCALE_I; + + if (restore_locale == NULL) { + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "restore_toggled_locale_i: No need to" \ + " restore %s; called from %" LINE_Tf "\n", \ + category_names[cat_index], caller_line)); + TOGGLE_UNLOCK(cat_index); + return; + } + + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "restore_toggled_locale_i: restoring locale for" \ + " %s to %s; called from %" LINE_Tf "\n", \ + category_names[cat_index], restore_locale, + caller_line)); + + void_setlocale_i_with_caller(cat_index, restore_locale, + __FILE__, caller_line); + TOGGLE_UNLOCK(cat_index); + +# ifndef DEBUGGING + PERL_UNUSED_ARG(caller_line); +# endif + +} + +#endif +#if defined(USE_LOCALE) || defined(HAS_SOME_LANGINFO) || defined(HAS_LOCALECONV) + +STATIC utf8ness_t +S_get_locale_string_utf8ness_i(pTHX_ const char * string, + const locale_utf8ness_t known_utf8, + const char * locale, + const locale_category_index cat_index) +{ + PERL_ARGS_ASSERT_GET_LOCALE_STRING_UTF8NESS_I; + +# ifndef USE_LOCALE + + return UTF8NESS_NO; + PERL_UNUSED_ARG(string); + PERL_UNUSED_ARG(known_utf8); + PERL_UNUSED_ARG(locale); + PERL_UNUSED_ARG(cat_index); + +# else + + /* Return to indicate if 'string' in the locale given by the input + * arguments should be considered UTF-8 or not. + * + * If the input 'locale' is not NULL, use that for the locale; otherwise + * use the current locale for the category specified by 'cat_index'. + */ + + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "Entering get_locale_string_utf8ness_i; locale=%s," + " index=%u(%s), string=%s, known_utf8=%d\n", + locale, cat_index, category_names[cat_index], + ((string) + ? _byte_dump_string((U8 *) string, + strlen(string), + 0) + : "nil"), + known_utf8)); + if (string == NULL) { + return UTF8NESS_IMMATERIAL; + } + + if (IN_BYTES) { /* respect 'use bytes' */ + return UTF8NESS_NO; + } + + Size_t len = strlen(string); + + /* UTF8ness is immaterial if the representation doesn't vary */ + const U8 * first_variant = NULL; + if (is_utf8_invariant_string_loc((U8 *) string, len, &first_variant)) { + return UTF8NESS_IMMATERIAL; + } + + /* Can't be UTF-8 if invalid */ + if (! is_strict_utf8_string((U8 *) first_variant, + len - ((char *) first_variant - string))) + { + return UTF8NESS_NO; + } + + /* Here and below, we know the string is legal UTF-8, containing at least + * one character requiring a sequence of two or more bytes. It is quite + * likely to be UTF-8. But it pays to be paranoid and do further checking. + * + * If we already know the UTF-8ness of the locale, then we immediately know + * what the string is */ + if (UNLIKELY(known_utf8 != LOCALE_UTF8NESS_UNKNOWN)) { + return (known_utf8 == LOCALE_IS_UTF8) ? UTF8NESS_YES : UTF8NESS_NO; + } + + if (locale == NULL) { + locale = querylocale_i(cat_index); + } + + /* If the locale is UTF-8, the string is UTF-8; otherwise it was + * coincidental that the string is legal UTF-8 + * + * However, if the perl is compiled to not pay attention to the category + * being passed in, you might think that that locale is essentially always + * the C locale, so it would make sense to say it isn't UTF-8. But to get + * here, the string has to contain characters unknown in the C locale. And + * in fact, Windows boxes are compiled without LC_MESSAGES, as their + * message catalog isn't really a part of the locale system. But those + * messages really could be UTF-8, and given that the odds are rather small + * of something not being UTF-8 but being syntactically valid UTF-8, khw + * has decided to call such strings as UTF-8. */ + return (is_locale_utf8(locale)) ? UTF8NESS_YES : UTF8NESS_NO; + +# endif + +} + +STATIC bool +S_is_locale_utf8(pTHX_ const char * locale) +{ + PERL_ARGS_ASSERT_IS_LOCALE_UTF8; + + /* Returns TRUE if the locale 'locale' is UTF-8; FALSE otherwise. */ + +# if ! defined(USE_LOCALE) \ + || ! defined(USE_LOCALE_CTYPE) \ + || defined(EBCDIC) /* There aren't any real UTF-8 locales at this time */ + + PERL_UNUSED_ARG(locale); + + return FALSE; + + /* Definitively, can't be UTF-8 */ +# define HAS_DEFINITIVE_UTF8NESS_DETERMINATION +# else + + /* If the input happens to be the same locale as we are currently setup + * for, the answer has already been cached. */ + if (strEQ(locale, PL_ctype_name)) { + return PL_in_utf8_CTYPE_locale; + } + + if (isNAME_C_OR_POSIX(locale)) { + return false; + } + +# if ! defined(HAS_SOME_LANGINFO) && ! defined(WIN32) + + /* On non-Windows without nl_langinfo(), we have to do some digging to get + * the answer. First, toggle to the desired locale so can query its state + * */ + const char * orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, locale); + +# define TEARDOWN_FOR_IS_LOCALE_UTF8 \ + restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale) + +# ifdef MB_CUR_MAX + + /* If there are fewer bytes available in this locale than are required + * to represent the largest legal UTF-8 code point, this isn't a UTF-8 + * locale. */ + const int mb_cur_max = MB_CUR_MAX; + if (mb_cur_max < (int) UNISKIP(PERL_UNICODE_MAX)) { + TEARDOWN_FOR_IS_LOCALE_UTF8; + return false; + } + +# endif +# if defined(HAS_MBTOWC) || defined(HAS_MBRTOWC) + + /* With these functions, we can definitively determine a locale's + * UTF-8ness */ +# define HAS_DEFINITIVE_UTF8NESS_DETERMINATION + + /* If libc mbtowc() evaluates the bytes that form the REPLACEMENT CHARACTER + * as that Unicode code point, this has to be a UTF-8 locale; otherwise it + * can't be */ + wchar_t wc = 0; + (void) Perl_mbtowc_(aTHX_ NULL, NULL, 0);/* Reset shift state */ + int mbtowc_ret = Perl_mbtowc_(aTHX_ &wc, + STR_WITH_LEN(REPLACEMENT_CHARACTER_UTF8)); + TEARDOWN_FOR_IS_LOCALE_UTF8; + return ( mbtowc_ret == STRLENs(REPLACEMENT_CHARACTER_UTF8) + && wc == UNICODE_REPLACEMENT); + +# else + + /* If the above two C99 functions aren't working, you could try some + * different methods. It seems likely that the obvious choices, + * wctomb() and wcrtomb(), wouldn't be working either. But you could + * choose one of the dozen-ish Unicode titlecase triples and verify + * that towupper/towlower work as expected. + * + * But, our emulation of nl_langinfo() works quite well, so avoid the + * extra code until forced to by some weird non-conforming platform. */ +# define USE_LANGINFO_FOR_UTF8NESS +# undef HAS_DEFINITIVE_UTF8NESS_DETERMINATION +# endif +# else + + /* On Windows or on platforms with nl_langinfo(), there is a direct way to + * get the locale's codeset, which will be some form of 'UTF-8' for a + * UTF-8 locale. langinfo_c() handles this, and we will call that + * below */ +# define HAS_DEFINITIVE_UTF8NESS_DETERMINATION +# define USE_LANGINFO_FOR_UTF8NESS +# define TEARDOWN_FOR_IS_LOCALE_UTF8 +# endif /* USE_LANGINFO_FOR_UTF8NESS */ + + /* If the above compiled into code, it found the locale's UTF-8ness, + * nothing more to do; if it didn't get compiled, + * USE_LANGINFO_FOR_UTF8NESS is defined. There are two possible reasons: + * 1) it is the preferred method because it knows directly for sure + * what the codeset is because the platform has libc functions that + * return this; or + * 2) the functions the above code section would compile to use don't + * exist or are unreliable on this platform; we are less sure of the + * langinfo_c() result, though it is very unlikely to be wrong + * about if it is UTF-8 or not */ +# ifdef USE_LANGINFO_FOR_UTF8NESS + + const char * codeset = langinfo_c(CODESET, LC_CTYPE, locale, NULL); + bool retval = is_codeset_name_UTF8(codeset); + + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "found codeset=%s, is_utf8=%d\n", codeset, retval)); + DEBUG_Lv(PerlIO_printf(Perl_debug_log, "is_locale_utf8(%s) returning %d\n", + locale, retval)); + TEARDOWN_FOR_IS_LOCALE_UTF8; + return retval; + +# endif +# endif /* End of the #else clause, for the non-trivial case */ + +} + +#endif + +#ifdef USE_LOCALE +# ifdef USE_LOCALE_CTYPE + +STATIC bool +S_is_codeset_name_UTF8(const char * name) +{ + /* Return a boolean as to if the passed-in name indicates it is a UTF-8 + * code set. Several variants are possible */ + const Size_t len = strlen(name); + + PERL_ARGS_ASSERT_IS_CODESET_NAME_UTF8; + +# ifdef WIN32 + + /* https://learn.microsoft.com/en-us/windows/win32/intl/code-page-identifiers */ + if (memENDs(name, len, "65001")) { + return TRUE; + } + +# endif + /* 'UTF8' or 'UTF-8' */ + return ( inRANGE(len, 4, 5) + && name[len-1] == '8' + && ( memBEGINs(name, len, "UTF") + || memBEGINs(name, len, "utf")) + && (len == 4 || name[3] == '-')); +} + +# endif +# ifdef WIN32 + +bool +Perl_get_win32_message_utf8ness(pTHX_ const char * string) +{ + /* This is because Windows doesn't have LC_MESSAGES. */ + +# ifdef USE_LOCALE_CTYPE + + /* We don't know the locale utf8ness here, and not even the locale itself. + * Since Windows uses a different mechanism to specify message language + * output than the locale system, it is going to be problematic deciding + * if we are to store it as UTF-8 or not. By specifying LOCALE_IS_UTF8, we + * are telling the called function to return true iff the string has + * non-ASCII characters in it that are all syntactically UTF-8. We are + * thus relying on the fact that a string that is syntactically valid UTF-8 + * is likely to be UTF-8. Should this ever cause problems, this function + * could be replaced by something more Windows-specific */ + return get_locale_string_utf8ness_i(string, LOCALE_IS_UTF8, + NULL, LC_CTYPE_INDEX_); +# else + + PERL_UNUSED_ARG(string); + return false; + +# endif + +} + +# endif + +STATIC void +S_set_save_buffer_min_size(pTHX_ Size_t min_len, + char **buf, + Size_t * buf_cursize) +{ + /* Make sure the buffer pointed to by *buf is at least as large 'min_len'; + * *buf_cursize is the size of 'buf' upon entry; it will be updated to the + * new size on exit. 'buf_cursize' being NULL is to be used when this is a + * single use buffer, which will shortly be freed by the caller. */ + + if (buf_cursize == NULL) { + Newx(*buf, min_len, char); + } + else if (*buf_cursize == 0) { + Newx(*buf, min_len, char); + *buf_cursize = min_len; + } + else if (min_len > *buf_cursize) { + Renew(*buf, min_len, char); + *buf_cursize = min_len; + } +} + +STATIC const char * +S_save_to_buffer(pTHX_ const char * string, char **buf, Size_t *buf_size) +{ + PERL_ARGS_ASSERT_SAVE_TO_BUFFER; + + /* Copy the NUL-terminated 'string' to a buffer whose address before this + * call began at *buf, and whose available length before this call was + * *buf_size. + * + * If the length of 'string' is greater than the space available, the + * buffer is grown accordingly, which may mean that it gets relocated. + * *buf and *buf_size will be updated to reflect this. + * + * Regardless, the function returns a pointer to where 'string' is now + * stored. + * + * 'string' may be NULL, which means no action gets taken, and NULL is + * returned. + * + * 'buf_size' being NULL is to be used when this is a single use buffer, + * which will shortly be freed by the caller. + * + * If *buf or 'buf_size' are NULL or *buf_size is 0, the buffer is assumed + * empty, and memory is malloc'd. + */ + + if (! string) { + return NULL; + } + + /* No-op to copy over oneself */ + if (string == *buf) { + return string; + } + + Size_t string_size = strlen(string) + 1; + set_save_buffer_min_size(string_size, buf, buf_size); + +# ifdef DEBUGGING + + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "Copying '%s' to %p\n", + ((is_strict_utf8_string((U8 *) string, 0)) + ? string + :_byte_dump_string((U8 *) string, strlen(string), 0)), + *buf)); + +# ifdef USE_LOCALE_CTYPE + + /* Catch glitches. Usually this is because LC_CTYPE needs to be the same + * locale as whatever is being worked on */ + if (UNLIKELY(instr(string, REPLACEMENT_CHARACTER_UTF8))) { + locale_panic_(Perl_form(aTHX_ + "Unexpected REPLACEMENT_CHARACTER in '%s'\n%s", + string, get_LC_ALL_display())); + } + +# endif +# endif + + Copy(string, *buf, string_size, char); + return *buf; +} + +#endif + +int +Perl_mbtowc_(pTHX_ const wchar_t * pwc, const char * s, const Size_t len) +{ + +#if ! defined(HAS_MBRTOWC) && ! defined(HAS_MBTOWC) + + PERL_UNUSED_ARG(pwc); + PERL_UNUSED_ARG(s); + PERL_UNUSED_ARG(len); + return -1; + +#else /* Below we have some form of mbtowc() */ +# if defined(HAS_MBRTOWC) \ + && (defined(MULTIPLICITY) || ! defined(HAS_MBTOWC)) +# define USE_MBRTOWC +# else +# undef USE_MBRTOWC +# endif + + CHECK_AND_WARN_PROBLEMATIC_LOCALE_; + int retval = -1; + + if (s == NULL) { /* Initialize the shift state to all zeros in + PL_mbrtowc_ps. */ + +# if defined(USE_MBRTOWC) + + memzero(&PL_mbrtowc_ps, sizeof(PL_mbrtowc_ps)); + return 0; + +# else + + SETERRNO(0, 0); + MBTOWC_LOCK_; + retval = mbtowc(NULL, NULL, 0); + MBTOWC_UNLOCK_; + return retval; + +# endif + + } + +# if defined(USE_MBRTOWC) + + SETERRNO(0, 0); + MBRTOWC_LOCK_; + retval = (SSize_t) mbrtowc((wchar_t *) pwc, s, len, &PL_mbrtowc_ps); + MBRTOWC_UNLOCK_; + +# else + + /* Locking prevents races, but locales can be switched out without locking, + * so this isn't a cure all */ + SETERRNO(0, 0); + MBTOWC_LOCK_; + retval = mbtowc((wchar_t *) pwc, s, len); + MBTOWC_UNLOCK_; + +# endif + + return retval; + +#endif + +} + +/* +=for apidoc Perl_localeconv + +This is a thread-safe version of the libc L. It is the same as +L (returning a hash of the C +fields), but directly callable from XS code. The hash is mortalized, so must +be dealt with immediately. + +=cut +*/ + +/* All Wndows versions we support, except possibly MingW, have general + * thread-safety, and even localeconv() is thread safe, returning into a + * per-thread buffer. MingW when built with a modern MS C runtime (UCRT as of + * this writing), also has those things. + * + * FreeBSD's localeconv() when used with uselocale() is supposed to be + * thread-safe (as is their localeconv_l()), but we currently don't use + * thread-safe locales there because of bugs. There may be other thread-safe + * localeconv() implementations, especially on *BSD derivatives, but khw knows + * of none, and hasn't really investigated, in part because of the past + * unreliability of vendor thread-safety claims */ +#if defined(WIN32) && (defined(_MSC_VER) || (defined(_UCRT))) +# define LOCALECONV_IS_THREAD_SAFE +#endif + +/* When multiple threads can be going at once, we need a critical section + * around doing the localeconv() and saving its return, unless localeconv() is + * thread-safe, and we are using it in a thread-safe manner, which we are only + * doing if safe threads are available and we don't have a broken localeconv() + * */ +#if defined(USE_THREADS) \ + && ( ! defined(LOCALECONV_IS_THREAD_SAFE) \ + || ! defined(USE_THREAD_SAFE_LOCALE) \ + || defined(TS_W32_BROKEN_LOCALECONV)) +# define LOCALECONV_NEEDS_CRITICAL_SECTION +#endif + +HV * +Perl_localeconv(pTHX) +{ + return (HV *) sv_2mortal((SV *) my_localeconv(0)); +} + +HV * +S_my_localeconv(pTHX_ const int item) +{ + PERL_ARGS_ASSERT_MY_LOCALECONV; + + /* This returns a mortalized hash containing all or certain elements + * returned by localeconv(). */ + HV * hv = newHV(); /* The returned hash, initially empty */ + + /* The function is used by Perl_localeconv() and POSIX::localeconv(), or + * internally from this file, and is thread-safe. + * + * localeconv() returns items from two different locale categories, + * LC_MONETARY and LC_NUMERIC. Various data structures in this function + * are arrays with two elements, one for each category, and these indexes + * indicate which array element applies to which category */ +#define NUMERIC_OFFSET 0 +#define MONETARY_OFFSET 1 + + /* Some operations apply to one or the other category, or both. A mask + * is used to specify all the possibilities. This macro converts from the + * category offset to its bit position in the mask. */ +#define OFFSET_TO_BIT(i) (1 << (i)) + + /* There are two use cases for this function: + * 1) Called as Perl_localeconv(), or from POSIX::locale_conv(). This + * returns the lconv structure copied to a hash, based on the current + * underlying locales for LC_NUMERIC and LC_MONETARY. An input item==0 + * signifies this case, or on many platforms it is the only use case + * compiled. + * 2) Certain items that nl_langinfo() provides are also derivable from + * the return of localeconv(). Windows notably doesn't have + * nl_langinfo(), so on that, and actually any platform lacking it, + * my_localeconv() is used also to emulate it for those particular + * items. The code to do this is compiled only on such platforms. + * Rather than going to the expense of creating a full hash when only + * one item is needed, the returned hash has just the desired item in + * it. + * + * To access all the localeconv() struct lconv fields, there is a data + * structure that contains every commonly documented field in it. (Maybe + * some minority platforms have extra fields. Those could be added here + * without harm; they would just be ignored on platforms lacking them.) + * + * Our structure is compiled to make looping through the fields easier by + * pointing each name to its value's offset within lconv, e.g., + { "thousands_sep", STRUCT_OFFSET(struct lconv, thousands_sep) } + */ +#define LCONV_ENTRY(name) {STRINGIFY(name), STRUCT_OFFSET(struct lconv, name)} + + /* These synonyms are just for clarity, and to make it easier in case + * something needs to change in the future */ +#define LCONV_NUMERIC_ENTRY(name) LCONV_ENTRY(name) +#define LCONV_MONETARY_ENTRY(name) LCONV_ENTRY(name) + + /* There are just a few fields for NUMERIC strings */ + const lconv_offset_t lconv_numeric_strings[] = { +#ifndef NO_LOCALECONV_GROUPING + LCONV_NUMERIC_ENTRY(grouping), +# endif + LCONV_NUMERIC_ENTRY(thousands_sep), +# define THOUSANDS_SEP_LITERAL "thousands_sep" + LCONV_NUMERIC_ENTRY(decimal_point), +# define DECIMAL_POINT_LITERAL "decimal_point" + {NULL, 0} + }; + + /* When used to implement nl_langinfo(), we save time by only populating + * the hash with the field(s) needed. Thus we would need a data structure + * of just: + * LCONV_NUMERIC_ENTRY(decimal_point), + * {NULL, 0} + * + * By placing the decimal_point field last in the full structure, we can + * use just the tail for this bit of it, saving space. This macro yields + * the address of the sub structure. */ +#define DECIMAL_POINT_ADDRESS \ + &lconv_numeric_strings[(C_ARRAY_LENGTH(lconv_numeric_strings) - 2)] + + /* And the MONETARY string fields */ + const lconv_offset_t lconv_monetary_strings[] = { + LCONV_MONETARY_ENTRY(int_curr_symbol), + LCONV_MONETARY_ENTRY(mon_decimal_point), +#ifndef NO_LOCALECONV_MON_THOUSANDS_SEP + LCONV_MONETARY_ENTRY(mon_thousands_sep), +#endif +#ifndef NO_LOCALECONV_MON_GROUPING + LCONV_MONETARY_ENTRY(mon_grouping), +#endif + LCONV_MONETARY_ENTRY(positive_sign), + LCONV_MONETARY_ENTRY(negative_sign), + LCONV_MONETARY_ENTRY(currency_symbol), +#define CURRENCY_SYMBOL_LITERAL "currency_symbol" + {NULL, 0} + }; + + /* Like above, this field being last can be used as a sub structure */ +#define CURRENCY_SYMBOL_ADDRESS \ + &lconv_monetary_strings[(C_ARRAY_LENGTH(lconv_monetary_strings) - 2)] + + /* Finally there are integer fields, all are for monetary purposes */ + const lconv_offset_t lconv_integers[] = { + LCONV_ENTRY(int_frac_digits), + LCONV_ENTRY(frac_digits), + LCONV_ENTRY(p_sep_by_space), + LCONV_ENTRY(n_cs_precedes), + LCONV_ENTRY(n_sep_by_space), + LCONV_ENTRY(p_sign_posn), + LCONV_ENTRY(n_sign_posn), +#ifdef HAS_LC_MONETARY_2008 + LCONV_ENTRY(int_p_cs_precedes), + LCONV_ENTRY(int_p_sep_by_space), + LCONV_ENTRY(int_n_cs_precedes), + LCONV_ENTRY(int_n_sep_by_space), + LCONV_ENTRY(int_p_sign_posn), + LCONV_ENTRY(int_n_sign_posn), +#endif +# define P_CS_PRECEDES_LITERAL "p_cs_precedes" + LCONV_ENTRY(p_cs_precedes), + {NULL, 0} + }; + + /* Like above, this field being last can be used as a sub structure */ +#define P_CS_PRECEDES_ADDRESS \ + &lconv_integers[(C_ARRAY_LENGTH(lconv_integers) - 2)] + + /* The actual populating of the hash is done by two sub functions that get + * passed an array of length two containing the data structure they are + * supposed to use to get the key names to fill the hash with. One element + * is always for the NUMERIC strings (or NULL if none to use), and the + * other element similarly for the MONETARY ones. */ + const lconv_offset_t * strings[2] = { lconv_numeric_strings, + lconv_monetary_strings + }; + + /* The LC_MONETARY category also has some integer-valued fields, whose + * information is kept in a separate parallel array to 'strings' */ + const lconv_offset_t * integers[2] = { + NULL, + lconv_integers + }; + +#if ! defined(HAS_LOCALECONV) \ + || (! defined(USE_LOCALE_NUMERIC) && ! defined(USE_LOCALE_MONETARY)) + + /* If both NUMERIC and MONETARY must be the "C" locale, simply populate the + * hash using the function that works on just that locale. */ + populate_hash_from_C_localeconv(hv, + "C", + ( OFFSET_TO_BIT(NUMERIC_OFFSET) + | OFFSET_TO_BIT(MONETARY_OFFSET)), + strings, integers); + + /* We shouldn't get to here for the case of an individual item, as + * preprocessor directives elsewhere in this file should have filled in the + * correct values at a higher level */ + assert(item == 0); + PERL_UNUSED_ARG(item); + + return hv; + +#else + + /* From here to the end of this function, at least one of NUMERIC or + * MONETARY can be non-C */ + + /* This is a mask, with one bit to tell the populate functions to populate + * the NUMERIC items; another bit for the MONETARY ones. This way they can + * choose which (or both) to populate from */ + U32 index_bits = 0; + + /* Some platforms, for correct non-mojibake results, require LC_CTYPE's + * locale to match LC_NUMERIC's for the numeric fields, and LC_MONETARY's + * for the monetary ones. What happens if LC_NUMERIC and LC_MONETARY + * aren't compatible? Wrong results. To avoid that, we call localeconv() + * twice, once for each locale, setting LC_CTYPE to match the category. + * But if the locales of both categories are the same, there is no need for + * a second call. Assume this is the case unless overridden below */ + bool requires_2nd_localeconv = false; - /* Return if the locale isn't changing */ - if (strEQ(PL_collation_name, newcoll)) { - return; - } + /* The actual hash populating is done by one of the two populate functions. + * Which one is appropriate for either the MONETARY_OFFSET or the + * NUMERIC_OFFSET is calculated and then stored in this table */ + void (*populate[2]) (pTHX_ + HV * , + const char *, + const U32, + const lconv_offset_t **, + const lconv_offset_t **); + + /* This gives the locale to use for the corresponding OFFSET, like the + * 'populate' array above */ + const char * locales[2]; - Safefree(PL_collation_name); - PL_collation_name = savepv(newcoll); - ++PL_collation_ix; +# ifdef HAS_SOME_LANGINFO - /* Set the new one up if trivial. Since this is called at process - * initialization, be aware that this bit can't rely on much being - * available. */ - PL_collation_standard = isNAME_C_OR_POSIX(newcoll); - if (PL_collation_standard) { - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "Setting PL_collation name='%s'\n", - PL_collation_name)); - PL_collxfrm_base = 0; - PL_collxfrm_mult = 2; - PL_in_utf8_COLLATE_locale = FALSE; - PL_strxfrm_NUL_replacement = '\0'; - PL_strxfrm_max_cp = 0; - return; - } + /* If the only use-case for this is the full localeconv(), the 'item' + * parameter is ignored. */ + PERL_UNUSED_ARG(item); - /* Flag that the remainder of the set up is being deferred until first - * need. */ - PL_collxfrm_mult = 0; - PL_collxfrm_base = 0; +# else /* This only gets compiled for the use-case of using localeconv() + to emulate nl_langinfo() when missing from the platform. */ -} +# ifdef USE_LOCALE_NUMERIC -# endif /* USE_LOCALE_COLLATE */ -#endif /* USE_LOCALE */ + /* We need this substructure to only return this field for the THOUSEP + * item. The other items also need substructures, but they were handled + * above by placing the substructure's item at the end of the full one, so + * the data structure could do double duty. However, both this and + * RADIXCHAR would need to be in the final position of the same full + * structure; an impossibility. So make this into a separate structure */ + const lconv_offset_t thousands_sep_string[] = { + LCONV_NUMERIC_ENTRY(thousands_sep), + {NULL, 0} + }; -#ifdef WIN32 +# endif -wchar_t * -S_Win_byte_string_to_wstring(const UINT code_page, const char * byte_string) -{ - /* Caller must arrange to free the returned string */ + /* End of all the initialization of data structures. Now for actual code. + * + * Without nl_langinfo(), the call to my_localeconv() could be for all of + * the localeconv() items or for just one of the following 3 items to + * emulate nl_langinfo(). + * + * This is compiled only when using perl_langinfo.h, which we control, and + * it has been constructed so that no item is numbered 0. + * + * For each individual item, either return the known value if the current + * locale is "C", or set up the appropriate parameters for the call below + * to the populate function */ + if (item != 0) { + const char *locale; - int req_size = MultiByteToWideChar(code_page, 0, byte_string, -1, NULL, 0); - if (! req_size) { - SET_EINVAL; - return NULL; - } + switch (item) { + default: + locale_panic_(Perl_form(aTHX_ + "Unexpected item passed to my_localeconv: %d", item)); + break; - wchar_t *wstring; - Newx(wstring, req_size, wchar_t); +# ifdef USE_LOCALE_NUMERIC - if (! MultiByteToWideChar(code_page, 0, byte_string, -1, wstring, req_size)) - { - Safefree(wstring); - SET_EINVAL; - return NULL; - } + case RADIXCHAR: + if (isNAME_C_OR_POSIX(PL_numeric_name)) { + (void) hv_stores(hv, DECIMAL_POINT_LITERAL, newSVpvs(".")); + return hv; + } - return wstring; -} + strings[NUMERIC_OFFSET] = DECIMAL_POINT_ADDRESS; + goto numeric_common; -#define Win_utf8_string_to_wstring(s) Win_byte_string_to_wstring(CP_UTF8, (s)) + case THOUSEP: + if (isNAME_C_OR_POSIX(PL_numeric_name)) { + (void) hv_stores(hv, THOUSANDS_SEP_LITERAL, newSVpvs("")); + return hv; + } -char * -S_Win_wstring_to_byte_string(const UINT code_page, const wchar_t * wstring) -{ - /* Caller must arrange to free the returned string */ + strings[NUMERIC_OFFSET] = thousands_sep_string; - int req_size = - WideCharToMultiByte(code_page, 0, wstring, -1, NULL, 0, NULL, NULL); + numeric_common: + index_bits = OFFSET_TO_BIT(NUMERIC_OFFSET); + locale = PL_numeric_name; + break; - char *byte_string; - Newx(byte_string, req_size, char); +# endif +# ifdef USE_LOCALE_MONETARY - if (! WideCharToMultiByte(code_page, 0, wstring, -1, byte_string, - req_size, NULL, NULL)) - { - Safefree(byte_string); - SET_EINVAL; - return NULL; - } + case CRNCYSTR: /* This item needs the values for both the currency + symbol, and another one used to construct the + nl_langino()-compatible return. */ - return byte_string; -} + locale = querylocale_c(LC_MONETARY); + if (isNAME_C_OR_POSIX(locale)) { + (void) hv_stores(hv, CURRENCY_SYMBOL_LITERAL, newSVpvs("")); + (void) hv_stores(hv, P_CS_PRECEDES_LITERAL, newSViv(-1)); + return hv; + } -#define Win_wstring_to_utf8_string(ws) Win_wstring_to_byte_string(CP_UTF8, (ws)) + strings[MONETARY_OFFSET] = CURRENCY_SYMBOL_ADDRESS; + integers[MONETARY_OFFSET] = P_CS_PRECEDES_ADDRESS; -STATIC const char * -S_wrap_wsetlocale(pTHX_ const int category, const char *locale) -{ - PERL_ARGS_ASSERT_WRAP_WSETLOCALE; + index_bits = OFFSET_TO_BIT(MONETARY_OFFSET); + break; - /* Calls _wsetlocale(), converting the parameters/return to/from - * Perl-expected forms as if plain setlocale() were being called instead. - */ +# endif - const wchar_t * wlocale = NULL; + } /* End of switch() */ - if (locale) { - wlocale = Win_utf8_string_to_wstring(locale); - if (! wlocale) { - return NULL; - } + /* There's only one item, so only one of each of these will get used, + * but cheap to initialize both */ + populate[MONETARY_OFFSET] = + populate[NUMERIC_OFFSET] = S_populate_hash_from_localeconv; + locales[MONETARY_OFFSET] = locales[NUMERIC_OFFSET] = locale; } + else /* End of for just one item to emulate nl_langinfo() */ - WSETLOCALE_LOCK; - const wchar_t * wresult = _wsetlocale(category, wlocale); - Safefree(wlocale); +# endif - if (! wresult) { - WSETLOCALE_UNLOCK; - return NULL; - } + { + /* Here, the call is for all of localeconv(). It has a bunch of + * items. The first function call always gets the MONETARY values */ + index_bits = OFFSET_TO_BIT(MONETARY_OFFSET); - const char * result = Win_wstring_to_utf8_string(wresult); - WSETLOCALE_UNLOCK; +# ifdef USE_LOCALE_MONETARY - SAVEFREEPV(result); /* is there something better we can do here? Answer: - Without restructuring, returning a unique value each - call is required. See GH #20434 */ - return result; -} + locales[MONETARY_OFFSET] = querylocale_c(LC_MONETARY); + populate[MONETARY_OFFSET] = + (isNAME_C_OR_POSIX(locales[MONETARY_OFFSET])) + ? S_populate_hash_from_C_localeconv + : S_populate_hash_from_localeconv; -STATIC const char * -S_win32_setlocale(pTHX_ int category, const char* locale) -{ - /* This, for Windows, emulates POSIX setlocale() behavior. There is no - * difference between the two unless the input locale is "", which normally - * means on Windows to get the machine default, which is set via the - * computer's "Regional and Language Options" (or its current equivalent). - * In POSIX, it instead means to find the locale from the user's - * environment. This routine changes the Windows behavior to first look in - * the environment, and, if anything is found, use that instead of going to - * the machine default. If there is no environment override, the machine - * default is used, by calling the real setlocale() with "". - * - * The POSIX behavior is to use the LC_ALL variable if set; otherwise to - * use the particular category's variable if set; otherwise to use the LANG - * variable. */ +# else - if (locale == NULL) { - return wrap_wsetlocale(category, NULL); - } + locales[MONETARY_OFFSET] = "C"; + populate[MONETARY_OFFSET] = S_populate_hash_from_C_localeconv; - if (strEQ(locale, "")) { - /* Note this function may change the locale, but that's ok because we - * are about to change it anyway */ - locale = find_locale_from_environment(get_category_index(category, "")); - } +# endif +# ifdef USE_LOCALE_NUMERIC - const char * result = wrap_wsetlocale(category, locale); - DEBUG_L(PerlIO_printf(Perl_debug_log, "%s\n", - setlocale_debug_string_r(category, locale, result))); + /* And if the locales for the two categories are the same, we can also + * do the NUMERIC values in the same call */ + if (strEQ(PL_numeric_name, locales[MONETARY_OFFSET])) { + index_bits |= OFFSET_TO_BIT(NUMERIC_OFFSET); + locales[NUMERIC_OFFSET] = locales[MONETARY_OFFSET]; + populate[NUMERIC_OFFSET] = populate[MONETARY_OFFSET]; + } + else { + requires_2nd_localeconv = true; + locales[NUMERIC_OFFSET] = PL_numeric_name; + populate[NUMERIC_OFFSET] = (isNAME_C_OR_POSIX(PL_numeric_name)) + ? S_populate_hash_from_C_localeconv + : S_populate_hash_from_localeconv; + } -# ifdef USE_PL_CUR_LC_ALL +# else - /* If we need to keep track of LC_ALL, update it to the new value. */ - Safefree(PL_cur_LC_ALL); - if (category == LC_ALL) { - PL_cur_LC_ALL = savepv(result); - } - else { - PL_cur_LC_ALL = savepv(wrap_wsetlocale(LC_ALL, NULL)); - } + /* When LC_NUMERIC is confined to "C", the two locales are the same + iff LC_MONETARY in this case is also "C". We set up the function + for that case above, so fastest to test just its address */ + locales[NUMERIC_OFFSET] = "C"; + if (populate[MONETARY_OFFSET] == S_populate_hash_from_C_localeconv) { + index_bits |= OFFSET_TO_BIT(NUMERIC_OFFSET); + populate[NUMERIC_OFFSET] = populate[MONETARY_OFFSET]; + } + else { + requires_2nd_localeconv = true; + populate[NUMERIC_OFFSET] = S_populate_hash_from_C_localeconv; + } # endif - return result; -} + } /* End of call is for localeconv() */ -#endif + /* Call the proper populate function (which may call localeconv()) and copy + * its results into the hash. All the parameters have been initialized + * above */ + (*populate[MONETARY_OFFSET])(aTHX_ + hv, locales[MONETARY_OFFSET], + index_bits, strings, integers); + +# ifndef HAS_SOME_LANGINFO /* Could be using this function to emulate + nl_langinfo() */ + + /* We are done when called with an individual item. There are no integer + * items to adjust, and it's best for the caller to determine if this + * string item is UTF-8 or not. This is because the locale's UTF-8ness is + * calculated below, and in some Configurations, that can lead to a + * recursive call to here, which could recurse infinitely. */ + if (item != 0) { + return hv; + } -/* -=for apidoc Perl_setlocale +# endif -This is an (almost) drop-in replacement for the system L>, -taking the same parameters, and returning the same information, except that it -returns the correct underlying C locale. Regular C will -instead return C if the underlying locale has a non-dot decimal point -character, or a non-empty thousands separator for displaying floating point -numbers. This is because perl keeps that locale category such that it has a -dot and empty separator, changing the locale briefly during the operations -where the underlying one is required. C knows about this, and -compensates; regular C doesn't. + /* The above call may have done all the hash fields, but not always, as + * already explained. If we need a second call it is always for the + * NUMERIC fields */ + if (requires_2nd_localeconv) { + (*populate[NUMERIC_OFFSET])(aTHX_ + hv, + locales[NUMERIC_OFFSET], + OFFSET_TO_BIT(NUMERIC_OFFSET), + strings, integers); + } + + /* Here, the hash has been completely populated. */ + +# ifdef LOCALECONV_NEEDS_CRITICAL_SECTION + + /* When the hash was populated during a critical section, the determination + * of whether or not a string element should be marked as UTF-8 was + * deferred, so as to minimize the amount of time in the critical section. + * But now we have the hash specific to this thread, and can do the + * adjusting without worrying about delaying other threads. */ + for (unsigned int i = 0; i < 2; i++) { /* Try both types of strings */ -Another reason it isn't completely a drop-in replacement is that it is -declared to return S>, whereas the system setlocale omits the -C (presumably because its API was specified long ago, and can't be -updated; it is illegal to change the information C returns; doing -so leads to segfaults.) + /* The return from this function is already adjusted */ + if (populate[i] == S_populate_hash_from_C_localeconv) { + continue; + } -Finally, C works under all circumstances, whereas plain -C can be completely ineffective on some platforms under some -configurations. + /* Examine each string */ + for (const lconv_offset_t *strp = strings[i]; strp->name; strp++) { + const char * name = strp->name; -Changing the locale is not a good idea when more than one thread is running, -except on systems where the predefined variable C<${^SAFE_LOCALES}> is 1. -This is because on such systems the locale is global to the whole process and -not local to just the thread calling the function. So changing it in one -thread instantaneously changes it in all. On some such systems, the system -C is ineffective, returning the wrong information, and failing to -actually change the locale. z/OS refuses to try to change the locale once a -second thread is created. C, should give you accurate results -of what actually happened on these problematic platforms, returning NULL if the -system forbade the locale change. + /* 'value' will contain the string that may need to be marked as + * UTF-8 */ + SV ** value = hv_fetch(hv, name, strlen(name), true); + if (value == NULL) { + continue; + } -The return points to a per-thread static buffer, which is overwritten the next -time C is called from the same thread. + /* Determine if the string should be marked as UTF-8. */ + if (UTF8NESS_YES == (get_locale_string_utf8ness_i(SvPVX(*value), + LOCALE_UTF8NESS_UNKNOWN, + locales[i], + LC_ALL_INDEX_ /* OOB */))) + { + SvUTF8_on(*value); + } + } + } -=cut +# endif -*/ + return hv; -#ifndef USE_LOCALE_NUMERIC -# define affects_LC_NUMERIC(cat) 0 -#elif defined(LC_ALL) -# define affects_LC_NUMERIC(cat) (cat == LC_NUMERIC || cat == LC_ALL) -#else -# define affects_LC_NUMERIC(cat) (cat == LC_NUMERIC) -#endif +#endif /* End of must have one or both USE_MONETARY, USE_NUMERIC */ -const char * -Perl_setlocale(const int category, const char * locale) -{ - /* This wraps POSIX::setlocale() */ +} -#ifndef USE_LOCALE +STATIC void +S_populate_hash_from_C_localeconv(pTHX_ HV * hv, + const char * locale, /* Unused */ - PERL_UNUSED_ARG(category); + /* bit mask of which categories to + * populate */ + const U32 which_mask, + + /* The string type values to return; + * one element for numeric; the other + * for monetary */ + const lconv_offset_t * strings[2], + + /* And the integer fields */ + const lconv_offset_t * integers[2]) +{ + PERL_ARGS_ASSERT_POPULATE_HASH_FROM_C_LOCALECONV; PERL_UNUSED_ARG(locale); + assert(isNAME_C_OR_POSIX(locale)); - return "C"; + /* Fill hv with the values that localeconv() is supposed to return for + * the C locale */ -#else + U32 working_mask = which_mask; + while (working_mask) { - const char * retval; - dTHX; + /* Get the bit position of the next lowest set bit. That is the + * index into the 'strings' array of the category we use in this loop + * iteration. Turn the bit off so we don't work on this category + * again in this function call. */ + const PERL_UINT_FAST8_T i = lsbit_pos(working_mask); + working_mask &= ~ (1 << i); - DEBUG_L(PerlIO_printf(Perl_debug_log, - "Entering Perl_setlocale(%d, \"%s\")\n", - category, locale)); + /* This category's string fields */ + const lconv_offset_t * category_strings = strings[i]; - /* A NULL locale means only query what the current one is. */ - if (locale == NULL) { +#ifndef HAS_SOME_LANGINFO /* This doesn't work properly if called on a single + item, which could only happen when there isn't + nl_langinfo on the platform */ + assert(category_strings[1].name != NULL); +#endif -# ifndef USE_LOCALE_NUMERIC + /* All string fields are empty except for one NUMERIC one. That one + * has been initialized to be the final one in the NUMERIC strings, so + * stop the loop early in that case. Otherwise, we would store an + * empty string to the hash, and immediately overwrite it with the + * correct value */ + const unsigned int stop_early = (i == NUMERIC_OFFSET) ? 1 : 0; - /* Without LC_NUMERIC, it's trivial; we just return the value */ - return save_to_buffer(querylocale_r(category), - &PL_setlocale_buf, &PL_setlocale_bufsize); -# else + /* A NULL element terminates the list */ + while ((category_strings + stop_early)->name) { + (void) hv_store(hv, + category_strings->name, + strlen(category_strings->name), + newSVpvs(""), + 0); - /* We have the LC_NUMERIC name saved, because we are normally switched - * into the C locale (or equivalent) for it. */ - if (category == LC_NUMERIC) { - DEBUG_L(PerlIO_printf(Perl_debug_log, - "Perl_setlocale(LC_NUMERIC, NULL) returning stashed '%s'\n", - PL_numeric_name)); + category_strings++; + } - /* We don't have to copy this return value, as it is a per-thread - * variable, and won't change until a future setlocale */ - return PL_numeric_name; + /* And fill in the NUMERIC exception */ + if (i == NUMERIC_OFFSET) { + (void) hv_stores(hv, "decimal_point", newSVpvs(".")); + category_strings++; } -# ifndef LC_ALL + /* Add any int fields. In the C locale, all are -1 */ + if (integers[i]) { + const lconv_offset_t * current = integers[i]; + while (current->name) { + (void) hv_store(hv, + current->name, strlen(current->name), + newSViv(-1), + 0); + current++; + } + } + } +} - /* Without LC_ALL, just return the value */ - return save_to_buffer(querylocale_r(category), - &PL_setlocale_buf, &PL_setlocale_bufsize); +#if defined(HAS_LOCALECONV) && ( defined(USE_LOCALE_NUMERIC) \ + || defined(USE_LOCALE_MONETARY)) -# else +STATIC void +S_populate_hash_from_localeconv(pTHX_ HV * hv, - /* Here, LC_ALL is available on this platform. It's the one - * complicating category (because it can contain a toggled LC_NUMERIC - * value), for all the remaining ones (we took care of LC_NUMERIC - * above), just return the value */ - if (category != LC_ALL) { - return save_to_buffer(querylocale_r(category), - &PL_setlocale_buf, &PL_setlocale_bufsize); - } + /* Switch to this locale to run + * localeconv() from */ + const char * locale, - bool toggled = FALSE; + /* bit mask of which categories to + * populate */ + const U32 which_mask, - /* For an LC_ALL query, switch back to the underlying numeric locale - * (if we aren't there already) so as to get the correct results. Our - * records for all the other categories are valid without switching */ - if (! PL_numeric_underlying) { - set_numeric_underlying(); - toggled = TRUE; - } + /* The string type values to return; one + * element for numeric; the other for + * monetary */ + const lconv_offset_t * strings[2], - retval = querylocale_c(LC_ALL); + /* And similarly the integer fields */ + const lconv_offset_t * integers[2]) +{ + PERL_ARGS_ASSERT_POPULATE_HASH_FROM_LOCALECONV; - if (toggled) { - set_numeric_standard(); - } + /* Run localeconv() and copy some or all of its results to the input 'hv' + * hash. Most localeconv() implementations return the values in a global + * static buffer, so for them, the operation must be performed in a + * critical section, ending only after the copy is completed. There are so + * many locks because localeconv() deals with two categories, and returns + * in a single global static buffer. Some locks might be no-ops on this + * platform, but not others. We need to lock if any one isn't a no-op. */ + + /* If the call could be for either or both of the two categories, we need + * to test which one; but if the Configuration is such that we will never + * be called with one of them, the code for that one will be #ifdef'd out + * below, leaving code for just the other category. That code will always + * want to be executed, no conditional required. Create a macro that + * replaces the condition with an always-true value so the compiler will + * omit the conditional */ +# if defined(USE_LOCALE_NUMERIC) && defined(USE_LOCALE_MONETARY) +# define CALL_IS_FOR(x) (which_mask & OFFSET_TO_BIT(x ## _OFFSET)) +# else +# define CALL_IS_FOR(x) 1 +# endif - DEBUG_L(PerlIO_printf(Perl_debug_log, "%s\n", - setlocale_debug_string_r(category, locale, retval))); + /* This function is unfortunately full of #ifdefs. It consists of three + * sections: + * 1) Setup: + * a) On platforms where it matters, toggle LC_CTYPE to the same + * locale that LC_NUMERIC and LC_MONETARY will be toggled to + * b) On calls that process LC_NUMERIC, toggle to the desired locale + * c) On calls that process LC_MONETARY, toggle to the desired + * locale + * d) Do any necessary mutex locking not (automatically) done by + * the toggling + * e) Work around some Windows-only issues and bugs + * 2) Do the localeconv(), copying the results. + * 3) Teardown, which is the inverse of setup. + * + * The setup and teardown are highly variable due to the variance in the + * possible Configurations. What is done here to make it slightly more + * understandable is each setup section creates the details of its + * corresponding teardown section, and macroizes them. So that the + * finished teardown product is just a linear series of macros. You can + * thus easily see the logic there. */ + + /* Setup any LC_CTYPE handling */ + start_DEALING_WITH_MISMATCHED_CTYPE(locale); +# define CTYPE_TEARDOWN end_DEALING_WITH_MISMATCHED_CTYPE(locale) - return save_to_buffer(retval, &PL_setlocale_buf, &PL_setlocale_bufsize); + /* Setup any LC_NUMERIC handling */ +# ifndef USE_LOCALE_NUMERIC +# define NUMERIC_TEARDOWN +# else -# endif /* Has LC_ALL */ -# endif /* Has LC_NUMERIC */ + /* We need to toggle the NUMERIC locale to the desired one if we are + * getting NUMERIC strings */ + const char * orig_NUMERIC_locale = NULL; + if (CALL_IS_FOR(NUMERIC)) { - } /* End of querying the current locale */ +# ifdef WIN32 + /* There is a bug in Windows in which setting LC_CTYPE after the others + * doesn't actually take effect for localeconv(). See commit + * 418efacd1950763f74ed3cc22f8cf9206661b892 for details. Thus we have + * to make sure that the locale we want is set after LC_CTYPE. We + * unconditionally toggle away from and back to the current locale + * prior to calling localeconv(). */ + orig_NUMERIC_locale = toggle_locale_c(LC_NUMERIC, "C"); + (void) toggle_locale_c(LC_NUMERIC, locale); + +# define NUMERIC_TEARDOWN \ + STMT_START { \ + if (CALL_IS_FOR(NUMERIC)) { \ + restore_toggled_locale_c(LC_NUMERIC, "C"); \ + restore_toggled_locale_c(LC_NUMERIC, orig_NUMERIC_locale); \ + } \ + } STMT_END - unsigned int cat_index = get_category_index(category, NULL); - retval = querylocale_i(cat_index); +# else - /* If the new locale is the same as the current one, nothing is actually - * being changed, so do nothing. */ - if ( retval != NULL && strEQ(retval, locale) - && ( ! affects_LC_NUMERIC(category) + /* No need for the extra toggle when not on Windows */ + orig_NUMERIC_locale = toggle_locale_c(LC_NUMERIC, locale); -# ifdef USE_LOCALE_NUMERIC +# define NUMERIC_TEARDOWN \ + STMT_START { \ + if (CALL_IS_FOR(NUMERIC)) { \ + restore_toggled_locale_c(LC_NUMERIC, orig_NUMERIC_locale); \ + } \ + } STMT_END +# endif - || strEQ(locale, PL_numeric_name) + } -# endif +# endif /* End of LC_NUMERIC setup */ - )) { - DEBUG_L(PerlIO_printf(Perl_debug_log, - "Already in requested locale: no action taken\n")); - return save_to_buffer(retval, &PL_setlocale_buf, &PL_setlocale_bufsize); - } + /* Setup any LC_MONETARY handling, using the same logic as for + * USE_LOCALE_NUMERIC just above */ +# ifndef USE_LOCALE_MONETARY +# define MONETARY_TEARDOWN +# else - /* Here, an actual change is being requested. Do it */ - retval = setlocale_i(cat_index, locale); + /* Same logic as LC_NUMERIC, and same Windows bug */ + const char * orig_MONETARY_locale = NULL; + if (CALL_IS_FOR(MONETARY)) { - if (! retval) { - DEBUG_L(PerlIO_printf(Perl_debug_log, "%s\n", - setlocale_debug_string_i(cat_index, locale, "NULL"))); - return NULL; - } +# ifdef WIN32 - assert(strNE(retval, "")); - retval = save_to_buffer(retval, &PL_setlocale_buf, &PL_setlocale_bufsize); + orig_MONETARY_locale = toggle_locale_c(LC_MONETARY, "C"); + (void) toggle_locale_c(LC_MONETARY, locale); - /* Now that have changed locales, we have to update our records to - * correspond. Only certain categories have extra work to update. */ - if (update_functions[cat_index]) { - update_functions[cat_index](aTHX_ retval, false); - } +# define MONETARY_TEARDOWN \ + STMT_START { \ + if (CALL_IS_FOR(MONETARY)) { \ + restore_toggled_locale_c(LC_MONETARY, "C"); \ + restore_toggled_locale_c(LC_MONETARY, orig_MONETARY_locale);\ + } \ + } STMT_END - DEBUG_L(PerlIO_printf(Perl_debug_log, "returning '%s'\n", retval)); +# else - return retval; + /* No need for the extra toggle when not on Windows */ + orig_MONETARY_locale = toggle_locale_c(LC_MONETARY, locale); -#endif +# define MONETARY_TEARDOWN \ + STMT_START { \ + if (CALL_IS_FOR(MONETARY)) { \ + restore_toggled_locale_c(LC_MONETARY, orig_MONETARY_locale);\ + } \ + } STMT_END -} +# endif -STATIC utf8ness_t -S_get_locale_string_utf8ness_i(pTHX_ const char * string, - const locale_utf8ness_t known_utf8, - const char * locale, - const unsigned cat_index) -{ - PERL_ARGS_ASSERT_GET_LOCALE_STRING_UTF8NESS_I; + } -#ifndef USE_LOCALE +# endif /* End of LC_MONETARY setup */ - return UTF8NESS_NO; - PERL_UNUSED_ARG(string); - PERL_UNUSED_ARG(known_utf8); - PERL_UNUSED_ARG(locale); - PERL_UNUSED_ARG(cat_index); + /* Here, have toggled to the correct locale. + * + * We don't need to worry about locking at all if localeconv() is + * thread-safe, regardless of if using threads or not. */ +# ifdef LOCALECONV_IS_THREAD_SAFE +# define LOCALECONV_UNLOCK +# else -#else + /* Otherwise, the gwLOCALE_LOCK macro expands to whatever locking is + * needed (none if there is only a single perl instance) */ + gwLOCALE_LOCK; - assert(cat_index <= NOMINAL_LC_ALL_INDEX); +# define LOCALECONV_UNLOCK gwLOCALE_UNLOCK +# endif +# if ! defined(TS_W32_BROKEN_LOCALECONV) || ! defined(USE_THREAD_SAFE_LOCALE) +# define WIN32_TEARDOWN +# else - /* Return to indicate if 'string' in the locale given by the input - * arguments should be considered UTF-8 or not. + /* This is a workaround for another bug in Windows. localeconv() was + * broken with thread-safe locales prior to VS 15. It looks at the global + * locale instead of the thread one. As a work-around, we toggle to the + * global locale; populate the return; then toggle back. We have to use + * LC_ALL instead of the individual categories because of yet another bug + * in Windows. And this all has to be done in a critical section. * - * If the input 'locale' is not NULL, use that for the locale; otherwise - * use the current locale for the category specified by 'cat_index'. + * This introduces a potential race with any other thread that has also + * converted to use the global locale, and doesn't protect its locale calls + * with mutexes. khw can't think of any reason for a thread to do so on + * Windows, as the locale API is the same regardless of thread-safety, + * except if the code is ported from working on another platform where + * there might be some reason to do this. But this is typically due to + * some alien-to-Perl library that thinks it owns locale setting. Such a + * library isn't likely to exist on Windows, so such an application is + * unlikely to be run on Windows */ + bool restore_per_thread = FALSE; - if (string == NULL) { - return UTF8NESS_NO; - } + /* Save the per-thread locale state */ + const char * save_thread = querylocale_c(LC_ALL); - if (IN_BYTES) { /* respect 'use bytes' */ - return UTF8NESS_NO; + /* Change to the global locale, and note if we already were there */ + int config_return = _configthreadlocale(_DISABLE_PER_THREAD_LOCALE); + if (config_return != _DISABLE_PER_THREAD_LOCALE) { + if (config_return == -1) { + locale_panic_("_configthreadlocale returned an error"); + } + + restore_per_thread = TRUE; } - Size_t len = strlen(string); + /* Save the state of the global locale; then convert to our desired + * state. */ + const char * save_global = querylocale_c(LC_ALL); + void_setlocale_c(LC_ALL, save_thread); - /* UTF8ness is immaterial if the representation doesn't vary */ - const U8 * first_variant = NULL; - if (is_utf8_invariant_string_loc((U8 *) string, len, &first_variant)) { - return UTF8NESS_IMMATERIAL; - } +# define WIN32_TEARDOWN \ + STMT_START { \ + /* Restore the global locale's prior state */ \ + void_setlocale_c(LC_ALL, save_global); \ + \ + /* And back to per-thread locales */ \ + if (restore_per_thread) { \ + if (_configthreadlocale(_ENABLE_PER_THREAD_LOCALE) == -1) { \ + locale_panic_("_configthreadlocale returned an error"); \ + } \ + } \ + \ + /* Restore the per-thread locale state */ \ + void_setlocale_c(LC_ALL, save_thread); \ + } STMT_END +# endif /* TS_W32_BROKEN_LOCALECONV */ - /* Can't be UTF-8 if invalid */ - if (! is_utf8_string((U8 *) first_variant, - len - ((char *) first_variant - string))) - { - return UTF8NESS_NO; - } - /* Here and below, we know the string is legal UTF-8, containing at least - * one character requiring a sequence of two or more bytes. It is quite - * likely to be UTF-8. But it pays to be paranoid and do further checking. - * - * If we already know the UTF-8ness of the locale, then we immediately know - * what the string is */ - if (UNLIKELY(known_utf8 != LOCALE_UTF8NESS_UNKNOWN)) { - if (known_utf8 == LOCALE_IS_UTF8) { - return UTF8NESS_YES; - } - else { - return UTF8NESS_NO; - } - } + /* Finally, everything is locked and loaded; do the actual call to + * localeconv() */ + const char *lcbuf_as_string = (const char *) localeconv(); -# ifdef HAS_RELIABLE_UTF8NESS_DETERMINATION + /* Copy its results for each desired category as determined by + * 'which_mask' */ + U32 working_mask = which_mask; + while (working_mask) { + + /* Get the bit position of the next lowest set bit. That is the + * index into the 'strings' array of the category we use in this loop + * iteration. Turn the bit off so we don't work on this category + * again in this function call. */ + const PERL_UINT_FAST8_T i = lsbit_pos32(working_mask); + working_mask &= ~ (1 << i); - /* Here, we have available the libc functions that can be used to - * accurately determine the UTF8ness of the underlying locale. If it is a - * UTF-8 locale, the string is UTF-8; otherwise it was coincidental that - * the string is legal UTF-8 - * - * However, if the perl is compiled to not pay attention to the category - * being passed in, you might think that that locale is essentially always - * the C locale, so it would make sense to say it isn't UTF-8. But to get - * here, the string has to contain characters unknown in the C locale. And - * in fact, Windows boxes are compiled without LC_MESSAGES, as their - * message catalog isn't really a part of the locale system. But those - * messages really could be UTF-8, and given that the odds are rather small - * of something not being UTF-8 but being syntactically valid UTF-8, khw - * has decided to call such strings as UTF-8. */ + /* Point to the string field list for the given category ... */ + const lconv_offset_t * category_strings = strings[i]; - if (locale == NULL) { - locale = querylocale_i(cat_index); - } - if (is_locale_utf8(locale)) { - return UTF8NESS_YES; - } + /* The string fields returned by localeconv() are stored as SVs in the + * hash. Their utf8ness needs to be calculated at some point, and the + * SV flagged accordingly. It is easier to do that now as we go + * through them, but strongly countering this is the need to minimize + * the length of time spent in a critical section with other threads + * locked out. Therefore, when this is being executed in a critical + * section, the strings are stored as-is, and the utf8ness calculation + * is done by our caller, outside the critical section, in an extra + * pass through the hash. But when this code is not being executed in + * a critical section, that extra pass would be extra work, so the + * calculation is done here. We have #defined a symbol that indicates + * whether or not this is being done in a critical section. But there + * is a complication. When this is being called with just a single + * string to populate the hash with, there may be extra adjustments + * needed, and the ultimate caller is expecting to do all adjustments, + * so the adjustment is deferred in this case even if there is no + * critical section. (This case is indicated by element [1] being a + * NULL marker, hence having only one real element.) */ +# ifndef LOCALECONV_NEEDS_CRITICAL_SECTION + const bool calculate_utf8ness_here = category_strings[1].name; +# endif + bool utf8ness = false; - return UTF8NESS_NO; + /* For each string field */ + while (category_strings->name) { -# else + /* We have set things up so that we know where in the returned + * structure, when viewed as a string, the corresponding value is. + * */ + char *value = *((char **)( lcbuf_as_string + + category_strings->offset)); + if (value) { /* Copy to the hash */ + +# ifndef LOCALECONV_NEEDS_CRITICAL_SECTION + + if (calculate_utf8ness_here) { + utf8ness = + ( UTF8NESS_YES + == get_locale_string_utf8ness_i(value, + LOCALE_UTF8NESS_UNKNOWN, + locale, + LC_ALL_INDEX_ /* OOB */)); + } +# endif + (void) hv_store(hv, + category_strings->name, + strlen(category_strings->name), + newSVpvn_utf8(value, strlen(value), utf8ness), + 0); + } - /* Here, we have a valid UTF-8 string containing non-ASCII characters, and - * don't have access to functions to check if the locale is UTF-8 or not. - * Assume that it is. khw tried adding a check that the string is entirely - * in a single Unicode script, but discovered the strftime() timezone is - * user-settable through the environment, which may be in a different - * script than the locale-expected value. */ - PERL_UNUSED_ARG(locale); - PERL_UNUSED_ARG(cat_index); + category_strings++; + } + + /* Add any int fields to the HV*. */ + if (integers[i]) { + const lconv_offset_t * current = integers[i]; + while (current->name) { + int value = *((const char *)( lcbuf_as_string + + current->offset)); + if (value == CHAR_MAX) { /* Change CHAR_MAX to -1 */ + value = -1; + } - return UTF8NESS_YES; + (void) hv_store(hv, + current->name, strlen(current->name), + newSViv(value), + 0); + current++; + } + } + } /* End of loop through the fields */ -# endif -#endif + /* Done with copying to the hash. Can unwind the critical section locks */ + /* Back out of what we set up */ + WIN32_TEARDOWN; + LOCALECONV_UNLOCK; + MONETARY_TEARDOWN; + NUMERIC_TEARDOWN; + CTYPE_TEARDOWN; } -STATIC bool -S_is_locale_utf8(pTHX_ const char * locale) -{ - /* Returns TRUE if the locale 'locale' is UTF-8; FALSE otherwise. It uses - * my_langinfo(), which employs various methods to get this information - * if nl_langinfo() isn't available, using heuristics as a last resort, in - * which case, the result will very likely be correct for locales for - * languages that have commonly used non-ASCII characters, but for notably - * English, it comes down to if the locale's name ends in something like - * "UTF-8". It errs on the side of not being a UTF-8 locale. */ +#endif /* defined(USE_LOCALE_NUMERIC) || defined(USE_LOCALE_MONETARY) */ -# if ! defined(USE_LOCALE) \ - || ! defined(USE_LOCALE_CTYPE) \ - || defined(EBCDIC) /* There aren't any real UTF-8 locales at this time */ +/* - PERL_UNUSED_ARG(locale); +=for apidoc Perl_langinfo +=for apidoc_item Perl_langinfo8 - return FALSE; +C is an (almost) drop-in replacement for the system +C>, taking the same C parameter values, and returning +the same information. But it is more thread-safe than regular +C, and hides the quirks of Perl's locale handling from your +code, and can be used on systems that lack a native C. -# else +However, you should instead use either the improved version of this, +L, or even better, L. The latter returns an SV, +handling all the possible non-standard returns of C, including +the UTF8ness of any returned string. - const char * scratch_buffer = NULL; - const char * codeset; - bool retval; +C is identical to C except for an additional +parameter, a pointer to a variable declared as L>, into which it +returns to you how you should treat the returned string with regards to it +being encoded in UTF-8 or not. - PERL_ARGS_ASSERT_IS_LOCALE_UTF8; +These two functions share private per-thread memory that will be changed the +next time either one of them is called with any input, but not before. - if (strEQ(locale, PL_ctype_name)) { - return PL_in_utf8_CTYPE_locale; - } +Concerning the differences between these and plain C: - codeset = my_langinfo_c(CODESET, LC_CTYPE, locale, - &scratch_buffer, NULL, NULL); - retval = is_codeset_name_UTF8(codeset); +=over - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "found codeset=%s, is_utf8=%d\n", codeset, retval)); +=item a. - Safefree(scratch_buffer); - return retval; +C has an extra parameter, described above. Besides this, the +other reason they aren't quite a drop-in replacement is actually an advantage. +The Cness of the return allows the compiler to catch attempts to write +into the returned buffer, which is illegal and could cause run-time crashes. -# endif +=item b. -} +They deliver the correct results for the C and C items, +without you having to write extra code. The reason for the extra code would be +because these are from the C locale category, which is normally +kept set by Perl so that the radix is a dot, and the separator is the empty +string, no matter what the underlying locale is supposed to be, and so to get +the expected results, you have to temporarily toggle into the underlying +locale, and later toggle back. (You could use plain C and +C> for this but then you wouldn't get +the other advantages of C; not keeping C in the C +(or equivalent) locale would break a lot of CPAN, which is expecting the radix +(decimal point) character to be a dot.) -#ifdef USE_LOCALE +=item c. -STATIC const char * -S_save_to_buffer(const char * string, const char **buf, Size_t *buf_size) -{ - /* Copy the NUL-terminated 'string' to a buffer whose address before this - * call began at *buf, and whose available length before this call was - * *buf_size. - * - * If the length of 'string' is greater than the space available, the - * buffer is grown accordingly, which may mean that it gets relocated. - * *buf and *buf_size will be updated to reflect this. - * - * Regardless, the function returns a pointer to where 'string' is now - * stored. - * - * 'string' may be NULL, which means no action gets taken, and NULL is - * returned. - * - * If *buf or 'buf_size' are NULL or *buf_size is 0, the buffer is assumed - * empty, and memory is malloc'd. 'buf-size' being NULL is to be used - * when this is a single use buffer, which will shortly be freed by the - * caller. - */ +The system function they replace can have its static return buffer trashed, +not only by a subsequent call to that function, but by a C, +C, or other locale change. The returned buffer of these functions +is not changed until the next call to one or the other, so the buffer is never +in a trashed state. - Size_t string_size; +=item d. - PERL_ARGS_ASSERT_SAVE_TO_BUFFER; +The return buffer is per-thread, so it also is never overwritten by a call to +these functions from another thread; unlike the function it replaces. - if (! string) { - return NULL; - } +=item e. - /* No-op to copy over oneself */ - if (string == *buf) { - return string; - } +But most importantly, they work on systems that don't have C, such +as Windows, hence making your code more portable. Of the fifty-some possible +items specified by the POSIX 2008 standard, +L, +only one is completely unimplemented, though on non-Windows platforms, another +significant one is not fully implemented). They use various techniques to +recover the other items, including calling C>, and +C>, both of which are specified in C89, so should be always be +available. Later C versions have additional capabilities. +If an item is not available on your system, this returns either the value +associated with the C locale, or simply C<"">, whichever is more appropriate. + +It is important to note that, when called with an item that is recovered by +using C, the buffer from any previous explicit call to +C> will be overwritten. But you shouldn't be using +C anyway because it is is very much not thread-safe, and suffers +from the same problems outlined in item 'b.' above for the fields it returns +that are controlled by the LC_NUMERIC locale category. Instead, avoid all of +those problems by calling L, which is thread-safe; or by +using the methods given in L to call +L|POSIX/localeconv>, which is also thread-safe. - string_size = strlen(string) + 1; +=back - if (buf_size == NULL) { - Newx(*buf, string_size, char); - } - else if (*buf_size == 0) { - Newx(*buf, string_size, char); - *buf_size = string_size; - } - else if (string_size > *buf_size) { - Renew(*buf, string_size, char); - *buf_size = string_size; - } +The details for those items which may deviate from what this emulation returns +and what a native C would return are specified in +L. - { - dTHX_DEBUGGING; - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "Copying '%s' to %p\n", - ((is_utf8_string((U8 *) string, 0)) - ? string - :_byte_dump_string((U8 *) string, strlen(string), 0)), - *buf)); - } +=for apidoc sv_langinfo + +This is the preferred interface for accessing the data that L +provides (or Perl's emulation of it on platforms lacking it), returning an SV. +Unlike, the earlier-defined interfaces to this (L and +L), which return strings, the UTF8ness of the result is +automatically handled for you. And like them, it is thread-safe and +automatically handles getting the proper values for the C and +C items (that calling the plain libc C could give the +wrong results for). Like them, this also doesn't play well with the libc +C; use L|POSIX/localeconv> instead. + +There are a few deviations from what a native C would return and +what this returns on platforms that don't implement that function. These are +detailed in L. -# ifdef DEBUGGING +=cut - /* Catch glitches. Usually this is because LC_CTYPE needs to be the same - * locale as whatever is being worked on */ - if (UNLIKELY(instr(string, REPLACEMENT_CHARACTER_UTF8))) { - dTHX_DEBUGGING; +*/ - locale_panic_(Perl_form(aTHX_ - "Unexpected REPLACEMENT_CHARACTER in '%s'\n%s", - string, get_LC_ALL_display())); - } +/* external_call_langinfo() is an interface to callers from outside this file to + * langinfo_sv_i(), calculating a necessary value for it. If those functions + * aren't defined, the fallback function is emulate_langinfo(), which doesn't + * use that value (as everything in this situation takes place in the "C" + * locale), and so we define this macro to transparently hide the absence of + * the missing functions */ +#ifndef external_call_langinfo +# define external_call_langinfo(item, sv, utf8p) \ + emulate_langinfo(item, "C", sv, utf8p) +#endif -# endif +SV * +Perl_sv_langinfo(pTHX_ const nl_item item) { + utf8ness_t dummy; /* Having this tells the layers below that we want the + UTF-8 flag in 'sv' to be set properly. */ - Copy(string, *buf, string_size, char); - return *buf; + SV * sv = newSV_type(SVt_PV); + (void) external_call_langinfo(item, sv, &dummy); + + return sv; } -# ifdef WIN32 +const char * +Perl_langinfo(const nl_item item) +{ + dTHX; -bool -Perl_get_win32_message_utf8ness(pTHX_ const char * string) + (void) external_call_langinfo(item, PL_langinfo_sv, NULL); + return SvPV_nolen(PL_langinfo_sv); +} + +const char * +Perl_langinfo8(const nl_item item, utf8ness_t * utf8ness) { - /* NULL => locale irrelevant, 0 => category irrelevant - * so returns based on the UTF-8 legality of the input string, ignoring the - * locale and category completely. - * - * This is because Windows doesn't have LC_MESSAGES */ - return get_locale_string_utf8ness_i(string, LOCALE_IS_UTF8, NULL, 0); + PERL_ARGS_ASSERT_PERL_LANGINFO8; + dTHX; + + (void) external_call_langinfo(item, PL_langinfo_sv, utf8ness); + return SvPV_nolen(PL_langinfo_sv); } -# endif -#endif /* USE_LOCALE */ +#ifdef USE_LOCALE +const char * +S_external_call_langinfo(pTHX_ const nl_item item, + SV * sv, + utf8ness_t * utf8ness) +{ + PERL_ARGS_ASSERT_EXTERNAL_CALL_LANGINFO; + + /* Find the locale category that controls the input 'item', and call + * langinfo_sv_i() including that value. + * + * If we are not paying attention to that category, instead call + * emulate_langinfo(), which knows how to handle this situation. */ + locale_category_index cat_index = LC_ALL_INDEX_; /* Out-of-bounds */ -int -Perl_mbtowc_(pTHX_ const wchar_t * pwc, const char * s, const Size_t len) -{ + switch (item) { + case CODESET: -#if ! defined(HAS_MBRTOWC) && ! defined(HAS_MBTOWC) +# ifdef USE_LOCALE_CTYPE + cat_index = LC_CTYPE_INDEX_; +# endif + break; - PERL_UNUSED_ARG(pwc); - PERL_UNUSED_ARG(s); - PERL_UNUSED_ARG(len); - return -1; -#else /* Below we have some form of mbtowc() */ -# if defined(HAS_MBRTOWC) \ - && (defined(USE_LOCALE_THREADS) || ! defined(HAS_MBTOWC)) -# define USE_MBRTOWC -# else -# undef USE_MBRTOWC + case YESEXPR: case YESSTR: case NOEXPR: case NOSTR: + +# ifdef USE_LOCALE_MESSAGES + cat_index = LC_MESSAGES_INDEX_; # endif + break; - int retval = -1; - if (s == NULL) { /* Initialize the shift state to all zeros in - PL_mbrtowc_ps. */ + case CRNCYSTR: -# if defined(USE_MBRTOWC) +# ifdef USE_LOCALE_MONETARY + cat_index = LC_MONETARY_INDEX_; +# endif + break; - memzero(&PL_mbrtowc_ps, sizeof(PL_mbrtowc_ps)); - return 0; -# else + case RADIXCHAR: case THOUSEP: + +# ifdef USE_LOCALE_NUMERIC + cat_index = LC_NUMERIC_INDEX_; +# endif + break; - MBTOWC_LOCK_; - SETERRNO(0, 0); - retval = mbtowc(NULL, NULL, 0); - MBTOWC_UNLOCK_; - return retval; + case _NL_ADDRESS_POSTAL_FMT: + case _NL_ADDRESS_COUNTRY_NAME: + case _NL_ADDRESS_COUNTRY_POST: + case _NL_ADDRESS_COUNTRY_AB2: + case _NL_ADDRESS_COUNTRY_AB3: + case _NL_ADDRESS_COUNTRY_CAR: + case _NL_ADDRESS_COUNTRY_NUM: + case _NL_ADDRESS_COUNTRY_ISBN: + case _NL_ADDRESS_LANG_NAME: + case _NL_ADDRESS_LANG_AB: + case _NL_ADDRESS_LANG_TERM: + case _NL_ADDRESS_LANG_LIB: +# ifdef USE_LOCALE_ADDRESS + cat_index = LC_ADDRESS_INDEX_; # endif + break; - } -# if defined(USE_MBRTOWC) + case _NL_IDENTIFICATION_TITLE: + case _NL_IDENTIFICATION_SOURCE: + case _NL_IDENTIFICATION_ADDRESS: + case _NL_IDENTIFICATION_CONTACT: + case _NL_IDENTIFICATION_EMAIL: + case _NL_IDENTIFICATION_TEL: + case _NL_IDENTIFICATION_FAX: + case _NL_IDENTIFICATION_LANGUAGE: + case _NL_IDENTIFICATION_TERRITORY: + case _NL_IDENTIFICATION_AUDIENCE: + case _NL_IDENTIFICATION_APPLICATION: + case _NL_IDENTIFICATION_ABBREVIATION: + case _NL_IDENTIFICATION_REVISION: + case _NL_IDENTIFICATION_DATE: + case _NL_IDENTIFICATION_CATEGORY: +# ifdef USE_LOCALE_IDENTIFICATION + cat_index = LC_IDENTIFICATION_INDEX_; +# endif + break; - SETERRNO(0, 0); - retval = (SSize_t) mbrtowc((wchar_t *) pwc, s, len, &PL_mbrtowc_ps); -# else + case _NL_MEASUREMENT_MEASUREMENT: +# ifdef USE_LOCALE_MEASUREMENT + cat_index = LC_MEASUREMENT_INDEX_; +# endif + break; - /* Locking prevents races, but locales can be switched out without locking, - * so this isn't a cure all */ - MBTOWC_LOCK_; - SETERRNO(0, 0); - retval = mbtowc((wchar_t *) pwc, s, len); - MBTOWC_UNLOCK_; + case _NL_NAME_NAME_FMT: + case _NL_NAME_NAME_GEN: + case _NL_NAME_NAME_MR: + case _NL_NAME_NAME_MRS: + case _NL_NAME_NAME_MISS: + case _NL_NAME_NAME_MS: +# ifdef USE_LOCALE_NAME + cat_index = LC_NAME_INDEX_; # endif + break; - return retval; -#endif + case _NL_PAPER_HEIGHT: + case _NL_PAPER_WIDTH: +# ifdef USE_LOCALE_PAPER + cat_index = LC_PAPER_INDEX_; +# endif + break; -} -/* -=for apidoc Perl_localeconv + case _NL_TELEPHONE_TEL_INT_FMT: + case _NL_TELEPHONE_TEL_DOM_FMT: + case _NL_TELEPHONE_INT_SELECT: + case _NL_TELEPHONE_INT_PREFIX: +# ifdef USE_LOCALE_TELEPHONE + cat_index = LC_TELEPHONE_INDEX_; +# endif + break; -This is a thread-safe version of the libc L. It is the same as -L (returning a hash of the C -fields), but directly callable from XS code. -=cut -*/ + default: /* The other possible items are all in LC_TIME. */ +# ifdef USE_LOCALE_TIME + cat_index = LC_TIME_INDEX_; +# endif + break; -HV * -Perl_localeconv(pTHX) -{ + } /* End of switch on item */ -#if ! defined(HAS_LOCALECONV) +# if defined(HAS_MISSING_LANGINFO_ITEM_) - return newHV(); + /* If the above didn't find the category's index, it has to be because the + * item is unknown to us (and the callee will handle that), or the category + * is confined to the "C" locale on this platform, which the callee also + * handles. (LC_MESSAGES is not required by the C Standard (the others + * above are), so we have to emulate it on platforms lacking it (such as + * Windows).) */ + if (cat_index == LC_ALL_INDEX_) { + return emulate_langinfo(item, "C", sv, utf8ness); + } -#else +# endif - return my_localeconv(0); + /* And get the value for this 'item', whose category has now been + * calculated. We need to find the current corresponding locale, and pass + * that as well. */ + return langinfo_sv_i(item, cat_index, + query_nominal_locale_i(cat_index), + sv, utf8ness); +} #endif +#if defined(USE_LOCALE) && defined(HAS_NL_LANGINFO) -} +STATIC const char * +S_langinfo_sv_i(pTHX_ + const nl_item item, /* The item to look up */ -#if defined(HAS_LOCALECONV) + /* The locale category that controls it */ + locale_category_index cat_index, -HV * -S_my_localeconv(pTHX_ const int item) + /* The locale to look up 'item' in. */ + const char * locale, + + /* The SV to store the result in; see below */ + SV * sv, + + /* If not NULL, the location to store the UTF8-ness of 'item's + * value, as documented */ + utf8ness_t * utf8ness) { - PERL_ARGS_ASSERT_MY_LOCALECONV; + PERL_ARGS_ASSERT_LANGINFO_SV_I; + assert(cat_index < LC_ALL_INDEX_); - /* This returns a mortalized hash containing all or one of the elements - * returned by localeconv(). It is used by Perl_localeconv() and - * POSIX::localeconv() and is thread-safe. - * - * There are two use cases: - * 1) Called from POSIX::locale_conv(). This returns the lconv structure - * copied to a hash, based on the current underlying locales for - * LC_NUMERIC and LC_MONETARY. An input item==0 signifies this case, or - * on many platforms it is the only use case compiled. - * 2) Certain items that nl_langinfo() provides are also derivable from - * the return of localeconv(). Windows notably doesn't have - * nl_langinfo(), so on that, and actually any platform lacking it, - * my_localeconv() is used also to emulate it for those particular - * items. The code to do this is compiled only on such platforms. - * Rather than going to the expense of creating a full hash when only - * one item is needed, the returned hash has just the desired item in - * it. - * - * To access all the localeconv() struct lconv fields, there is a data - * structure that contains every commonly documented field in it. (Maybe - * some minority platforms have extra fields. Those could be added here - * without harm; they would just be ignored on platforms lacking them.) + /* This function is the interface to nl_langinfo(), returning a thread-safe + * result, valid until its next call that uses the same 'sv'. Similarly, + * the S_emulate_langinfo() function below does the same, when + * nl_langinfo() isn't available for the desired locale, or is completely + * absent from the system. It is hopefully invisible to an outside caller + * as to which one of the two actually ends up processing the request. + * This comment block hence generally describes the two functions as a + * unit. + * + * The two functions both return values (using 'return' statements) and + * potentially change the contents of the passed in SV 'sv'. However, in + * any given call, only one of the return types is reliable. + * + * When the passed in SV is 'PL_scratch_langinfo', the functions make sure + * that the 'return' statements return the correct value, but whatever + * value is in 'PL_scratch_langinfo' should be considered garbage. When it + * is any other SV, that SV will get the correct result, and the value + * returned by a 'return' statement should be considered garbage. + * + * The reason for this is twofold: + * + * 1) These functions serve two masters. For most purposes when called + * from within this file, the desired value is used immediately, and + * then no longer required. For these, the 'return' statement values + * are most convenient. + * + * But when the call is initiated from an external XS source, like + * I18N::Langinfo, the value needs to be able to be stable for a longer + * time and likely returned to Perl space. An SV return is most + * convenient for these + * + * Further, some Configurations use these functions reentrantly. For + * those, an SV must be passed. + * + * 2) In S_emulate_langinfo(), most langinfo items are easy or even + * trivial to get. These are amenable to being returned by 'return' + * statements. But others are more complex, and use the infrastructure + * provided by perl's SV functions to help out. + * + * So for some items, it is most convenient to 'return' a simple value; for + * others an SV is most convenient. And some callers want a simple value; + * others want or need an SV. It would be wasteful to have an SV, convert + * it to a simple value, discarding the SV, then create a new SV. + * + * The solution adopted here is to always pass an SV, and have a reserved + * one, PL_scratch_langinfo, indicate that a 'return' is desired. That SV + * is then used as scratch for the items that it is most convenient to use + * an SV in calculating. Besides these two functions and initialization, + * the only mention of PL_scratch_langinfo is in the expansion of a single + * macro that is used by the code in this file that desires a non-SV return + * value. * - * Our structure is compiled to make looping through the fields easier by - * pointing each name to its value's offset within lconv, e.g., - { "thousands_sep", STRUCT_OFFSET(struct lconv, thousands_sep) } - */ -# define LCONV_ENTRY(name) \ - {STRINGIFY(name), STRUCT_OFFSET(struct lconv, name)} + * A wart of this interface is that to get the UTF-8 flag of the passed-in + * SV set, you have to also pass a non-null 'utf8ness' parameter. This is + * entirely to prevent the extra expense of calculating UTF-8ness when the + * caller is plain Perl_langinfo(), which doesn't care about this. If that + * seems too kludgy, other mechanisms could be devised. But be aware that + * the SV interface has to have a way to not calculate UTF-8ness, or else + * the reentrant uses could infinitely recurse */ - /* These synonyms are just for clarity, and to make it easier in case - * something needs to change in the future */ -# define LCONV_NUMERIC_ENTRY(name) LCONV_ENTRY(name) -# define LCONV_MONETARY_ENTRY(name) LCONV_ENTRY(name) + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "Entering langinfo_sv_i item=%jd, using locale %s\n", + (PERL_INTMAX_T) item, locale)); - /* There are just a few fields for NUMERIC strings */ - const lconv_offset_t lconv_numeric_strings[] = { -# ifndef NO_LOCALECONV_GROUPING - LCONV_NUMERIC_ENTRY(grouping), -# endif - LCONV_NUMERIC_ENTRY(thousands_sep), - LCONV_NUMERIC_ENTRY(decimal_point), - {NULL, 0} - }; +# ifdef HAS_MISSING_LANGINFO_ITEM_ - /* When used to implement nl_langinfo(), we save time by only populating - * the hash with the field(s) needed. Thus we would need a data structure - * of just: - * LCONV_NUMERIC_ENTRY(decimal_point), - * {NULL, 0} - * - * By placing the decimal_point field last in the full structure, we can - * use just the tail for this bit of it, saving space. This macro yields - * the address of the sub structure. */ -# define DECIMAL_POINT_ADDRESS \ - &lconv_numeric_strings[(C_ARRAY_LENGTH(lconv_numeric_strings) - 2)] + if (! category_available[cat_index]) { + return emulate_langinfo(item, locale, sv, utf8ness); + } - /* And the MONETARY string fields */ - const lconv_offset_t lconv_monetary_strings[] = { - LCONV_MONETARY_ENTRY(int_curr_symbol), - LCONV_MONETARY_ENTRY(mon_decimal_point), -# ifndef NO_LOCALECONV_MON_THOUSANDS_SEP - LCONV_MONETARY_ENTRY(mon_thousands_sep), -# endif -# ifndef NO_LOCALECONV_MON_GROUPING - LCONV_MONETARY_ENTRY(mon_grouping), # endif - LCONV_MONETARY_ENTRY(positive_sign), - LCONV_MONETARY_ENTRY(negative_sign), - LCONV_MONETARY_ENTRY(currency_symbol), - {NULL, 0} - }; - /* Like above, this field being last can be used as a sub structure */ -# define CURRENCY_SYMBOL_ADDRESS \ - &lconv_monetary_strings[(C_ARRAY_LENGTH(lconv_monetary_strings) - 2)] + /* One might be tempted to avoid any toggling by instead using + * nl_langinfo_l() on platforms that have it. This would entail creating a + * locale object with newlocale() and freeing it afterwards. But doing so + * runs significantly slower than just doing the toggle ourselves. + * lib/locale_threads.t was slowed down by 25% on Ubuntu 22.04 */ - /* Finally there are integer fields, all are for monetary purposes */ - const lconv_offset_t lconv_integers[] = { - LCONV_ENTRY(int_frac_digits), - LCONV_ENTRY(frac_digits), - LCONV_ENTRY(p_sep_by_space), - LCONV_ENTRY(n_cs_precedes), - LCONV_ENTRY(n_sep_by_space), - LCONV_ENTRY(p_sign_posn), - LCONV_ENTRY(n_sign_posn), -# ifdef HAS_LC_MONETARY_2008 - LCONV_ENTRY(int_p_cs_precedes), - LCONV_ENTRY(int_p_sep_by_space), - LCONV_ENTRY(int_n_cs_precedes), - LCONV_ENTRY(int_n_sep_by_space), - LCONV_ENTRY(int_p_sign_posn), - LCONV_ENTRY(int_n_sign_posn), -# endif - LCONV_ENTRY(p_cs_precedes), - {NULL, 0} - }; + start_DEALING_WITH_MISMATCHED_CTYPE(locale); - /* Like above, this field being last can be used as a sub structure */ -# define P_CS_PRECEDES_ADDRESS \ - &lconv_integers[(C_ARRAY_LENGTH(lconv_integers) - 2)] + const char * orig_switched_locale = toggle_locale_i(cat_index, locale); - /* If we aren't paying attention to a given category, use LC_CTYPE instead; - * If not paying attention to that either, the code below should end up not - * using this. Make sure that things blow up if that avoidance gets lost, - * by setting the category to -1 */ - unsigned int numeric_index; - unsigned int monetary_index; +/* nl_langinfo() is supposedly thread-safe except for its return value. The + * POSIX 2017 Standard states: + * + * "The pointer returned by nl_langinfo() might be invalidated or the string + * content might be overwritten by a subsequent call to nl_langinfo() in any + * thread or to nl_langinfo_l() in the same thread or the initial thread, by + * subsequent calls to setlocale() with a category corresponding to the + * category of item (see ) or the category LC_ALL, or by + * subsequent calls to uselocale() which change the category corresponding + * to the category of item." + * + * The implications of this are: + * a) Threaded: nl_langinfo()'s return must be saved in a critical section + * to avoid having another thread's call to it destroying the + * result. That means that the whole call to nl_langinfo() + * plus the save must be done in a critical section. + * b) Unthreaded: No critical section is needed (accomplished by having the + * locks below be no-ops in this case). But any subsequent + * setlocale() or uselocale() could still destroy it. + * Note that before returning, this function restores any + * toggled locale categories. These could easily end up + * calling uselocale() or setlocale(), destroying our + * result. (And in some Configurations, this file currently + * calls nl_langinfo_l() to determine if a uselocale() is + * needed.) So, a copy of the result is made in this case as + * well. + */ + const char * retval = NULL; + utf8ness_t is_utf8 = UTF8NESS_UNKNOWN; -# ifdef USE_LOCALE_NUMERIC - numeric_index = LC_NUMERIC_INDEX_; -# elif defined(USE_LOCALE_CTYPE) - numeric_index = LC_CTYPE_INDEX_; -# else - numeric_index = (unsigned) -1; -# endif -# ifdef USE_LOCALE_MONETARY - monetary_index = LC_MONETARY_INDEX_; -# elif defined(USE_LOCALE_CTYPE) - monetary_index = LC_CTYPE_INDEX_; + /* Do a bit of extra work so avoid + * switch() { default: ... } + * where the only case in it is the default: */ +# if defined(USE_LOCALE_PAPER) \ + || defined(USE_LOCALE_MEASUREMENT) \ + || defined(USE_LOCALE_ADDRESS) +# define IS_SWITCH 1 +# define MAYBE_SWITCH(n) switch(n) # else - monetary_index = (unsigned) -1; +# define IS_SWITCH 0 +# define MAYBE_SWITCH(n) # endif - /* Some platforms, for correct non-mojibake results, require LC_CTYPE's - * locale to match LC_NUMERIC's for the numeric fields, and LC_MONETARY's - * for the monetary ones. What happens if LC_NUMERIC and LC_MONETARY - * aren't compatible? Wrong results. To avoid that, we call localeconv() - * twice, once for each locale, setting LC_CTYPE to match the category. - * But if the locales of both categories are the same, there is no need for - * a second call. Assume this is the case unless overridden below */ - bool requires_2nd_localeconv = false; - - /* The actual hash populating is done by S_populate_hash_from_localeconv(). - * It gets passed an array of length two containing the data structure it - * is supposed to use to get the key names to fill the hash with. One - * element is alwasy for the NUMERIC strings (or NULL if none to use), and - * the other element similarly for the MONETARY ones. */ -# define NUMERIC_STRING_OFFSET 0 -# define MONETARY_STRING_OFFSET 1 - const lconv_offset_t * strings[2] = { NULL, NULL }; - - /* This is a mask, with one bit to tell S_populate_hash_from_localeconv to - * populate the NUMERIC items; another bit for the MONETARY ones. This way - * it can choose which (or both) to populate from */ - U32 index_bits = 0; - - /* This converts from a locale index to its bit position in the above mask. - * */ -# define INDEX_TO_BIT(i) (1 << (i)) - - /* The two categories can have disparate locales. Initialize them to C and - * override later whichever one(s) we pay attention to */ - const char * numeric_locale = "C"; - const char * monetary_locale = "C"; - - /* This will be either 'numeric_locale' or 'monetary_locale' depending on - * what we are working on at the moment */ - const char * locale; - - /* The LC_MONETARY category also has some integer-valued fields, whose - * information is kept in a separate list */ - const lconv_offset_t * integers; - -# ifdef HAS_SOME_LANGINFO - - /* If the only use-case for this is the full localeconv(), the 'item' - * parameter is ignored. */ - PERL_UNUSED_ARG(item); + GCC_DIAG_IGNORE_STMT(-Wimplicit-fallthrough); -# else + MAYBE_SWITCH(item) { - /* This only gets compiled for the use-case of using localeconv() to - * emulate an nl_langinfo() missing from the platform. - * - * We need this substructure to only return this field for the THOUSEP - * item. The other items also need substructures, but they were handled - * above by placing the substructure's item at the end of the full one, so - * the data structure could do double duty. However, both this and - * RADIXCHAR would need to be in the final position of the same full - * structure; an impossibility. So make this into a separate structure */ - const lconv_offset_t thousands_sep_string[] = { - LCONV_NUMERIC_ENTRY(thousands_sep), - {NULL, 0} - }; +# if defined(USE_LOCALE_MEASUREMENT) - /* End of all the initialization of datastructures. Now for actual code. - * - * Without nl_langinfo(), the call to my_localeconv() could be for just one - * of the following 3 items to emulate nl_langinfo(). This is compiled - * only when using perl_langinfo.h, which we control, and it has been - * constructed so that no item is numbered 0. - * - * For each, setup the appropriate parameters for the call below to - * S_populate_hash_from_localeconv() */ - if (item != 0) switch (item) { - default: - locale_panic_(Perl_form(aTHX_ - "Unexpected item passed to my_localeconv: %d", item)); - break; + case _NL_MEASUREMENT_MEASUREMENT: + { + /* An ugly API; only the first byte of the returned char* address means + * anything */ + gwLOCALE_LOCK; + char char_value = nl_langinfo(item)[0]; + gwLOCALE_UNLOCK; -# ifdef USE_LOCALE_NUMERIC + sv_setuv(sv, char_value); + } - case RADIXCHAR: - locale = numeric_locale = PL_numeric_name; - index_bits = INDEX_TO_BIT(LC_NUMERIC_INDEX_); - strings[NUMERIC_STRING_OFFSET] = DECIMAL_POINT_ADDRESS; - integers = NULL; - break; + goto non_string_common; - case THOUSEP: - index_bits = INDEX_TO_BIT(LC_NUMERIC_INDEX_); - locale = numeric_locale = PL_numeric_name; - strings[NUMERIC_STRING_OFFSET] = thousands_sep_string; - integers = NULL; - break; +# endif +# if defined(USE_LOCALE_ADDRESS) || defined(USE_LOCALE_PAPER) +# if defined(USE_LOCALE_ADDRESS) -# endif -# ifdef USE_LOCALE_MONETARY + case _NL_ADDRESS_COUNTRY_NUM: - case CRNCYSTR: - index_bits = INDEX_TO_BIT(LC_MONETARY_INDEX_); - locale = monetary_locale = querylocale_i(LC_MONETARY_INDEX_); + /* Some glibc's return random values for this item and locale; + * workaround by special casing it. */ + if (isNAME_C_OR_POSIX(locale)) { + sv_setuv(sv, 0); + goto non_string_common; + } - /* This item needs the values for both the currency symbol, and another - * one used to construct the nl_langino()-compatible return */ - strings[MONETARY_STRING_OFFSET] = CURRENCY_SYMBOL_ADDRESS; - integers = P_CS_PRECEDES_ADDRESS; - break; + /* FALLTHROUGH */ # endif +# if defined(USE_LOCALE_PAPER) - } /* End of switch() */ + case _NL_PAPER_HEIGHT: case _NL_PAPER_WIDTH: - else /* End of for just one item to emulate nl_langinfo() */ +# endif -# endif + { /* A slightly less ugly API; the int portion of the returned char* + * address is an integer. */ + gwLOCALE_LOCK; + int int_value = (int) PTR2UV(nl_langinfo(item)); + gwLOCALE_UNLOCK; - { /* Here, the call is for all of localeconv(). It has a bunch of - * items. As in the individual item case, set up the parameters for - * S_populate_hash_from_localeconv(); */ + sv_setuv(sv, int_value); + } -# ifdef USE_LOCALE_NUMERIC - numeric_locale = PL_numeric_name; -# elif defined(USE_LOCALE_CTYPE) - numeric_locale = querylocale_i(numeric_index); -# endif -# if defined(USE_LOCALE_MONETARY) || defined(USE_LOCALE_CTYPE) - monetary_locale = querylocale_i(monetary_index); # endif +# if IS_SWITCH +# if defined(USE_LOCALE_MEASUREMENT) - /* The first call to S_populate_hash_from_localeconv() will be for the - * MONETARY values */ - index_bits = INDEX_TO_BIT(monetary_index); - locale = monetary_locale; + non_string_common: - /* And if the locales for the two categories are the same, we can also - * do the NUMERIC values in the same call */ - if (strEQ(numeric_locale, monetary_locale)) { - index_bits |= INDEX_TO_BIT(numeric_index); - } - else { - requires_2nd_localeconv = true; +# endif + + /* In all cases that get here, the char* instead delivers a numeric + * value, so its UTF-8ness is meaningless */ + is_utf8 = UTF8NESS_IMMATERIAL; + + if (sv == PL_scratch_langinfo) { + retval = SvPV_nomg_const_nolen(sv); } - /* We always pass both sets of strings. 'index_bits' tells - * S_populate_hash_from_localeconv which to actually look at */ - strings[NUMERIC_STRING_OFFSET] = lconv_numeric_strings; - strings[MONETARY_STRING_OFFSET] = lconv_monetary_strings; - - /* And pass the integer values to populate; again 'index_bits' will - * say to use them or not */ - integers = lconv_integers; + break; - } /* End of call is for localeconv() */ + default: - /* The code above has determined the parameters to - S_populate_hash_from_localeconv() for both cases of an individual item - and for the entire structure. Below is code common to both */ +# endif - HV * hv = newHV(); /* The returned hash, initially empty */ - sv_2mortal((SV*)hv); + /* The rest of the possibilities deliver a true char* pointer to a + * string (or sequence of strings in the case of ALT_DIGITS) */ + gwLOCALE_LOCK; + + retval = nl_langinfo(item); + Size_t total_len = strlen(retval); + + /* Initialized only to silence some dumber compilers warning that + * might be uninitialized */ + char separator = ';'; + + if (UNLIKELY(item == ALT_DIGITS) && total_len > 0) { + + /* The return from nl_langinfo(ALT_DIGITS) is specified by the + * 2017 POSIX Standard as a string consisting of "semicolon- + * separated symbols. The first is the alternative symbol + * corresponding to zero, the second is the symbol corresponding to + * one, and so on. Up to 100 alternative symbols may be + * specified". Infuriatingly, Linux does not follow this, and uses + * the least C-language-friendly separator possible, the NUL. In + * case other platforms also violate the standard, the code below + * looks for NUL and any graphic \W character as a potential + * separator. */ + const char * sep_pos = strchr(retval, ';'); + if (! sep_pos) { + sep_pos = strpbrk(retval, " !\"#$%&'()*+,-./:<=>?@[\\]^_`{|}~"); + } + if (sep_pos) { + separator = *sep_pos; + } + else if (strpbrk(retval, "123456789")) { + + /* Alternate digits, with the possible exception of 0, + * shouldn't be standard digits, so if we get any back, return + * that there aren't alternate digits. 0 is an exception + * because there may be locales that do not have a zero, such + * as Roman numerals. It could therefore be that alt-0 is 0, + * but alt-1 better be some multi-byte Unicode character(s) + * like U+2160, ROMAN NUMERAL ONE. This clause is necessary + * because the total length of the ASCII digits won't trigger + * the conditional in the next clause that protects against + * non-Standard libc returns, such as in Alpine platforms, but + * multi-byte returns will trigger it */ + retval = ""; + total_len = 0; + } + else if (UNLIKELY(total_len > + 2 * UVCHR_SKIP(PERL_UNICODE_MAX) * 4)) + { /* But as a check against the possibility that the separator is + * some other character, look at the length of the returned + * string. If the separator is a NUL, the length will be just + * for the first NUL-terminated segment; if it is some other + * character, there is only a single segment with all returned + * alternate digits, which will be quite a bit longer than just + * the first one. Many locales will always have a leading zero + * to represent 0-9 (hence the 2* in the conditional above). + * The conditional uses the worst case value of the most number + * of byte possible for a Unicode character, and it is possible + * that it requires several characters to represent a single + * value; hence the final multiplier. This length represents a + * conservative upper limit of the number of bytes for the + * alternative representation of 00, but if the string + * represents even only the first 10 alternative digits, it + * will be much longer than that. So to reach here, the + * separator must be some other byte. */ + locale_panic_(Perl_form(aTHX_ + "Can't find separator in ALT_DIGITS" + " representation '%s' for locale '%s'", + _byte_dump_string((U8 *) retval, + total_len, 0), + locale)); + } + else { + separator = '\0'; - /* Call localeconv() and copy its results into the hash. All the - * parameters have been initialized above */ - populate_hash_from_localeconv(hv, - locale, - index_bits, - strings, - integers - ); + /* Must be using NUL to separate the digits. There are up to + * 100 of them. Find the length of the entire sequence. + * + * The only way it could work if fewer is if it ends in two + * NULs. khw has seen cases where there is no 2nd NUL on a 100 + * digit return. */ + const char * s = retval + total_len + 1; + + for (unsigned int i = 1; i <= 99; i++) { + Size_t len = strlen(s) + 1; + total_len += len; - /* The above call may have done all the hash fields, but not always, as - * already explained. If we need a second call it is always for the - * NUMERIC fields */ - if (requires_2nd_localeconv) { - populate_hash_from_localeconv(hv, - numeric_locale, - INDEX_TO_BIT(numeric_index), - strings, - NULL /* There are No NUMERIC integer - fields */ - ); - } + if (len == 1) { /* Only a NUL */ + break; + } - /* Here, the hash has been completely populated. - * - * Now go through all the items and: - * a) For string items, see if they should be marked as UTF-8 or not. - * This would have been more convenient and faster to do while - * populating the hash in the first place, but that operation has to be - * done within a critical section, keeping other threads from - * executing, so only the minimal amount of work necessary is done at - * that time. - * b) For integer items, convert the C CHAR_MAX value into -1. Again, - * this could have been done in the critical section, but was deferred - * to here to keep to the bare minimum amount the time spent owning the - * processor. CHAR_MAX is a C concept for an 8-bit character type. - * Perl has no such type; the closest fit is a -1. - * - * XXX On unthreaded perls, this code could be #ifdef'd out, and the - * corrections determined at hash population time, at an extra maintenance - * cost which khw doesn't think is worth it - */ - for (unsigned int i = 0; i < 2; i++) { /* Try both types of strings */ - if (! strings[i]) { /* Skip if no strings of this type */ - continue; + s += len; + } + } } - locale = (i == NUMERIC_STRING_OFFSET) - ? numeric_locale - : monetary_locale; + sv_setpvn(sv, retval, total_len); - locale_utf8ness_t locale_is_utf8 = LOCALE_UTF8NESS_UNKNOWN; + gwLOCALE_UNLOCK; -# ifdef HAS_RELIABLE_UTF8NESS_DETERMINATION + /* Convert the ALT_DIGITS separator to a semi-colon if not already */ + if (UNLIKELY(item == ALT_DIGITS) && total_len > 0 && separator != ';') { - /* It saves time in the loop below to have predetermined the UTF8ness - * of the locale. But only do so if the platform reliably has this - * information; otherwise to do it, this could recurse indefinitely. - * - * When we don't do it here, it will be done on a per-element basis in - * the loop. The per-element check is intelligent enough to not - * recurse */ - - locale_is_utf8 = (is_locale_utf8(locale)) - ? LOCALE_IS_UTF8 - : LOCALE_NOT_UTF8; + /* Operate directly on the string in the SV */ + char * digit_string = SvPVX(sv); + char * s = digit_string; + char * e = s + total_len; - if (locale_is_utf8 == LOCALE_NOT_UTF8) { - continue; /* No string can be UTF-8 if the locale isn't */ + do { + char * this_end = (char *) memchr(s, separator, total_len); + if (! this_end || this_end >= e) { + break; + } + + *this_end = ';'; + s = this_end; + } while (1); } -# endif + SvUTF8_off(sv); + retval = SvPV_nomg_const_nolen(sv); + } - /* Examine each string */ - while (1) { - const char * name = strings[i]->name; + GCC_DIAG_RESTORE_STMT; - if (! name) { /* Reached the end */ - break; - } + restore_toggled_locale_i(cat_index, orig_switched_locale); + end_DEALING_WITH_MISMATCHED_CTYPE(locale); - /* 'value' will contain the string that may need to be marked as - * UTF-8 */ - SV ** value = hv_fetch(hv, name, strlen(name), true); - if (! value) { - continue; - } + if (utf8ness) { + if (LIKELY(is_utf8 == UTF8NESS_UNKNOWN)) { /* default: case above */ + is_utf8 = get_locale_string_utf8ness_i(retval, + LOCALE_UTF8NESS_UNKNOWN, + locale, cat_index); + } - /* Determine if the string should be marked as UTF-8. */ - if (UTF8NESS_YES == (get_locale_string_utf8ness_i(SvPVX(*value), - locale_is_utf8, - NULL, 0))) - { - SvUTF8_on(*value); - } + *utf8ness = is_utf8; - strings[i]++; /* Iterate */ + if (*utf8ness == UTF8NESS_YES) { + SvUTF8_on(sv); } - } /* End of fixing up UTF8ness */ - + } - /* Examine each integer */ - if (integers) while (1) { - const char * name = integers->name; + return retval; +} - if (! name) { /* Reached the end */ - break; - } +# undef IS_SWITCH +# undef MAYBE_SWITCH +#endif +#ifndef HAS_DEFINITIVE_UTF8NESS_DETERMINATION - SV ** value = hv_fetch(hv, name, strlen(name), true); - if (! value) { - continue; - } +/* Forward declaration of function that we don't put into embed.fnc so as to + * make its removal easier, as there may not be any extant platforms that need + * it; and the function is located after emulate_langinfo() because it's easier + * to understand when placed in the context of that code */ +STATIC bool +S_maybe_override_codeset(pTHX_ const char * codeset, + const char * locale, + const char ** new_codeset); +#endif +#if ! defined(HAS_NL_LANGINFO) || defined(HAS_MISSING_LANGINFO_ITEM_) - /* Change CHAR_MAX to -1 */ - if (SvIV(*value) == CHAR_MAX) { - sv_setiv(*value, -1); - } +STATIC const char * +S_emulate_langinfo(pTHX_ const PERL_INTMAX_T item, + const char * locale, + SV * sv, + utf8ness_t * utf8ness) +{ + PERL_ARGS_ASSERT_EMULATE_LANGINFO; + PERL_UNUSED_ARG(locale); /* Too complicated to specify which + Configurations use this vs which don't */ + + /* This emulates nl_langinfo() on platforms: + * 1) where it doesn't exist; or + * 2) where it does exist, but there are categories that it shouldn't be + * called on because they don't exist on the platform or we are + * supposed to always stay in the C locale for them. This function + * has hard-coded in the results for those for the C locale. + * + * This function returns a thread-safe result, valid until its next call + * that uses the same 'sv'. Similarly, the S_langinfo_sv_i() function + * above does the same when nl_langinfo() is available. Its comments + * include a general description of the interface for both it and this + * function. That function should be the one called by code outside this + * little group. If it can't handle the request, it gets handed off to + * this function. + * + * The major platform lacking nl_langinfo() is Windows. It does have + * GetLocaleInfoEx() that could be used to get most of the items, but it + * (and other similar Windows API functions) use what MS calls "locale + * names", whereas the C functions use what MS calls "locale strings". The + * locale string "English_United_States.1252" is equivalent to the locale + * name "en_US". There are tables inside Windows that translate between + * the two forms, but they are not exposed. Also calling setlocale(), then + * calling GetThreadLocale() doesn't work, as the former doesn't change the + * latter's return. Therefore we are stuck using the mechanisms below. */ - integers++; /* Iterate */ - } + /* Almost all the items will have ASCII return values. Set that here, and + * override if necessary */ + utf8ness_t is_utf8 = UTF8NESS_IMMATERIAL; + const char * retval = NULL; - return hv; -} + /* This function returns its result either by returning the calculated + * value 'retval' if the 'sv' argument is PL_scratch_langinfo; or for any + * other value of 'sv', it places the result into that 'sv'. For some + * paths through the code, it is more convenient, in the moment, to use one + * or the other to hold the calculated result. And, the calculation could + * end up with the value in both places. At the end, if the caller + * wants the convenient result, we are done; but if it wants the opposite + * type of value, it must be converted. These macros are used to tell the + * code at the end where the value got placed. */ +# define RETVAL_IN_retval -1 +# define RETVAL_IN_BOTH 0 +# define RETVAL_IN_sv 1 +# define isRETVAL_IN_sv(type) ((type) >= RETVAL_IN_BOTH) +# define isRETVAL_IN_retval(type) ((type) <= RETVAL_IN_BOTH) + + /* Most calculations place the result in 'retval', so initialize to that, + * and override if necessary */ + int retval_type = RETVAL_IN_retval; -STATIC void -S_populate_hash_from_localeconv(pTHX_ HV * hv, + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "Entering emulate_langinfo item=%jd, using locale %s\n", + item, locale)); - /* Switch to this locale to run - * localeconv() from */ - const char * locale, +# if defined(HAS_LOCALECONV) \ + && ! defined(HAS_SOME_LANGINFO) \ + && (defined(USE_LOCALE_NUMERIC) || defined(USE_LOCALE_MONETARY)) - /* bit mask of which categories to - * populate */ - const U32 which_mask, + locale_category_index cat_index; + const char * localeconv_key; + I32 localeconv_klen; - /* strings[0] points the numeric - * string fields; [1] to the monetary */ - const lconv_offset_t * strings[2], +# endif - /* And to the monetary integer fields */ - const lconv_offset_t * integers) -{ - PERL_ARGS_ASSERT_POPULATE_HASH_FROM_LOCALECONV; - PERL_UNUSED_ARG(which_mask); /* Some configurations don't use this; - complicated to figure out which */ + GCC_DIAG_IGNORE_STMT(-Wimplicit-fallthrough); - /* Run localeconv() and copy some or all of its results to the input 'hv' - * hash. Most localeconv() implementations return the values in a global - * static buffer, so the operation must be performed in a critical section, - * ending only after the copy is completed. There are so many locks - * because localeconv() deals with two categories, and returns in a single - * global static buffer. Some locks might be no-ops on this platform, but - * not others. We need to lock if any one isn't a no-op. */ + switch (item) { -# ifdef USE_LOCALE_CTYPE +# if ! defined(HAS_SOME_LANGINFO) || ! LC_MESSAGES_AVAIL_ - /* Some platforms require LC_CTYPE to be congruent with the category we are - * looking for */ - const char * orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, locale); + /* The following items have no way khw could figure out how to get except + * via nl_langinfo() */ + case YESEXPR: retval = "^[+1yY]"; break; + case YESSTR: retval = "yes"; break; + case NOEXPR: retval = "^[-0nN]"; break; + case NOSTR: retval = "no"; break; # endif -# ifdef USE_LOCALE_NUMERIC +# if ! defined(HAS_SOME_LANGINFO) || ! LC_MONETARY_AVAIL_ +# if defined(USE_LOCALE_MONETARY) && defined(HAS_LOCALECONV) +# define NEED_USE_LOCALECONV - /* We need to toggle to the underlying NUMERIC locale if we are getting - * NUMERIC strings */ - const char * orig_NUMERIC_locale = NULL; - if (which_mask & INDEX_TO_BIT(LC_NUMERIC_INDEX_)) { - LC_NUMERIC_LOCK(0); - orig_NUMERIC_locale = toggle_locale_i(LC_NUMERIC_INDEX_, locale); - } + case CRNCYSTR: + cat_index = LC_MONETARY_INDEX_; + localeconv_key = CURRENCY_SYMBOL_LITERAL; + localeconv_klen = STRLENs(CURRENCY_SYMBOL_LITERAL); + goto use_localeconv; -# endif +# else - /* Finally ready to do the actual localeconv(). Lock to prevent other - * accesses until we have made a copy of its returned static buffer */ - gwLOCALE_LOCK; + case CRNCYSTR: -# ifdef TS_W32_BROKEN_LOCALECONV + /* The locale's currency symbol may be empty. But if not, the return + * from nl_langinfo() prefixes it with a character that indicates where + * in the monetary value the symbol is to be placed + * a) before, like $9.99 + * b) middle, rare, but would like be 9$99 + * c) after, like 9.99USD + * + * The POSIX Standard permits an implementation to choose whether or + * not to omit the prefix character if the symbol is empty (the + * placement position is meaningless if there is nothing to place). + * glibc has chosen to always prefix an empty symbol by a minus (which + * is the prefix for 'before' positioning). FreeBSD has chosen to + * return an empty string for an empty symbol. Perl has always + * emulated the glibc way (probably with little thought). */ + retval = "-"; + break; - /* This is a workaround for another bug in Windows. localeconv() was - * broken with thread-safe locales prior to VS 15. It looks at the global - * locale instead of the thread one. As a work-around, we toggle to the - * global locale; populate the return; then toggle back. We have to use - * LC_ALL instead of the individual categories because of yet another bug - * in Windows. And this all has to be done in a critical section. - * - * This introduces a potential race with any other thread that has also - * converted to use the global locale, and doesn't protect its locale calls - * with mutexes. khw can't think of any reason for a thread to do so on - * Windows, as the locale API is the same regardless of thread-safety, except - * if the code is ported from working on another platform where there might - * be some reason to do this. But this is typically due to some - * alien-to-Perl library that thinks it owns locale setting. Such a - * library isn't likely to exist on Windows, so such an application is - * unlikely to be run on Windows - */ - bool restore_per_thread = FALSE; +# endif +# endif +# if ! defined(HAS_SOME_LANGINFO) || ! LC_NUMERIC_AVAIL_ +# if defined(USE_LOCALE_NUMERIC) && defined(HAS_LOCALECONV) +# define NEED_USE_LOCALECONV - /* Save the per-thread locale state */ - const char * save_thread = querylocale_c(LC_ALL); + case THOUSEP: + cat_index = LC_NUMERIC_INDEX_; + localeconv_key = THOUSANDS_SEP_LITERAL; + localeconv_klen = STRLENs(THOUSANDS_SEP_LITERAL); + goto use_localeconv; - /* Change to the global locale, and note if we already were there */ - if (_configthreadlocale(_DISABLE_PER_THREAD_LOCALE) - != _DISABLE_PER_THREAD_LOCALE) - { - restore_per_thread = TRUE; - } +# else - /* Save the state of the global locale; then convert to our desired - * state. */ - const char * save_global = querylocale_c(LC_ALL); - void_setlocale_c(LC_ALL, save_thread); + case THOUSEP: + retval = C_thousands_sep; + break; -# endif /* TS_W32_BROKEN_LOCALECONV */ +# endif - /* Finally, do the actual localeconv */ - const char *lcbuf_as_string = (const char *) localeconv(); + case RADIXCHAR: - /* Fill in the string fields of the HV* */ - for (unsigned int i = 0; i < 2; i++) { +# if defined(USE_LOCALE_NUMERIC) && defined(HAS_STRTOD) -# ifdef USE_LOCALE_NUMERIC + { + /* khw knows of only three possible radix characters used in the world. + * By far the two most common are comma and dot. We can use strtod() + * to quickly check for those without without much fuss. If it is + * something other than those two, the code drops down and lets + * localeconv() find it. + * + * We don't have to toggle LC_CTYPE here because all locales Perl + * supports are compatible with ASCII, which the two possibilities are. + * */ + const char * orig_switched_locale = toggle_locale_c(LC_NUMERIC, locale); - /* One iteration is only for the numeric string fields */ - if ( i == NUMERIC_STRING_OFFSET - && (which_mask & INDEX_TO_BIT(LC_NUMERIC_INDEX_)) == 0) - { - continue; + /* Comma tried first in case strtod() always accepts dot regardless of + * the locale */ + if (strtod("1,5", NULL) > 1.4) { + retval = ","; + } + else if (strtod("1.5", NULL) > 1.4) { + retval = "."; + } + else { + retval = NULL; } -# endif -# ifdef USE_LOCALE_MONETARY + restore_toggled_locale_c(LC_NUMERIC, orig_switched_locale); - /* The other iteration is only for the monetary string fields */ - if ( i == MONETARY_STRING_OFFSET - && (which_mask & INDEX_TO_BIT(LC_MONETARY_INDEX_)) == 0) - { - continue; + if (retval) { + break; } + } + +# endif /* Trying strtod() */ + + /* If gets to here, the strtod() method wasn't compiled, or it failed; + * drop down. + * + * (snprintf() used to be used instead of strtod(), but it was removed + * as being somewhat more clumsy, and maybe non-conforming on some + * platforms. But before resorting to localeconv(), the code that was + * removed by the strtod commit could be inserted here. This seems + * unlikely to be wanted unless some really broken localeconv() shows + * up) */ + +# if ! defined(USE_LOCALE_NUMERIC) || ! defined(HAS_LOCALECONV) + + retval = C_decimal_point; + break; + +# else +# define NEED_USE_LOCALECONV + cat_index = LC_NUMERIC_INDEX_; + localeconv_key = DECIMAL_POINT_LITERAL; + localeconv_klen = STRLENs(DECIMAL_POINT_LITERAL); + +# endif # endif +# ifdef NEED_USE_LOCALECONV - /* For each field for the given category ... */ - const lconv_offset_t * category_strings = strings[i]; - while (1) { - const char * name = category_strings->name; - if (! name) { /* Quit at the end */ - break; - } + /* These items are available from localeconv(). */ - /* we have set things up so that we know where in the returned - * structure, when viewed as a string, the corresponding value is. - * */ - const char *value = *((const char **)( lcbuf_as_string - + category_strings->offset)); + /* case RADIXCHAR: // May drop down to here in some configurations + case THOUSEP: // Jumps to here + case CRNCYSTR: // Jumps to here */ + use_localeconv: + { - /* Set to get next string on next iteration */ - category_strings++; + /* The hash gets populated with just the field(s) related to 'item'. */ + HV * result_hv = my_localeconv(item); + SV* string = hv_delete(result_hv, localeconv_key, localeconv_klen, 0); - /* Skip if this platform doesn't have this field. */ - if (! value) { - continue; +# ifdef USE_LOCALE_MONETARY + + if (item == CRNCYSTR) { + + /* CRNCYSTR localeconv() returns a slightly different value + * than the nl_langinfo() API calls for, so have to modify this one + * to conform. We need another value from localeconv() to know + * what to change it to. my_localeconv() has populated the hash + * with exactly both fields. */ + SV* precedes = hv_deletes(result_hv, P_CS_PRECEDES_LITERAL, 0); + if (! precedes) { + locale_panic_("my_localeconv() unexpectedly didn't return" + " a value for " P_CS_PRECEDES_LITERAL); } - /* Copy to the hash */ - (void) hv_store(hv, - name, strlen(name), - newSVpv(value, strlen(value)), - 0); + /* The modification is to prefix the localeconv() return with a + * single byte, calculated as follows: */ + const char * prefix = (LIKELY(SvIV(precedes) != -1)) + ? ((precedes != 0) ? "-" : "+") + : "."; + /* (khw couldn't find any documentation that the dot is signalled + * by CHAR_MAX (which we modify to -1), but cygwin uses it thusly, + * and it makes sense given that CHAR_MAX indicates the value isn't + * used, so it neither precedes nor succeeds) */ + + /* Perform the modification */ + sv_insert(string, 0, 0, prefix, 1); } - /* Add any int fields to the HV* */ - if (i == MONETARY_STRING_OFFSET && integers) { - while (integers->name) { - const char value = *((const char *)( lcbuf_as_string - + integers->offset)); - (void) hv_store(hv, integers->name, - strlen(integers->name), newSViv(value), 0); - integers++; - } +# endif + + /* Here, 'string' contains the value we want to return, and the + * hv_delete() has left it mortalized so its PV may be reused instead of + * copied */ + sv_setsv_nomg(sv, string); + retval_type = RETVAL_IN_sv; + + if (utf8ness) { + is_utf8 = get_locale_string_utf8ness_i(SvPVX(sv), + LOCALE_UTF8NESS_UNKNOWN, + locale, + cat_index); } - } /* End of loop through the fields */ - /* Done with copying to the hash. Can unwind the critical section locks */ + SvREFCNT_dec_NN(result_hv); + break; + } + +# endif /* Using localeconv() for something or other */ +# undef NEED_USE_LOCALECONV +# if ! defined(HAS_SOME_LANGINFO) || ! LC_CTYPE_AVAIL_ +# ifndef USE_LOCALE_CTYPE + + case CODESET: + retval = C_codeset; + break; -# ifdef TS_W32_BROKEN_LOCALECONV +# else - /* Restore the global locale's prior state */ - void_setlocale_c(LC_ALL, save_global); + case CODESET: - /* And back to per-thread locales */ - if (restore_per_thread) { - _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); - } + /* The trivial case */ + if (isNAME_C_OR_POSIX(locale)) { + retval = C_codeset; + break; + } - /* Restore the per-thread locale state */ - void_setlocale_c(LC_ALL, save_thread); + /* If this happens to match our cached value */ + if (PL_in_utf8_CTYPE_locale && strEQ(locale, PL_ctype_name)) { + retval = "UTF-8"; + break; + } -# endif /* TS_W32_BROKEN_LOCALECONV */ +# ifdef WIN32 +# ifdef WIN32_USE_FAKE_OLD_MINGW_LOCALES +# define CODE_PAGE_FORMAT "%s" +# define CODE_PAGE_FUNCTION nl_langinfo(CODESET) +# else +# define CODE_PAGE_FORMAT "%d" + + /* This Windows function retrieves the code page. It is subject to + * change, but is documented, and has been stable for many releases */ +# define CODE_PAGE_FUNCTION ___lc_codepage_func() +# endif + + const char * orig_CTYPE_locale; + orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, locale); + Perl_sv_setpvf(aTHX_ sv, CODE_PAGE_FORMAT, CODE_PAGE_FUNCTION); + retval_type = RETVAL_IN_sv; + + /* We just assume the codeset is ASCII; no need to check for it being + * UTF-8 */ + SvUTF8_off(sv); - gwLOCALE_UNLOCK; /* Finished with the critical section of a - globally-accessible buffer */ + restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale); -# ifdef USE_LOCALE_NUMERIC + DEBUG_Lv(PerlIO_printf(Perl_debug_log, "locale='%s' cp=%s\n", + locale, SvPVX(sv))); + break; - restore_toggled_locale_i(LC_NUMERIC_INDEX_, orig_NUMERIC_locale); - if (which_mask & INDEX_TO_BIT(LC_NUMERIC_INDEX_)) { - LC_NUMERIC_UNLOCK; - } +# else /* Below is ! Win32 */ -# endif -# ifdef USE_LOCALE_CTYPE + /* The codeset is important, but khw did not figure out a way for it to + * be retrieved on non-Windows boxes without nl_langinfo(). But even + * if we can't get it directly, we can usually determine if it is a + * UTF-8 locale or not. If it is UTF-8, we (correctly) use that for + * the code set. */ + +# ifdef HAS_DEFINITIVE_UTF8NESS_DETERMINATION + + if (is_locale_utf8(locale)) { + retval = "UTF-8"; + break; + } + +# endif - restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale); + /* Here, the code set has not been found. The only other option khw + * could think of is to see if the codeset is part of the locale name. + * This is very less than ideal; often there is no code set in the + * name; and at other times they even lie. + * + * But there is an XPG standard syntax, which many locales follow: + * + * language[_territory[.codeset]][@modifier] + * + * So we take the part between the dot and any '@' */ + const char * name; + name = strchr(locale, '.'); + if (! name) { + retval = ""; /* Alas, no dot */ + } + else { -# endif + /* Don't include the dot */ + name++; -} + /* The code set name is considered to be everything between the dot + * and any '@', so stop before any '@' */ + const char * modifier = strchr(name, '@'); + if (modifier) { + sv_setpvn(sv, name, modifier - name); + } + else { + sv_setpv(sv, name); + } + SvUTF8_off(sv); -#endif /* defined(HAS_LOCALECONV) */ -#ifndef HAS_SOME_LANGINFO + retval_type = RETVAL_IN_sv; + } -typedef int nl_item; /* Substitute 'int' for emulated nl_langinfo() */ +# ifndef HAS_DEFINITIVE_UTF8NESS_DETERMINATION -#endif + /* Here, 'retval' contains any codeset name derived from the locale + * name. That derived name may be empty or not necessarily indicative + * of the real codeset. But we can often determine if it should be + * UTF-8, regardless of what the name is. On most platforms, that + * determination is definitive, and was already done. But for this + * code to be compiled, this platform is not one of them. However, + * there are typically tools available to make a very good guess, and + * knowing the derived codeset name improves the quality of that guess. + * The following function overrides the derived codeset name when it + * guesses that it actually should be UTF-8. It could be inlined here, + * but was moved out of this switch() so as to make the switch() + * control flow easier to follow */ + if (isRETVAL_IN_sv(retval_type)) { + retval = SvPVX_const(sv); + retval_type = RETVAL_IN_BOTH; + } -/* + if (S_maybe_override_codeset(aTHX_ retval, locale, &retval)) { + retval_type = RETVAL_IN_retval; + } -=for apidoc Perl_langinfo -=for apidoc_item Perl_langinfo8 +# endif -C is an (almost) drop-in replacement for the system -C>, taking the same C parameter values, and returning -the same information. But it is more thread-safe than regular -C, and hides the quirks of Perl's locale handling from your -code, and can be used on systems that lack a native C. + break; -However, you should instead use the improved version of this: -L, which behaves identically except for an additional -parameter, a pointer to a variable declared as L>, into which it -returns to you how you should treat the returned string with regards to it -being encoded in UTF-8 or not. +# endif /* ! WIN32 */ +# endif /* USE_LOCALE_CTYPE */ +# endif -Concerning the differences between these and plain C: + /* The _NL_foo items are mostly empty; the rest are copied from Ubuntu C + * locale values. khw fairly arbitrarily decided which of its non-empty + * values to copy and which to change to empty. All the numeric ones needed + * some value */ + +# if ! defined(HAS_SOME_LANGINFO) || ! LC_ADDRESS_AVAIL_ + + case _NL_ADDRESS_POSTAL_FMT: + case _NL_ADDRESS_COUNTRY_NAME: + case _NL_ADDRESS_COUNTRY_POST: + case _NL_ADDRESS_COUNTRY_AB2: + case _NL_ADDRESS_COUNTRY_AB3: + case _NL_ADDRESS_COUNTRY_CAR: + case _NL_ADDRESS_COUNTRY_ISBN: + case _NL_ADDRESS_LANG_NAME: + case _NL_ADDRESS_LANG_AB: + case _NL_ADDRESS_LANG_TERM: + case _NL_ADDRESS_LANG_LIB: + retval = ""; + break; -=over + case _NL_ADDRESS_COUNTRY_NUM: + sv_setuv(sv, 0); + retval_type = RETVAL_IN_sv; + break; -=item a. +# endif +# if ! defined(HAS_SOME_LANGINFO) || ! LC_IDENTIFICATION_AVAIL_ -C has an extra parameter, described above. Besides this, the -other reason they aren't quite a drop-in replacement is actually an advantage. -The Cness of the return allows the compiler to catch attempts to write -into the returned buffer, which is illegal and could cause run-time crashes. + case _NL_IDENTIFICATION_ADDRESS: + case _NL_IDENTIFICATION_CONTACT: + case _NL_IDENTIFICATION_EMAIL: + case _NL_IDENTIFICATION_TEL: + case _NL_IDENTIFICATION_FAX: + case _NL_IDENTIFICATION_LANGUAGE: + case _NL_IDENTIFICATION_AUDIENCE: + case _NL_IDENTIFICATION_APPLICATION: + case _NL_IDENTIFICATION_ABBREVIATION: + retval = ""; + break; -=item b. + case _NL_IDENTIFICATION_DATE: retval = "1997-12-20"; break; + case _NL_IDENTIFICATION_REVISION: retval = "1.0"; break; + case _NL_IDENTIFICATION_CATEGORY: retval = "i18n:1999"; break; + case _NL_IDENTIFICATION_TERRITORY:retval = "ISO"; break; -They deliver the correct results for the C and C items, -without you having to write extra code. The reason for the extra code would be -because these are from the C locale category, which is normally -kept set by Perl so that the radix is a dot, and the separator is the empty -string, no matter what the underlying locale is supposed to be, and so to get -the expected results, you have to temporarily toggle into the underlying -locale, and later toggle back. (You could use plain C and -C> for this but then you wouldn't get -the other advantages of C; not keeping C in the C -(or equivalent) locale would break a lot of CPAN, which is expecting the radix -(decimal point) character to be a dot.) + case _NL_IDENTIFICATION_TITLE: + retval = "ISO/IEC 14652 i18n FDCC-set"; + break; -=item c. + case _NL_IDENTIFICATION_SOURCE: + retval = "ISO/IEC JTC1/SC22/WG20 - internationalization"; + break; -The system function they replace can have its static return buffer trashed, -not only by a subsequent call to that function, but by a C, -C, or other locale change. The returned buffer of these functions -is not changed until the next call to one or the other, so the buffer is never -in a trashed state. +# endif +# if ! defined(HAS_SOME_LANGINFO) || ! LC_MEASUREMENT_AVAIL_ -=item d. + case _NL_MEASUREMENT_MEASUREMENT: + sv_setuv(sv, 1); + retval_type = RETVAL_IN_sv; + break; -The return buffer is per-thread, so it also is never overwritten by a call to -these functions from another thread; unlike the function it replaces. +# endif +# if ! defined(HAS_SOME_LANGINFO) || ! LC_NAME_AVAIL_ -=item e. + case _NL_NAME_NAME_FMT: + case _NL_NAME_NAME_GEN: + case _NL_NAME_NAME_MR: + case _NL_NAME_NAME_MRS: + case _NL_NAME_NAME_MISS: + case _NL_NAME_NAME_MS: + retval = ""; + break; -But most importantly, they work on systems that don't have C, such -as Windows, hence making your code more portable. Of the fifty-some possible -items specified by the POSIX 2008 standard, -L, -only one is completely unimplemented, though on non-Windows platforms, another -significant one is not fully implemented). They use various techniques to -recover the other items, including calling C>, and -C>, both of which are specified in C89, so should be always be -available. Later C versions have additional capabilities; What the -C locale yields or C<""> is returned for any item not available on your system. +# endif +# if ! defined(HAS_SOME_LANGINFO) || ! LC_PAPER_AVAIL_ -It is important to note that, when called with an item that is recovered by -using C, the buffer from any previous explicit call to -C> will be overwritten. But you shouldn't be using -C anyway because it is is very much not thread-safe, and suffers -from the same problems outlined in item 'b.' above for the fields it returns that -are controlled by the LC_NUMERIC locale category. Instead, avoid all of those -problems by calling L, which is thread-safe; or by using the -methods given in L to call -L|POSIX/localeconv>, which is also thread-safe. + case _NL_PAPER_HEIGHT: + sv_setuv(sv, 297); + retval_type = RETVAL_IN_sv; + break; -=back + case _NL_PAPER_WIDTH: + sv_setuv(sv, 210); + retval_type = RETVAL_IN_sv; + break; -The details for those items which may deviate from what this emulation returns -and what a native C would return are specified in -L. +# endif +# if ! defined(HAS_SOME_LANGINFO) || ! LC_TELEPHONE_AVAIL_ -When using C (or plain C) on systems that don't -have a native C, you must + case _NL_TELEPHONE_INT_SELECT: + case _NL_TELEPHONE_INT_PREFIX: + case _NL_TELEPHONE_TEL_DOM_FMT: + retval = ""; + break; - #include "perl_langinfo.h" + case _NL_TELEPHONE_TEL_INT_FMT: + retval = "+%c %a %l"; + break; -before the C C<#include>. You can replace your F -C<#include> with this one. (Doing it this way keeps out the symbols that plain -F would try to import into the namespace for code that doesn't need -it.) +# endif -=cut + /* When we have to emulate TIME-related items, this bit of code is compiled + * to have the default: case be a nested switch() which distinguishes + * between legal inputs and unknown ones. This bit does initialization and + * then at the end calls switch(). But when we aren't emulating TIME, by + * the time we get to here all legal inputs have been handled above, and it + * is cleaner to not have a nested switch(). So this bit of code is skipped + * and the other-wise nested default: case is compiled as part of the outer + * (and actually only) switch() */ +# if ! defined(HAS_SOME_LANGINFO) || ! LC_TIME_AVAIL_ -*/ + default: /* Anything else that is legal is LC_TIME-related */ + { -const char * -Perl_langinfo(const nl_item item) -{ - return Perl_langinfo8(item, NULL); -} + const char * format = NULL; + retval = NULL; -const char * -Perl_langinfo8(const nl_item item, utf8ness_t * utf8ness) -{ - dTHX; - unsigned cat_index; +# ifdef HAS_STRFTIME - PERL_ARGS_ASSERT_PERL_LANGINFO8; + bool return_format = FALSE; - if (utf8ness) { /* Assume for now */ - *utf8ness = UTF8NESS_IMMATERIAL; - } + /* Without strftime(), default compiled-in values are returned. + * Otherwise, we generally compute a date as explained below. + * Initialize default values for that computation */ + int mon = 0; + int mday = 1; + int hour = 6; - /* Find the locale category that controls the input 'item'. If we are not - * paying attention to that category, instead return a default value. Also - * return the default value if there is no way for us to figure out the - * correct value. If we have some form of nl_langinfo(), we can always - * figure it out, but lacking that, there may be alternative methods that - * can be used to recover most of the possible items. Some of those - * methods need libc functions, which may or may not be available. If - * unavailable, we can't compute the correct value, so must here return the - * default. */ - switch (item) { +# endif - case CODESET: + /* Nested switch for LC_TIME items, plus the default: case is for + * unknown items */ + switch (item) { -#ifdef USE_LOCALE_CTYPE +# endif /* ! defined(HAS_SOME_LANGINFO) || ! LC_TIME_AVAIL_ */ - cat_index = LC_CTYPE_INDEX_; - break; + default: -#else - return C_codeset; -#endif -#if defined(USE_LOCALE_MESSAGES) && defined(HAS_SOME_LANGINFO) + /* On systems with langinfo.h, 'item' is an enum. If we don't + * handle one of those, the code needs to change to be able to do + * so. But otherwise, the parameter can be any int, and so could + * be a garbage value and all we can do is to return that it is + * invalid. */; +# if defined(I_LANGINFO) - case YESEXPR: case YESSTR: case NOEXPR: case NOSTR: - cat_index = LC_MESSAGES_INDEX_; - break; -#else - case YESEXPR: return "^[+1yY]"; - case YESSTR: return "yes"; - case NOEXPR: return "^[-0nN]"; - case NOSTR: return "no"; -#endif + Perl_croak_nocontext("panic: Unexpected nl_langinfo() item %jd", + item); - case CRNCYSTR: +# else + assert(item < 0); /* Make sure using perl_langinfo.h */ + SET_EINVAL; + retval = ""; + break; +# endif -#if defined(USE_LOCALE_MONETARY) \ - && (defined(HAS_SOME_LANGINFO) || defined(HAS_LOCALECONV)) + /* Back to the nested switch() */ +# if ! defined(HAS_SOME_LANGINFO) || ! LC_TIME_AVAIL_ - cat_index = LC_MONETARY_INDEX_; - break; -#else - return "-"; -#endif + /* The case: statments in this switch are all for LC_TIME related + * values. There are four types of values returned. One type is + * "Give me the name in this locale of the 3rd month of the year" + * (March in an English locale). The second main type is "Give me + * the best format string understood by strftime(), like '%c', for + * formatting the date and time in this locale." The other two + * types are for ERA and ALT_DIGITS, and are explained at the case + * statements for them. + * + * For the first type, suppose we want to find the name of the 3rd + * month of the year. We pass a date/time to strftime() that is + * known to evaluate to sometime in March, along with a format that + * tells strftime() to return the month's name. We then return + * that to our caller. Similarly for the names of the days of the + * week, like "Tuesday". There are also abbreviated versions for + * each of these. + * + * To implement the second type (returning to the caller a string + * containing a format suitable for passing to strftime() ) we + * guess a format, pass that to strftime, and examine its return to + * see if that format is known on this platform. If so, we return + * that guess. Otherwise we return the empty string "". There are + * no second guesses, as there don't seem to be alternatives + * lurking out there. For some formats that are supposed to be + * known to all strftime()s since C89, we just assume that they are + * valid, not bothering to check. The guesses may not be the best + * available for this locale on this platform, but should be good + * enough, so that a native speaker would find them understandable. + * */ - case RADIXCHAR: + /* Unimplemented by perl; for use with strftime() %E modifier */ + case ERA: retval = ""; break; -#ifdef CAN_CALCULATE_RADIX +# if ! defined(USE_LOCALE_TIME) || ! defined(HAS_STRFTIME) - cat_index = LC_NUMERIC_INDEX_; - break; -#else - return C_decimal_point; -#endif + case AM_STR: retval = "AM"; break; + case PM_STR: retval = "PM"; break; +# else + case PM_STR: hour = 18; + case AM_STR: + format = "%p"; + break; +# endif +# if ! defined(USE_LOCALE_TIME) || ! defined(HAS_STRFTIME) - case THOUSEP: + case ABDAY_1: retval = "Sun"; break; + case ABDAY_2: retval = "Mon"; break; + case ABDAY_3: retval = "Tue"; break; + case ABDAY_4: retval = "Wed"; break; + case ABDAY_5: retval = "Thu"; break; + case ABDAY_6: retval = "Fri"; break; + case ABDAY_7: retval = "Sat"; break; +# else + case ABDAY_7: mday++; + case ABDAY_6: mday++; + case ABDAY_5: mday++; + case ABDAY_4: mday++; + case ABDAY_3: mday++; + case ABDAY_2: mday++; + case ABDAY_1: + format = "%a"; + break; +# endif +# if ! defined(USE_LOCALE_TIME) || ! defined(HAS_STRFTIME) -#if defined(USE_LOCALE_NUMERIC) \ - && (defined(HAS_SOME_LANGINFO) || defined(HAS_LOCALECONV)) + case DAY_1: retval = "Sunday"; break; + case DAY_2: retval = "Monday"; break; + case DAY_3: retval = "Tuesday"; break; + case DAY_4: retval = "Wednesday"; break; + case DAY_5: retval = "Thursday"; break; + case DAY_6: retval = "Friday"; break; + case DAY_7: retval = "Saturday"; break; +# else + case DAY_7: mday++; + case DAY_6: mday++; + case DAY_5: mday++; + case DAY_4: mday++; + case DAY_3: mday++; + case DAY_2: mday++; + case DAY_1: + format = "%A"; + break; +# endif +# if ! defined(USE_LOCALE_TIME) || ! defined(HAS_STRFTIME) + case ABMON_1: retval = "Jan"; break; + case ABMON_2: retval = "Feb"; break; + case ABMON_3: retval = "Mar"; break; + case ABMON_4: retval = "Apr"; break; + case ABMON_5: retval = "May"; break; + case ABMON_6: retval = "Jun"; break; + case ABMON_7: retval = "Jul"; break; + case ABMON_8: retval = "Aug"; break; + case ABMON_9: retval = "Sep"; break; + case ABMON_10: retval = "Oct"; break; + case ABMON_11: retval = "Nov"; break; + case ABMON_12: retval = "Dec"; break; +# else + case ABMON_12: mon++; + case ABMON_11: mon++; + case ABMON_10: mon++; + case ABMON_9: mon++; + case ABMON_8: mon++; + case ABMON_7: mon++; + case ABMON_6: mon++; + case ABMON_5: mon++; + case ABMON_4: mon++; + case ABMON_3: mon++; + case ABMON_2: mon++; + case ABMON_1: + format = "%b"; + break; +# endif +# if ! defined(USE_LOCALE_TIME) || ! defined(HAS_STRFTIME) - cat_index = LC_NUMERIC_INDEX_; - break; -#else - return C_thousands_sep; -#endif + case MON_1: retval = "January"; break; + case MON_2: retval = "February"; break; + case MON_3: retval = "March"; break; + case MON_4: retval = "April"; break; + case MON_5: retval = "May"; break; + case MON_6: retval = "June"; break; + case MON_7: retval = "July"; break; + case MON_8: retval = "August"; break; + case MON_9: retval = "September";break; + case MON_10: retval = "October"; break; + case MON_11: retval = "November"; break; + case MON_12: retval = "December"; break; +# else + case MON_12: mon++; + case MON_11: mon++; + case MON_10: mon++; + case MON_9: mon++; + case MON_8: mon++; + case MON_7: mon++; + case MON_6: mon++; + case MON_5: mon++; + case MON_4: mon++; + case MON_3: mon++; + case MON_2: mon++; + case MON_1: + format = "%B"; + break; +# endif +# ifndef HAS_STRFTIME -/* The other possible items are all in LC_TIME. */ -#ifdef USE_LOCALE_TIME + /* If no strftime() on this system, no format will be recognized, so + * return empty */ + case D_FMT: case T_FMT: case D_T_FMT: + case ERA_D_FMT: case ERA_T_FMT: case ERA_D_T_FMT: + case T_FMT_AMPM: + retval = ""; + break; +# else + /* These strftime formats are defined by C89, so we assume that + * strftime supports them, and so are returned unconditionally; they + * may not be what the locale actually says, but should give good + * enough results for someone using them as formats (as opposed to + * trying to parse them to figure out what the locale says). The + * other format items are actually tested to verify they work on the + * platform */ + case D_FMT: retval = "%x"; break; + case T_FMT: retval = "%X"; break; + case D_T_FMT: retval = "%c"; break; + + /* This format isn't in C89; test that it actually works on the + * platform */ + case T_FMT_AMPM: + format = "%r"; + return_format = TRUE; + break; - default: - cat_index = LC_TIME_INDEX_; - break; +# if defined(WIN32) || ! defined(USE_LOCALE_TIME) -#endif -#if ! defined(USE_LOCALE_TIME) || ! defined(HAS_SOME_LANGINFO) + /* strftime() on Windows doesn't have the POSIX (beyond C89) + * extensions that would allow it to recover these, so use the plain + * non-ERA formats. Also, when LC_TIME is constrained to the C + * locale, the %E modifier is useless, so don't return it. */ + case ERA_D_FMT: retval = "%x"; break; + case ERA_T_FMT: retval = "%X"; break; + case ERA_D_T_FMT: retval = "%c"; break; +# else + case ERA_D_FMT: + format = "%Ex"; + return_format = TRUE; /* Test that this works on the platform */ + break; - /* If not using LC_TIME, hard code the rest. Or, if there is no - * nl_langinfo(), we use strftime() as an alternative, and it is missing - * functionality to get every single one, so hard-code those */ - - case ERA: return ""; /* Unimplemented; for use with strftime() %E - modifier */ - - /* These formats are defined by C89, so we assume that strftime supports - * them, and so are returned unconditionally; they may not be what the - * locale actually says, but should give good enough results for someone - * using them as formats (as opposed to trying to parse them to figure - * out what the locale says). The other format items are actually tested - * to verify they work on the platform */ - case D_FMT: return "%x"; - case T_FMT: return "%X"; - case D_T_FMT: return "%c"; - -# if defined(WIN32) || ! defined(USE_LOCALE_TIME) - - /* strftime() on Windows doesn't have the POSIX (beyond C89) extensions - * that would allow it to recover these */ - case ERA_D_FMT: return "%x"; - case ERA_T_FMT: return "%X"; - case ERA_D_T_FMT: return "%c"; - case ALT_DIGITS: return "0"; - -# endif -# ifndef USE_LOCALE_TIME - - case T_FMT_AMPM: return "%r"; - case ABDAY_1: return "Sun"; - case ABDAY_2: return "Mon"; - case ABDAY_3: return "Tue"; - case ABDAY_4: return "Wed"; - case ABDAY_5: return "Thu"; - case ABDAY_6: return "Fri"; - case ABDAY_7: return "Sat"; - case AM_STR: return "AM"; - case PM_STR: return "PM"; - case ABMON_1: return "Jan"; - case ABMON_2: return "Feb"; - case ABMON_3: return "Mar"; - case ABMON_4: return "Apr"; - case ABMON_5: return "May"; - case ABMON_6: return "Jun"; - case ABMON_7: return "Jul"; - case ABMON_8: return "Aug"; - case ABMON_9: return "Sep"; - case ABMON_10: return "Oct"; - case ABMON_11: return "Nov"; - case ABMON_12: return "Dec"; - case DAY_1: return "Sunday"; - case DAY_2: return "Monday"; - case DAY_3: return "Tuesday"; - case DAY_4: return "Wednesday"; - case DAY_5: return "Thursday"; - case DAY_6: return "Friday"; - case DAY_7: return "Saturday"; - case MON_1: return "January"; - case MON_2: return "February"; - case MON_3: return "March"; - case MON_4: return "April"; - case MON_5: return "May"; - case MON_6: return "June"; - case MON_7: return "July"; - case MON_8: return "August"; - case MON_9: return "September"; - case MON_10: return "October"; - case MON_11: return "November"; - case MON_12: return "December"; + case ERA_T_FMT: + format = "%EX"; + return_format = TRUE; + break; -# endif -#endif + case ERA_D_T_FMT: + format = "%Ec"; + return_format = TRUE; + break; +# endif +# endif +# if defined(WIN32) || ! defined(USE_LOCALE_TIME) || ! defined(HAS_STRFTIME) - } /* End of switch on item */ + case ALT_DIGITS: retval = ""; break; +# else +# define CAN_BE_ALT_DIGITS -#ifndef USE_LOCALE + case ALT_DIGITS: + format = "%Ow"; /* Find the alternate digit for 0 */ + break; +# endif - Perl_croak_nocontext("panic: Unexpected nl_langinfo() item %d", item); - NOT_REACHED; /* NOTREACHED */ - PERL_UNUSED_VAR(cat_index); + } /* End of inner switch() */ -#else -# ifdef USE_LOCALE_NUMERIC + /* The inner switch() above has set 'retval' iff that is the final + * answer */ + if (retval) { + break; + } - /* Use either the underlying numeric, or the other underlying categories */ - if (cat_index == LC_NUMERIC_INDEX_) { - return my_langinfo_c(item, LC_NUMERIC, PL_numeric_name, - &PL_langinfo_buf, &PL_langinfo_bufsize, utf8ness); - } - else + /* And it hasn't set 'format' iff it can't figure out a good value on + * this platform. */ + if (! format) { + retval = ""; + break; + } -# endif +# ifdef HAS_STRFTIME - { - return my_langinfo_i(item, cat_index, querylocale_i(cat_index), - &PL_langinfo_buf, &PL_langinfo_bufsize, utf8ness); - } + /* Here we have figured out what to call strftime() with */ -#endif + struct tm mytm; + const char * orig_TIME_locale + = toggle_locale_c_unless_locking(LC_TIME, locale); + + /* The year was deliberately chosen so that January 1 is on the + * first day of the week. Since we're only getting one thing at a + * time, it all works */ + ints_to_tm(&mytm, locale, 30, 30, hour, mday, mon, 2011, 0, 0, 0); + bool succeeded; + if (utf8ness) { + succeeded = strftime8(format, + sv, + locale, + &mytm, -} + /* All possible formats specified above are + * entirely ASCII */ + UTF8NESS_IMMATERIAL, + + &is_utf8, + false /* not calling from sv_strftime */ + ); + } + else { + succeeded = strftime_tm(format, sv, locale, &mytm); + } -#ifdef USE_LOCALE + restore_toggled_locale_c_unless_locking(LC_TIME, orig_TIME_locale); -/* There are several implementations of my_langinfo, depending on the - * Configuration. They all share the same beginning of the function */ -STATIC const char * -S_my_langinfo_i(pTHX_ - const nl_item item, /* The item to look up */ - const unsigned int cat_index, /* The locale category that - controls it */ - /* The locale to look up 'item' in. */ - const char * locale, + if (UNLIKELY(! succeeded)) { + retval = ""; + break; + } - /* Where to store the result, and where the size of that buffer - * is stored, updated on exit. retbuf_sizep may be NULL for an - * empty-on-entry, single use buffer whose size we don't need - * to keep track of */ - const char ** retbufp, - Size_t * retbuf_sizep, +# ifdef CAN_BE_ALT_DIGITS - /* If not NULL, the location to store the UTF8-ness of 'item's - * value, as documented */ - utf8ness_t * utf8ness) -{ - const char * retval = NULL; + if (LIKELY(item != ALT_DIGITS)) - PERL_ARGS_ASSERT_MY_LANGINFO_I; - assert(cat_index < NOMINAL_LC_ALL_INDEX); +# endif - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "Entering my_langinfo item=%ld, using locale %s\n", - (long) item, locale)); -/*--------------------------------------------------------------------------*/ -/* Above is the common beginning to all the implementations of my_langinfo(). - * Below are the various completions. - * - * Some platforms don't deal well with non-ASCII strings in locale X when - * LC_CTYPE is not in X. (Actually it is probably when X is UTF-8 and LC_CTYPE - * isn't, or vice versa). There is explicit code to bring the categories into - * sync. This doesn't seem to be a problem with nl_langinfo(), so that - * implementation doesn't currently worry about it. But it is a problem on - * Windows boxes, which don't have nl_langinfo(). */ + { -/*--------------------------------------------------------------------------*/ -# if defined(HAS_NL_LANGINFO) /* nl_langinfo() is available. */ -# ifdef USE_LOCALE_CTYPE + /* If to return what strftime() returns, are done */ + if (! return_format) { + retval_type = RETVAL_IN_sv; + break; + } - /* Ths function sorts out if things actually have to be switched or not, - * for both calls. */ - const char * orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, locale); + /* Here are to return the format, not the value. This is used when + * we are testing if the format we expect to return is legal on + * this platform. We have passed the format, say "%r, to + * strftime(), and now have in 'sv' what strftime processed it + * to be. But the caller doesnt't want that; it wants the actual + * %r, if it is understood on this platform, and "" if it isn't. + * Some strftime()s return "" for an unknown format. (None of the + * formats exposed by langinfo can have "" be a legal result.) + * Other strftime()s return the format unchanged if not understood. + * So if we pass "%r" to strftime(), and it's illegal, we will get + * back either "" or "%r", and we return "" to our caller. If the + * strftime() return is anything else, we conclude that "%r" is + * understood by the platform, and return "%r". */ + if (strEQ(SvPVX(sv), format)) { + retval = ""; + } + else { + retval = format; + } -# endif + /* A format is always in ASCII */ + is_utf8 = UTF8NESS_IMMATERIAL; - const char * orig_switched_locale = toggle_locale_i(cat_index, locale); + break; + } - gwLOCALE_LOCK; - retval = save_to_buffer(nl_langinfo(item), retbufp, retbuf_sizep); - gwLOCALE_UNLOCK; +# ifdef CAN_BE_ALT_DIGITS - if (utf8ness) { - *utf8ness = get_locale_string_utf8ness_i(retval, - LOCALE_UTF8NESS_UNKNOWN, - locale, cat_index); - } + /* Here, the item is 'ALT_DIGITS' and 'sv' contains the zeroth + * alternate digit. If empty, return that there aren't alternate + * digits */ + Size_t alt0_len = SvCUR(sv); + if (alt0_len == 0) { + retval_type = RETVAL_IN_sv; + break; + } - restore_toggled_locale_i(cat_index, orig_switched_locale); + /* ALT_DIGITS requires special handling because it requires up to 100 + * values. Below we generate those by using the %O modifier to + * strftime() formats. + * + * We already have the alternate digit for zero in 'sv', generated + * using the %Ow format, which was used because it seems least likely + * to have a leading zero. But some locales return the equivalent of + * 00 anyway. If the first half of 'sv' is identical to the second + * half, assume that is the case, and use just the first half */ + if ((alt0_len & 1) == 0) { + Size_t half_alt0_len = alt0_len / 2; + if (strnEQ(SvPVX(sv), SvPVX(sv) + half_alt0_len, half_alt0_len)) { + alt0_len = half_alt0_len; + SvCUR_set(sv, alt0_len); + } + } + + sv_catpvn_nomg (sv, ";", 1); + + /* Many of the remaining digits have representations that include at + * least two 0-sized strings */ + SV* alt_dig_sv = newSV(2 * alt0_len); + + /* Various %O formats can be used to derive the alternate digits. Only + * %Oy can go up to the full 100 values. If it doesn't work, we try + * various fallbacks in decreasing order of how many values they can + * deliver. maxes[] tells the highest value that the format applies + * to; offsets[] compensates for 0-based vs 1-based indices; and vars[] + * holds what field in the 'struct tm' to applies to the corresponding + * format */ + int year, min, sec; + const char * fmts[] = {"%Oy", "%OM", "%OS", "%Od", "%OH", "%Om", "%Ow" }; + const Size_t maxes[] = { 99, 59, 59, 31, 23, 11, 6 }; + const int offsets[] = { 0, 0, 0, 1, 0, 1, 0 }; + int * vars[] = {&year, &min, &sec, &mday, &hour, &mon, &mday }; + Size_t j = 0; /* Current index into the above tables */ + + orig_TIME_locale = toggle_locale_c_unless_locking(LC_TIME, locale); + + for (unsigned int i = 1; i <= 99; i++) { + struct tm mytm; + + redo: + if (j >= C_ARRAY_LENGTH(fmts)) { + break; /* Exhausted formats early; can't continue */ + } + + if (i > maxes[j]) { + j++; /* Exhausted this format; try next one */ + goto redo; + } + + year = (strchr(fmts[j], 'y')) ? 1900 : 2011; + hour = 0; + min = 0; + sec = 0; + mday = 1; + mon = 0; + + /* Change the variable corresponding to this format to the + * current time being run in 'i' */ + *(vars[j]) += i - offsets[j]; + + /* Do the strftime. Once we have determined the UTF8ness (if + * we want it), assume the rest will be the same, and use + * strftime_tm(), which doesn't recalculate UTF8ness */ + ints_to_tm(&mytm, locale, sec, min, hour, mday, mon, year, 0, 0, 0); + if (utf8ness && is_utf8 != UTF8NESS_NO && is_utf8 != UTF8NESS_YES) { + succeeded = strftime8(fmts[j], + alt_dig_sv, + locale, + &mytm, + UTF8NESS_IMMATERIAL, + &is_utf8, + false /* not calling from sv_strftime */ + ); + } + else { + succeeded = strftime_tm(fmts[j], alt_dig_sv, locale, &mytm); + } -# ifdef USE_LOCALE_CTYPE - restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale); -# endif + /* If didn't recognize this format, try the next */ + if (UNLIKELY(! succeeded)) { + j++; + goto redo; + } - return retval; -/*--------------------------------------------------------------------------*/ -# else /* Below, emulate nl_langinfo as best we can */ + const char * current = SvPVX(alt_dig_sv); + + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "i=%d, format=%s, alt='%s'\n", + i, fmts[j], current)); - /* And the third and final completion is where we have to emulate - * nl_langinfo(). There are various possibilities depending on the - * Configuration */ -# ifdef USE_LOCALE_CTYPE + /* If it returned regular digits, give up on this format, to try + * the next candidate one */ + if (strpbrk(current, "0123456789")) { + j++; + goto redo; + } - const char * orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, locale); + /* If there is a leading alternate zero, skip past it, to get the + * second one in the string. The first 'alt0_len' bytes in 'sv' + * will be the alternate-zero representation */ + if (strnEQ(current, SvPVX(sv), alt0_len)) { + current += alt0_len; + } -# endif + /* Append this number to the ongoing list, including the separator. + * */ + sv_catpv_nomg (sv, current); + sv_catpvn_nomg (sv, ";", 1); + } /* End of loop generating ALT_DIGIT strings */ - const char * orig_switched_locale = toggle_locale_i(cat_index, locale); + /* Above we accepted 0 for alt-0 in case the locale doesn't have a + * zero, but we rejected any other ASCII digits. Now that we have + * processed everything, if that 0 is the only thing we found, it was a + * false positive, and the locale doesn't have alternate digits */ + if (SvCUR(sv) == alt0_len + 1) { + SvCUR_set(sv, 0); + } - /* Here, we are in the locale we want information about */ + SvREFCNT_dec_NN(alt_dig_sv); - /* Almost all the items will have ASCII return values. Set that here, and - * override if necessary */ - utf8ness_t is_utf8 = UTF8NESS_IMMATERIAL; + restore_toggled_locale_c_unless_locking(LC_TIME, orig_TIME_locale); - switch (item) { - default: - assert(item < 0); /* Make sure using perl_langinfo.h */ - retval = ""; + retval_type = RETVAL_IN_sv; break; - case RADIXCHAR: +# endif /* End of CAN_BE_ALT_DIGITS */ +# endif /* End of HAS_STRFTIME */ -# if defined(HAS_SNPRINTF) \ - && (! defined(HAS_LOCALECONV) || defined(TS_W32_BROKEN_LOCALECONV)) + } /* End of braced group for outer switch 'default:' case */ - { - /* snprintf() can be used to find the radix character by outputting - * a known simple floating point number to a buffer, and parsing - * it, inferring the radix as the bytes separating the integer and - * fractional parts. But localeconv() is more direct, not - * requiring inference, so use it instead of the code just below, - * if (likely) it is available and works ok */ +# endif - char * floatbuf = NULL; - const Size_t initial_size = 10; + } /* Giant switch() of nl_langinfo() items */ - Newx(floatbuf, initial_size, char); + GCC_DIAG_RESTORE_STMT; - /* 1.5 is exactly representable on binary computers */ - Size_t needed_size = snprintf(floatbuf, initial_size, "%.1f", 1.5); + if (sv != PL_scratch_langinfo) { /* Caller wants return in 'sv' */ + if (! isRETVAL_IN_sv(retval_type)) { + sv_setpv(sv, retval); + SvUTF8_off(sv); + } - /* If our guess wasn't big enough, increase and try again, based on - * the real number that snprintf() is supposed to return */ - if (UNLIKELY(needed_size >= initial_size)) { - needed_size++; /* insurance */ - Renew(floatbuf, needed_size, char); - Size_t new_needed = snprintf(floatbuf, needed_size, "%.1f", 1.5); - assert(new_needed <= needed_size); - needed_size = new_needed; + if (utf8ness) { + *utf8ness = is_utf8; + if (is_utf8 == UTF8NESS_YES) { + SvUTF8_on(sv); } + } - char * s = floatbuf; - char * e = floatbuf + needed_size; + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "Leaving emulate_langinfo item=%jd, using locale %s\n", + item, locale)); - /* Find the '1' */ - while (s < e && *s != '1') { - s++; - } + /* The caller shouldn't also be wanting a 'retval'; make sure segfaults + * if they call this wrong */ + return NULL; + } - if (LIKELY(s < e)) { - s++; - } + /* Here, wants a 'retval' return. Extract that if not already there. */ + if (! isRETVAL_IN_retval(retval_type)) { + retval = SvPV_nolen(sv); + } - /* Find the '5' */ - char * item_start = s; - while (s < e && *s != '5') { - s++; - } + /* Here, 'retval' started as a simple value, or has been converted into + * being simple */ + if (utf8ness) { + *utf8ness = is_utf8; + } - /* Everything in between is the radix string */ - if (LIKELY(s < e)) { - *s = '\0'; - retval = save_to_buffer(item_start, retbufp, retbuf_sizep); - Safefree(floatbuf); + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "Leaving emulate_langinfo item=%jd, using locale %s\n", + item, locale)); + return retval; - if (utf8ness) { - is_utf8 = get_locale_string_utf8ness_i(retval, - LOCALE_UTF8NESS_UNKNOWN, - locale, cat_index); - } +# undef RETVAL_IN_retval +# undef RETVAL_IN_BOTH +# undef RETVAL_IN_sv +# undef isRETVAL_IN_sv +# undef isRETVAL_IN_retval - break; - } +} - Safefree(floatbuf); - } +#endif /* Needs emulate_langinfo() */ +#ifndef HAS_DEFINITIVE_UTF8NESS_DETERMINATION -# ifdef HAS_LOCALECONV /* snprintf() failed; drop down to use - localeconv() */ +STATIC bool +S_maybe_override_codeset(pTHX_ const char * codeset, + const char * locale, + const char ** new_codeset) +{ +# define NAME_INDICATES_UTF8 0x1 +# define MB_CUR_MAX_SUGGESTS_UTF8 0x2 + + /* Override 'codeset' with UTF-8 if this routine guesses that it should be. + * Conversely (but rarely), "UTF-8" in the locale name might be wrong. We + * return "" as the code set name if we find that to be the case. */ + + unsigned int lean_towards_being_utf8 = 0; + if (is_codeset_name_UTF8(codeset)) { + lean_towards_being_utf8 |= NAME_INDICATES_UTF8; + } - /* FALLTHROUGH */ + const char * orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, locale); -# else /* snprintf() failed and no localeconv() */ + /* For this portion of the file to compile, some C99 functions aren't + * available to us, even though we now require C99. So, something must be + * wrong with them. The code here should be good enough to work around + * this issue, but should the need arise, comments in S_is_locale_utf8() + * list some alternative C99 functions that could be tried. + * + * But MB_CUR_MAX is a C89 construct that helps a lot, is simple for a + * vendor to implement, and our experience with it is that it works well on + * a variety of platforms. We have found that it returns a too-large + * number on some platforms for the C locale, but for no others. That + * locale was already ruled out in the code that called this function. (If + * MB_CUR_MAX returned too small a number, that would break a lot of + * things, and likely would be quickly corrected by the vendor.) khw has + * some confidence that it doesn't return >1 when 1 is meant, as that would + * trigger a Perl warning, and we've had no reports of invalid occurrences + * of such. */ +# ifdef MB_CUR_MAX - retval = C_decimal_point; - break; + /* If there are fewer bytes available in this locale than are required to + * represent the largest legal UTF-8 code point, this definitely isn't a + * UTF-8 locale, even if the locale name says it is. */ + const int mb_cur_max = MB_CUR_MAX; + if (mb_cur_max < (int) UNISKIP(PERL_UNICODE_MAX)) { + restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale); -# endif -# endif -# ifdef HAS_LOCALECONV + if (lean_towards_being_utf8 & NAME_INDICATES_UTF8) { + *new_codeset = ""; /* The name is wrong; override */ + return true; + } - /* These items are available from localeconv(). (To avoid using - * TS_W32_BROKEN_LOCALECONV, one could use GetNumberFormat and - * GetCurrencyFormat; patches welcome) */ + return false; + } -# define P_CS_PRECEDES "p_cs_precedes" -# define CURRENCY_SYMBOL "currency_symbol" + /* But if the locale could be UTF-8, and also the name corroborates this, + * assume it is so */ + if (lean_towards_being_utf8 & NAME_INDICATES_UTF8) { + restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale); + return false; + } - /* case RADIXCHAR: // May drop down to here in some configurations */ - case THOUSEP: - case CRNCYSTR: - { + restore_toggled_locale_c_if_locking(LC_CTYPE, orig_CTYPE_locale); - /* The hash gets populated with just the field(s) related to 'item'. */ - HV * result_hv = my_localeconv(item); + /* Here, the name doesn't indicate UTF-8, but MB_CUR_MAX indicates it could + * be. khw knows of only two other locales in the world, EUC-TW and GB + * 18030, that legitimately require this many bytes (4). So, if the name + * is one of those, MB_CUR_MAX has corroborated that. */ + bool name_implies_non_utf8 = false; + if (foldEQ(codeset, "GB", 2)) { + const char * s = codeset + 2; + if (*s == '-' || *s == '_') { + s++; + } - SV* string; - if (item != CRNCYSTR) { + if strEQ(s, "18030") { + name_implies_non_utf8 = true; + } + } + else if (foldEQ(codeset, "EUC", 3)) { + const char * s = codeset + 3; + if (*s == '-' || *s == '_') { + s++; + } - /* These items have been populated with just one key => value */ - (void) hv_iterinit(result_hv); - HE * entry = hv_iternext(result_hv); - string = hv_iterval(result_hv, entry); + if (foldEQ(s, "TW", 2)) { + name_implies_non_utf8 = true; } - else { + } - /* But CRNCYSTR localeconv() returns a slightly different value - * than the nl_langinfo() API calls for, so have to modify this one - * to conform. We need another value from localeconv() to know - * what to change it to. my_localeconv() has populated the hash - * with exactly both fields. Delete this one, leaving just the - * CRNCYSTR one in the hash */ - SV* precedes = hv_delete(result_hv, - P_CS_PRECEDES, STRLENs(P_CS_PRECEDES), - 0); - if (! precedes) { - locale_panic_("my_localeconv() unexpectedly didn't return" - " a value for " P_CS_PRECEDES); - } + /* Otherwise, the locale is likely UTF-8 */ + if (! name_implies_non_utf8) { + lean_towards_being_utf8 |= MB_CUR_MAX_SUGGESTS_UTF8; + } - /* The modification is to prefix the localeconv() return with a - * single byte, calculated as follows: */ - char prefix = (LIKELY(SvIV(precedes) != -1)) - ? ((precedes != 0) ? '-' : '+') + /* (In both those two other multibyte locales, the single byte characters + * are the same as ASCII. No multi-byte character in EUC-TW is legal UTF-8 + * (since the first byte of each is a continuation). GB 18030 has no three + * byte sequences, and none of the four byte ones is legal UTF-8 (as the + * second byte for these is a non-continuation). But every legal UTF-8 two + * byte sequence is also legal in GB 18030, though none have the same + * meaning, and no Han code point expressed in UTF-8 is two byte. So the + * further tests below which look for native expressions of currency and + * time will not return two byte sequences, hence they will reliably rule + * out such a locale as being UTF-8, even if the code set name checked + * above isn't correct.) */ - /* khw couldn't find any documentation that - * CHAR_MAX (which we modify to -1) is the signal, - * but cygwin uses it thusly, and it makes sense - * given that CHAR_MAX indicates the value isn't - * used, so it neither precedes nor succeeds */ - : '.'; - - /* Now get CRNCYSTR */ - (void) hv_iterinit(result_hv); - HE * entry = hv_iternext(result_hv); - string = hv_iterval(result_hv, entry); +# endif /* has MB_CUR_MAX */ - /* And perform the modification */ - Perl_sv_setpvf(aTHX_ string, "%c%s", prefix, SvPV_nolen(string)); - } + /* Here, MB_CUR_MAX is not available, or was inconclusive. What we do is + * to look at various strings associated with the locale: + * 1) If any are illegal UTF-8, the locale can't be UTF-8. + * 2) If all are legal UTF-8, and some non-ASCII characters are present, + * it is likely to be UTF-8, because of the strictness of UTF-8 + * syntax. So assume it is UTF-8 + * 3) If all are ASCII and the locale name and/or MB_CUR_MAX indicate + * UTF-8, assume the locale is UTF-8. + * 4) Otherwise, assume the locale isn't UTF-8 + * + * To save cycles, if the locale name indicates it is a UTF-8 locale, we + * stop looking at the first instance with legal non-ASCII UTF-8. It is + * very unlikely this combination is coincidental. */ - /* Here, 'string' contains the value we want to return */ - retval = save_to_buffer(SvPV_nolen(string), retbufp, retbuf_sizep); + utf8ness_t strings_utf8ness = UTF8NESS_UNKNOWN; - if (utf8ness) { - is_utf8 = (SvUTF8(string)) - ? UTF8NESS_YES - : (is_utf8_invariant_string( (U8 *) retval, - strlen(retval))) - ? UTF8NESS_IMMATERIAL - : UTF8NESS_NO; - } + /* List of strings to look at */ + const int trials[] = { - break; +# if defined(USE_LOCALE_MONETARY) && defined(HAS_LOCALECONV) - } + /* The first string tried is the locale currency name. Often that will + * be in the native script. + * + * But this is usable only if localeconv() is available, as that's the + * way we find out the currency symbol. */ -# endif /* Some form of localeconv */ -# ifdef HAS_STRFTIME + CRNCYSTR, - /* These formats are only available in later strftime's */ - case ERA_D_FMT: case ERA_T_FMT: case ERA_D_T_FMT: case T_FMT_AMPM: +# endif +# ifdef USE_LOCALE_TIME - /* The rest can be gotten from most versions of strftime(). */ - case ABDAY_1: case ABDAY_2: case ABDAY_3: - case ABDAY_4: case ABDAY_5: case ABDAY_6: case ABDAY_7: - case ALT_DIGITS: - case AM_STR: case PM_STR: - case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4: - case ABMON_5: case ABMON_6: case ABMON_7: case ABMON_8: - case ABMON_9: case ABMON_10: case ABMON_11: case ABMON_12: - case DAY_1: case DAY_2: case DAY_3: case DAY_4: - case DAY_5: case DAY_6: case DAY_7: - case MON_1: case MON_2: case MON_3: case MON_4: - case MON_5: case MON_6: case MON_7: case MON_8: - case MON_9: case MON_10: case MON_11: case MON_12: - { - const char * format; - bool return_format = FALSE; - int mon = 0; - int mday = 1; - int hour = 6; - - GCC_DIAG_IGNORE_STMT(-Wimplicit-fallthrough); - - switch (item) { - default: - locale_panic_(Perl_form(aTHX_ "switch case: %d problem", item)); - NOT_REACHED; /* NOTREACHED */ + /* We can also try various strings associated with LC_TIME, like the names + * of months or days of the week */ - case PM_STR: hour = 18; - case AM_STR: - format = "%p"; - break; - case ABDAY_7: mday++; - case ABDAY_6: mday++; - case ABDAY_5: mday++; - case ABDAY_4: mday++; - case ABDAY_3: mday++; - case ABDAY_2: mday++; - case ABDAY_1: - format = "%a"; - break; - case DAY_7: mday++; - case DAY_6: mday++; - case DAY_5: mday++; - case DAY_4: mday++; - case DAY_3: mday++; - case DAY_2: mday++; - case DAY_1: - format = "%A"; - break; - case ABMON_12: mon++; - case ABMON_11: mon++; - case ABMON_10: mon++; - case ABMON_9: mon++; - case ABMON_8: mon++; - case ABMON_7: mon++; - case ABMON_6: mon++; - case ABMON_5: mon++; - case ABMON_4: mon++; - case ABMON_3: mon++; - case ABMON_2: mon++; - case ABMON_1: - format = "%b"; - break; - case MON_12: mon++; - case MON_11: mon++; - case MON_10: mon++; - case MON_9: mon++; - case MON_8: mon++; - case MON_7: mon++; - case MON_6: mon++; - case MON_5: mon++; - case MON_4: mon++; - case MON_3: mon++; - case MON_2: mon++; - case MON_1: - format = "%B"; - break; - case T_FMT_AMPM: - format = "%r"; - return_format = TRUE; - break; - case ERA_D_FMT: - format = "%Ex"; - return_format = TRUE; - break; - case ERA_T_FMT: - format = "%EX"; - return_format = TRUE; - break; - case ERA_D_T_FMT: - format = "%Ec"; - return_format = TRUE; - break; - case ALT_DIGITS: - format = "%Ow"; /* Find the alternate digit for 0 */ - break; - } + DAY_1, DAY_2, DAY_3, DAY_4, DAY_5, DAY_6, DAY_7, + MON_1, MON_2, MON_3, MON_4, MON_5, MON_6, MON_7, MON_8, + MON_9, MON_10, MON_11, MON_12, + ALT_DIGITS, AM_STR, PM_STR, + ABDAY_1, ABDAY_2, ABDAY_3, ABDAY_4, ABDAY_5, ABDAY_6, ABDAY_7, + ABMON_1, ABMON_2, ABMON_3, ABMON_4, ABMON_5, ABMON_6, + ABMON_7, ABMON_8, ABMON_9, ABMON_10, ABMON_11, ABMON_12 - GCC_DIAG_RESTORE_STMT; +# endif - /* The year was deliberately chosen so that January 1 is on the - * first day of the week. Since we're only getting one thing at a - * time, it all works */ - const char * temp = my_strftime8_temp(format, 30, 30, hour, mday, mon, - 2011, 0, 0, 0, &is_utf8); - retval = save_to_buffer(temp, retbufp, retbuf_sizep); - Safefree(temp); - - /* If the item is 'ALT_DIGITS', '*retbuf' contains the alternate - * format for wday 0. If the value is the same as the normal 0, - * there isn't an alternate, so clear the buffer. - * - * (wday was chosen because its range is all a single digit. - * Things like tm_sec have two digits as the minimum: '00'.) */ - if (item == ALT_DIGITS && strEQ(*retbufp, "0")) { - retval = ""; - break; - } + }; - /* ALT_DIGITS is problematic. Experiments on it showed that - * strftime() did not always work properly when going from alt-9 to - * alt-10. Only a few locales have this item defined, and in all - * of them on Linux that khw was able to find, nl_langinfo() merely - * returned the alt-0 character, possibly doubled. Most Unicode - * digits are in blocks of 10 consecutive code points, so that is - * sufficient information for such scripts, as we can infer alt-1, - * alt-2, .... But for a Japanese locale, a CJK ideographic 0 is - * returned, and the CJK digits are not in code point order, so you - * can't really infer anything. The localedef for this locale did - * specify the succeeding digits, so that strftime() works properly - * on them, without needing to infer anything. But the - * nl_langinfo() return did not give sufficient information for the - * caller to understand what's going on. So until there is - * evidence that it should work differently, this returns the alt-0 - * string for ALT_DIGITS. */ - - if (return_format) { - - /* If to return the format, not the value, overwrite the buffer - * with it. But some strftime()s will keep the original format - * if illegal, so change those to "" */ - if (strEQ(*retbufp, format)) { - retval = ""; - } - else { - retval = format; - } +# ifdef USE_LOCALE_TIME - /* A format is always in ASCII */ - is_utf8 = UTF8NESS_IMMATERIAL; - } + /* The code in the recursive call below can handle switching the locales, + * but by doing it now here, that code will check and discover that there + * is no need to switch then restore, avoiding those each loop iteration. + * + * But don't do this if toggling actually creates a critical section, so as + * to minimize the amount of time spent in each critical section. */ + const char * orig_TIME_locale = + toggle_locale_c_unless_locking(LC_TIME, locale); - break; - } +# endif + + /* The trials array may consist of strings from two different locale + * categories. The call to langinfo_i() below needs to pass the proper + * category for each string. There is a max of 1 trial for LC_MONETARY; + * the rest are LC_TIME. So the array is arranged so the LC_MONETARY item + * (if any) is first, and all subsequent iterations will use LC_TIME. + * These #ifdefs set up the values for all possible combinations. */ +# if defined(USE_LOCALE_MONETARY) && defined(HAS_LOCALECONV) + + locale_category_index cat_index = LC_MONETARY_INDEX_; + +# ifdef USE_LOCALE_TIME + + const locale_category_index follow_on_cat_index = LC_TIME_INDEX_; + assert(trials[1] == DAY_1); /* Make sure only a single non-time entry */ + +# else + + /* Effectively out-of-bounds, as there is only the monetary entry */ + const locale_category_index follow_on_cat_index = LC_ALL_INDEX_; # endif +# elif defined(USE_LOCALE_TIME) - case CODESET: + locale_category_index cat_index = LC_TIME_INDEX_; + const locale_category_index follow_on_cat_index = LC_TIME_INDEX_; - /* The trivial case */ - if (isNAME_C_OR_POSIX(locale)) { - retval = C_codeset; - break; - } +# else -# ifdef WIN32 + /* Effectively out-of-bounds, as here there are no trial entries at all. + * This allows this code to compile, but there are no strings to test, and + * so the answer will always be non-UTF-8. */ + locale_category_index cat_index = LC_ALL_INDEX_; + const locale_category_index follow_on_cat_index = LC_ALL_INDEX_; - /* This function retrieves the code page. It is subject to change, but - * is documented and has been stable for many releases */ - UINT ___lc_codepage_func(void); +# endif - retval = save_to_buffer(Perl_form(aTHX_ "%d", ___lc_codepage_func()), - retbufp, retbuf_sizep); - DEBUG_Lv(PerlIO_printf(Perl_debug_log, "locale='%s' cp=%s\n", - locale, retval)); - break; + /* We will need to use the reentrant interface. */ + SV * sv = newSVpvs(""); -# else + /* Everything set up; look through all the strings */ + for (PERL_UINT_FAST8_T i = 0; i < C_ARRAY_LENGTH(trials); i++) { - /* The codeset is important, but khw did not figure out a way for it to - * be retrieved on non-Windows boxes without nl_langinfo(). But even - * if we can't get it directly, we can usually determine if it is a - * UTF-8 locale or not. If it is UTF-8, we (correctly) use that for - * the code set. */ + /* To prevent infinite recursive calls, we don't ask for the UTF-8ness + * of the string. Instead we examine the result below */ + langinfo_sv_i(trials[i], cat_index, locale, sv, NULL); -# if defined(HAS_MBTOWC) || defined(HAS_MBRTOWC) + cat_index = follow_on_cat_index; - /* If libc mbtowc() evaluates the bytes that form the REPLACEMENT - * CHARACTER as that Unicode code point, this has to be a UTF-8 locale. - * */ - wchar_t wc = 0; - (void) Perl_mbtowc_(aTHX_ NULL, NULL, 0);/* Reset shift state */ - int mbtowc_ret = Perl_mbtowc_(aTHX_ &wc, - STR_WITH_LEN(REPLACEMENT_CHARACTER_UTF8)); - if (mbtowc_ret >= 0 && wc == UNICODE_REPLACEMENT) { - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "mbtowc returned REPLACEMENT\n")); - retval = "UTF-8"; - break; + const char * result = SvPVX(sv); + const Size_t len = strlen(result); + const U8 * first_variant; + + /* If the string is identical whether or not it is encoded as UTF-8, it + * isn't helpful in determining UTF8ness. */ + if (is_utf8_invariant_string_loc((U8 *) result, len, &first_variant)) + { + continue; } - /* Here, it isn't a UTF-8 locale. */ + /* Here, has non-ASCII. If not legal UTF-8, isn't a UTF-8 locale */ + if (! is_strict_utf8_string(first_variant, + len - (first_variant - (U8 *) result))) + { + strings_utf8ness = UTF8NESS_NO; + break; + } -# else /* mbtowc() is not available. */ + /* Here, is a legal non-ASCII UTF-8 string; tentatively set the return + * to YES; possibly overridden by later iterations */ + strings_utf8ness = UTF8NESS_YES; - /* Sling together several possibilities, depending on platform - * capabilities and what we found. - * - * For non-English locales or non-dollar currency locales, we likely - * will find out whether a locale is UTF-8 or not */ + /* But if this corroborates our expectation, quit now */ + if (lean_towards_being_utf8 & NAME_INDICATES_UTF8) { + break; + } + } - utf8ness_t is_utf8 = UTF8NESS_UNKNOWN; - const char * scratch_buf = NULL; +# ifdef USE_LOCALE_TIME -# if defined(USE_LOCALE_MONETARY) && defined(HAS_LOCALECONV) + restore_toggled_locale_c_unless_locking(LC_TIME, orig_TIME_locale); - /* Can't use this method unless localeconv() is available, as that's - * the way we find out the currency symbol. */ - - /* First try looking at the currency symbol (via a recursive call) to - * see if it disambiguates things. Often that will be in the native - * script, and if the symbol isn't legal UTF-8, we know that the locale - * isn't either. */ - (void) my_langinfo_c(CRNCYSTR, LC_MONETARY, locale, &scratch_buf, NULL, - &is_utf8); - Safefree(scratch_buf); +# endif -# endif -# ifdef USE_LOCALE_TIME + restore_toggled_locale_c_unless_locking(LC_CTYPE, orig_CTYPE_locale); - /* If we have ruled out being UTF-8, no point in checking further. */ - if (is_utf8 != UTF8NESS_NO) { + if (strings_utf8ness == UTF8NESS_NO) { + return false; /* No override */ + } - /* But otherwise do check more. This is done even if the currency - * symbol looks to be UTF-8, just in case that's a false positive. - * - * Look at the LC_TIME entries, like the names of the months or - * weekdays. We quit at the first one that is illegal UTF-8 */ + /* Here all tested strings are legal UTF-8. + * + * Above we set UTF8NESS_YES if any string wasn't ASCII. But even if they + * are all ascii, and the locale name indicates it is a UTF-8 locale, + * assume the locale is UTF-8. */ + if (lean_towards_being_utf8) { + strings_utf8ness = UTF8NESS_YES; + } - utf8ness_t this_is_utf8 = UTF8NESS_UNKNOWN; - const int times[] = { - DAY_1, DAY_2, DAY_3, DAY_4, DAY_5, DAY_6, DAY_7, - MON_1, MON_2, MON_3, MON_4, MON_5, MON_6, MON_7, MON_8, - MON_9, MON_10, MON_11, MON_12, - ALT_DIGITS, AM_STR, PM_STR, - ABDAY_1, ABDAY_2, ABDAY_3, ABDAY_4, ABDAY_5, ABDAY_6, - ABDAY_7, - ABMON_1, ABMON_2, ABMON_3, ABMON_4, ABMON_5, ABMON_6, - ABMON_7, ABMON_8, ABMON_9, ABMON_10, ABMON_11, ABMON_12 - }; - - /* The code in the recursive call can handle switching the locales, - * but by doing it here, we avoid switching each iteration of the - * loop */ - const char * orig_TIME_locale = toggle_locale_c(LC_TIME, locale); - - for (PERL_UINT_FAST8_T i = 0; i < C_ARRAY_LENGTH(times); i++) { - scratch_buf = NULL; - (void) my_langinfo_c(times[i], LC_TIME, locale, &scratch_buf, - NULL, &this_is_utf8); - Safefree(scratch_buf); - if (this_is_utf8 == UTF8NESS_NO) { - is_utf8 = UTF8NESS_NO; - break; - } + if (strings_utf8ness == UTF8NESS_YES) { + *new_codeset = "UTF-8"; + return true; + } - if (this_is_utf8 == UTF8NESS_YES) { - is_utf8 = UTF8NESS_YES; - } - } + /* Here, nothing examined indicates that the codeset is or isn't UTF-8. + * But what is it? The other locale categories are not likely to be of + * further help: + * + * LC_NUMERIC Only a few locales in the world have a non-ASCII radix or + * group separator. + * LC_CTYPE This code wouldn't be compiled if mbtowc() existed and was + * reliable. This is unlikely in C99. There are other + * functions that could be used instead, but are they going to + * exist, and be able to distinguish between UTF-8 and 8859-1? + * Deal with this only if it becomes necessary. + * LC_MESSAGES The strings returned from strerror() would seem likely + * candidates, but experience has shown that many systems + * don't actually have translations installed for them. They + * are instead always in English, so everything in them is + * ASCII, which is of no help to us. A Configure probe could + * possibly be written to see if this platform has non-ASCII + * error messages. But again, wait until it turns out to be + * an actual problem. + * + * Things like YESSTR, NOSTR, might not be in ASCII, but need + * nl_langinfo() to access, which we don't have. + */ - /* Here we have gone through all the LC_TIME elements. is_utf8 has - * been set as follows: - * UTF8NESS_NO If at least one is't legal UTF-8 - * UTF8NESS_IMMMATERIAL If all are ASCII - * UTF8NESS_YES If all are legal UTF-8 (including - * ASCIIi), and at least one isn't - * ASCII. */ + /* Otherwise, assume the locale isn't UTF-8. This can be wrong if we don't + * have MB_CUR_MAX, and the locale is English without UTF-8 in its name, + * and with a dollar currency symbol. */ + return false; /* No override */ +} - restore_toggled_locale_c(LC_TIME, orig_TIME_locale); - } +# endif /* ! HAS_DEFINITIVE_UTF8NESS_DETERMINATION */ -# endif /* LC_TIME */ +/* +=for apidoc_section $time +=for apidoc sv_strftime_tm +=for apidoc_item my_strftime - /* If nothing examined above rules out it being UTF-8, and at least one - * thing fits as UTF-8 (and not plain ASCII), assume the codeset is - * UTF-8. */ - if (is_utf8 == UTF8NESS_YES) { - retval = "UTF-8"; - break; - } +These implement the libc strftime(). - /* Here, nothing examined indicates that the codeset is UTF-8. But - * what is it? The other locale categories are not likely to be of - * further help: - * - * LC_NUMERIC Only a few locales in the world have a non-ASCII radix - * or group separator. - * LC_CTYPE This code wouldn't be compiled if mbtowc() existed and - * was reliable. This is unlikely in C99. There are - * other functions that could be used instead, but are - * they going to exist, and be able to distinguish between - * UTF-8 and 8859-1? Deal with this only if it becomes - * necessary. - * LC_MESSAGES The strings returned from strerror() would seem likely - * candidates, but experience has shown that many systems - * don't actually have translations installed for them. - * They are instead always in English, so everything in - * them is ASCII, which is of no help to us. A Configure - * probe could possibly be written to see if this platform - * has non-ASCII error messages. But again, wait until it - * turns out to be an actual problem. */ +On failure, they return NULL, and set C to C. -# endif /* ! mbtowc() */ +C is preferred, as it transparently handles the UTF-8ness of +the current locale, the input C, and the returned result. Only if the +current C locale is a UTF-8 one (and S> is not in effect) +will the result be marked as UTF-8. - /* Rejoin the mbtowc available/not-available cases. - * - * We got here only because we haven't been able to find the codeset. - * The only other option khw could think of is to see if the codeset is - * part of the locale name. This is very less than ideal; often there - * is no code set in the name; and at other times they even lie. - * - * But there is an XPG standard syntax, which many locales follow: - * - * language[_territory[.codeset]][@modifier] - * - * So we take the part between the dot and any '@' */ - retval = (const char *) strchr(locale, '.'); - if (! retval) { - retval = ""; /* Alas, no dot */ - break; - } +C takes a pointer to a filled-in S> parameter. It +ignores the values of the C and C fields in it. The other fields +give enough information to accurately calculate these values, and are used for +that purpose. - /* Don't include the dot */ - retval++; +The caller assumes ownership of the returned SV with a reference count of 1. - /* And stop before any '@' */ - const char * modifier = strchr(retval, '@'); - if (modifier) { - char * code_set_name; - const Size_t name_len = modifier - retval; - Newx(code_set_name, name_len + 1, char); /* +1 for NUL */ - my_strlcpy(code_set_name, retval, name_len + 1); - SAVEFREEPV(code_set_name); - retval = code_set_name; - } +C is kept for backwards compatibility. Knowing if its result +should be considered UTF-8 or not requires significant extra logic. -# if defined(HAS_MBTOWC) || defined(HAS_MBRTOWC) +The return value is a pointer to the formatted result (which MUST be arranged +to be FREED BY THE CALLER). This allows this function to increase the buffer +size as needed, so that the caller doesn't have to worry about that, unlike +libc C. - /* When these functions, are available, they were tried earlier and - * indicated that the locale did not act like a proper UTF-8 one. So - * if it claims to be UTF-8, it is a lie */ - if (is_codeset_name_UTF8(retval)) { - retval = ""; - break; - } +The C, C, and C parameters are ignored by C. +Daylight savings time is never considered to exist, and the values returned for +the other two fields (if C even calls for them) are calculated from the +other parameters, without need for referencing these. -# endif +Note that both functions are always executed in the underlying +C locale of the program, giving results based on that locale. - /* Otherwise the code set name is considered to be everything between - * the dot and the '@' */ - retval = save_to_buffer(retval, retbufp, retbuf_sizep); +=cut + */ - break; +char * +Perl_my_strftime(pTHX_ const char *fmt, int sec, int min, int hour, + int mday, int mon, int year, int wday, int yday, + int isdst) +{ /* Documented above */ + PERL_ARGS_ASSERT_MY_STRFTIME; -# endif +#ifdef USE_LOCALE_TIME + const char * locale = querylocale_c(LC_TIME); +#else + const char * locale = "C"; +#endif - } /* Giant switch() of nl_langinfo() items */ + struct tm mytm; + ints_to_tm(&mytm, locale, sec, min, hour, mday, mon, year, wday, yday, + isdst); + if (! strftime_tm(fmt, PL_scratch_langinfo, locale, &mytm)) { + return NULL; + } - restore_toggled_locale_i(cat_index, orig_switched_locale); + return savepv(SvPVX(PL_scratch_langinfo)); +} -# ifdef USE_LOCALE_CTYPE - restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale); -# endif +SV * +Perl_sv_strftime_ints(pTHX_ SV * fmt, int sec, int min, int hour, + int mday, int mon, int year, int wday, + int yday, int isdst) +{ /* Documented above */ + PERL_ARGS_ASSERT_SV_STRFTIME_INTS; - if (utf8ness) { - *utf8ness = is_utf8; - } +#ifdef USE_LOCALE_TIME + const char * locale = querylocale_c(LC_TIME); +#else + const char * locale = "C"; +#endif - return retval; + struct tm mytm; + ints_to_tm(&mytm, locale, sec, min, hour, mday, mon, year, wday, yday, + isdst); + return sv_strftime_common(fmt, locale, &mytm); +} -# endif /* All the implementations of my_langinfo() */ +SV * +Perl_sv_strftime_tm(pTHX_ SV * fmt, const struct tm * mytm) +{ /* Documented above */ + PERL_ARGS_ASSERT_SV_STRFTIME_TM; -/*--------------------------------------------------------------------------*/ +#ifdef USE_LOCALE_TIME -} /* my_langinfo() */ + return sv_strftime_common(fmt, querylocale_c(LC_TIME), mytm); -#endif /* USE_LOCALE */ +#else -char * -Perl_my_strftime(pTHX_ const char *fmt, int sec, int min, int hour, int mday, int mon, int year, int wday, int yday, int isdst) -{ -#ifdef HAS_STRFTIME + return sv_strftime_common(fmt, "C", mytm); -/* -=for apidoc_section $time -=for apidoc my_strftime +#endif -strftime(), but with a different API so that the return value is a pointer -to the formatted result (which MUST be arranged to be FREED BY THE -CALLER). This allows this function to increase the buffer size as needed, -so that the caller doesn't have to worry about that. +} -On failure it returns NULL. +SV * +S_sv_strftime_common(pTHX_ SV * fmt, + const char * locale, + const struct tm * mytm) +{ /* Documented above */ + PERL_ARGS_ASSERT_SV_STRFTIME_COMMON; -Note that yday and wday effectively are ignored by this function, as -mini_mktime() overwrites them. + STRLEN fmt_cur; + const char *fmt_str = SvPV_const(fmt, fmt_cur); -Also note that it is always executed in the underlying C locale of -the program, giving results based on that locale. + utf8ness_t fmt_utf8ness = (SvUTF8(fmt) && LIKELY(! IN_BYTES)) + ? UTF8NESS_YES + : UTF8NESS_UNKNOWN; + + utf8ness_t result_utf8ness; + + /* Use a fairly generous guess as to how big the buffer needs to be, so as + * to get almost all the typical returns to fit without the called function + * having to realloc; this is a somewhat educated guess, but feel free to + * tweak it. */ + SV* sv = newSV(MAX(fmt_cur * 2, 64)); + if (! strftime8(fmt_str, + sv, + locale, + mytm, + fmt_utf8ness, + &result_utf8ness, + true /* calling from sv_strftime */ )) + { + return NULL; + } -=cut - */ - PERL_ARGS_ASSERT_MY_STRFTIME; - /* An empty format yields an empty result */ - const int fmtlen = strlen(fmt); - if (fmtlen == 0) { - char *ret; - Newxz (ret, 1, char); - return ret; + if (result_utf8ness == UTF8NESS_YES) { + SvUTF8_on(sv); } - /* Set mytm to now */ - struct tm mytm; - init_tm(&mytm); /* XXX workaround - see Perl_init_tm() */ + return sv; +} + +STATIC void +S_ints_to_tm(pTHX_ struct tm * mytm, + const char * locale, + int sec, int min, int hour, int mday, int mon, int year, + int wday, int yday, int isdst) +{ + /* Create a struct tm structure from the input time-related integer + * variables for 'locale' */ /* Override with the passed-in values */ - mytm.tm_sec = sec; - mytm.tm_min = min; - mytm.tm_hour = hour; - mytm.tm_mday = mday; - mytm.tm_mon = mon; - mytm.tm_year = year; - mytm.tm_wday = wday; - mytm.tm_yday = yday; - mytm.tm_isdst = isdst; - mini_mktime(&mytm); - - /* use libc to get the values for tm_gmtoff and tm_zone on platforms that - * have them [perl #18238] */ -#if defined(HAS_MKTIME) && (defined(HAS_TM_TM_GMTOFF) || defined(HAS_TM_TM_ZONE)) - struct tm mytm2; - mytm2 = mytm; + Zero(mytm, 1, struct tm); + mytm->tm_sec = sec; + mytm->tm_min = min; + mytm->tm_hour = hour; + mytm->tm_mday = mday; + mytm->tm_mon = mon; + mytm->tm_year = year; + mytm->tm_wday = wday; + mytm->tm_yday = yday; + mytm->tm_isdst = isdst; + + /* Long-standing behavior is to ignore the effects of locale (in + * particular, daylight savings time) on the input, so we use mini_mktime. + * See GH #22062. */ + mini_mktime(mytm); + + /* But some of those effect are deemed desirable, so use libc to get the + * values for tm_gmtoff and tm_zone on platforms that have them [perl + * #18238] */ +#if defined(HAS_MKTIME) \ + && (defined(HAS_TM_TM_GMTOFF) || defined(HAS_TM_TM_ZONE)) + + const char * orig_TIME_locale = toggle_locale_c(LC_TIME, locale); + struct tm mytm2 = *mytm; MKTIME_LOCK; mktime(&mytm2); MKTIME_UNLOCK; + restore_toggled_locale_c(LC_TIME, orig_TIME_locale); + # ifdef HAS_TM_TM_GMTOFF - mytm.tm_gmtoff = mytm2.tm_gmtoff; + mytm->tm_gmtoff = mytm2.tm_gmtoff; # endif # ifdef HAS_TM_TM_ZONE - mytm.tm_zone = mytm2.tm_zone; + mytm->tm_zone = mytm2.tm_zone; # endif #endif -#if defined(USE_LOCALE_CTYPE) && defined(USE_LOCALE_TIME) - const char * orig_CTYPE_LOCALE = toggle_locale_c(LC_CTYPE, - querylocale_c(LC_TIME)); + return; +} + +STATIC bool +S_strftime_tm(pTHX_ const char *fmt, + SV * sv, + const char *locale, + const struct tm *mytm) +{ + PERL_ARGS_ASSERT_STRFTIME_TM; + + /* Execute strftime() based on the input struct tm, and the current LC_TIME + * locale. + * + * Returns 'true' if succeeded, with the PV pointer in 'sv' filled with the + * result, and all other C bits disabled, and not marked as UTF-8. + * Determining the UTF-8ness must be done at a higher level. + * + * 'false' is returned if if fails; the state of 'sv' is unspecified. */ + + /* An empty format yields an empty result */ + const Size_t fmtlen = strlen(fmt); + if (fmtlen == 0) { + sv_setpvs(sv, ""); + SvUTF8_off(sv); + return true; + } + + bool succeeded = false; + +#ifndef HAS_STRFTIME + Perl_croak(aTHX_ "panic: no strftime"); +#endif + + start_DEALING_WITH_MISMATCHED_CTYPE(locale); + +#if defined(USE_LOCALE_TIME) + + const char * orig_TIME_locale = toggle_locale_c(LC_TIME, locale); + +# define LC_TIME_TEARDOWN \ + restore_toggled_locale_c(LC_TIME, orig_TIME_locale) +#else + PERL_UNUSED_ARG(locale); +# define LC_TIME_TEARDOWN #endif - /* Guess an initial size for the returned string based on an expansion - * factor of the input format, but with a minimum that should handle most - * common cases. If this guess is too small, we will try again with a - * larger one */ - int bufsize = MAX(fmtlen * 2, 64); + /* Assume the caller has furnished a reasonable sized guess, but guard + * against one that won't work */ + Size_t bufsize = MAX(2, SvLEN(sv)); + SvUPGRADE(sv, SVt_PV); + SvPOK_only(sv); - char *buf = NULL; /* Makes Renew() act as Newx() on the first iteration */ do { - Renew(buf, bufsize, char); + char * buf = SvGROW(sv, bufsize); + + /* allowing user-supplied (rather than literal) formats is normally + * frowned upon as a potential security risk; but this is part of the + * API so we have to allow it (and the available formats have a much + * lower chance of doing something bad than the ones for printf etc. */ + GCC_DIAG_IGNORE_STMT(-Wformat-nonliteral); + +#ifdef WIN32 /* Windows will tell you if the input is invalid */ + + /* Needed because the LOCK might (or might not) save/restore errno */ + bool strftime_failed = false; + + STRFTIME_LOCK; + dSAVE_ERRNO; + errno = 0; + + Size_t len = strftime(buf, bufsize, fmt, mytm); + if (errno == EINVAL) { + strftime_failed = true; + } - GCC_DIAG_IGNORE_STMT(-Wformat-nonliteral); /* fmt checked by caller */ + RESTORE_ERRNO; + STRFTIME_UNLOCK; + + if (strftime_failed) { + goto strftime_failed; + } +#else STRFTIME_LOCK; - int len = strftime(buf, bufsize, fmt, &mytm); + Size_t len = strftime(buf, bufsize, fmt, mytm); STRFTIME_UNLOCK; +#endif GCC_DIAG_RESTORE_STMT; @@ -4894,7 +8355,9 @@ the program, giving results based on tha * indicates we have at least one byte of spare space (which will be * used for the terminating NUL). */ if (inRANGE(len, 1, bufsize - 1)) { - goto strftime_success; + succeeded = true; + SvCUR_set(sv, len); + goto strftime_return; } /* There are several possible reasons for a 0 return code for a @@ -4913,7 +8376,7 @@ the program, giving results based on tha * 268:2 byte ratio, or a bit more than 128:1 = 2**7:1. Some strftime * implementations allow you to say %1000c to pad to 1000 bytes. This * shows that it is impossible to implement this without a heuristic - * (that can fail). But it indicates we need to be generous in the + * (which can fail). But it indicates we need to be generous in the * upper limit before failing. The previous heuristic used was too * stingy. Since the size doubles per iteration, it doesn't take many * to reach the limit */ @@ -4926,75 +8389,264 @@ the program, giving results based on tha * when the format is precisely "%p". That is the only documented format * that can have an empty result. */ if (strEQ(fmt, "%p")) { - Renew(buf, 1, char); - *buf = '\0'; - goto strftime_success; + sv_setpvs(sv, ""); + SvUTF8_off(sv); + succeeded = true; + goto strftime_return; } /* The other reason is that the format string is malformed. Probably it is - * an illegal conversion specifier.) */ - Safefree(buf); - return NULL; + * that the string is syntactically invalid for the locale. On some + * platforms an invalid conversion specifier '%?' (for all illegal '?') is + * treated as a literal, but others may fail when '?' is illegal */ - strftime_success: - -#if defined(USE_LOCALE_CTYPE) && defined(USE_LOCALE_TIME) +#ifdef WIN32 + strftime_failed: +#endif - restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_LOCALE); + SET_EINVAL; + succeeded = false; -#endif - return buf; + strftime_return: -#else - Perl_croak(aTHX_ "panic: no strftime"); - return NULL; -#endif + LC_TIME_TEARDOWN; + end_DEALING_WITH_MISMATCHED_CTYPE(locale); + return succeeded; } -char * -Perl_my_strftime8_temp(pTHX_ const char *fmt, int sec, int min, int hour, int mday, - int mon, int year, int wday, int yday, int isdst, - utf8ness_t * utf8ness) -{ /* Documented above */ - char * retval = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, - yday, isdst); - - PERL_ARGS_ASSERT_MY_STRFTIME8_TEMP; +STATIC bool +S_strftime8(pTHX_ const char * fmt, + SV * sv, + const char * locale, + const struct tm * mytm, + const utf8ness_t fmt_utf8ness, + utf8ness_t * result_utf8ness, + const bool called_externally) +{ + PERL_ARGS_ASSERT_STRFTIME8; - if (utf8ness) { + /* Wrap strftime_tm, taking into account the input and output UTF-8ness */ #ifdef USE_LOCALE_TIME - *utf8ness = get_locale_string_utf8ness_i(retval, - LOCALE_UTF8NESS_UNKNOWN, - NULL, LC_TIME_INDEX_); +# define INDEX_TO_USE LC_TIME_INDEX_ + + locale_utf8ness_t locale_utf8ness = LOCALE_UTF8NESS_UNKNOWN; + #else - *utf8ness = UTF8NESS_IMMATERIAL; +# define INDEX_TO_USE LC_ALL_INDEX_ /* Effectively out of bounds */ + + locale_utf8ness_t locale_utf8ness = LOCALE_NOT_UTF8; + #endif + switch (fmt_utf8ness) { + case UTF8NESS_IMMATERIAL: + break; + + case UTF8NESS_NO: /* Known not to be UTF-8; must not be UTF-8 locale */ + if (is_locale_utf8(locale)) { + SET_EINVAL; + return false; + } + + locale_utf8ness = LOCALE_NOT_UTF8; + break; + + case UTF8NESS_YES: /* Known to be UTF-8; must be UTF-8 locale if can't + downgrade. */ + if (! is_locale_utf8(locale)) { + locale_utf8ness = LOCALE_NOT_UTF8; + + bool is_utf8 = true; + Size_t fmt_len = strlen(fmt); + fmt = (char *) bytes_from_utf8((U8 *) fmt, &fmt_len, &is_utf8); + if (is_utf8) { + SET_EINVAL; + return false; + } + + SAVEFREEPV(fmt); + } + else { + locale_utf8ness = LOCALE_IS_UTF8; + } + + break; + + case UTF8NESS_UNKNOWN: + if (! is_locale_utf8(locale)) { + locale_utf8ness = LOCALE_NOT_UTF8; + } + else { + locale_utf8ness = LOCALE_IS_UTF8; + if (called_externally) { + + /* All internal calls from this file use ASCII-only formats; + * but otherwise the format could be anything, so make sure to + * upgrade it to UTF-8 for a UTF-8 locale. Otherwise the + * locale would find any UTF-8 variant characters to be + * malformed */ + Size_t fmt_len = strlen(fmt); + fmt = (char *) bytes_to_utf8((U8 *) fmt, &fmt_len); + SAVEFREEPV(fmt); + } + } + + break; + } + + if (! strftime_tm(fmt, sv, locale, mytm)) { + return false; } + *result_utf8ness = get_locale_string_utf8ness_i(SvPVX(sv), + locale_utf8ness, + locale, + INDEX_TO_USE); DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "fmt=%s, retval=%s", fmt, - ((is_utf8_string((U8 *) retval, 0)) - ? retval - :_byte_dump_string((U8 *) retval, strlen(retval), 0))); - if (utf8ness) PerlIO_printf(Perl_debug_log, "; utf8ness=%d", - (int) *utf8ness); - PerlIO_printf(Perl_debug_log, "\n"); - ); + "fmt=%s, retval=%s; utf8ness=%d", + fmt, + ((is_strict_utf8_string((U8 *) SvPVX(sv), 0)) + ? SvPVX(sv) + :_byte_dump_string((U8 *) SvPVX(sv), SvCUR(sv) ,0)), + *result_utf8ness)); + return true; - return retval; +#undef INDEX_TO_USE + +} + +#ifdef USE_LOCALE + +STATIC void +S_give_perl_locale_control(pTHX_ +# ifdef LC_ALL + const char * lc_all_string, +# else + const char ** locales, +# endif + const line_t caller_line) +{ + PERL_UNUSED_ARG(caller_line); + + /* This is called when the program is in the global locale and are + * switching to per-thread (if available). And it is called at + * initialization time to do the same. + */ + +# if defined(WIN32) && defined(USE_THREAD_SAFE_LOCALE) + + /* On Windows, convert to per-thread behavior. This isn't necessary in + * POSIX 2008, as the conversion gets done automatically in the + * void_setlocale_i() calls below. */ + if (_configthreadlocale(_ENABLE_PER_THREAD_LOCALE) == -1) { + locale_panic_("_configthreadlocale returned an error"); + } + +# endif +# if ! defined(USE_THREAD_SAFE_LOCALE) \ + && ! defined(USE_POSIX_2008_LOCALE) +# if defined(LC_ALL) + PERL_UNUSED_ARG(lc_all_string); +# else + PERL_UNUSED_ARG(locales); +# endif +# else + + /* This platform has per-thread locale handling. Do the conversion. */ + +# if defined(LC_ALL) + + void_setlocale_c_with_caller(LC_ALL, lc_all_string, __FILE__, caller_line); + +# else + + for_all_individual_category_indexes(i) { + void_setlocale_i_with_caller(i, locales[i], __FILE__, caller_line); + } + +# endif +# endif + + /* Finally, update our remaining records. 'true' => force recalculation. + * This is needed because we don't know what's happened while Perl hasn't + * had control, so we need to figure out the current state */ + +# if defined(LC_ALL) + + new_LC_ALL(lc_all_string, true); + +# else + + new_LC_ALL(calculate_LC_ALL_string(locales, + INTERNAL_FORMAT, + WANT_TEMP_PV, + caller_line), + true); +# endif + +} + +STATIC void +S_output_check_environment_warning(pTHX_ const char * const language, + const char * const lc_all, + const char * const lang) +{ + PerlIO_printf(Perl_error_log, + "perl: warning: Please check that your locale settings:\n"); + +# ifdef __GLIBC__ + + PerlIO_printf(Perl_error_log, "\tLANGUAGE = %c%s%c,\n", + language ? '"' : '(', + language ? language : "unset", + language ? '"' : ')'); +# else + PERL_UNUSED_ARG(language); +# endif + + PerlIO_printf(Perl_error_log, "\tLC_ALL = %c%s%c,\n", + lc_all ? '"' : '(', + lc_all ? lc_all : "unset", + lc_all ? '"' : ')'); + + for_all_individual_category_indexes(i) { + const char * value = PerlEnv_getenv(category_names[i]); + PerlIO_printf(Perl_error_log, + "\t%s = %c%s%c,\n", + category_names[i], + value ? '"' : '(', + value ? value : "unset", + value ? '"' : ')'); + } + + PerlIO_printf(Perl_error_log, "\tLANG = %c%s%c\n", + lang ? '"' : '(', + lang ? lang : "unset", + lang ? '"' : ')'); + PerlIO_printf(Perl_error_log, + " are supported and installed on your system.\n"); } +#endif + +/* A helper macro for the next function. Needed because would be called in two + * places. Knows about the internal workings of the function */ +#define GET_DESCRIPTION(trial, name) \ + ((isNAME_C_OR_POSIX(name)) \ + ? "the standard locale" \ + : ((trial == (system_default_trial) \ + ? "the system default locale" \ + : "a fallback locale"))) + /* * Initialize locale awareness. */ int Perl_init_i18nl10n(pTHX_ int printwarn) { - /* printwarn is - * + /* printwarn is: * 0 if not to output warning when setup locale is bad * 1 if to output warning based on value of PERL_BADLANG * >1 if to output regardless of PERL_BADLANG @@ -5007,114 +8659,92 @@ Perl_init_i18nl10n(pTHX_ int printwarn) * Under -DDEBUGGING, if the environment variable PERL_DEBUG_LOCALE_INIT is * set, debugging information is output. * - * This looks more complicated than it is, mainly due to the #ifdefs and - * error handling. + * This routine effectively does the following in most cases: * - * Besides some asserts, data structure initialization, and specific - * platform complications, this routine is effectively represented by this - * pseudo-code: - * - * setlocale(LC_ALL, ""); x - * foreach (subcategory) { x - * curlocales[f(subcategory)] = setlocale(subcategory, NULL); x - * } x - * if (platform_so_requires) { - * foreach (subcategory) { - * PL_curlocales[f(subcategory)] = curlocales[f(subcategory)] + * basic initialization; + * asserts that the compiled tables are consistent; + * initialize data structures; + * make sure we are in the global locale; + * setlocale(LC_ALL, ""); + * switch to per-thread locale if applicable; + * + * The "" causes the locale to be set to what the environment variables at + * the time say it should be. + * + * To handle possible failures, the setlocale is expanded to be like: + * + * trial_locale = pre-first-trial; + * while (has_another_trial()) { + * trial_locale = next_trial(); + * if setlocale(LC_ALL, trial_locale) { + * ok = true; + * break; * } + * + * had_failure = true; + * warn(); * } - * foreach (subcategory) { - * if (needs_special_handling[f(subcategory)] &this_subcat_handler + * + * if (had_failure) { + * warn_even_more(); + * if (! ok) warn_still_more(); * } * - * This sets all the categories to the values in the current environment, - * saves them temporarily in curlocales[] until they can be handled and/or - * on some platforms saved in a per-thread array PL_curlocales[]. - * - * f(foo) is a mapping from the opaque system category numbers to small - * non-negative integers used most everywhere in this file as indices into - * arrays (such as curlocales[]) so the program doesn't have to otherwise - * deal with the opaqueness. - * - * If the platform doesn't have LC_ALL, the lines marked 'x' above are - * effectively replaced by: - * foreach (subcategory) { y - * curlocales[f(subcategory)] = setlocale(subcategory, ""); y - * } y - * - * The only differences being the lack of an LC_ALL call, and using "" - * instead of NULL in the setlocale calls. - * - * But there are, of course, complications. - * - * it has to deal with if this is an embedded perl, whose locale doesn't - * come from the environment, but has been set up by the caller. This is - * pretty simply handled: the "" in the setlocale calls is not a string - * constant, but a variable which is set to NULL in the embedded case. - * - * But the major complication is handling failure and doing fallback. All - * the code marked 'x' or 'y' above is actually enclosed in an outer loop, - * using the array trial_locales[]. On entry, trial_locales[] is - * initialized to just one entry, containing the NULL or "" locale argument - * shown above. If, as is almost always the case, everything works, it - * exits after just the one iteration, going on to the next step. - * - * But if there is a failure, the code tries its best to honor the - * environment as much as possible. It self-modifies trial_locales[] to - * have more elements, one for each of the POSIX-specified settings from - * the environment, such as LANG, ending in the ultimate fallback, the C - * locale. Thus if there is something bogus with a higher priority - * environment variable, it will try with the next highest, until something - * works. If everything fails, it limps along with whatever state it got - * to. - * - * A further complication is that Windows has an additional fallback, the - * user-default ANSI code page obtained from the operating system. This is - * added as yet another loop iteration, just before the final "C" - * - * A slight complication is that in embedded Perls, the locale may already - * be set-up, and we don't want to get it from the normal environment - * variables. This is handled by having a special environment variable - * indicate we're in this situation. We simply set setlocale's 2nd - * parameter to be a NULL instead of "". That indicates to setlocale that - * it is not to change anything, but to return the current value, - * effectively initializing perl's db to what the locale already is. - * - * We play the same trick with NULL if a LC_ALL succeeds. We call - * setlocale() on the individual categories with NULL to get their existing - * values for our db, instead of trying to change them. - * */ + * The first trial is either: + * "" to examine the environment variables for the locale + * NULL to use the values already set for the locale by the program + * embedding this perl instantiation. + * + * Something is wrong if this trial fails, but there is a sequence of + * fallbacks to try should that happen. They are given in the enum below. + + * If there is no LC_ALL defined on the system, the setlocale() above is + * replaced by a loop setting each individual category separately. + * + * In a non-embeded environment, this code is executed exactly once. It + * sets up the global locale environment. At the end, if some sort of + * thread-safety is in effect, it will turn thread 0 into using that, with + * the same locale as the global initially. thread 0 can then change its + * locale at will without affecting the global one. + * + * At destruction time, thread 0 will revert to the global locale as the + * other threads die. + * + * Care must be taken in an embedded environment. This code will be + * executed for each instantiation. Since it changes the global locale, it + * could clash with another running instantiation that isn't using + * per-thread locales. perlembed suggests having the controlling program + * set each instantiation's locale and set PERL_SKIP_LOCALE_INIT so this + * code uses that without actually changing anything. Then the onus is on + * the controlling program to prevent any races. The code below does + * enough locking so as to prevent system calls from overwriting data + * before it is safely copied here, but that isn't a general solution. + */ - int ok = 1; + if (PL_langinfo_sv == NULL) { + PL_langinfo_sv = newSVpvs(""); + } + if (PL_scratch_langinfo == NULL) { + PL_scratch_langinfo = newSVpvs(""); + } #ifndef USE_LOCALE PERL_UNUSED_ARG(printwarn); + const int ok = 1; + +#else /* USE_LOCALE to near the end of the routine */ + + int ok = 0; -#else /* USE_LOCALE */ # ifdef __GLIBC__ const char * const language = PerlEnv_getenv("LANGUAGE"); +# else + const char * const language = NULL; /* Unused placeholder */ # endif - /* NULL uses the existing already set up locale */ - const char * const setlocale_init = (PerlEnv_getenv("PERL_SKIP_LOCALE_INIT")) - ? NULL - : ""; - typedef struct trial_locales_struct_s { - const char* trial_locale; - const char* fallback_desc; - const char* fallback_name; - } trial_locales_struct; - /* 5 = 1 each for "", LC_ALL, LANG, (Win32) system default locale, C */ - trial_locales_struct trial_locales[5]; - unsigned int trial_locales_count; - const char * const lc_all = PerlEnv_getenv("LC_ALL"); - const char * const lang = PerlEnv_getenv("LANG"); - bool setlocale_failure = FALSE; - unsigned int i; - /* A later getenv() could zap this, so only use here */ const char * const bad_lang_use_once = PerlEnv_getenv("PERL_BADLANG"); @@ -5126,10 +8756,6 @@ Perl_init_i18nl10n(pTHX_ int printwarn) *bad_lang_use_once && strNE("0", bad_lang_use_once))))); - /* current locale for given category; should have been copied so aren't - * volatile */ - const char * curlocales[NOMINAL_LC_ALL_INDEX + 1]; - # ifndef DEBUGGING # define DEBUG_LOCALE_INIT(a,b,c) # else @@ -5140,113 +8766,18 @@ Perl_init_i18nl10n(pTHX_ int printwarn) DEBUG_L(PerlIO_printf(Perl_debug_log, "%s\n", \ setlocale_debug_string_i(cat_index, locale, result))); -/* Make sure the parallel arrays are properly set up */ -# ifdef USE_LOCALE_NUMERIC - assert(categories[LC_NUMERIC_INDEX_] == LC_NUMERIC); - assert(strEQ(category_names[LC_NUMERIC_INDEX_], "LC_NUMERIC")); -# ifdef USE_POSIX_2008_LOCALE - assert(category_masks[LC_NUMERIC_INDEX_] == LC_NUMERIC_MASK); -# endif -# endif -# ifdef USE_LOCALE_CTYPE - assert(categories[LC_CTYPE_INDEX_] == LC_CTYPE); - assert(strEQ(category_names[LC_CTYPE_INDEX_], "LC_CTYPE")); -# ifdef USE_POSIX_2008_LOCALE - assert(category_masks[LC_CTYPE_INDEX_] == LC_CTYPE_MASK); -# endif -# endif -# ifdef USE_LOCALE_COLLATE - assert(categories[LC_COLLATE_INDEX_] == LC_COLLATE); - assert(strEQ(category_names[LC_COLLATE_INDEX_], "LC_COLLATE")); -# ifdef USE_POSIX_2008_LOCALE - assert(category_masks[LC_COLLATE_INDEX_] == LC_COLLATE_MASK); -# endif -# endif -# ifdef USE_LOCALE_TIME - assert(categories[LC_TIME_INDEX_] == LC_TIME); - assert(strEQ(category_names[LC_TIME_INDEX_], "LC_TIME")); -# ifdef USE_POSIX_2008_LOCALE - assert(category_masks[LC_TIME_INDEX_] == LC_TIME_MASK); -# endif -# endif -# ifdef USE_LOCALE_MESSAGES - assert(categories[LC_MESSAGES_INDEX_] == LC_MESSAGES); - assert(strEQ(category_names[LC_MESSAGES_INDEX_], "LC_MESSAGES")); -# ifdef USE_POSIX_2008_LOCALE - assert(category_masks[LC_MESSAGES_INDEX_] == LC_MESSAGES_MASK); -# endif -# endif -# ifdef USE_LOCALE_MONETARY - assert(categories[LC_MONETARY_INDEX_] == LC_MONETARY); - assert(strEQ(category_names[LC_MONETARY_INDEX_], "LC_MONETARY")); -# ifdef USE_POSIX_2008_LOCALE - assert(category_masks[LC_MONETARY_INDEX_] == LC_MONETARY_MASK); -# endif -# endif -# ifdef USE_LOCALE_ADDRESS - assert(categories[LC_ADDRESS_INDEX_] == LC_ADDRESS); - assert(strEQ(category_names[LC_ADDRESS_INDEX_], "LC_ADDRESS")); -# ifdef USE_POSIX_2008_LOCALE - assert(category_masks[LC_ADDRESS_INDEX_] == LC_ADDRESS_MASK); -# endif -# endif -# ifdef USE_LOCALE_IDENTIFICATION - assert(categories[LC_IDENTIFICATION_INDEX_] == LC_IDENTIFICATION); - assert(strEQ(category_names[LC_IDENTIFICATION_INDEX_], "LC_IDENTIFICATION")); -# ifdef USE_POSIX_2008_LOCALE - assert(category_masks[LC_IDENTIFICATION_INDEX_] == LC_IDENTIFICATION_MASK); -# endif -# endif -# ifdef USE_LOCALE_MEASUREMENT - assert(categories[LC_MEASUREMENT_INDEX_] == LC_MEASUREMENT); - assert(strEQ(category_names[LC_MEASUREMENT_INDEX_], "LC_MEASUREMENT")); -# ifdef USE_POSIX_2008_LOCALE - assert(category_masks[LC_MEASUREMENT_INDEX_] == LC_MEASUREMENT_MASK); -# endif -# endif -# ifdef USE_LOCALE_PAPER - assert(categories[LC_PAPER_INDEX_] == LC_PAPER); - assert(strEQ(category_names[LC_PAPER_INDEX_], "LC_PAPER")); -# ifdef USE_POSIX_2008_LOCALE - assert(category_masks[LC_PAPER_INDEX_] == LC_PAPER_MASK); -# endif -# endif -# ifdef USE_LOCALE_TELEPHONE - assert(categories[LC_TELEPHONE_INDEX_] == LC_TELEPHONE); - assert(strEQ(category_names[LC_TELEPHONE_INDEX_], "LC_TELEPHONE")); -# ifdef USE_POSIX_2008_LOCALE - assert(category_masks[LC_TELEPHONE_INDEX_] == LC_TELEPHONE_MASK); -# endif -# endif -# ifdef USE_LOCALE_NAME - assert(categories[LC_NAME_INDEX_] == LC_NAME); - assert(strEQ(category_names[LC_NAME_INDEX_], "LC_NAME")); -# ifdef USE_POSIX_2008_LOCALE - assert(category_masks[LC_NAME_INDEX_] == LC_NAME_MASK); -# endif -# endif -# ifdef USE_LOCALE_SYNTAX - assert(categories[LC_SYNTAX_INDEX_] == LC_SYNTAX); - assert(strEQ(category_names[LC_SYNTAX_INDEX_], "LC_SYNTAX")); -# ifdef USE_POSIX_2008_LOCALE - assert(category_masks[LC_SYNTAX_INDEX_] == LC_SYNTAX_MASK); -# endif -# endif -# ifdef USE_LOCALE_TOD - assert(categories[LC_TOD_INDEX_] == LC_TOD); - assert(strEQ(category_names[LC_TOD_INDEX_], "LC_TOD")); -# ifdef USE_POSIX_2008_LOCALE - assert(category_masks[LC_TOD_INDEX_] == LC_TOD_MASK); -# endif -# endif # ifdef LC_ALL assert(categories[LC_ALL_INDEX_] == LC_ALL); assert(strEQ(category_names[LC_ALL_INDEX_], "LC_ALL")); - STATIC_ASSERT_STMT(NOMINAL_LC_ALL_INDEX == LC_ALL_INDEX_); # ifdef USE_POSIX_2008_LOCALE assert(category_masks[LC_ALL_INDEX_] == LC_ALL_MASK); # endif # endif + + for_all_individual_category_indexes(i) { + assert(category_name_lengths[i] == strlen(category_names[i])); + } + # endif /* DEBUGGING */ /* Initialize the per-thread mbrFOO() state variables. See POSIX.xs for @@ -5260,392 +8791,460 @@ Perl_init_i18nl10n(pTHX_ int printwarn) # ifdef HAS_WCTOMBR wcrtomb(NULL, L'\0', &PL_wcrtomb_ps); # endif -# ifdef USE_THREAD_SAFE_LOCALE -# ifdef WIN32 +# ifdef USE_PL_CURLOCALES + + for (unsigned int i = 0; i <= LC_ALL_INDEX_; i++) { + PL_curlocales[i] = savepv("C"); + } + +# endif +# ifdef USE_PL_CUR_LC_ALL + + PL_cur_LC_ALL = savepv("C"); + +# endif +# if ! defined(PERL_LC_ALL_USES_NAME_VALUE_PAIRS) && defined(LC_ALL) + + LOCALE_LOCK; - _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); + /* If we haven't done so already, translate the LC_ALL positions of + * categories into our internal indices. */ + if (map_LC_ALL_position_to_index[0] == LC_ALL_INDEX_) { +# ifdef PERL_LC_ALL_CATEGORY_POSITIONS_INIT + /* Use this array, initialized by a config.h constant */ + int lc_all_category_positions[] = PERL_LC_ALL_CATEGORY_POSITIONS_INIT; + STATIC_ASSERT_STMT( C_ARRAY_LENGTH(lc_all_category_positions) + == LC_ALL_INDEX_); + + for (unsigned int i = 0; + i < C_ARRAY_LENGTH(lc_all_category_positions); + i++) + { + map_LC_ALL_position_to_index[i] = + get_category_index(lc_all_category_positions[i]); + } +# else + /* It is possible for both PERL_LC_ALL_USES_NAME_VALUE_PAIRS and + * PERL_LC_ALL_CATEGORY_POSITIONS_INIT not to be defined, e.g. on + * systems with only a C locale during ./Configure. Assume that this + * can only happen as part of some sort of bootstrapping so allow + * compilation to succeed by ignoring correctness. + */ + for (unsigned int i = 0; + i < C_ARRAY_LENGTH(map_LC_ALL_position_to_index); + i++) + { + map_LC_ALL_position_to_index[i] = 0; + } # endif + + } + + LOCALE_UNLOCK; + # endif # ifdef USE_POSIX_2008_LOCALE - if (! PL_C_locale_obj) { - PL_C_locale_obj = newlocale(LC_ALL_MASK, "C", (locale_t) 0); - } - if (! PL_C_locale_obj) { - locale_panic_(Perl_form(aTHX_ - "Cannot create POSIX 2008 C locale object")); + /* This is a global, so be sure to keep another instance from zapping it */ + LOCALE_LOCK; + if (PL_C_locale_obj) { + LOCALE_UNLOCK; } + else { + PL_C_locale_obj = newlocale(LC_ALL_MASK, "C", (locale_t) 0); + if (! PL_C_locale_obj) { + LOCALE_UNLOCK; + locale_panic_("Cannot create POSIX 2008 C locale object"); + } + LOCALE_UNLOCK; - DEBUG_Lv(PerlIO_printf(Perl_debug_log, "created C object %p\n", - PL_C_locale_obj)); + DEBUG_Lv(PerlIO_printf(Perl_debug_log, "created C object %p\n", + PL_C_locale_obj)); + } /* Switch to using the POSIX 2008 interface now. This would happen below * anyway, but deferring it can lead to leaks of memory that would also get - * malloc'd in the interim */ - uselocale(PL_C_locale_obj); + * malloc'd in the interim. We arbitrarily switch to the C locale, + * overridden below */ + if (! uselocale(PL_C_locale_obj)) { + locale_panic_(Perl_form(aTHX_ + "Can't uselocale(%p), LC_ALL supposed to" + " be 'C'", + PL_C_locale_obj)); + } -# ifdef USE_LOCALE_NUMERIC +# ifdef MULTIPLICITY - PL_underlying_numeric_obj = duplocale(PL_C_locale_obj); + PL_cur_locale_obj = PL_C_locale_obj; # endif # endif + + /* Now initialize some data structures. This is entirely so that + * later-executed code doesn't have to concern itself with things not being + * initialized. Arbitrarily use the C locale (which we know has to exist + * on the system). */ + # ifdef USE_LOCALE_NUMERIC PL_numeric_radix_sv = newSV(1); PL_underlying_radix_sv = newSV(1); Newxz(PL_numeric_name, 1, char); /* Single NUL character */ - new_numeric("C", false); # endif # ifdef USE_LOCALE_COLLATE Newxz(PL_collation_name, 1, char); - new_collate("C", false); # endif # ifdef USE_LOCALE_CTYPE Newxz(PL_ctype_name, 1, char); - new_ctype("C", false); # endif -# ifdef USE_PL_CURLOCALES - /* Initialize our records. */ - for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { - (void) emulate_setlocale_i(i, posix_setlocale(categories[i], NULL), - RECALCULATE_LC_ALL_ON_FINAL_INTERATION, - __LINE__); - } + new_LC_ALL("C", true /* Don't shortcut */); + +/*===========================================================================*/ + + /* Now ready to override the initialization with the values that the user + * wants. This is done in the global locale as explained in the + * introductory comments to this function */ + switch_to_global_locale(); + + const char * const lc_all = PerlEnv_getenv("LC_ALL"); + const char * const lang = PerlEnv_getenv("LANG"); + /* We try each locale in the enum, in order, until we get one that works, + * or exhaust the list. Normally the loop is executed just once. + * + * Each enum value is +1 from the previous */ + typedef enum { + dummy_trial = -1, + environment_trial = 0, /* "" or NULL; code below assumes value + 0 is the first real trial */ + LC_ALL_trial, /* ENV{LC_ALL} */ + LANG_trial, /* ENV{LANG} */ + system_default_trial, /* Windows .ACP */ + C_trial, /* C locale */ + beyond_final_trial, + } trials; + + trials trial; + unsigned int already_checked = 0; + const char * checked[C_trial]; + +# ifdef LC_ALL + const char * lc_all_string; +# else + const char * curlocales[LC_ALL_INDEX_]; # endif - /* We try each locale in the list until we get one that works, or exhaust - * 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_struct ts = { - .trial_locale = setlocale_init, - .fallback_desc = NULL, - .fallback_name = NULL, - }; - trial_locales[0] = ts; - trial_locales_count = 1; + /* Loop through the initial setting and all the possible fallbacks, + * breaking out of the loop on success */ + trial = dummy_trial; + while (trial != beyond_final_trial) { + + /* Each time through compute the next trial to use based on the one in + * the previous iteration and switch to the new one. This enforces the + * order in which the fallbacks are applied */ + next_trial: + trial = (trials) ((int) trial + 1); /* Casts are needed for g++ */ + + const char * locale = NULL; + + /* Set up the parameters for this trial */ + switch (trial) { + case dummy_trial: + locale_panic_("Unexpectedly got 'dummy_trial"); + break; - for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { - curlocales[i] = NULL; - } + case environment_trial: + /* This is either "" to get the values from the environment, or + * NULL if the calling program has initialized the values already. + * */ + locale = (PerlEnv_getenv("PERL_SKIP_LOCALE_INIT")) + ? NULL + : ""; + break; + + case LC_ALL_trial: + if (! lc_all || strEQ(lc_all, "")) { + continue; /* No-op */ + } + + locale = lc_all; + break; + + case LANG_trial: + if (! lang || strEQ(lang, "")) { + continue; /* No-op */ + } + + locale = lang; + break; + + case system_default_trial: + +# if ! defined(WIN32) || ! defined(LC_ALL) + + continue; /* No-op */ + +# else + /* For Windows, we also try the system default locale before "C". + * (If there exists a Windows without LC_ALL we skip this because + * it gets too complicated. For those, "C" is the next fallback + * possibility). */ + locale = ".ACP"; +# endif + break; + + case C_trial: + locale = "C"; + break; + + case beyond_final_trial: + continue; /* No-op, causes loop to exit */ + } + + /* If the locale is a substantive name, don't try the same locale + * twice. */ + if (locale && strNE(locale, "")) { + for (unsigned int i = 0; i < already_checked; i++) { + if (strEQ(checked[i], locale)) { + goto next_trial; + } + } - for (i= 0; i < trial_locales_count; i++) { - const char * trial_locale = trial_locales[i].trial_locale; - setlocale_failure = FALSE; + /* And, for future iterations, indicate we've tried this locale */ + assert(already_checked < C_ARRAY_LENGTH(checked)); + checked[already_checked] = savepv(locale); + SAVEFREEPV(checked[already_checked]); + already_checked++; + } # ifdef LC_ALL - /* setlocale() return vals; not copied so must be looked at - * immediately. */ - const char * sl_result[NOMINAL_LC_ALL_INDEX + 1]; - sl_result[LC_ALL_INDEX_] = stdized_setlocale(LC_ALL, trial_locale); - DEBUG_LOCALE_INIT(LC_ALL_INDEX_, trial_locale, sl_result[LC_ALL_INDEX_]); - if (! sl_result[LC_ALL_INDEX_]) { - setlocale_failure = TRUE; + STDIZED_SETLOCALE_LOCK; + lc_all_string = savepv(stdized_setlocale(LC_ALL, locale)); + STDIZED_SETLOCALE_UNLOCK; + + DEBUG_LOCALE_INIT(LC_ALL_INDEX_, locale, lc_all_string); + + if (LIKELY(lc_all_string)) { /* Succeeded */ + ok = 1; + break; } - else { - /* Since LC_ALL succeeded, it should have changed all the other - * categories it can to its value; so we massage things so that the - * setlocales below just return their category's current values. - * This adequately handles the case in NetBSD where LC_COLLATE may - * not be defined for a locale, and setting it individually will - * fail, whereas setting LC_ALL succeeds, leaving LC_COLLATE set to - * the POSIX locale. */ - trial_locale = NULL; + + if (trial == 0 && locwarn) { + PerlIO_printf(Perl_error_log, + "perl: warning: Setting locale failed.\n"); + output_check_environment_warning(language, lc_all, lang); } -# endif /* LC_ALL */ +# else /* Below is ! LC_ALL */ - if (! setlocale_failure) { - unsigned int j; - for (j = 0; j < NOMINAL_LC_ALL_INDEX; j++) { - curlocales[j] = stdized_setlocale(categories[j], trial_locale); - if (! curlocales[j]) { - setlocale_failure = TRUE; + bool setlocale_failure = FALSE; /* This trial hasn't failed so far */ + bool dowarn = trial == 0 && locwarn; + + for_all_individual_category_indexes(j) { + STDIZED_SETLOCALE_LOCK; + curlocales[j] = savepv(stdized_setlocale(categories[j], locale)); + STDIZED_SETLOCALE_UNLOCK; + + DEBUG_LOCALE_INIT(j, locale, curlocales[j]); + + if (UNLIKELY(! curlocales[j])) { + setlocale_failure = TRUE; + + /* If are going to warn below, continue to loop so all failures + * are included in the message */ + if (! dowarn) { + break; } - curlocales[j] = savepv(curlocales[j]); - DEBUG_LOCALE_INIT(j, trial_locale, curlocales[j]); } + } - if (LIKELY(! setlocale_failure)) { /* All succeeded */ - break; /* Exit trial_locales loop */ - } + if (LIKELY(! setlocale_failure)) { /* All succeeded */ + ok = 1; + break; /* Exit trial_locales loop */ } - /* Here, something failed; will need to try a fallback. */ - ok = 0; + /* Here, this trial failed */ - if (i == 0) { - unsigned int j; + if (dowarn) { + PerlIO_printf(Perl_error_log, + "perl: warning: Setting locale failed for the categories:\n"); - if (locwarn) { /* Output failure info only on the first one */ + for_all_individual_category_indexes(j) { + if (! curlocales[j]) { + PerlIO_printf(Perl_error_log, "\t%s\n", category_names[j]); + } + } -# ifdef LC_ALL + output_check_environment_warning(language, lc_all, lang); + } /* end of warning on first failure */ - PerlIO_printf(Perl_error_log, - "perl: warning: Setting locale failed.\n"); +# endif /* LC_ALL */ -# else /* !LC_ALL */ + } /* end of looping through the trial locales */ - PerlIO_printf(Perl_error_log, - "perl: warning: Setting locale failed for the categories:\n"); + /* If we had to do more than the first trial, it means that one failed, and + * we may need to output a warning, and, if none worked, do more */ + if (UNLIKELY(trial != 0)) { + if (locwarn) { + const char * description = "a fallback locale"; + const char * name = NULL;; - for (j = 0; j < NOMINAL_LC_ALL_INDEX; j++) { - if (! curlocales[j]) { - PerlIO_printf(Perl_error_log, "\t%s\n", category_names[j]); - } + /* If we didn't find a good fallback, list all we tried */ + if (! ok && already_checked > 0) { + PerlIO_printf(Perl_error_log, "perl: warning: Failed to fall" + " back to "); + if (already_checked > 1) { /* more than one was tried */ + PerlIO_printf(Perl_error_log, "any of:\n"); } -# endif /* LC_ALL */ + while (already_checked > 0) { + name = checked[--already_checked]; + description = GET_DESCRIPTION(trial, name); + PerlIO_printf(Perl_error_log, "%s (\"%s\")\n", + description, name); + } + } - PerlIO_printf(Perl_error_log, - "perl: warning: Please check that your locale settings:\n"); + if (ok) { -# ifdef __GLIBC__ + /* Here, a fallback worked. So we have saved its name, and the + * trial that succeeded is still valid */ +# ifdef LC_ALL + const char * individ_locales[LC_ALL_INDEX_] = { NULL }; - PerlIO_printf(Perl_error_log, - "\tLANGUAGE = %c%s%c,\n", - language ? '"' : '(', - language ? language : "unset", - language ? '"' : ')'); -# endif + /* Even though we know the valid string for LC_ALL that worked, + * translate it into our internal format, which is the + * name=value pairs notation. This is easier for a human to + * decipher than the positional notation. Some platforms + * can return "C C C C C C" for LC_ALL. This code also + * standardizes that result into plain "C". */ + switch (parse_LC_ALL_string(lc_all_string, + (const char **) &individ_locales, + no_override, + false, /* Return only [0] if + suffices */ + false, /* Don't panic on error */ + __LINE__)) + { + case invalid: - PerlIO_printf(Perl_error_log, - "\tLC_ALL = %c%s%c,\n", - lc_all ? '"' : '(', - lc_all ? lc_all : "unset", - lc_all ? '"' : ')'); + /* Here, the parse failed, which shouldn't happen, but if + * it does, we have an easy fallback that allows us to keep + * going. */ + name = lc_all_string; + break; -# if defined(USE_ENVIRON_ARRAY) + case no_array: /* The original is a single locale */ + name = lc_all_string; + break; - { - char **e; + case only_element_0: /* element[0] is a single locale valid + for all categories */ + SAVEFREEPV(individ_locales[0]); + name = individ_locales[0]; + break; - /* Look through the environment for any variables of the - * form qr/ ^ LC_ [A-Z]+ = /x, except LC_ALL which was - * already handled above. These are assumed to be locale - * settings. Output them and their values. */ - for (e = environ; *e; e++) { - const STRLEN prefix_len = sizeof("LC_") - 1; - STRLEN uppers_len; - - if ( strBEGINs(*e, "LC_") - && ! strBEGINs(*e, "LC_ALL=") - && (uppers_len = strspn(*e + prefix_len, - "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) - && ((*e)[prefix_len + uppers_len] == '=')) - { - PerlIO_printf(Perl_error_log, "\t%.*s = \"%s\",\n", - (int) (prefix_len + uppers_len), *e, - *e + prefix_len + uppers_len + 1); - } + case full_array: + name = calculate_LC_ALL_string(individ_locales, + INTERNAL_FORMAT, + WANT_TEMP_PV, + __LINE__); + for_all_individual_category_indexes(j) { + Safefree(individ_locales[j]); } } - # else - - PerlIO_printf(Perl_error_log, - "\t(possibly more locale environment variables)\n"); - + name = calculate_LC_ALL_string(curlocales, + INTERNAL_FORMAT, + WANT_TEMP_PV, + __LINE__); # endif + description = GET_DESCRIPTION(trial, name); + } + else { - PerlIO_printf(Perl_error_log, - "\tLANG = %c%s%c\n", - lang ? '"' : '(', - lang ? lang : "unset", - lang ? '"' : ')'); + /* Nothing seems to be working, yet we want to continue + * executing. It may well be that locales are mostly + * irrelevant to this particular program, and there must be + * some locale underlying the program. Figure it out as best + * we can, by querying the system's current locale */ - PerlIO_printf(Perl_error_log, - " are supported and installed on your system.\n"); - } +# ifdef LC_ALL - /* Calculate what fallback locales to try. We have avoided this - * until we have to, because failure is quite unlikely. This will - * usually change the upper bound of the loop we are in. - * - * Since the system's default way of setting the locale has not - * found one that works, We use Perl's defined ordering: LC_ALL, - * LANG, and the C locale. We don't try the same locale twice, so - * don't add to the list if already there. (On POSIX systems, the - * LC_ALL element will likely be a repeat of the 0th element "", - * but there's no harm done by doing it explicitly. - * - * Note that this tries the LC_ALL environment variable even on - * systems which have no LC_ALL locale setting. This may or may - * not have been originally intentional, but there's no real need - * to change the behavior. */ - if (lc_all) { - for (j = 0; j < trial_locales_count; j++) { - if (strEQ(lc_all, trial_locales[j].trial_locale)) { - goto done_lc_all; - } - } - 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: - - if (lang) { - for (j = 0; j < trial_locales_count; j++) { - if (strEQ(lang, trial_locales[j].trial_locale)) { - goto done_lang; - } + STDIZED_SETLOCALE_LOCK; + name = stdized_setlocale(LC_ALL, NULL); + STDIZED_SETLOCALE_UNLOCK; + + if (UNLIKELY(! name)) { + name = "locale name not determinable"; } - 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: -# if defined(WIN32) && defined(LC_ALL) +# else /* Below is ! LC_ALL */ - /* For Windows, we also try the system default locale before "C". - * (If there exists a Windows without LC_ALL we skip this because - * it gets too complicated. For those, the "C" is the next - * fallback possibility). */ - { - /* Note that this may change the locale, but we are going to do - * that anyway. - * - * Our normal Windows setlocale() implementation ignores the - * system default locale to make things work like POSIX. This - * is the only place where we want to consider it, so have to - * use wrap_wsetlocale(). */ - const char *system_default_locale = - stdize_locale(LC_ALL, - wrap_wsetlocale(LC_ALL, ""), - &PL_stdize_locale_buf, - &PL_stdize_locale_bufsize, - __LINE__); - DEBUG_LOCALE_INIT(LC_ALL_INDEX_, "", system_default_locale); - - /* Skip if invalid or if it's already on the list of locales to - * try */ - if (! system_default_locale) { - goto done_system_default; - } - for (j = 0; j < trial_locales_count; j++) { - if (strEQ(system_default_locale, trial_locales[j].trial_locale)) { - goto done_system_default; + const char * system_locales[LC_ALL_INDEX_] = { NULL }; + + for_all_individual_category_indexes(j) { + STDIZED_SETLOCALE_LOCK; + system_locales[j] = savepv(stdized_setlocale(categories[j], + NULL)); + STDIZED_SETLOCALE_UNLOCK; + + if (UNLIKELY(! system_locales[j])) { + system_locales[j] = "not determinable"; } } - 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: - -# endif + /* We use the name=value form for the string, as that is more + * human readable than the positional notation */ + name = calculate_LC_ALL_string(system_locales, + INTERNAL_FORMAT, + WANT_TEMP_PV, + __LINE__); + description = "what the system says"; - for (j = 0; j < trial_locales_count; j++) { - if (strEQ("C", trial_locales[j].trial_locale)) { - goto done_C; + for_all_individual_category_indexes(j) { + Safefree(system_locales[j]); } +# endif } - { - /* 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 */ - - if (ok < 1) { /* If we tried to fallback */ - const char* msg; - if (! setlocale_failure) { /* fallback succeeded */ - msg = "Falling back to"; - } - else { /* fallback failed */ - unsigned int j; - - /* We dropped off the end of the loop, so have to decrement i to - * get back to the value the last time through */ - i--; - - ok = -1; - msg = "Failed to fall back to"; - - /* To continue, we should use whatever values we've got */ - - for (j = 0; j < NOMINAL_LC_ALL_INDEX; j++) { - Safefree(curlocales[j]); - curlocales[j] = savepv(stdized_setlocale(categories[j], NULL)); - DEBUG_LOCALE_INIT(j, NULL, curlocales[j]); - } - } - if (locwarn) { - const char * description = trial_locales[i].fallback_desc; - const char * name = trial_locales[i].fallback_name; + PerlIO_printf(Perl_error_log, + "perl: warning: Falling back to %s (\"%s\").\n", + description, name); - if (name && strNE(name, "")) { - PerlIO_printf(Perl_error_log, - "perl: warning: %s %s (\"%s\").\n", msg, description, name); - } - else { - PerlIO_printf(Perl_error_log, - "perl: warning: %s %s.\n", msg, description); - } + /* Here, ok being true indicates that the first attempt failed, but + * a fallback succeeded; false => nothing working. Translate to + * API return values. */ + ok = (ok) ? 0 : -1; } - } /* End of tried to fallback */ + } -# ifdef USE_POSIX_2008_LOCALE +# ifdef LC_ALL - /* The stdized setlocales haven't affected the P2008 locales. Initialize - * them now, calculating LC_ALL only on the final go round, when all have - * been set. */ - for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { - (void) emulate_setlocale_i(i, curlocales[i], - RECALCULATE_LC_ALL_ON_FINAL_INTERATION, - __LINE__); - } + give_perl_locale_control(lc_all_string, __LINE__); + Safefree(lc_all_string); -# endif +# else - /* Done with finding the locales; update the auxiliary records */ - new_LC_ALL(NULL, false); + give_perl_locale_control((const char **) &curlocales, __LINE__); - for (i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { - Safefree(curlocales[i]); + for_all_individual_category_indexes(j) { + Safefree(curlocales[j]); } +# endif # if defined(USE_PERLIO) && defined(USE_LOCALE_CTYPE) /* Set PL_utf8locale to TRUE if using PerlIO _and_ the current LC_CTYPE - * locale is UTF-8. The call to new_ctype() just above has already + * locale is UTF-8. give_perl_locale_control() just above has already * calculated the latter value and saved it in PL_in_utf8_CTYPE_locale. If * both PL_utf8locale and PL_unicode (set by -C or by $ENV{PERL_UNICODE}) * are true, perl.c:S_parse_body() will turn on the PerlIO :utf8 layer on @@ -5663,14 +9262,23 @@ Perl_init_i18nl10n(pTHX_ int printwarn) } # endif -#endif /* USE_LOCALE */ +# if defined(USE_POSIX_2008_LOCALE) && defined(MULTIPLICITY) + DEBUG_Lv(PerlIO_printf(Perl_debug_log, + "finished Perl_init_i18nl10n; actual obj=%p," + " expected obj=%p, initial=%s\n", + uselocale(0), PL_cur_locale_obj, + get_LC_ALL_display())); +# endif /* So won't continue to output stuff */ DEBUG_INITIALIZATION_set(FALSE); +#endif /* USE_LOCALE */ + return ok; } +#undef GET_DESCRIPTION #ifdef USE_LOCALE_COLLATE STATIC void @@ -5758,7 +9366,7 @@ S_compute_collxfrm_coefficients(pTHX) * function by telling it the string is in UTF-8 * if the locale is a UTF-8 one. Since the string * passed here is invariant under UTF-8, we can - * claim it's UTF-8 even though it isn't. */ + * claim it's UTF-8 even if it isn't. */ PL_in_utf8_COLLATE_locale); Safefree(x_longer); @@ -5875,7 +9483,7 @@ Perl_mem_collxfrm_(pTHX_ const char *inp if (PL_collxfrm_mult == 0) { /* unknown or bad */ if (PL_collxfrm_base != 0) { /* bad collation => skip */ DEBUG_L(PerlIO_printf(Perl_debug_log, - "mem_collxfrm_: locale's collation is defective\n")); + "mem_collxfrm_: locale's collation is defective\n")); goto bad; } @@ -5928,8 +9536,11 @@ Perl_mem_collxfrm_(pTHX_ const char *inp /* In this case we use isCNTRL_LC() below, which relies on * LC_CTYPE, so that must be switched to correspond with the * LC_COLLATE locale */ - if (! try_non_controls && ! PL_in_utf8_COLLATE_locale) { - orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, PL_collation_name); + const bool need_to_toggle = ( ! try_non_controls + && ! PL_in_utf8_COLLATE_locale); + if (need_to_toggle) { + orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, + PL_collation_name); } # endif /* Look through all legal code points (NUL isn't) */ @@ -5977,7 +9588,10 @@ Perl_mem_collxfrm_(pTHX_ const char *inp } /* end of loop through all 255 characters */ # ifdef USE_LOCALE_CTYPE - restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale); + + if (need_to_toggle) { + restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale); + } # endif /* Stop looking if found */ @@ -6210,7 +9824,7 @@ Perl_mem_collxfrm_(pTHX_ const char *inp } /* Store the collation id */ - *(U32*)xbuf = PL_collation_ix; + *(PERL_UINTMAX_T *)xbuf = PL_collation_ix; # if defined(USE_POSIX_2008_LOCALE) && defined HAS_STRXFRM_L # ifdef USE_LOCALE_CTYPE @@ -6247,7 +9861,10 @@ Perl_mem_collxfrm_(pTHX_ const char *inp for (;;) { errno = 0; - *xlen = my_strxfrm(xbuf + COLLXFRM_HDR_LEN, s, xAlloc - COLLXFRM_HDR_LEN); + *xlen = my_strxfrm(xbuf + COLLXFRM_HDR_LEN, + s, + xAlloc - COLLXFRM_HDR_LEN); + /* If the transformed string occupies less space than we told strxfrm() * was available, it means it transformed the whole string. */ @@ -6361,7 +9978,7 @@ Perl_mem_collxfrm_(pTHX_ const char *inp "mem_collxfrm_ required more space than previously" " calculated for locale %s, trying again with new" " guess=%zu+%zu\n", - PL_collation_name, COLLXFRM_HDR_LEN, + PL_collation_name, COLLXFRM_HDR_LEN, xAlloc - COLLXFRM_HDR_LEN)); } @@ -6393,284 +10010,88 @@ Perl_mem_collxfrm_(pTHX_ const char *inp CLEANUP_STRXFRM; DEBUG_L(print_collxfrm_input_and_return(s, s + len, NULL, 0, utf8)); - Safefree(xbuf); - if (s != input_string) { - Safefree(s); - } - *xlen = 0; - - return NULL; -} - -# ifdef DEBUGGING - -STATIC void -S_print_collxfrm_input_and_return(pTHX_ - const char * s, - const char * e, - const char * xbuf, - const STRLEN xlen, - const bool is_utf8) -{ - - PERL_ARGS_ASSERT_PRINT_COLLXFRM_INPUT_AND_RETURN; - - PerlIO_printf(Perl_debug_log, - "mem_collxfrm_[ix %" UVuf "] for locale '%s':\n" - " input=%s\n return=%s\n return len=%zu\n", - (UV) PL_collation_ix, PL_collation_name, - get_displayable_string(s, e, is_utf8), - ((xbuf == NULL) - ? "(null)" - : _byte_dump_string((U8 *) xbuf + COLLXFRM_HDR_LEN, xlen, 0)), - xlen); -} - -# endif /* DEBUGGING */ - -SV * -Perl_strxfrm(pTHX_ SV * src) -{ - PERL_ARGS_ASSERT_STRXFRM; - - /* For use by POSIX::strxfrm(). If they differ, toggle LC_CTYPE to - * LC_COLLATE to avoid potential mojibake. - * - * If we can't calculate a collation, 'src' is instead returned, so that - * future comparisons will be by code point order */ - -# ifdef USE_LOCALE_CTYPE - - const char * orig_ctype = toggle_locale_c(LC_CTYPE, - querylocale_c(LC_COLLATE)); -# endif - - SV * dst = src; - STRLEN dstlen; - STRLEN srclen; - const char *p = SvPV_const(src,srclen); - const U32 utf8_flag = SvUTF8(src); - char *d = mem_collxfrm_(p, srclen, &dstlen, cBOOL(utf8_flag)); - - assert(utf8_flag == 0 || utf8_flag == SVf_UTF8); - - if (d != NULL) { - assert(dstlen > 0); - dst =newSVpvn_flags(d + COLLXFRM_HDR_LEN, - dstlen, SVs_TEMP|utf8_flag); - Safefree(d); - } - -# ifdef USE_LOCALE_CTYPE - - restore_toggled_locale_c(LC_CTYPE, orig_ctype); - -# endif - - return dst; -} - -#endif /* USE_LOCALE_COLLATE */ -#if defined(DEBUGGING) || defined(USE_POSIX_2008_LOCALE) - -STATIC const char * -S_get_displayable_string(pTHX_ - const char * const s, - const char * const e, - const bool is_utf8) -{ - PERL_ARGS_ASSERT_GET_DISPLAYABLE_STRING; - - const char * t = s; - bool prev_was_printable = TRUE; - bool first_time = TRUE; - char * ret; - - if (e <= s) { - return ""; - } - - /* Worst case scenario: All are non-printable so have a blank between each. - * If UTF-8, all are the largest possible code point; otherwise all are a - * single byte. '(2 + 1)' is from each byte takes 2 characters to - * display, and a blank (or NUL for the final one) after it */ - Newxz(ret, (e - s) * (2 + 1) * ((is_utf8) ? UVSIZE : 1), char); - SAVEFREEPV(ret); - - while (t < e) { - UV cp = (is_utf8) - ? utf8_to_uvchr_buf((U8 *) t, e, NULL) - : * (U8 *) t; - if (isPRINT(cp)) { - if (! prev_was_printable) { - my_strlcat(ret, " ", sizeof(ret)); - } - - /* Escape these to avoid any ambiguity */ - if (cp == ' ' || cp == '\\') { - my_strlcat(ret, "\\", sizeof(ret)); - } - my_strlcat(ret, Perl_form(aTHX_ "%c", (U8) cp), sizeof(ret)); - prev_was_printable = TRUE; - } - else { - if (! first_time) { - my_strlcat(ret, " ", sizeof(ret)); - } - my_strlcat(ret, Perl_form(aTHX_ "%02" UVXf, cp), sizeof(ret)); - prev_was_printable = FALSE; - } - t += (is_utf8) ? UTF8SKIP(t) : 1; - first_time = FALSE; - } - - return ret; -} - -#endif -#ifdef USE_LOCALE - -STATIC const char * -S_toggle_locale_i(pTHX_ const unsigned cat_index, - const char * new_locale, - const line_t caller_line) -{ - /* Changes the locale for the category specified by 'index' to 'new_locale, - * if they aren't already the same. - * - * Returns a copy of the name of the original locale for 'cat_index' - * so can be switched back to with the companion function - * restore_toggled_locale_i(), (NULL if no restoral is necessary.) */ - - const char * locale_to_restore_to = NULL; - - PERL_ARGS_ASSERT_TOGGLE_LOCALE_I; - assert(cat_index <= NOMINAL_LC_ALL_INDEX); - - /* Find the original locale of the category we may need to change, so that - * it can be restored to later */ - - locale_to_restore_to = querylocale_i(cat_index); - - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "(%" LINE_Tf "): toggle_locale_i: index=%d(%s), wanted=%s," - " actual=%s\n", - caller_line, cat_index, category_names[cat_index], - new_locale, locale_to_restore_to)); - - if (! locale_to_restore_to) { - locale_panic_(Perl_form(aTHX_ - "Could not find current %s locale, errno=%d", - category_names[cat_index], errno)); - } - - /* If the locales are the same, there's nothing to do */ - if (strEQ(locale_to_restore_to, new_locale)) { - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "(%" LINE_Tf "): %s locale unchanged as %s\n", - caller_line, category_names[cat_index], - new_locale)); - - return NULL; - } - - /* Finally, change the locale to the new one */ - void_setlocale_i(cat_index, new_locale); - - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "(%" LINE_Tf "): %s locale switched to %s\n", - caller_line, category_names[cat_index], new_locale)); - - return locale_to_restore_to; - -# ifndef DEBUGGING - PERL_UNUSED_ARG(caller_line); -# endif + Safefree(xbuf); + if (s != input_string) { + Safefree(s); + } + *xlen = 0; + return NULL; } +# ifdef DEBUGGING + STATIC void -S_restore_toggled_locale_i(pTHX_ const unsigned int cat_index, - const char * restore_locale, - const line_t caller_line) +S_print_collxfrm_input_and_return(pTHX_ + const char * s, + const char * e, + const char * xbuf, + const STRLEN xlen, + const bool is_utf8) { - /* Restores the locale for LC_category corresponding to cat_indes to - * 'restore_locale' (which is a copy that will be freed by this function), - * or do nothing if the latter parameter is NULL */ - - PERL_ARGS_ASSERT_RESTORE_TOGGLED_LOCALE_I; - assert(cat_index <= NOMINAL_LC_ALL_INDEX); - if (restore_locale == NULL) { - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "(%" LINE_Tf "): No need to restore %s\n", - caller_line, category_names[cat_index])); - return; - } + PERL_ARGS_ASSERT_PRINT_COLLXFRM_INPUT_AND_RETURN; - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "(%" LINE_Tf "): %s restoring locale to %s\n", - caller_line, category_names[cat_index], - restore_locale)); + PerlIO_printf(Perl_debug_log, + "mem_collxfrm_[ix %" UVuf "] for locale '%s':\n" + " input=%s\n return=%s\n return len=%zu\n", + (UV) PL_collation_ix, PL_collation_name, + get_displayable_string(s, e, is_utf8), + ((xbuf == NULL) + ? "(null)" + : ((xlen == 0) + ? "(empty)" + : _byte_dump_string((U8 *) xbuf + COLLXFRM_HDR_LEN, + xlen, 0))), + xlen); +} - void_setlocale_i(cat_index, restore_locale); +# endif /* DEBUGGING */ -# ifndef DEBUGGING - PERL_UNUSED_ARG(caller_line); -# endif +SV * +Perl_strxfrm(pTHX_ SV * src) +{ + PERL_ARGS_ASSERT_STRXFRM; -} + /* For use by POSIX::strxfrm(). If they differ, toggle LC_CTYPE to + * LC_COLLATE to avoid potential mojibake. + * + * If we can't calculate a collation, 'src' is instead returned, so that + * future comparisons will be by code point order */ # ifdef USE_LOCALE_CTYPE -STATIC bool -S_is_codeset_name_UTF8(const char * name) -{ - /* Return a boolean as to if the passed-in name indicates it is a UTF-8 - * code set. Several variants are possible */ - const Size_t len = strlen(name); + const char * orig_ctype = toggle_locale_c(LC_CTYPE, + querylocale_c(LC_COLLATE)); +# endif - PERL_ARGS_ASSERT_IS_CODESET_NAME_UTF8; + SV * dst = src; + STRLEN dstlen; + STRLEN srclen; + const char *p = SvPV_const(src, srclen); + const U32 utf8_flag = SvUTF8(src); + char *d = mem_collxfrm_(p, srclen, &dstlen, cBOOL(utf8_flag)); -# ifdef WIN32 + assert(utf8_flag == 0 || utf8_flag == SVf_UTF8); - /* http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756.aspx */ - if (memENDs(name, len, "65001")) { - return TRUE; + if (d != NULL) { + assert(dstlen > 0); + dst =newSVpvn_flags(d + COLLXFRM_HDR_LEN, + dstlen, SVs_TEMP|utf8_flag); + Safefree(d); } -# endif - /* 'UTF8' or 'UTF-8' */ - return ( inRANGE(len, 4, 5) - && name[len-1] == '8' - && ( memBEGINs(name, len, "UTF") - || memBEGINs(name, len, "utf")) - && (len == 4 || name[3] == '-')); -} - -# endif -#endif /* USE_LOCALE */ - -bool -Perl__is_in_locale_category(pTHX_ const bool compiling, const int category) -{ - /* Internal function which returns if we are in the scope of a pragma that - * enables the locale category 'category'. 'compiling' should indicate if - * this is during the compilation phase (TRUE) or not (FALSE). */ +# ifdef USE_LOCALE_CTYPE - const COP * const cop = (compiling) ? &PL_compiling : PL_curcop; + restore_toggled_locale_c(LC_CTYPE, orig_ctype); - SV *these_categories = cop_hints_fetch_pvs(cop, "locale", 0); - if (! these_categories || these_categories == &PL_sv_placeholder) { - return FALSE; - } +# endif - /* The pseudo-category 'not_characters' is -1, so just add 1 to each to get - * a valid unsigned */ - assert(category >= -1); - return cBOOL(SvUV(these_categories) & (1U << (category + 1))); + return dst; } +#endif /* USE_LOCALE_COLLATE */ + /* my_strerror() returns a mortalized copy of the text of the error message * associated with 'errnum'. * @@ -6710,6 +10131,7 @@ Perl__is_in_locale_category(pTHX_ const "my_strerror called with errnum %d;" \ " Within locale scope=%d\n", \ errnum, in_locale)) + #define DEBUG_STRERROR_RETURN(errstr, utf8ness) \ DEBUG_Lv(PerlIO_printf(Perl_debug_log, \ "Strerror returned; saving a copy: '%s';" \ @@ -6727,7 +10149,7 @@ Perl__is_in_locale_category(pTHX_ const # define WHICH_LC_INDEX LC_MESSAGES_INDEX_ #endif -/*==========================================================================*/ +/*===========================================================================*/ /* First set of implementations, when have strerror_l() */ #if defined(USE_POSIX_2008_LOCALE) && defined(HAS_STRERROR_L) @@ -6800,11 +10222,13 @@ Perl_my_strerror(pTHX_ const int errnum, matches */ locale_t cur = duplocale(use_curlocale_scratch()); - cur = newlocale(LC_CTYPE_MASK, querylocale_c(LC_MESSAGES), cur); + const char * locale = querylocale_c(LC_MESSAGES); + cur = newlocale(LC_CTYPE_MASK, locale, cur); errstr = savepv(strerror_l(errnum, cur)); *utf8ness = get_locale_string_utf8ness_i(errstr, LOCALE_UTF8NESS_UNKNOWN, - NULL, LC_MESSAGES_INDEX_); + locale, + LC_MESSAGES_INDEX_); freelocale(cur); } @@ -6814,7 +10238,7 @@ Perl_my_strerror(pTHX_ const int errnum, return errstr; } # endif /* Above is using strerror_l */ -/*==========================================================================*/ +/*===========================================================================*/ #else /* Below is not using strerror_l */ # if ! defined(USE_LOCALE_CTYPE) && ! defined(USE_LOCALE_MESSAGES) @@ -6860,7 +10284,7 @@ Perl_my_strerror(pTHX_ const int errnum, } else { - SETLOCALE_LOCK; + LOCALE_LOCK; const char * orig_locale = toggle_locale_i(WHICH_LC_INDEX, "C"); @@ -6868,10 +10292,9 @@ Perl_my_strerror(pTHX_ const int errnum, restore_toggled_locale_i(WHICH_LC_INDEX, orig_locale); - SETLOCALE_UNLOCK; + LOCALE_UNLOCK; *utf8ness = UTF8NESS_IMMATERIAL; - } DEBUG_STRERROR_RETURN(errstr, utf8ness); @@ -6898,9 +10321,10 @@ Perl_my_strerror(pTHX_ const int errnum, : "C"; /* XXX Can fail on z/OS */ - SETLOCALE_LOCK; + LOCALE_LOCK; - const char* orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, desired_locale); + const char* orig_CTYPE_locale = toggle_locale_c(LC_CTYPE, + desired_locale); const char* orig_MESSAGES_locale = toggle_locale_c(LC_MESSAGES, desired_locale); const char *errstr = savepv(Strerror(errnum)); @@ -6908,10 +10332,11 @@ Perl_my_strerror(pTHX_ const int errnum, restore_toggled_locale_c(LC_MESSAGES, orig_MESSAGES_locale); restore_toggled_locale_c(LC_CTYPE, orig_CTYPE_locale); - SETLOCALE_UNLOCK; + LOCALE_UNLOCK; *utf8ness = get_locale_string_utf8ness_i(errstr, LOCALE_UTF8NESS_UNKNOWN, - NULL, LC_MESSAGES_INDEX_); + desired_locale, + LC_MESSAGES_INDEX_); DEBUG_STRERROR_RETURN(errstr, utf8ness); SAVEFREEPV(errstr); @@ -6922,8 +10347,29 @@ Perl_my_strerror(pTHX_ const int errnum, # endif /* end of not using strerror_l() */ #endif /* end of all the my_strerror() implementations */ +bool +Perl__is_in_locale_category(pTHX_ const bool compiling, const int category) +{ + /* Internal function which returns if we are in the scope of a pragma that + * enables the locale category 'category'. 'compiling' should indicate if + * this is during the compilation phase (TRUE) or not (FALSE). */ + + const COP * const cop = (compiling) ? &PL_compiling : PL_curcop; + + SV *these_categories = cop_hints_fetch_pvs(cop, "locale", 0); + if (! these_categories || these_categories == &PL_sv_placeholder) { + return FALSE; + } + + /* The pseudo-category 'not_characters' is -1, so just add 1 to each to get + * a valid unsigned */ + assert(category >= -1); + return cBOOL(SvUV(these_categories) & (1U << (category + 1))); +} + /* +=for apidoc_section $locale =for apidoc switch_to_global_locale This function copies the locale state of the calling thread into the program's @@ -6957,7 +10403,7 @@ the global locale), but only if you use =item L, items C and C -=item L, items C and C +=item L, items C and C =back @@ -6976,6 +10422,32 @@ handle all cases of single- vs multi-thr =cut */ +#if defined(WIN32) && defined(USE_THREAD_SAFE_LOCALE) +# define CHANGE_SYSTEM_LOCALE_TO_GLOBAL \ + STMT_START { \ + if (_configthreadlocale(_DISABLE_PER_THREAD_LOCALE) == -1) { \ + locale_panic_("_configthreadlocale returned an error"); \ + } \ + } STMT_END +#elif defined(USE_POSIX_2008_LOCALE) +# define CHANGE_SYSTEM_LOCALE_TO_GLOBAL \ + STMT_START { \ + locale_t old_locale = uselocale(LC_GLOBAL_LOCALE); \ + if (! old_locale) { \ + locale_panic_("Could not change to global locale"); \ + } \ + \ + /* Free the per-thread memory */ \ + if ( old_locale != LC_GLOBAL_LOCALE \ + && old_locale != PL_C_locale_obj) \ + { \ + freelocale(old_locale); \ + } \ + } STMT_END +#else +# define CHANGE_SYSTEM_LOCALE_TO_GLOBAL +#endif + void Perl_switch_to_global_locale(pTHX) { @@ -6984,24 +10456,25 @@ Perl_switch_to_global_locale(pTHX) DEBUG_L(PerlIO_printf(Perl_debug_log, "Entering switch_to_global; %s\n", get_LC_ALL_display())); - bool perl_controls = false; - -# ifdef USE_THREAD_SAFE_LOCALE /* In these cases, we use the system state to determine if we are in the * global locale or not. */ +# ifdef USE_POSIX_2008_LOCALE -# ifdef USE_POSIX_2008_LOCALE + const bool perl_controls = (LC_GLOBAL_LOCALE != uselocale((locale_t) 0)); - perl_controls = (LC_GLOBAL_LOCALE != uselocale((locale_t) 0)); +# elif defined(USE_THREAD_SAFE_LOCALE) && defined(WIN32) -# elif defined(WIN32) + int config_return = _configthreadlocale(0); + if (config_return == -1) { + locale_panic_("_configthreadlocale returned an error"); + } + const bool perl_controls = (config_return == _ENABLE_PER_THREAD_LOCALE); - perl_controls = (_configthreadlocale(0) == _ENABLE_PER_THREAD_LOCALE); +# else + + const bool perl_controls = false; -# else -# error Unexpected Configuration -# endif # endif /* No-op if already in global */ @@ -7009,43 +10482,33 @@ Perl_switch_to_global_locale(pTHX) return; } -# ifdef USE_THREAD_SAFE_LOCALE -# if defined(WIN32) +# ifdef LC_ALL - const char * thread_locale = posix_setlocale(LC_ALL, NULL); - _configthreadlocale(_DISABLE_PER_THREAD_LOCALE); + const char * thread_locale = calculate_LC_ALL_string(NULL, + EXTERNAL_FORMAT_FOR_SET, + WANT_TEMP_PV, + __LINE__); + CHANGE_SYSTEM_LOCALE_TO_GLOBAL; posix_setlocale(LC_ALL, thread_locale); -# else /* Must be USE_POSIX_2008_LOCALE) */ +# else /* Must be USE_POSIX_2008_LOCALE) */ - const char * cur_thread_locales[NOMINAL_LC_ALL_INDEX + 1]; + const char * cur_thread_locales[LC_ALL_INDEX_]; /* Save each category's current per-thread state */ - for (unsigned i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { + for_all_individual_category_indexes(i) { cur_thread_locales[i] = querylocale_i(i); } - /* Now switch to global */ - DEBUG_Lv(PerlIO_printf(Perl_debug_log, "Switching to global locale\n")); - - locale_t old_locale = uselocale(LC_GLOBAL_LOCALE); - if (! old_locale) { - locale_panic_("Could not change to global locale"); - } - - /* Free the per-thread memory */ - if (old_locale != LC_GLOBAL_LOCALE && old_locale != PL_C_locale_obj) { - freelocale(old_locale); - } + CHANGE_SYSTEM_LOCALE_TO_GLOBAL; /* Set the global to what was our per-thread state */ POSIX_SETLOCALE_LOCK; - for (unsigned int i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { + for_all_individual_category_indexes(i) { posix_setlocale(categories[i], cur_thread_locales[i]); } POSIX_SETLOCALE_UNLOCK; -# endif # endif # ifdef USE_LOCALE_NUMERIC @@ -7116,12 +10579,15 @@ Perl_sync_locale(pTHX) # ifdef USE_THREAD_SAFE_LOCALE # if defined(WIN32) - was_in_global = _configthreadlocale(_DISABLE_PER_THREAD_LOCALE) - == _DISABLE_PER_THREAD_LOCALE; + int config_return = _configthreadlocale(_DISABLE_PER_THREAD_LOCALE); + if (config_return == -1) { + locale_panic_("_configthreadlocale returned an error"); + } + was_in_global = (config_return == _DISABLE_PER_THREAD_LOCALE); # elif defined(USE_POSIX_2008_LOCALE) - was_in_global = (LC_GLOBAL_LOCALE == uselocale((locale_t) 0)); + was_in_global = (LC_GLOBAL_LOCALE == uselocale(LC_GLOBAL_LOCALE)); # else # error Unexpected Configuration @@ -7129,113 +10595,74 @@ Perl_sync_locale(pTHX) # endif /* USE_THREAD_SAFE_LOCALE */ /* Here, we are in the global locale. Get and save the values for each - * category. */ - const char * current_globals[NOMINAL_LC_ALL_INDEX]; - for (unsigned i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { - POSIX_SETLOCALE_LOCK; - current_globals[i] = savepv(stdized_setlocale(categories[i], NULL)); - POSIX_SETLOCALE_UNLOCK; - } + * category, and convert the current thread to use them */ - /* Now we have to convert the current thread to use them */ +# ifdef LC_ALL -# if defined(WIN32) + STDIZED_SETLOCALE_LOCK; + const char * lc_all_string = savepv(stdized_setlocale(LC_ALL, NULL)); + STDIZED_SETLOCALE_UNLOCK; - /* On Windows, convert to per-thread behavior. This isn't necessary in - * POSIX 2008, as the conversion gets done automatically in the loop below. - * */ - _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); + give_perl_locale_control(lc_all_string, __LINE__); + Safefree(lc_all_string); -# endif +# else - for (unsigned i = 0; i < NOMINAL_LC_ALL_INDEX; i++) { - setlocale_i(i, current_globals[i]); - Safefree(current_globals[i]); + const char * current_globals[LC_ALL_INDEX_]; + for_all_individual_category_indexes(i) { + STDIZED_SETLOCALE_LOCK; + current_globals[i] = savepv(stdized_setlocale(categories[i], NULL)); + STDIZED_SETLOCALE_UNLOCK; } - /* And update our remaining records. 'true' => force recalculation */ - new_LC_ALL(NULL, true); - - return was_in_global; - -#endif - -} - -#if defined(DEBUGGING) && defined(USE_LOCALE) - -STATIC char * -S_my_setlocale_debug_string_i(pTHX_ - const unsigned cat_index, - const char* locale, /* Optional locale name */ - - /* return value from setlocale() when attempting - * to set 'category' to 'locale' */ - const char* retval, - - const line_t line) -{ - /* Returns a pointer to a NUL-terminated string in static storage with - * added text about the info passed in. This is not thread safe and will - * be overwritten by the next call, so this should be used just to - * formulate a string to immediately print or savepv() on. */ - - const char * locale_quote; - const char * retval_quote; - - assert(cat_index <= NOMINAL_LC_ALL_INDEX); - - if (locale == NULL) { - locale_quote = ""; - locale = "NULL"; - } - else { - locale_quote = "\""; - } + give_perl_locale_control((const char **) ¤t_globals, __LINE__); - if (retval == NULL) { - retval_quote = ""; - retval = "NULL"; - } - else { - retval_quote = "\""; + for_all_individual_category_indexes(i) { + Safefree(current_globals[i]); } -# ifdef USE_LOCALE_THREADS -# define THREAD_FORMAT "%p:" -# define THREAD_ARGUMENT aTHX_ -# else -# define THREAD_FORMAT -# define THREAD_ARGUMENT # endif - return Perl_form(aTHX_ - "%s:%" LINE_Tf ": " THREAD_FORMAT - " setlocale(%s[%d], %s%s%s) returned %s%s%s\n", + return was_in_global; + +#endif - __FILE__, line, THREAD_ARGUMENT - category_names[cat_index], categories[cat_index], - locale_quote, locale, locale_quote, - retval_quote, retval, retval_quote); } -#endif #ifdef USE_PERL_SWITCH_LOCALE_CONTEXT void -Perl_switch_locale_context() +Perl_switch_locale_context(pTHX) { /* libc keeps per-thread locale status information in some configurations. * So, we can't just switch out aTHX to switch to a new thread. libc has * to follow along. This routine does that based on per-interpreter - * variables we keep just for this purpose */ - - /* Can't use pTHX, because we may be called from a place where that - * isn't available */ - dTHX; + * variables we keep just for this purpose. + * + * There are two implementations where this is an issue. For the other + * implementations, it doesn't matter because libc is using global values + * that all threads know about. + * + * The two implementations are where libc keeps thread-specific information + * on its own. These are + * + * POSIX 2008: The current locale is kept by libc as an object. We save + * a copy of that in the per-thread PL_cur_locale_obj, and so + * this routine uses that copy to tell the thread it should be + * operating with that object + * Windows thread-safe locales: A given thread in Windows can be being run + * with per-thread locales, or not. When the thread context + * changes, libc doesn't automatically know if the thread is + * using per-thread locales, nor does it know what the new + * thread's locale is. We keep that information in the + * per-thread variables: + * PL_controls_locale indicates if this thread is using + * per-thread locales or not + * PL_cur_LC_ALL indicates what the locale should be + * if it is a per-thread locale. + */ - if (UNLIKELY( aTHX == NULL - || PL_veto_switch_non_tTHX_context + if (UNLIKELY( PL_veto_switch_non_tTHX_context || PL_phase == PERL_PHASE_CONSTRUCT)) { return; @@ -7245,7 +10672,8 @@ Perl_switch_locale_context() if (! uselocale(PL_cur_locale_obj)) { locale_panic_(Perl_form(aTHX_ - "Can't uselocale(%p), LC_ALL supposed to be '%s", + "Can't uselocale(%p), LC_ALL supposed to" + " be '%s'", PL_cur_locale_obj, get_LC_ALL_display())); } @@ -7260,13 +10688,14 @@ Perl_switch_locale_context() } #endif +#ifdef USE_THREADS void Perl_thread_locale_init(pTHX) { -#ifdef USE_THREAD_SAFE_LOCALE -# ifdef USE_POSIX_2008_LOCALE +# ifdef USE_THREAD_SAFE_LOCALE +# ifdef USE_POSIX_2008_LOCALE /* Called from a thread on startup. * @@ -7279,16 +10708,27 @@ Perl_thread_locale_init(pTHX) " calling setlocale(LC_ALL, \"C\")\n", get_LC_ALL_display())); - uselocale(PL_C_locale_obj); + if (! uselocale(PL_C_locale_obj)) { -# elif defined(WIN32) + /* Not being able to change to the C locale is severe; don't keep + * going. */ + locale_panic_(Perl_form(aTHX_ + "Can't uselocale(%p), 'C'", PL_C_locale_obj)); + NOT_REACHED; /* NOTREACHED */ + } + + PL_cur_locale_obj = PL_C_locale_obj; + +# elif defined(WIN32) /* On Windows, make sure new thread has per-thread locales enabled */ - _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); + if (_configthreadlocale(_ENABLE_PER_THREAD_LOCALE) == -1) { + locale_panic_("_configthreadlocale returned an error"); + } void_setlocale_c(LC_ALL, "C"); +# endif # endif -#endif } @@ -7301,13 +10741,10 @@ Perl_thread_locale_term(pTHX) * they affect libc's knowledge of the thread; libc has no knowledge of * aTHX */ -#ifdef USE_POSIX_2008_LOCALE - - /* C starts the new thread in the global C locale. If we are thread-safe, - * we want to not be in the global locale */ +# if defined(USE_POSIX_2008_LOCALE) - /* Free up */ - locale_t actual_obj = uselocale(LC_GLOBAL_LOCALE); + /* Switch to the global locale, so can free up the per-thread object */ + locale_t actual_obj = uselocale(LC_GLOBAL_LOCALE); if (actual_obj != LC_GLOBAL_LOCALE && actual_obj != PL_C_locale_obj) { freelocale(actual_obj); } @@ -7323,9 +10760,30 @@ Perl_thread_locale_term(pTHX) PL_cur_locale_obj = LC_GLOBAL_LOCALE; -#endif +# endif +# ifdef WIN32_USE_FAKE_OLD_MINGW_LOCALES + + /* When faking the mingw implementation, we coerce this function into doing + * something completely different from its intent -- namely to free up our + * static buffer to avoid a leak. This function gets called for each + * thread that is terminating, so will give us a chance to free the buffer + * from the appropriate pool. On unthreaded systems, it gets called by the + * mutex termination code. */ + + if (aTHX != wsetlocale_buf_aTHX) { + return; + } + + if (wsetlocale_buf_size > 0) { + Safefree(wsetlocale_buf); + wsetlocale_buf_size = 0; + } + +# endif } + +#endif /* * ex: set ts=8 sts=4 sw=4 et: Index: gnu/usr.bin/perl/locale_table.h =================================================================== RCS file: gnu/usr.bin/perl/locale_table.h diff -N gnu/usr.bin/perl/locale_table.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/locale_table.h 22 Jan 2025 00:37:44 -0000 @@ -0,0 +1,242 @@ +/* -*- mode: C; buffer-read-only: t -*- + * + * locale_table.h + * + * Copyright (C) 2023, 2024 by Larry Wall and others + * + * You may distribute under the terms of either the GNU General Public + * License or the Artistic License, as specified in the README file. + * + * !!!!!!! DO NOT EDIT THIS FILE !!!!!!! + * This file is built by regen/locale.pl from data in regen/locale.pl. + * Any changes made here will be lost! + */ + +/* This defines a macro for each individual locale category used on the this + * system. (The congomerate category LC_ALL is not included.) This + * file will be #included as the interior of various parallel arrays and in + * other constructs; each usage will re-#define the macro to generate its + * appropriate data. + * + * This guarantees the arrays will be parallel, and populated in the order + * given here. That order is mostly arbitrary. LC_CTYPE is first because when + * we are setting multiple categories, CTYPE often needs to match the other(s), + * and the way the code is constructed, if we set the other category first, we + * might otherwise have to set CTYPE twice. + * + * Each entry takes the token giving the category name, and either the name of + * a function to call that does specialized set up for this category when it is + * changed into, or NULL if no such set up is needed + */ + +#ifdef LC_CTYPE +# if defined(NO_LOCALE) || defined(NO_LOCALE_CTYPE) + + PERL_LOCALE_TABLE_ENTRY(CTYPE, NULL) + +# define HAS_IGNORED_LOCALE_CATEGORIES_ +# define LC_CTYPE_AVAIL_ 0 +# else + + PERL_LOCALE_TABLE_ENTRY(CTYPE, S_new_ctype) + +# define LC_CTYPE_AVAIL_ 1 +# define USE_LOCALE_CTYPE +# endif +#else +# define LC_CTYPE_AVAIL_ 0 +#endif +#ifdef LC_NUMERIC +# if defined(NO_LOCALE) || defined(NO_LOCALE_NUMERIC) + + PERL_LOCALE_TABLE_ENTRY(NUMERIC, NULL) + +# define HAS_IGNORED_LOCALE_CATEGORIES_ +# define LC_NUMERIC_AVAIL_ 0 +# else + + PERL_LOCALE_TABLE_ENTRY(NUMERIC, S_new_numeric) + +# define LC_NUMERIC_AVAIL_ 1 +# define USE_LOCALE_NUMERIC +# endif +#else +# define LC_NUMERIC_AVAIL_ 0 +#endif +#ifdef LC_COLLATE + + /* Perl outsources all its collation efforts to the libc strxfrm(), so + * if it isn't available on the system, default "C" locale collation + * gets used */ +# if defined(NO_LOCALE) || defined(NO_LOCALE_COLLATE) || ! defined(HAS_STRXFRM) + + PERL_LOCALE_TABLE_ENTRY(COLLATE, NULL) + +# define HAS_IGNORED_LOCALE_CATEGORIES_ +# define LC_COLLATE_AVAIL_ 0 +# else + + PERL_LOCALE_TABLE_ENTRY(COLLATE, S_new_collate) + +# define LC_COLLATE_AVAIL_ 1 +# define USE_LOCALE_COLLATE +# endif +#else +# define LC_COLLATE_AVAIL_ 0 +#endif +#ifdef LC_TIME + + PERL_LOCALE_TABLE_ENTRY(TIME, NULL) + +# if defined(NO_LOCALE) || defined(NO_LOCALE_TIME) +# define HAS_IGNORED_LOCALE_CATEGORIES_ +# define LC_TIME_AVAIL_ 0 +# else +# define LC_TIME_AVAIL_ 1 +# define USE_LOCALE_TIME +# endif +#else +# define LC_TIME_AVAIL_ 0 +#endif +#ifdef LC_MESSAGES + + PERL_LOCALE_TABLE_ENTRY(MESSAGES, NULL) + +# if defined(NO_LOCALE) || defined(NO_LOCALE_MESSAGES) +# define HAS_IGNORED_LOCALE_CATEGORIES_ +# define LC_MESSAGES_AVAIL_ 0 +# else +# define LC_MESSAGES_AVAIL_ 1 +# define USE_LOCALE_MESSAGES +# endif +#else +# define LC_MESSAGES_AVAIL_ 0 +#endif +#ifdef LC_MONETARY + + PERL_LOCALE_TABLE_ENTRY(MONETARY, NULL) + +# if defined(NO_LOCALE) || defined(NO_LOCALE_MONETARY) +# define HAS_IGNORED_LOCALE_CATEGORIES_ +# define LC_MONETARY_AVAIL_ 0 +# else +# define LC_MONETARY_AVAIL_ 1 +# define USE_LOCALE_MONETARY +# endif +#else +# define LC_MONETARY_AVAIL_ 0 +#endif +#ifdef LC_ADDRESS + + PERL_LOCALE_TABLE_ENTRY(ADDRESS, NULL) + +# if defined(NO_LOCALE) || defined(NO_LOCALE_ADDRESS) +# define HAS_IGNORED_LOCALE_CATEGORIES_ +# define LC_ADDRESS_AVAIL_ 0 +# else +# define LC_ADDRESS_AVAIL_ 1 +# define USE_LOCALE_ADDRESS +# endif +#else +# define LC_ADDRESS_AVAIL_ 0 +#endif +#ifdef LC_IDENTIFICATION + + PERL_LOCALE_TABLE_ENTRY(IDENTIFICATION, NULL) + +# if defined(NO_LOCALE) || defined(NO_LOCALE_IDENTIFICATION) +# define HAS_IGNORED_LOCALE_CATEGORIES_ +# define LC_IDENTIFICATION_AVAIL_ 0 +# else +# define LC_IDENTIFICATION_AVAIL_ 1 +# define USE_LOCALE_IDENTIFICATION +# endif +#else +# define LC_IDENTIFICATION_AVAIL_ 0 +#endif +#ifdef LC_MEASUREMENT + + PERL_LOCALE_TABLE_ENTRY(MEASUREMENT, NULL) + +# if defined(NO_LOCALE) || defined(NO_LOCALE_MEASUREMENT) +# define HAS_IGNORED_LOCALE_CATEGORIES_ +# define LC_MEASUREMENT_AVAIL_ 0 +# else +# define LC_MEASUREMENT_AVAIL_ 1 +# define USE_LOCALE_MEASUREMENT +# endif +#else +# define LC_MEASUREMENT_AVAIL_ 0 +#endif +#ifdef LC_PAPER + + PERL_LOCALE_TABLE_ENTRY(PAPER, NULL) + +# if defined(NO_LOCALE) || defined(NO_LOCALE_PAPER) +# define HAS_IGNORED_LOCALE_CATEGORIES_ +# define LC_PAPER_AVAIL_ 0 +# else +# define LC_PAPER_AVAIL_ 1 +# define USE_LOCALE_PAPER +# endif +#else +# define LC_PAPER_AVAIL_ 0 +#endif +#ifdef LC_TELEPHONE + + PERL_LOCALE_TABLE_ENTRY(TELEPHONE, NULL) + +# if defined(NO_LOCALE) || defined(NO_LOCALE_TELEPHONE) +# define HAS_IGNORED_LOCALE_CATEGORIES_ +# define LC_TELEPHONE_AVAIL_ 0 +# else +# define LC_TELEPHONE_AVAIL_ 1 +# define USE_LOCALE_TELEPHONE +# endif +#else +# define LC_TELEPHONE_AVAIL_ 0 +#endif +#ifdef LC_NAME + + PERL_LOCALE_TABLE_ENTRY(NAME, NULL) + +# if defined(NO_LOCALE) || defined(NO_LOCALE_NAME) +# define HAS_IGNORED_LOCALE_CATEGORIES_ +# define LC_NAME_AVAIL_ 0 +# else +# define LC_NAME_AVAIL_ 1 +# define USE_LOCALE_NAME +# endif +#else +# define LC_NAME_AVAIL_ 0 +#endif +#ifdef LC_SYNTAX + + PERL_LOCALE_TABLE_ENTRY(SYNTAX, NULL) + +# if defined(NO_LOCALE) || defined(NO_LOCALE_SYNTAX) +# define HAS_IGNORED_LOCALE_CATEGORIES_ +# define LC_SYNTAX_AVAIL_ 0 +# else +# define LC_SYNTAX_AVAIL_ 1 +# define USE_LOCALE_SYNTAX +# endif +#else +# define LC_SYNTAX_AVAIL_ 0 +#endif +#ifdef LC_TOD + + PERL_LOCALE_TABLE_ENTRY(TOD, NULL) + +# if defined(NO_LOCALE) || defined(NO_LOCALE_TOD) +# define HAS_IGNORED_LOCALE_CATEGORIES_ +# define LC_TOD_AVAIL_ 0 +# else +# define LC_TOD_AVAIL_ 1 +# define USE_LOCALE_TOD +# endif +#else +# define LC_TOD_AVAIL_ 0 +#endif + +/* ex: set ro ft=c: */ Index: gnu/usr.bin/perl/makedef.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/makedef.pl,v diff -u -p -a -u -p -r1.18 makedef.pl --- gnu/usr.bin/perl/makedef.pl 14 May 2024 19:38:54 -0000 1.18 +++ gnu/usr.bin/perl/makedef.pl 22 Jan 2025 00:37:44 -0000 @@ -38,7 +38,6 @@ use warnings; my $fold; my %ARGS; my %define; - BEGIN { %ARGS = (CCTYPE => 'MSVC', TARG_DIR => ''); @@ -52,7 +51,7 @@ BEGIN { my $flag = shift; if ($flag =~ /^(?:CC_FLAGS=)?(-D\w.*)/) { process_cc_flags($1); - } elsif ($flag =~ /^(CCTYPE|FILETYPE|PLATFORM|TARG_DIR)=(.+)$/) { + } elsif ($flag =~ /^(CCTYPE|FILETYPE|PLATFORM|TARG_DIR|CONFIG_H)=(.+)$/) { $ARGS{$1} = $2; } elsif ($flag eq '--sort-fold') { ++$fold; @@ -104,7 +103,7 @@ my %exportperlmalloc = my $exportperlmalloc = PLATFORM eq 'os2'; -my $config_h = 'config.h'; +my $config_h = $ARGS{CONFIG_H} || "config.h"; open(CFG, '<', $config_h) || die "Cannot open $config_h: $!\n"; while () { $define{$1} = 1 if /^\s*\#\s*define\s+(MYMALLOC|MULTIPLICITY @@ -113,21 +112,23 @@ while () { } close(CFG); +if ($define{WIN32_USE_FAKE_OLD_MINGW_LOCALES}) { + $define{NO_POSIX_2008_LOCALE} = 1; +} + #========================================================================== # perl.h logic duplication begins -if ($define{USE_ITHREADS}) { +if ($define{USE_THREADS}) { if (!$define{MULTIPLICITY}) { $define{MULTIPLICITY} = 1; } } -$define{MULTIPLICITY} ||= - $define{USE_ITHREADS} || - $define{PERL_IMPLICIT_CONTEXT} ; +$define{MULTIPLICITY} ||= $define{PERL_IMPLICIT_CONTEXT} ; -if ($define{USE_ITHREADS} && ! $define{WIN32}) { +if ($define{MULTIPLICITY} && ! $define{WIN32}) { $define{USE_REENTRANT_API} = 1; } @@ -148,19 +149,23 @@ if (! $define{NO_LOCALE}) { # https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering my $cctype = $ARGS{CCTYPE} =~ s/MSVC//r; -if ($define{USE_ITHREADS} && ! $define{NO_LOCALE_THREADS}) { +if ( $define{USE_THREADS} + && $define{USE_LOCALE} + && ! $define{NO_LOCALE_THREADS}) +{ $define{USE_LOCALE_THREADS} = 1; } if ( $define{HAS_POSIX_2008_LOCALE} - && ( ! $define{HAS_SETLOCALE} || ( $define{USE_LOCALE_THREADS} - && ! $define{NO_POSIX_2008_LOCALE}))) + && $define{USE_LOCALE} + && (! $define{HAS_SETLOCALE} || ( $define{USE_LOCALE_THREADS} + && ! $define{NO_POSIX_2008_LOCALE}) + && ! $define{NO_THREAD_SAFE_LOCALE})) { $define{USE_POSIX_2008_LOCALE} = 1; } -if ($define{USE_LOCALE_THREADS} && ! $define{NO_THREAD_SAFE_LOCALE}) -{ +if ($define{USE_LOCALE_THREADS} && ! $define{NO_THREAD_SAFE_LOCALE}) { if ( $define{USE_POSIX_2008_LOCALE} || ($define{WIN32} && ( $cctype !~ /\D/ && $cctype >= 80))) @@ -169,22 +174,26 @@ if ($define{USE_LOCALE_THREADS} && ! $de } } -if ($define{USE_POSIX_2008_LOCALE} && $define{HAS_QUERYLOCALE}) +if ( $define{USE_POSIX_2008_LOCALE} + && ( $define{HAS_QUERYLOCALE} + || ( $Config{cppsymbols} =~ /__GLIBC__/ + && $define{HAS_NL_LANGINFO_L} + && ! $define{SETLOCALE_ACCEPTS_ANY_LOCALE_NAME}))) { $define{USE_QUERYLOCALE} = 1; - - # Don't need glibc only code from perl.h } if ($define{USE_POSIX_2008_LOCALE} && ! $define{USE_QUERYLOCALE}) { $define{USE_PL_CURLOCALES} = 1; - $define{USE_PL_CUR_LC_ALL} = 1; } -if ($define{WIN32} && $define{USE_THREAD_SAFE_LOCALE}) +if ($define{WIN32}) { - $define{USE_PL_CUR_LC_ALL} = 1; + if ($define{USE_THREAD_SAFE_LOCALE}) + { + $define{USE_PL_CUR_LC_ALL} = 1; + } if ($cctype < 140) { $define{TS_W32_BROKEN_LOCALECONV} = 1; @@ -403,7 +412,6 @@ unless ($define{'USE_ITHREADS'}) { ++$skip{$_} foreach qw( PL_keyword_plugin_mutex PL_check_mutex - PL_cur_locale_obj PL_op_mutex PL_regex_pad PL_regex_padav @@ -446,12 +454,17 @@ unless ($define{'USE_ITHREADS'}) { ); } +unless ($define{'USE_THREADS'}) { + ++$skip{Perl_thread_locale_init}; + ++$skip{Perl_thread_locale_term}; +} + unless ($define{USE_POSIX_2008_LOCALE}) { ++$skip{$_} foreach qw( PL_C_locale_obj PL_scratch_locale_obj - PL_underlying_numeric_obj + PL_cur_locale_obj ); } unless ($define{USE_PL_CURLOCALES}) @@ -477,6 +490,7 @@ unless ($define{USE_PERL_SWITCH_LOCALE_C unless ($define{'MULTIPLICITY'}) { ++$skip{$_} foreach qw( + PL_cur_locale_obj PL_my_cxt_index PL_my_cxt_list PL_my_cxt_size @@ -595,10 +609,11 @@ unless ($define{USE_LOCALE_COLLATE}) { ); } -unless ($define{USE_LOCALE_NUMERIC}) { +unless ($define{USE_LOCALE_THREADS} && ! $define{USE_THREAD_SAFE_LOCALE}) { ++$skip{$_} foreach qw( - PL_underlying_numeric_obj - ); + PL_less_dicey_locale_buf + PL_less_dicey_locale_bufsize + ); } unless ($define{USE_LOCALE_CTYPE}) { @@ -609,6 +624,17 @@ unless ($define{USE_LOCALE_CTYPE}) { ); } +unless ( ! $define{HAS_NL_LANGINFO} + && $define{USE_LOCALE_CTYPE} + && ! $define{WIN32} + && ! $define{HAS_MBTOWC} + && ! $define{HAS_MBRTOWC}) + { + ++$skip{$_} foreach qw( + PL_langinfo_recursed + ); + } + unless ($define{'USE_C_BACKTRACE'}) { ++$skip{Perl_get_c_backtrace_dump}; ++$skip{Perl_dump_c_backtrace}; @@ -632,6 +658,14 @@ if ($define{HAS_SIGNBIT}) { ++$skip{PL_hash_chars} unless $define{PERL_USE_SINGLE_CHAR_HASH_CACHE}; + +unless ($define{PERL_RC_STACK}) { + ++$skip{$_} foreach qw( + Perl_pp_wrap + Perl_xs_wrap + Perl_runops_wrap + ); +} # functions from *.sym files Index: gnu/usr.bin/perl/malloc.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/malloc.c,v diff -u -p -a -u -p -r1.21 malloc.c --- gnu/usr.bin/perl/malloc.c 14 May 2024 19:38:54 -0000 1.21 +++ gnu/usr.bin/perl/malloc.c 22 Jan 2025 00:37:44 -0000 @@ -239,13 +239,9 @@ #define PERL_IN_MALLOC_C #include "perl.h" #if defined(MULTIPLICITY) -# define croak Perl_croak_nocontext # define croak2 Perl_croak_nocontext -# define warn Perl_warn_nocontext -# define warn2 Perl_warn_nocontext #else # define croak2 croak -# define warn2 warn #endif #ifdef USE_ITHREADS # define PERL_MAYBE_ALIVE PL_thr_key @@ -1708,7 +1704,7 @@ morecore(int bucket) #endif if (bucket == sizeof(MEM_SIZE)*8*BUCKETS_PER_POW2) { MALLOC_UNLOCK; - croak("%s", "Out of memory during ridiculously large request"); + croak2("%s", "Out of memory during ridiculously large request"); } if (bucket > max_bucket) max_bucket = bucket; Index: gnu/usr.bin/perl/metaconfig.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/metaconfig.h,v diff -u -p -a -u -p -r1.7 metaconfig.h --- gnu/usr.bin/perl/metaconfig.h 14 May 2024 19:38:54 -0000 1.7 +++ gnu/usr.bin/perl/metaconfig.h 22 Jan 2025 00:37:44 -0000 @@ -13,6 +13,112 @@ * Symbols should only be here temporarily. Once they are actually used, * they should be removed from here. * - * HAS_NON_INT_BITFIELDS - * + * BIN + * CASTI32 + * CASTNEGFLOAT + * CPPLAST + * CPPMINUS + * CPPRUN + * CPPSTDIN + * DOSUID + * DOUBLE_HAS_NEGATIVE_ZERO + * DOUBLE_HAS_SUBNORMALS + * DOUBLEMANTBITS + * DOUBLE_STYLE_CRAY + * DOUBLE_STYLE_IBM + * DOUBLE_STYLE_IEEE + * DOUBLE_STYLE_VAX + * DRAND48_R_PROTO + * Gid_t_f + * HAS_ASCTIME64 + * HAS_ATOLF + * HAS_BUILTIN_ADD_OVERFLOW + * HAS_BUILTIN_MUL_OVERFLOW + * HAS_BUILTIN_SUB_OVERFLOW + * HAS_CSH + * HAS_CTERMID + * HAS_CTIME64 + * HAS_DIFFTIME64 + * HAS_DRAND48_PROTO + * HAS_DRAND48_R + * HAS_FD_SET + * HAS_FFS + * HAS_FFSL + * HAS_GETMNT + * HAS_GMTIME64 + * HAS_GNULIBC + * HAS_INT64_T + * HAS_IPV6_MREQ_SOURCE + * HAS_ISLESS + * HAS_ISNORMAL + * HAS_LGAMMA_R + * HAS_LOCALECONV_L + * HAS_LOCALTIME64 + * HAS_LSEEK_PROTO + * HAS_MKTIME64 + * HAS_NANOSLEEP + * HAS_OPEN3 + * HAS_OPENAT + * HAS_PRCTL + * HAS_PSEUDOFORK + * HAS_RANDOM_R + * HAS_SIGINFO_SI_VALUE + * HAS_SIGSETJMP + * HAS_SRAND48_R + * HAS_SRANDOM_R + * HAS_STRTOD_L + * HAS_STRTOLD_L + * HAS_STRUCT_FS_DATA + * HAS_STRUCT_STATFS + * HAS_STRUCT_STATFS_F_FLAGS + * HAS_TIME + * HAS_USTAT + * HAS_VFORK + * HAS_WCSCMP + * HAS_WCSXFRM + * I16SIZE + * I32SIZE + * I64SIZE + * I8SIZE + * I_GDBM + * INSTALL_USR_BIN_PERL + * I_STDBOOL + * I_SYS_MOUNT + * I_SYS_STATFS + * I_SYS_STATVFS + * I_SYS_VFS + * I_TIME + * I_USTAT + * I_VFORK + * I_XLOCALE + * LOCALTIME_R_NEEDS_TZSET + * LOC_SED + * LONGDBLMANTBITS + * LONG_DOUBLE_STYLE_IEEE + * LONG_DOUBLE_STYLE_IEEE_DOUBLEDOUBLE + * LONG_DOUBLE_STYLE_IEEE_EXTENDED + * LONG_DOUBLE_STYLE_IEEE_STD + * LONG_DOUBLE_STYLE_VAX + * OSVERS + * PERL_LC_ALL_CATEGORY_POSITIONS_INIT + * PERL_LC_ALL_SEPARATOR + * PERL_LC_ALL_USES_NAME_VALUE_PAIRS + * PERL_PRIeldbl + * PERL_SCNfldbl + * PERL_TARGETARCH + * PERL_VENDORARCH + * RANDOM_R_PROTO + * SRAND48_R_PROTO + * SRANDOM_R_PROTO + * STARTPERL + * ST_INO_SIGN + * ST_INO_SIZE + * U32_ALIGNMENT_REQUIRED + * U32of + * U32xf + * U32Xf + * U8SIZE + * Uid_t_f + * USE_CROSS_COMPILE + * USE_MORE_BITS */ Index: gnu/usr.bin/perl/mg.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/mg.c,v diff -u -p -a -u -p -r1.29 mg.c --- gnu/usr.bin/perl/mg.c 14 May 2024 19:38:54 -0000 1.29 +++ gnu/usr.bin/perl/mg.c 22 Jan 2025 00:37:44 -0000 @@ -1470,7 +1470,6 @@ Perl_magic_clear_all_env(pTHX_ SV *sv, M return 0; } -#ifndef PERL_MICRO #ifdef HAS_SIGPROCMASK static void restore_sigmask(pTHX_ SV *save_sv) @@ -1527,6 +1526,7 @@ Perl_magic_clearsig(pTHX_ SV *sv, MAGIC } +PERL_STACK_REALIGN #ifdef PERL_USE_3ARG_SIGHANDLER Signal_t Perl_csighandler(int sig, Siginfo_t *sip, void *uap) @@ -1870,7 +1870,6 @@ Perl_magic_setsig(pTHX_ SV *sv, MAGIC *m SvREFCNT_dec(to_dec); return 0; } -#endif /* !PERL_MICRO */ int Perl_magic_setsigall(pTHX_ SV* sv, MAGIC* mg) @@ -3789,7 +3788,6 @@ Perl_perly_sighandler(int sig, Siginfo_t if (SvTRUE_NN(errsv)) { SvREFCNT_dec(errsv_save); -#ifndef PERL_MICRO /* Handler "died", for example to get out of a restart-able read(). * Before we re-do that on its behalf re-enable the signal which was * blocked by the system when we entered. @@ -3815,7 +3813,6 @@ Perl_perly_sighandler(int sig, Siginfo_t (void)rsignal(sig, SIG_IGN); (void)rsignal(sig, PL_csighandlerp); # endif -#endif /* !PERL_MICRO */ die_sv(errsv); } Index: gnu/usr.bin/perl/mg_vtable.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/mg_vtable.h,v diff -u -p -a -u -p -r1.5 mg_vtable.h --- gnu/usr.bin/perl/mg_vtable.h 14 May 2024 19:38:54 -0000 1.5 +++ gnu/usr.bin/perl/mg_vtable.h 22 Jan 2025 00:37:44 -0000 @@ -198,11 +198,7 @@ EXT_MGVTBL PL_magic_vtables[magic_vtable { Perl_magic_regdatum_get, Perl_magic_regdatum_set, 0, 0, 0, 0, 0, 0 }, { 0, Perl_magic_setregexp, 0, 0, 0, 0, 0, 0 }, { 0, Perl_magic_setsigall, 0, 0, 0, 0, 0, 0 }, -#ifndef PERL_MICRO { Perl_magic_getsig, Perl_magic_setsig, 0, Perl_magic_clearsig, 0, 0, 0, 0 }, -#else - { 0, 0, 0, 0, 0, 0, 0, 0 }, -#endif { Perl_magic_getsubstr, Perl_magic_setsubstr, 0, 0, 0, 0, 0, 0 }, { Perl_magic_get, Perl_magic_set, 0, 0, 0, 0, 0, 0 }, { Perl_magic_gettaint, Perl_magic_settaint, 0, 0, 0, 0, 0, 0 }, Index: gnu/usr.bin/perl/miniperlmain.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/miniperlmain.c,v diff -u -p -a -u -p -r1.19 miniperlmain.c --- gnu/usr.bin/perl/miniperlmain.c 14 May 2024 19:38:54 -0000 1.19 +++ gnu/usr.bin/perl/miniperlmain.c 22 Jan 2025 00:37:44 -0000 @@ -133,14 +133,12 @@ main(int argc, char **argv, char **env) perl_run(my_perl); } -#ifndef PERL_MICRO /* Unregister our signal handler before destroying my_perl */ for (i = 1; PL_sig_name[i]; i++) { if (rsignal_state(PL_sig_num[i]) == (Sighandler_t) PL_csighandlerp) { rsignal(PL_sig_num[i], (Sighandler_t) SIG_DFL); } } -#endif exitstatus = perl_destruct(my_perl); Index: gnu/usr.bin/perl/mro_core.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/mro_core.c,v diff -u -p -a -u -p -r1.6 mro_core.c --- gnu/usr.bin/perl/mro_core.c 14 May 2024 19:38:54 -0000 1.6 +++ gnu/usr.bin/perl/mro_core.c 22 Jan 2025 00:37:44 -0000 @@ -266,7 +266,7 @@ S_mro_get_linear_isa_dfs(pTHX_ HV *stash /* not in cache, make a new one */ - retval = MUTABLE_AV(newSV_type_mortal(SVt_PVAV)); + retval = newAV_mortal(); /* We use this later in this function, but don't need a reference to it beyond the end of this function, so reference count is fine. */ our_name = newSVhek(stashhek); Index: gnu/usr.bin/perl/nostdio.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/nostdio.h,v diff -u -p -a -u -p -r1.8 nostdio.h --- gnu/usr.bin/perl/nostdio.h 15 Feb 2023 01:36:13 -0000 1.8 +++ gnu/usr.bin/perl/nostdio.h 22 Jan 2025 00:37:44 -0000 @@ -18,116 +18,116 @@ */ #if !defined(_STDIO_H) && !defined(FILE) && !defined(_STDIO_INCLUDED) && !defined(__STDIO_LOADED) -#define _STDIO_H -#define _STDIO_INCLUDED -#define __STDIO_LOADED +# define _STDIO_H +# define _STDIO_INCLUDED +# define __STDIO_LOADED struct _FILE; -#define FILE struct _FILE +# define FILE struct _FILE #endif #if !defined(OEMVS) -#define _CANNOT "CANNOT" +# define _CANNOT "CANNOT" -#undef clearerr -#undef fclose -#undef fdopen -#undef feof -#undef ferror -#undef fflush -#undef fgetc -#undef fgetpos -#undef fgets -#undef fileno -#undef flockfile -#undef fopen -#undef fprintf -#undef fputc -#undef fputs -#undef fread -#undef freopen -#undef fscanf -#undef fseek -#undef fsetpos -#undef ftell -#undef ftrylockfile -#undef funlockfile -#undef fwrite -#undef getc -#undef getc_unlocked -#undef getw -#undef pclose -#undef popen -#undef putc -#undef putc_unlocked -#undef putw -#undef rewind -#undef setbuf -#undef setvbuf -#undef stderr -#undef stdin -#undef stdout -#undef tmpfile -#undef ungetc -#undef vfprintf -#undef printf +# undef clearerr +# undef fclose +# undef fdopen +# undef feof +# undef ferror +# undef fflush +# undef fgetc +# undef fgetpos +# undef fgets +# undef fileno +# undef flockfile +# undef fopen +# undef fprintf +# undef fputc +# undef fputs +# undef fread +# undef freopen +# undef fscanf +# undef fseek +# undef fsetpos +# undef ftell +# undef ftrylockfile +# undef funlockfile +# undef fwrite +# undef getc +# undef getc_unlocked +# undef getw +# undef pclose +# undef popen +# undef putc +# undef putc_unlocked +# undef putw +# undef rewind +# undef setbuf +# undef setvbuf +# undef stderr +# undef stdin +# undef stdout +# undef tmpfile +# undef ungetc +# undef vfprintf +# undef printf -#define fprintf _CANNOT _fprintf_ -#define printf _CANNOT _printf_ -#define stdin _CANNOT _stdin_ -#define stdout _CANNOT _stdout_ -#define stderr _CANNOT _stderr_ -#ifndef OS2 -#define tmpfile() _CANNOT _tmpfile_ -#endif -#define fclose(f) _CANNOT _fclose_ -#define fflush(f) _CANNOT _fflush_ -#define fopen(p,m) _CANNOT _fopen_ -#define freopen(p,m,f) _CANNOT _freopen_ -#define setbuf(f,b) _CANNOT _setbuf_ -#define setvbuf(f,b,x,s) _CANNOT _setvbuf_ -#define fscanf _CANNOT _fscanf_ -#define vfprintf(f,fmt,a) _CANNOT _vfprintf_ -#define fgetc(f) _CANNOT _fgetc_ -#define fgets(s,n,f) _CANNOT _fgets_ -#define fputc(c,f) _CANNOT _fputc_ -#define fputs(s,f) _CANNOT _fputs_ -#define getc(f) _CANNOT _getc_ -#define putc(c,f) _CANNOT _putc_ -#ifndef OS2 -#define ungetc(c,f) _CANNOT _ungetc_ -#endif -#define fread(b,s,c,f) _CANNOT _fread_ -#define fwrite(b,s,c,f) _CANNOT _fwrite_ -#define fgetpos(f,p) _CANNOT _fgetpos_ -#define fseek(f,o,w) _CANNOT _fseek_ -#define fsetpos(f,p) _CANNOT _fsetpos_ -#define ftell(f) _CANNOT _ftell_ -#define rewind(f) _CANNOT _rewind_ -#define clearerr(f) _CANNOT _clearerr_ -#define feof(f) _CANNOT _feof_ -#define ferror(f) _CANNOT _ferror_ -#define __filbuf(f) _CANNOT __filbuf_ -#define __flsbuf(c,f) _CANNOT __flsbuf_ -#define _filbuf(f) _CANNOT _filbuf_ -#define _flsbuf(c,f) _CANNOT _flsbuf_ -#define fdopen(fd,p) _CANNOT _fdopen_ -#define fileno(f) _CANNOT _fileno_ -#if defined(SFIO_VERSION) && SFIO_VERSION < 20000101L -#define flockfile(f) _CANNOT _flockfile_ -#define ftrylockfile(f) _CANNOT _ftrylockfile_ -#define funlockfile(f) _CANNOT _funlockfile_ -#endif -#define getc_unlocked(f) _CANNOT _getc_unlocked_ -#define putc_unlocked(c,f) _CANNOT _putc_unlocked_ -#define popen(c,m) _CANNOT _popen_ -#define getw(f) _CANNOT _getw_ -#define putw(v,f) _CANNOT _putw_ -#ifndef OS2 -#define pclose(f) _CANNOT _pclose_ -#endif +# define fprintf _CANNOT _fprintf_ +# define printf _CANNOT _printf_ +# define stdin _CANNOT _stdin_ +# define stdout _CANNOT _stdout_ +# define stderr _CANNOT _stderr_ +# ifndef OS2 +# define tmpfile() _CANNOT _tmpfile_ +# endif +# define fclose(f) _CANNOT _fclose_ +# define fflush(f) _CANNOT _fflush_ +# define fopen(p,m) _CANNOT _fopen_ +# define freopen(p,m,f) _CANNOT _freopen_ +# define setbuf(f,b) _CANNOT _setbuf_ +# define setvbuf(f,b,x,s) _CANNOT _setvbuf_ +# define fscanf _CANNOT _fscanf_ +# define vfprintf(f,fmt,a) _CANNOT _vfprintf_ +# define fgetc(f) _CANNOT _fgetc_ +# define fgets(s,n,f) _CANNOT _fgets_ +# define fputc(c,f) _CANNOT _fputc_ +# define fputs(s,f) _CANNOT _fputs_ +# define getc(f) _CANNOT _getc_ +# define putc(c,f) _CANNOT _putc_ +# ifndef OS2 +# define ungetc(c,f) _CANNOT _ungetc_ +# endif +# define fread(b,s,c,f) _CANNOT _fread_ +# define fwrite(b,s,c,f) _CANNOT _fwrite_ +# define fgetpos(f,p) _CANNOT _fgetpos_ +# define fseek(f,o,w) _CANNOT _fseek_ +# define fsetpos(f,p) _CANNOT _fsetpos_ +# define ftell(f) _CANNOT _ftell_ +# define rewind(f) _CANNOT _rewind_ +# define clearerr(f) _CANNOT _clearerr_ +# define feof(f) _CANNOT _feof_ +# define ferror(f) _CANNOT _ferror_ +# define __filbuf(f) _CANNOT __filbuf_ +# define __flsbuf(c,f) _CANNOT __flsbuf_ +# define _filbuf(f) _CANNOT _filbuf_ +# define _flsbuf(c,f) _CANNOT _flsbuf_ +# define fdopen(fd,p) _CANNOT _fdopen_ +# define fileno(f) _CANNOT _fileno_ +# if defined(SFIO_VERSION) && SFIO_VERSION < 20000101L +# define flockfile(f) _CANNOT _flockfile_ +# define ftrylockfile(f) _CANNOT _ftrylockfile_ +# define funlockfile(f) _CANNOT _funlockfile_ +# endif +# define getc_unlocked(f) _CANNOT _getc_unlocked_ +# define putc_unlocked(c,f) _CANNOT _putc_unlocked_ +# define popen(c,m) _CANNOT _popen_ +# define getw(f) _CANNOT _getw_ +# define putw(v,f) _CANNOT _putw_ +# ifndef OS2 +# define pclose(f) _CANNOT _pclose_ +# endif -#endif /*not define EBCDIC */ +#endif /*not define OEMVS */ /* * ex: set ts=8 sts=4 sw=4 et: Index: gnu/usr.bin/perl/op.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/op.c,v diff -u -p -a -u -p -r1.28 op.c --- gnu/usr.bin/perl/op.c 14 May 2024 19:38:54 -0000 1.28 +++ gnu/usr.bin/perl/op.c 22 Jan 2025 00:37:44 -0000 @@ -284,7 +284,7 @@ S_link_freed_op(pTHX_ OPSLAB *slab, OP * slab->opslab_freed = (OP**)PerlMemShared_calloc((slab->opslab_freed_size), sizeof(OP*)); if (!slab->opslab_freed) - croak_no_mem(); + croak_no_mem_ext(STR_WITH_LEN("op:link_freed_op")); } else if (index >= slab->opslab_freed_size) { /* It's probably not worth doing exponential expansion here, the number of op sizes @@ -295,7 +295,7 @@ S_link_freed_op(pTHX_ OPSLAB *slab, OP * OP **p = (OP **)PerlMemShared_realloc(slab->opslab_freed, newsize * sizeof(OP*)); if (!p) - croak_no_mem(); + croak_no_mem_ext(STR_WITH_LEN("op:link_freed_op")); Zero(p+slab->opslab_freed_size, newsize - slab->opslab_freed_size, OP *); @@ -712,17 +712,27 @@ Perl_no_bareword_allowed(pTHX_ OP *o) o->op_private &= ~OPpCONST_STRICT; /* prevent warning twice about the same OP */ } +/* +Return true if the supplied string is the name of one of the built-in +filehandles. +*/ + +PERL_STATIC_INLINE bool +S_is_standard_filehandle_name(const char *fhname) { + return strEQ(fhname, "STDERR") + || strEQ(fhname, "STDOUT") + || strEQ(fhname, "STDIN") + || strEQ(fhname, "_") + || strEQ(fhname, "ARGV") + || strEQ(fhname, "ARGVOUT") + || strEQ(fhname, "DATA"); +} + void Perl_no_bareword_filehandle(pTHX_ const char *fhname) { PERL_ARGS_ASSERT_NO_BAREWORD_FILEHANDLE; - if (strNE(fhname, "STDERR") - && strNE(fhname, "STDOUT") - && strNE(fhname, "STDIN") - && strNE(fhname, "_") - && strNE(fhname, "ARGV") - && strNE(fhname, "ARGVOUT") - && strNE(fhname, "DATA")) { + if (!is_standard_filehandle_name(fhname)) { qerror(Perl_mess(aTHX_ "Bareword filehandle \"%s\" not allowed under 'no feature \"bareword_filehandles\"'", fhname)); } } @@ -1324,7 +1334,7 @@ Perl_op_clear(pTHX_ OP *o) { UNOP_AUX_item *aux = cUNOP_AUXo->op_aux; /* Every item in aux is a UV, so nothing in it to free */ - Safefree(aux); + PerlMemShared_free(aux); } break; @@ -1332,7 +1342,7 @@ Perl_op_clear(pTHX_ OP *o) { UNOP_AUX_item *aux = cUNOP_AUXo->op_aux; /* Every item in aux is a UV, so nothing in it to free */ - Safefree(aux); + PerlMemShared_free(aux); } break; } @@ -1361,7 +1371,6 @@ S_cop_free(pTHX_ COP* cop) if (av) { SV * const * const svp = av_fetch(av, CopLINE(cop), FALSE); if (svp && *svp != &PL_sv_undef && SvIVX(*svp) == PTR2IV(cop) ) { - (void)SvIOK_off(*svp); SvIV_set(*svp, 0); } } @@ -2125,14 +2134,6 @@ Perl_scalarvoid(pTHX_ OP *arg) goto get_next_op; } - if ((o->op_private & OPpTARGET_MY) - && (PL_opargs[o->op_type] & OA_TARGLEX))/* OPp share the meaning */ - { - /* newASSIGNOP has already applied scalar context, which we - leave, as if this op is inside SASSIGN. */ - goto get_next_op; - } - o->op_flags = (o->op_flags & ~OPf_WANT) | OPf_WANT_VOID; switch (o->op_type) { @@ -2219,6 +2220,14 @@ Perl_scalarvoid(pTHX_ OP *arg) case OP_PROTOTYPE: case OP_RUNCV: func_ops: + if ( (PL_opargs[o->op_type] & OA_TARGLEX) + && (o->op_private & OPpTARGET_MY) + ) + /* '$lex = $a + $b' etc is optimised to '$a + $b' but + * where the add op's TARG is actually $lex. So it's not + * useless to be in void context in this special case */ + break; + useless = OP_DESC(o); break; @@ -2411,6 +2420,7 @@ Perl_scalarvoid(pTHX_ OP *arg) case OP_LINESEQ: case OP_LEAVEGIVEN: case OP_LEAVEWHEN: + case OP_ONCE: kids: next_kid = cLISTOPo->op_first; break; @@ -2440,6 +2450,12 @@ Perl_scalarvoid(pTHX_ OP *arg) case OP_SCALAR: scalar(o); break; + case OP_EMPTYAVHV: + if (!(o->op_private & OPpTARGET_MY)) + useless = (o->op_private & OPpEMPTYAVHV_IS_HV) ? + "anonymous hash ({})" : + "anonymous array ([])"; + break; } if (useless_sv) { @@ -2742,7 +2758,11 @@ Perl_check_hash_fields_and_hekify(pTHX_ { SSize_t keylen; const char * const key = SvPV_const(sv, *(STRLEN*)&keylen); - SV *nsv = newSVpvn_share(key, SvUTF8(sv) ? -keylen : keylen, 0); + if (keylen > I32_MAX) { + Perl_croak_nocontext("Sorry, hash keys must be smaller than 2**31 bytes"); + } + + SV *nsv = newSVpvn_share(key, SvUTF8(sv) ? -(I32)keylen : (I32)keylen, 0); SvREFCNT_dec_NN(sv); *svp = nsv; } @@ -3988,10 +4008,8 @@ S_move_proto_attr(pTHX_ OP **proto, OP * Perl_warner(aTHX_ packWARN(WARN_MISC), "Attribute prototype(%" UTF8f ") discards earlier prototype attribute in same sub", UTF8fARG(SvUTF8(cSVOPo_sv), new_len, newp)); - op_free(new_proto); } - else if (new_proto) - op_free(new_proto); + op_free(new_proto); new_proto = o; /* excise new_proto from the list */ op_sibling_splice(*attrs, lasto, 1, NULL); @@ -4041,8 +4059,7 @@ S_move_proto_attr(pTHX_ OP **proto, OP * UTF8fARG(SvUTF8(cSVOPx_sv(new_proto)), new_len, newp), SVfARG(svname)); } - if (*proto) - op_free(*proto); + op_free(*proto); *proto = new_proto; } } @@ -4293,6 +4310,47 @@ Perl_invert(pTHX_ OP *o) return newUNOP(OP_NOT, OPf_SPECIAL, scalar(o)); } +/* Warn about possible precedence issues if op is a control flow operator that + does not terminate normally (return, exit, next, etc). +*/ +static bool +S_is_control_transfer(pTHX_ OP *op) +{ + assert(op != NULL); + + /* [perl #59802]: Warn about things like "return $a or $b", which + is parsed as "(return $a) or $b" rather than "return ($a or + $b)". + */ + switch (op->op_type) { + case OP_DUMP: + case OP_NEXT: + case OP_LAST: + case OP_REDO: + case OP_EXIT: + case OP_RETURN: + case OP_DIE: + case OP_GOTO: + /* XXX: Currently we allow people to "shoot themselves in the + foot" by explicitly writing "(return $a) or $b". + + Warn unless we are looking at the result from folding or if + the programmer explicitly grouped the operators like this. + The former can occur with e.g. + + use constant FEATURE => ( $] >= ... ); + sub { not FEATURE and return or do_stuff(); } + */ + if (!op->op_folded && !(op->op_flags & OPf_PARENS)) + Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), + "Possible precedence issue with control flow operator (%s)", OP_DESC(op)); + + return true; + } + + return false; +} + OP * Perl_cmpchain_start(pTHX_ I32 type, OP *left, OP *right) { @@ -4301,6 +4359,8 @@ Perl_cmpchain_start(pTHX_ I32 type, OP * if (!left) left = newOP(OP_NULL, 0); + else + (void)S_is_control_transfer(aTHX_ left); if (!right) right = newOP(OP_NULL, 0); scalar(left); @@ -4693,10 +4753,12 @@ Perl_newPROG(pTHX_ OP *o) if (PERLDB_INTER) { CV * const cv = get_cvs("DB::postponed", 0); if (cv) { - dSP; - PUSHMARK(SP); - XPUSHs(MUTABLE_SV(CopFILEGV(&PL_compiling))); - PUTBACK; + PUSHMARK(PL_stack_sp); + SV *comp = MUTABLE_SV(CopFILEGV(&PL_compiling)); +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); +#endif + rpp_xpush_1(comp); call_sv(MUTABLE_SV(cv), G_DISCARD); } } @@ -4945,7 +5007,7 @@ S_fold_constants(pTHX_ OP *const o) PL_op = curop; old_cxix = cxstack_ix; - create_eval_scope(NULL, G_FAKINGEVAL); + create_eval_scope(NULL, PL_stack_sp, G_FAKINGEVAL); /* Verify that we don't need to save it: */ assert(PL_curcop == &PL_compiling); @@ -4965,7 +5027,11 @@ S_fold_constants(pTHX_ OP *const o) switch (ret) { case 0: - sv = *(PL_stack_sp--); + sv = *PL_stack_sp; + if (rpp_stack_is_rc()) + SvREFCNT_dec(sv); + PL_stack_sp--; + if (o->op_targ && sv == PAD_SV(o->op_targ)) { /* grab pad temp? */ pad_swipe(o->op_targ, FALSE); } @@ -5062,7 +5128,7 @@ S_gen_constant_list(pTHX_ OP *o) PL_op = curop; old_cxix = cxstack_ix; - create_eval_scope(NULL, G_FAKINGEVAL); + create_eval_scope(NULL, PL_stack_sp, G_FAKINGEVAL); old_curcop = PL_curcop; StructCopy(old_curcop, ¬_compiling, COP); @@ -5080,7 +5146,7 @@ S_gen_constant_list(pTHX_ OP *o) switch (ret) { case 0: -#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY +#ifdef PERL_USE_HWM PL_curstackinfo->si_stack_hwm = 0; /* stop valgrind complaining */ #endif Perl_pp_pushmark(aTHX); @@ -5120,11 +5186,12 @@ S_gen_constant_list(pTHX_ OP *o) o->op_flags &= ~OPf_REF; /* treat \(1..2) like an ordinary list */ o->op_flags |= OPf_PARENS; /* and flatten \(1..2,3) */ o->op_opt = 0; /* needs to be revisited in rpeep() */ - av = (AV *)SvREFCNT_inc_NN(*PL_stack_sp--); + av = (AV *)*PL_stack_sp; /* replace subtree with an OP_CONST */ curop = cUNOPo->op_first; op_sibling_splice(o, NULL, -1, newSVOP(OP_CONST, 0, (SV *)av)); + rpp_pop_1_norc(); op_free(curop); if (AvFILLp(av) != -1) @@ -5588,6 +5655,10 @@ appropriate. What you want to do in tha C, append more children to it, and then call L. See L for more information. +If a compiletime-known fixed list of child ops is required, the +L function can be used as a convenient shortcut, avoiding the +need to create a temporary plain C in a new variable. + =cut */ @@ -5632,6 +5703,45 @@ Perl_newLISTOP(pTHX_ I32 type, I32 flags } /* +=for apidoc newLISTOPn + +Constructs, checks, and returns an op of any list type. C is +the opcode. C gives the eight bits of C, except that +C will be set automatically if required. The variable number of +arguments after C must all be OP pointers, terminated by a final +C pointer. These will all be consumed as direct children of the list +op and become part of the constructed op tree. + +Do not forget to end the arguments list with a C pointer. + +This function is useful as a shortcut to performing the sequence of +C, C on each element and final +C in the case where a compiletime-known fixed sequence of +child ops is required. If a variable number of elements are required, or for +splicing in an entire sub-list of child ops, see instead L and +L. + +=cut +*/ + +OP * +Perl_newLISTOPn(pTHX_ I32 type, I32 flags, ...) +{ + va_list args; + va_start(args, flags); + + OP *o = newLISTOP(OP_LIST, 0, NULL, NULL); + + OP *kid; + while((kid = va_arg(args, OP *))) + o = op_append_elem(OP_LIST, o, kid); + + va_end(args); + + return op_convert_list(type, flags, o); +} + +/* =for apidoc newOP Constructs, checks, and returns an op of any base type (any type that @@ -5857,10 +5967,29 @@ Perl_newBINOP(pTHX_ I32 type, I32 flags, ASSUME((PL_opargs[type] & OA_CLASS_MASK) == OA_BINOP || type == OP_NULL || type == OP_CUSTOM); - NewOp(1101, binop, 1, BINOP); - if (!first) first = newOP(OP_NULL, 0); + else if (type != OP_SASSIGN && S_is_control_transfer(aTHX_ first)) { + /* Skip OP_SASSIGN. + * '$x = return 42' is represented by (SASSIGN (RETURN 42) (GVSV *x)); + * in other words, OP_SASSIGN has its operands "backwards". Skip the + * control transfer check because '$x = return $y' is not a precedence + * issue (the '$x =' part has no runtime effect no matter how you + * parenthesize it). + * Also, don't try to optimize the OP_SASSIGN case because the logical + * assignment ops like //= are represented by an OP_{AND,OR,DOR}ASSIGN + * containing an OP_SASSIGN with a single child (first == last): + * '$x //= return 42' is (DORASSIGN (GVSV *x) (SASSIGN (RETURN 42))). + * Naively eliminating the OP_ASSIGN leaves the incomplete (DORASSIGN + * (GVSV *x) (RETURN 42)), which e.g. B::Deparse doesn't handle. + */ + assert(first != last); + op_free(last); + first->op_folded = 1; + return first; + } + + NewOp(1101, binop, 1, BINOP); OpTYPE_set(binop, type); binop->op_first = first; @@ -7845,10 +7974,11 @@ Perl_utilize(pTHX_ int aver, I32 floor, /* Fake up a method call to VERSION */ meth = newSVpvs_share("VERSION"); - veop = op_convert_list(OP_ENTERSUB, OPf_STACKED, - op_append_elem(OP_LIST, - op_prepend_elem(OP_LIST, pack, version), - newMETHOP_named(OP_METHOD_NAMED, 0, meth))); + veop = newLISTOPn(OP_ENTERSUB, OPf_STACKED, + pack, + version, + newMETHOP_named(OP_METHOD_NAMED, 0, meth), + NULL); } } @@ -7898,6 +8028,34 @@ Perl_utilize(pTHX_ int aver, I32 floor, U16 shortver = S_extract_shortver(aTHX_ use_version); + if (shortver && PL_prevailing_version) { + /* use VERSION while another use VERSION is in scope + * This should provoke at least a warning, if not an outright error + */ + if (PL_prevailing_version < SHORTVER(5, 10)) { + /* if the old version had no side effects, we can allow this + * without any warnings or errors */ + } + else if (shortver == PL_prevailing_version) { + /* requesting the same version again is fine */ + } + else if (shortver >= SHORTVER(5, 39)) { + croak("use VERSION of 5.39 or above is not permitted while another use VERSION is in scope"); + } + else if (PL_prevailing_version >= SHORTVER(5, 39)) { + croak("use VERSION is not permitted while another use VERSION of 5.39 or above is in scope"); + } + else if (PL_prevailing_version >= SHORTVER(5, 11) && shortver < SHORTVER(5, 11)) { + /* downgrading from >= 5.11 to < 5.11 is now fatal */ + croak("Downgrading a use VERSION declaration to below v5.11 is not permitted"); + } + else { + /* OK let's at least warn */ + deprecate_fatal_in(WARN_DEPRECATED__SUBSEQUENT_USE_VERSION, "5.44", + "Changing use VERSION while another use VERSION is in scope"); + } + } + /* If a version >= 5.11.0 is requested, strictures are on by default! */ if (shortver >= SHORTVER(5, 11)) { if (!(PL_hints & HINT_EXPLICIT_STRICT_REFS)) @@ -7907,15 +8065,13 @@ Perl_utilize(pTHX_ int aver, I32 floor, if (!(PL_hints & HINT_EXPLICIT_STRICT_VARS)) PL_hints |= HINT_STRICT_VARS; - if (shortver >= SHORTVER(5, 35)) + if (shortver >= SHORTVER(5, 35) && !(PL_dowarn & G_WARN_ALL_MASK)) { free_and_set_cop_warnings(&PL_compiling, pWARN_ALL); + PL_dowarn |= G_WARN_ONCE; + } } /* otherwise they are off */ else { - if(PL_prevailing_version >= SHORTVER(5, 11)) - deprecate_fatal_in(WARN_DEPRECATED__VERSION_DOWNGRADE, "5.40", - "Downgrading a use VERSION declaration to below v5.11"); - if (!(PL_hints & HINT_EXPLICIT_STRICT_REFS)) PL_hints &= ~HINT_STRICT_REFS; if (!(PL_hints & HINT_EXPLICIT_STRICT_SUBS)) @@ -7924,6 +8080,16 @@ Perl_utilize(pTHX_ int aver, I32 floor, PL_hints &= ~HINT_STRICT_VARS; } + /* As an optimisation, there's no point scanning for changes of + * visible builtin functions when switching between versions earlier + * than v5.39, when any became visible at all + */ + if ((shortver >= SHORTVER(5, 39)) || (PL_prevailing_version >= SHORTVER(5, 39))) { + prepare_export_lexical(); + import_builtin_bundle(shortver); + finish_export_lexical(); + } + PL_prevailing_version = shortver; } @@ -8207,7 +8373,6 @@ S_newONCEOP(pTHX_ OP *initop, OP *padop) OpTYPE_set(condop, OP_ONCE); other->op_targ = target; - nullop->op_flags |= OPf_WANT_SCALAR; /* Store the initializedness of state vars in a separate pad entry. */ @@ -8648,44 +8813,6 @@ S_new_logop(pTHX_ I32 type, I32 flags, O first = *firstp; other = *otherp; - /* [perl #59802]: Warn about things like "return $a or $b", which - is parsed as "(return $a) or $b" rather than "return ($a or - $b)". NB: This also applies to xor, which is why we do it - here. - */ - switch (first->op_type) { - case OP_NEXT: - case OP_LAST: - case OP_REDO: - /* XXX: Perhaps we should emit a stronger warning for these. - Even with the high-precedence operator they don't seem to do - anything sensible. - - But until we do, fall through here. - */ - case OP_RETURN: - case OP_EXIT: - case OP_DIE: - case OP_GOTO: - /* XXX: Currently we allow people to "shoot themselves in the - foot" by explicitly writing "(return $a) or $b". - - Warn unless we are looking at the result from folding or if - the programmer explicitly grouped the operators like this. - The former can occur with e.g. - - use constant FEATURE => ( $] >= ... ); - sub { not FEATURE and return or do_stuff(); } - */ - if (!first->op_folded && !(first->op_flags & OPf_PARENS)) - Perl_ck_warner(aTHX_ packWARN(WARN_SYNTAX), - "Possible precedence issue with control flow operator"); - /* XXX: Should we optimze this to "return $a;" (i.e. remove - the "or $b" part)? - */ - break; - } - if (type == OP_XOR) /* Not short circuit, but here by precedence. */ return newBINOP(type, flags, scalar(first), scalar(other)); @@ -8694,6 +8821,12 @@ S_new_logop(pTHX_ I32 type, I32 flags, O scalarboolean(first); + if (S_is_control_transfer(aTHX_ first)) { + op_free(other); + first->op_folded = 1; + return first; + } + /* search for a constant op that could let us fold the test */ if ((cstop = search_const(first))) { if (cstop->op_private & OPpCONST_STRICT) @@ -8860,6 +8993,13 @@ Perl_newCONDOP(pTHX_ I32 flags, OP *firs return newLOGOP(OP_OR, 0, first, falseop); scalarboolean(first); + if (S_is_control_transfer(aTHX_ first)) { + op_free(trueop); + op_free(falseop); + first->op_folded = 1; + return first; + } + if ((cstop = search_const(first))) { /* Left or right arm of the conditional? */ const bool left = SvTRUE(cSVOPx(cstop)->op_sv); @@ -8923,7 +9063,7 @@ The C argument is currently ignor OP * Perl_newTRYCATCHOP(pTHX_ I32 flags, OP *tryblock, OP *catchvar, OP *catchblock) { - OP *o, *catchop; + OP *catchop; PERL_ARGS_ASSERT_NEWTRYCATCHOP; assert(catchvar->op_type == OP_PADSV); @@ -8955,10 +9095,10 @@ Perl_newTRYCATCHOP(pTHX_ I32 flags, OP * op_free(catchvar); /* Build the optree structure */ - o = newLISTOP(OP_LIST, 0, tryblock, catchop); - o = op_convert_list(OP_ENTERTRYCATCH, 0, o); - - return o; + return newLISTOPn(OP_ENTERTRYCATCH, 0, + tryblock, + catchop, + NULL); } /* @@ -10054,6 +10194,17 @@ S_already_defined(pTHX_ CV *const cv, OP return; } +/* +=for apidoc newMYSUB + +Construct a Perl lexical subroutine, also performing some surrounding jobs, and +returning a pointer to the constructed subroutine. + +Similar in action to L>. + +=cut +*/ + CV * Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block) { @@ -10364,10 +10515,11 @@ Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP if (HvTOTALKEYS(hv) > 0 && hv_exists_ent(hv, tmpstr, 0)) { CV * const pcv = GvCV(db_postponed); if (pcv) { - dSP; - PUSHMARK(SP); - XPUSHs(tmpstr); - PUTBACK; + PUSHMARK(PL_stack_sp); +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); +#endif + rpp_xpush_1(tmpstr); call_sv(MUTABLE_SV(pcv), G_DISCARD); } } @@ -10487,15 +10639,23 @@ any use of the returned pointer. It is ensure that it knows which of these situations applies. =for apidoc newATTRSUB -Construct a Perl subroutine, also performing some surrounding jobs. +Construct a Perl subroutine, also performing some surrounding jobs, +returning a pointer to the constructed subroutine. -This is the same as L> with its C parameter set to -FALSE. This means that if C is null, the new sub will be anonymous; otherwise -the name will be derived from C in the way described (as with all other -details) in L>. +This is the same as L> with its C parameter +set to FALSE. This means that if C is null, the new sub will be anonymous; +otherwise the name will be derived from C in the way described (as with all +other details) in L>. =for apidoc newSUB -Like C>, but without attributes. +Construct a Perl subroutine without attributes, and also performing some +surrounding jobs, returning a pointer to the constructed subroutine. + +This is the same as L> with its C parameter +set to FALSE, and its C parameter to NULL. This means that if C is +null, the new sub will be anonymous; otherwise the name will be derived from +C in the way described (as with all other details) in +L>. =cut */ @@ -10967,10 +11127,11 @@ Perl_newATTRSUB_x(pTHX_ I32 floor, OP *o if (HvTOTALKEYS(hv) > 0 && hv_exists_ent(hv, tmpstr, 0)) { CV * const pcv = GvCV(db_postponed); if (pcv) { - dSP; - PUSHMARK(SP); - XPUSHs(tmpstr); - PUTBACK; + PUSHMARK(PL_stack_sp); +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); +#endif + rpp_xpush_1(tmpstr); call_sv(MUTABLE_SV(pcv), G_DISCARD); } } @@ -11217,16 +11378,6 @@ S_process_special_blocks(pTHX_ I32 floor } } -/* -=for apidoc newCONSTSUB - -Behaves like L, except that C is nul-terminated -rather than of counted length, and no flags are set. (This means that -C is always interpreted as Latin-1.) - -=cut -*/ - CV * Perl_newCONSTSUB(pTHX_ HV *stash, const char *name, SV *sv) { @@ -11234,7 +11385,8 @@ Perl_newCONSTSUB(pTHX_ HV *stash, const } /* -=for apidoc newCONSTSUB_flags +=for apidoc newCONSTSUB +=for apidoc_item newCONSTSUB_flags Construct a constant subroutine, also performing some surrounding jobs. A scalar constant-valued subroutine is eligible for inlining @@ -11264,16 +11416,22 @@ after this function has returned. If C is null then the subroutine will be anonymous, with its C referring to an C<__ANON__> glob. If C is non-null then the subroutine will be named accordingly, referenced by the appropriate glob. -C is a string of length C bytes giving a sigilless symbol -name, in UTF-8 if C has the C bit set and in Latin-1 -otherwise. The name may be either qualified or unqualified. If the + + +C is a string, giving a sigilless symbol name. +For C, C is NUL-terminated, interpreted as Latin-1. + +For C, C has length C bytes, hence may contain +embedded NULs. It is interpreted as UTF-8 if C has the C bit +set, and Latin-1 otherwise. C should not have bits set other than +C. + +The name may be either qualified or unqualified. If the name is unqualified then it defaults to being in the stash specified by C if that is non-null, or to C if C is null. The symbol is always added to the stash if necessary, with C semantics. -C should not have bits set other than C. - If there is already a subroutine of the specified name, then the new sub will replace the existing one in the glob. A warning may be generated about the redefinition. @@ -11644,24 +11802,71 @@ Perl_newFORM(pTHX_ I32 floor, OP *o, OP PL_compiling.cop_seq = 0; } +/* +=for apidoc newANONLIST + +Constructs, checks, and returns an anonymous list op. + +=cut +*/ + OP * Perl_newANONLIST(pTHX_ OP *o) { - return op_convert_list(OP_ANONLIST, OPf_SPECIAL, o); + return (o) ? op_convert_list(OP_ANONLIST, OPf_SPECIAL, o) + : newOP(OP_EMPTYAVHV, 0); } +/* +=for apidoc newANONHASH + +Constructs, checks, and returns an anonymous hash op. + +=cut +*/ + OP * Perl_newANONHASH(pTHX_ OP *o) { - return op_convert_list(OP_ANONHASH, OPf_SPECIAL, o); + OP * anon = (o) ? op_convert_list(OP_ANONHASH, OPf_SPECIAL, o) + : newOP(OP_EMPTYAVHV, 0); + if (!o) + anon->op_private |= OPpEMPTYAVHV_IS_HV; + return anon; } +/* +=for apidoc newANONSUB + +Construct a nameless (anonymous) Perl subroutine without attributes, also +performing some surrounding jobs. + +This is the same as L> with its C parameter +set to FALSE, and its C and C parameters to NULL. +For more details, see L>. + +=cut +*/ + OP * Perl_newANONSUB(pTHX_ I32 floor, OP *proto, OP *block) { return newANONATTRSUB(floor, proto, NULL, block); } +/* +=for apidoc newANONATTRSUB + +Construct a nameless (anonymous) Perl subroutine, also performing some +surrounding jobs. + +This is the same as L> with its C parameter +set to FALSE, and its C parameter to NULL. +For more details, see L>. + +=cut +*/ + OP * Perl_newANONATTRSUB(pTHX_ I32 floor, OP *proto, OP *attrs, OP *block) { @@ -11675,9 +11880,9 @@ Perl_newANONATTRSUB(pTHX_ I32 floor, OP if (is_const) { anoncode = newUNOP(OP_ANONCONST, OPf_REF, - op_convert_list(OP_ENTERSUB, - OPf_STACKED|OPf_WANT_SCALAR, - anoncode)); + newLISTOPn(OP_ENTERSUB, OPf_STACKED|OPf_WANT_SCALAR, + anoncode, + NULL)); } return anoncode; @@ -11735,6 +11940,14 @@ Perl_oopsHV(pTHX_ OP *o) return o; } +/* +=for apidoc newAVREF + +Constructs, checks, and returns an arrary reference op. + +=cut +*/ + OP * Perl_newAVREF(pTHX_ OP *o) { @@ -11751,6 +11964,14 @@ Perl_newAVREF(pTHX_ OP *o) return newUNOP(OP_RV2AV, 0, scalar(o)); } +/* +=for apidoc newGVREF + +Constructs, checks, and returns a glob reference op. + +=cut +*/ + OP * Perl_newGVREF(pTHX_ I32 type, OP *o) { @@ -11766,6 +11987,14 @@ Perl_newGVREF(pTHX_ I32 type, OP *o) return ref(newUNOP(OP_RV2GV, OPf_REF, o), type); } +/* +=for apidoc newHVREF + +Constructs, checks, and returns a hash reference op. + +=cut +*/ + OP * Perl_newHVREF(pTHX_ OP *o) { @@ -11782,6 +12011,14 @@ Perl_newHVREF(pTHX_ OP *o) return newUNOP(OP_RV2HV, 0, scalar(o)); } +/* +=for apidoc newCVREF + +Constructs, checks, and returns a code reference op. + +=cut +*/ + OP * Perl_newCVREF(pTHX_ I32 flags, OP *o) { @@ -11791,6 +12028,14 @@ Perl_newCVREF(pTHX_ I32 flags, OP *o) return newUNOP(OP_RV2CV, flags, scalar(o)); } +/* +=for apidoc newSVREF + +Constructs, checks, and returns a scalar reference op. + +=cut +*/ + OP * Perl_newSVREF(pTHX_ OP *o) { @@ -12171,6 +12416,8 @@ Perl_ck_eval(pTHX_ OP *o) PERL_ARGS_ASSERT_CK_EVAL; PL_hints |= HINT_BLOCK_SCOPE; + if(PL_prevailing_version != 0) + PL_hints |= HINT_LOCALIZE_HH; if (o->op_flags & OPf_KIDS) { SVOP * const kid = cSVOPx(cUNOPo->op_first); assert(kid); @@ -12212,8 +12459,8 @@ Perl_ck_eval(pTHX_ OP *o) && !(o->op_private & OPpEVAL_COPHH) && GvHV(PL_hintgv)) { /* Store a copy of %^H that pp_entereval can pick up. */ HV *hh = hv_copy_hints_hv(GvHV(PL_hintgv)); + hv_stores(hh, "CORE/prevailing_version", newSVuv(PL_prevailing_version)); OP *hhop; - STOREFEATUREBITSHH(hh); hhop = newSVOP(OP_HINTSEVAL, 0, MUTABLE_SV(hh)); /* append hhop to only child */ op_sibling_splice(o, cUNOPo->op_first, 0, hhop); @@ -12248,8 +12495,7 @@ Perl_ck_trycatch(pTHX_ OP *o) /* cut whole sibling chain free from o */ op_sibling_splice(o, NULL, -1, NULL); - if(to_free) - op_free(to_free); + op_free(to_free); op_free(o); enter = alloc_LOGOP(OP_ENTERTRYCATCH, NULL, NULL); @@ -13059,18 +13305,29 @@ S_maybe_targlex(pTHX_ OP *o) OP * const kkid = OpSIBLING(kid); /* Can just relocate the target. */ - if (kkid && kkid->op_type == OP_PADSV - && (!(kkid->op_private & OPpLVAL_INTRO) - || kkid->op_private & OPpPAD_STATE)) - { - kid->op_targ = kkid->op_targ; - kkid->op_targ = 0; - /* Now we do not need PADSV and SASSIGN. - * Detach kid and free the rest. */ - op_sibling_splice(o, NULL, 1, NULL); - op_free(o); - kid->op_private |= OPpTARGET_MY; /* Used for context settings */ - return kid; + if (kkid && kkid->op_type == OP_PADSV) { + if (kid->op_type == OP_EMPTYAVHV) { + kid->op_flags |= kid->op_flags | + (o->op_flags & (OPf_WANT|OPf_PARENS)); + kid->op_private |= OPpTARGET_MY | + (kkid->op_private & (OPpLVAL_INTRO|OPpPAD_STATE)); + goto swipe_and_detach; + } else if (!(kkid->op_private & OPpLVAL_INTRO) + || (kkid->op_private & OPpPAD_STATE)) + { + kid->op_private |= OPpTARGET_MY; /* Used for context settings */ + /* give the lexical op the context of the parent sassign */ + kid->op_flags = (kid->op_flags & ~OPf_WANT) + | (o->op_flags & OPf_WANT); + swipe_and_detach: + kid->op_targ = kkid->op_targ; + kkid->op_targ = 0; + /* Now we do not need PADSV and SASSIGN. + * Detach kid and free the rest. */ + op_sibling_splice(o, NULL, 1, NULL); + op_free(o); + return kid; + } } } return o; @@ -13249,7 +13506,8 @@ Perl_ck_refassign(pTHX_ OP *o) settarg: o->op_private |= (varop->op_private & (OPpLVAL_INTRO|OPpPAD_STATE)); o->op_targ = varop->op_targ; - varop->op_targ = 0; + if (!(o->op_private & (OPpPAD_STATE|OPpLVAL_INTRO))) + varop->op_targ = 0; PAD_COMPNAME_GEN_set(o->op_targ, PERL_INT_MAX); break; @@ -13323,6 +13581,9 @@ Perl_ck_refassign(pTHX_ OP *o) o->op_flags &=~ OPf_STACKED; op_sibling_splice(o, right, 1, NULL); } + if (o->op_private & OPpPAD_STATE && o->op_private & OPpLVAL_INTRO) { + o = S_newONCEOP(aTHX_ o, varop); + } op_free(left); return o; } @@ -13444,6 +13705,13 @@ Perl_ck_return(pTHX_ OP *o) PERL_ARGS_ASSERT_CK_RETURN; + if (o->op_flags & OPf_STACKED) { + kid = cUNOPx(OpSIBLING(cLISTOPo->op_first))->op_first; + if (kid->op_type != OP_SCOPE && kid->op_type != OP_LEAVE) + yyerror("Missing comma after first argument to return"); + o->op_flags &= ~OPf_STACKED; + } + kid = OpSIBLING(cLISTOPo->op_first); if (PL_compcv && CvLVALUE(PL_compcv)) { for (; kid; kid = OpSIBLING(kid)) @@ -14327,20 +14595,19 @@ Perl_ck_entersub_args_core(pTHX_ OP *ent op_free(entersubop); switch(cvflags >> 16) { - case 'F': return newSVOP(OP_CONST, 0, - newSVpv(CopFILE(PL_curcop),0)); - case 'L': return newSVOP( - OP_CONST, 0, - Perl_newSVpvf(aTHX_ - "%" LINE_Tf, CopLINE(PL_curcop) - ) - ); - case 'P': return newSVOP(OP_CONST, 0, - (PL_curstash - ? newSVhek(HvNAME_HEK(PL_curstash)) - : &PL_sv_undef - ) - ); + case 'C': /* __CLASS__ */ + return newOP(OP_CLASSNAME, 0); + case 'F': /* __FILE__ */ + return newSVOP(OP_CONST, 0, + newSVpv(CopFILE(PL_curcop),0)); + case 'L': /* __LINE__ */ + return newSVOP(OP_CONST, 0, + Perl_newSVpvf(aTHX_ "%" LINE_Tf, CopLINE(PL_curcop))); + case 'P': /* __PACKAGE__ */ + return newSVOP(OP_CONST, 0, + (PL_curstash + ? newSVhek(HvNAME_HEK(PL_curstash)) + : &PL_sv_undef)); } NOT_REACHED; /* NOTREACHED */ } @@ -14601,6 +14868,7 @@ Perl_ck_subr(pTHX_ OP *o) CV *cv; GV *namegv; SV **const_class = NULL; + OP *const_op = NULL; PERL_ARGS_ASSERT_CK_SUBR; @@ -14630,20 +14898,29 @@ Perl_ck_subr(pTHX_ OP *o) if (aop->op_type == OP_CONST) { aop->op_private &= ~OPpCONST_STRICT; const_class = &cSVOPx(aop)->op_sv; + const_op = aop; } else if (aop->op_type == OP_LIST) { OP * const sib = OpSIBLING(cUNOPx(aop)->op_first); if (sib && sib->op_type == OP_CONST) { sib->op_private &= ~OPpCONST_STRICT; const_class = &cSVOPx(sib)->op_sv; + const_op = sib; } } /* make class name a shared cow string to speedup method calls */ /* constant string might be replaced with object, f.e. bigint */ if (const_class && SvPOK(*const_class)) { + assert(const_op); STRLEN len; const char* str = SvPV(*const_class, len); if (len) { + if (!FEATURE_BAREWORD_FILEHANDLES_IS_ENABLED + && !is_standard_filehandle_name(str) + && (const_op->op_private & OPpCONST_BARE)) { + cvop->op_private |= OPpMETH_NO_BAREWORD_IO; + } + SV* const shared = newSVpvn_share( str, SvUTF8(*const_class) ? -(SSize_t)len : (SSize_t)len, @@ -15249,6 +15526,7 @@ Perl_core_prototype(pTHX_ SV *sv, const case KEY_values: retsetpvs("\\[%@]", OP_VALUES); case KEY_each: retsetpvs("\\[%@]", OP_EACH); case KEY_pos: retsetpvs(";\\[$*]", OP_POS); + case KEY___CLASS__: case KEY___FILE__: case KEY___LINE__: case KEY___PACKAGE__: retsetpvs("", 0); case KEY_evalbytes: @@ -15613,8 +15891,10 @@ Perl_rcpv_new(pTHX_ const char *pv, STRL if (!pv && (flags & RCPVf_NO_COPY) == 0) return NULL; - if (flags & RCPVf_USE_STRLEN) + if (flags & RCPVf_USE_STRLEN) { + assert(pv); len = strlen(pv); + } assert(len || (flags & RCPVf_ALLOW_EMPTY)); @@ -15622,7 +15902,7 @@ Perl_rcpv_new(pTHX_ const char *pv, STRL rcpv = (RCPV *)PerlMemShared_malloc(sizeof(struct rcpv) + len); if (!rcpv) - croak_no_mem(); + croak_no_mem_ext(STR_WITH_LEN("op:rcpv_new")); rcpv->len = len; /* store length including null, RCPV_LEN() subtracts 1 to account for this */ Index: gnu/usr.bin/perl/opcode.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/opcode.h,v diff -u -p -a -u -p -r1.22 opcode.h --- gnu/usr.bin/perl/opcode.h 14 May 2024 19:38:54 -0000 1.22 +++ gnu/usr.bin/perl/opcode.h 22 Jan 2025 00:37:44 -0000 @@ -567,6 +567,7 @@ EXTCONST char* const PL_op_name[] INIT({ "helemexistsor", "methstart", "initfield", + "classname", "freed", }); @@ -992,6 +993,7 @@ EXTCONST char* const PL_op_desc[] INIT({ "hash element exists or", "method start", "initialise field", + "class name", "freed op", }); @@ -1422,6 +1424,7 @@ INIT({ Perl_pp_helemexistsor, Perl_pp_methstart, Perl_pp_initfield, + Perl_pp_classname, }); EXT Perl_check_t PL_check[] /* or perlvars.h */ @@ -1847,6 +1850,7 @@ INIT({ Perl_ck_helemexistsor, /* helemexistsor */ Perl_ck_null, /* methstart */ Perl_ck_null, /* initfield */ + Perl_ck_classname, /* classname */ }); EXTCONST U32 PL_opargs[] INIT({ @@ -1952,8 +1956,8 @@ EXTCONST U32 PL_opargs[] INIT({ 0x0001120e, /* sbit_and */ 0x0001120e, /* sbit_xor */ 0x0001120e, /* sbit_or */ - 0x0000112e, /* negate */ - 0x0000110e, /* i_negate */ + 0x0000113e, /* negate */ + 0x0000111e, /* i_negate */ 0x00001106, /* not */ 0x0000110e, /* complement */ 0x0000111e, /* ncomplement */ @@ -2014,7 +2018,7 @@ EXTCONST U32 PL_opargs[] INIT({ 0x00224200, /* lslice */ 0x00002405, /* anonlist */ 0x00002405, /* anonhash */ - 0x0000241c, /* emptyavhv */ + 0x0000001c, /* emptyavhv */ 0x02993401, /* splice */ 0x0002341d, /* push */ 0x0000bb04, /* pop */ @@ -2271,6 +2275,7 @@ EXTCONST U32 PL_opargs[] INIT({ 0x00011300, /* helemexistsor */ 0x00000f00, /* methstart */ 0x00000f00, /* initfield */ + 0x00000008, /* classname */ }); END_EXTERN_C @@ -2287,12 +2292,14 @@ END_EXTERN_C #define OPpTRANS_CAN_FORCE_UTF8 0x01 #define OPpARGELEM_AV 0x02 #define OPpCONST_NOVER 0x02 +#define OPpCONST_TOKEN_BITS 0x02 #define OPpCOREARGS_DEREF2 0x02 #define OPpEVAL_HAS_HH 0x02 #define OPpFT_ACCESS 0x02 #define OPpHINT_STRICT_REFS 0x02 #define OPpINITFIELD_AV 0x02 #define OPpITER_REVERSED 0x02 +#define OPpMETH_NO_BAREWORD_IO 0x02 #define OPpSORT_INTEGER 0x02 #define OPpTRANS_USE_SVOP 0x02 #define OPpARG2_MASK 0x03 @@ -2312,6 +2319,7 @@ END_EXTERN_C #define OPpTRANS_IDENTICAL 0x04 #define OPpUSEINT 0x04 #define OPpARGELEM_MASK 0x06 +#define OPpCONST_TOKEN_SHIFT 0x06 #define OPpARG3_MASK 0x07 #define OPpPADRANGE_COUNTSHIFT 0x07 #define OPpCONST_STRICT 0x08 @@ -2341,6 +2349,7 @@ END_EXTERN_C #define OPpSUBSTR_REPL_FIRST 0x10 #define OPpTARGET_MY 0x10 #define OPpASSIGN_COMMON_RC1 0x20 +#define OPpCONST_BARE 0x20 #define OPpDEREF_HV 0x20 #define OPpEARLY_CV 0x20 #define OPpEMPTYAVHV_IS_HV 0x20 @@ -2364,7 +2373,7 @@ END_EXTERN_C #define OPpASSIGN_BACKWARDS 0x40 #define OPpASSIGN_COMMON_SCALAR 0x40 #define OPpCONCAT_NESTED 0x40 -#define OPpCONST_BARE 0x40 +#define OPpCONST_TOKEN_LINE 0x40 #define OPpCOREARGS_SCALARMOD 0x40 #define OPpENTERSUB_DB 0x40 #define OPpEVAL_EVALSV 0x40 @@ -2384,6 +2393,7 @@ END_EXTERN_C #define OPpPADRANGE_COUNTMASK 0x7f #define OPpARG_IF_UNDEF 0x80 #define OPpASSIGN_CV_TO_GV 0x80 +#define OPpCONST_TOKEN_FILE 0x80 #define OPpCOREARGS_PUSHMARK 0x80 #define OPpDEFER_FINALLY 0x80 #define OPpENTERSUB_NOPAREN 0x80 @@ -2395,6 +2405,8 @@ END_EXTERN_C #define OPpOPEN_OUT_CRLF 0x80 #define OPpPV_IS_UTF8 0x80 #define OPpTRANS_DELETE 0x80 +#define OPpCONST_TOKEN_MASK 0xc0 +#define OPpCONST_TOKEN_PACKAGE 0xc0 START_EXTERN_C #ifndef DOINIT @@ -2455,6 +2467,7 @@ EXTCONST char PL_op_private_labels[] = { 'E','V','A','L','S','V','\0', 'E','X','I','S','T','S','\0', 'F','A','K','E','\0', + 'F','I','L','E','\0', 'F','I','N','A','L','L','Y','\0', 'F','T','A','C','C','E','S','S','\0', 'F','T','A','F','T','E','R','t','\0', @@ -2482,6 +2495,7 @@ EXTCONST char PL_op_private_labels[] = { 'K','E','Y','S','\0', 'K','V','S','L','I','C','E','\0', 'L','E','X','\0', + 'L','I','N','E','\0', 'L','I','N','E','N','U','M','\0', 'L','V','\0', 'L','V','D','E','F','E','R','\0', @@ -2493,10 +2507,12 @@ EXTCONST char PL_op_private_labels[] = { 'N','O','(',')','\0', 'N','O','I','N','I','T','\0', 'N','O','V','E','R','\0', + 'N','O','_','B','A','R','E','W','O','R','D','_','I','O','\0', 'N','U','M','\0', 'O','U','R','I','N','T','R','\0', 'O','U','T','B','I','N','\0', 'O','U','T','C','R','\0', + 'P','A','C','K','A','G','E','\0', 'R','E','F','C','\0', 'R','E','P','A','R','S','E','\0', 'R','E','P','L','1','S','T','\0', @@ -2513,6 +2529,7 @@ EXTCONST char PL_op_private_labels[] = { 'S','V','\0', 'T','A','R','G','\0', 'T','A','R','G','M','Y','\0', + 'T','O','K','E','N','\0', 'U','N','I','\0', 'U','S','E','I','N','T','\0', 'U','S','E','_','S','V','O','P','\0', @@ -2538,14 +2555,15 @@ EXTCONST char PL_op_private_labels[] = { EXTCONST I16 PL_op_private_bitfields[] = { 0, 8, -1, 0, 8, -1, - 0, 675, -1, + 0, 714, -1, 0, 8, -1, 0, 8, -1, - 0, 682, -1, - 0, 671, -1, - 1, -1, 0, 632, 1, 39, 2, 319, -1, + 0, 721, -1, + 0, 710, -1, + 1, -1, 0, 665, 1, 39, 2, 324, -1, 4, -1, 1, 185, 2, 192, 3, 199, -1, - 4, -1, 0, 632, 1, 39, 2, 319, 3, 131, -1, + 4, -1, 0, 665, 1, 39, 2, 324, 3, 131, -1, + 6, 680, 1, 455, 2, 246, 3, 567, -1, }; @@ -2560,26 +2578,26 @@ EXTCONST I16 PL_op_private_bitdef_ix[] 1, /* pushmark */ 3, /* wantarray */ 4, /* const */ - 9, /* gvsv */ - 11, /* gv */ - 12, /* gelem */ - 13, /* padsv */ - 16, /* padsv_store */ - 19, /* padav */ - 24, /* padhv */ + 10, /* gvsv */ + 12, /* gv */ + 13, /* gelem */ + 14, /* padsv */ + 17, /* padsv_store */ + 20, /* padav */ + 25, /* padhv */ -1, /* padany */ - 31, /* rv2gv */ - 38, /* rv2sv */ - 43, /* av2arylen */ - 45, /* rv2cv */ + 32, /* rv2gv */ + 39, /* rv2sv */ + 44, /* av2arylen */ + 46, /* rv2cv */ -1, /* anoncode */ 0, /* prototype */ 0, /* refgen */ 0, /* srefgen */ - 52, /* ref */ - 55, /* bless */ - 56, /* backtick */ - 55, /* glob */ + 53, /* ref */ + 56, /* bless */ + 57, /* backtick */ + 56, /* glob */ 0, /* readline */ -1, /* rcatline */ 0, /* regcmaybe */ @@ -2587,20 +2605,20 @@ EXTCONST I16 PL_op_private_bitdef_ix[] 0, /* regcomp */ -1, /* match */ -1, /* qr */ - 61, /* subst */ + 62, /* subst */ 0, /* substcont */ - 62, /* trans */ - 62, /* transr */ - 69, /* sassign */ - 72, /* aassign */ + 63, /* trans */ + 63, /* transr */ + 70, /* sassign */ + 73, /* aassign */ 0, /* chop */ 0, /* schop */ - 78, /* chomp */ - 78, /* schomp */ + 79, /* chomp */ + 79, /* schomp */ 0, /* defined */ - 80, /* undef */ + 81, /* undef */ 0, /* study */ - 85, /* pos */ + 86, /* pos */ 0, /* preinc */ 0, /* i_preinc */ 0, /* predec */ @@ -2609,314 +2627,314 @@ EXTCONST I16 PL_op_private_bitdef_ix[] 0, /* i_postinc */ 0, /* postdec */ 0, /* i_postdec */ - 88, /* pow */ - 88, /* multiply */ - 88, /* i_multiply */ - 88, /* divide */ - 88, /* i_divide */ - 88, /* modulo */ - 88, /* i_modulo */ - 90, /* repeat */ - 88, /* add */ - 88, /* i_add */ - 88, /* subtract */ - 88, /* i_subtract */ - 92, /* concat */ - 95, /* multiconcat */ - 101, /* stringify */ - 103, /* left_shift */ - 103, /* right_shift */ - 12, /* lt */ - 12, /* i_lt */ - 12, /* gt */ - 12, /* i_gt */ - 12, /* le */ - 12, /* i_le */ - 12, /* ge */ - 12, /* i_ge */ - 12, /* eq */ - 12, /* i_eq */ - 12, /* ne */ - 12, /* i_ne */ - 12, /* ncmp */ - 12, /* i_ncmp */ - 12, /* slt */ - 12, /* sgt */ - 12, /* sle */ - 12, /* sge */ - 12, /* seq */ - 12, /* sne */ - 12, /* scmp */ - 105, /* bit_and */ - 105, /* bit_xor */ - 105, /* bit_or */ - 103, /* nbit_and */ - 103, /* nbit_xor */ - 103, /* nbit_or */ - 105, /* sbit_and */ - 105, /* sbit_xor */ - 105, /* sbit_or */ - 0, /* negate */ - 0, /* i_negate */ + 89, /* pow */ + 89, /* multiply */ + 89, /* i_multiply */ + 89, /* divide */ + 89, /* i_divide */ + 89, /* modulo */ + 89, /* i_modulo */ + 91, /* repeat */ + 89, /* add */ + 89, /* i_add */ + 89, /* subtract */ + 89, /* i_subtract */ + 93, /* concat */ + 96, /* multiconcat */ + 102, /* stringify */ + 104, /* left_shift */ + 104, /* right_shift */ + 13, /* lt */ + 13, /* i_lt */ + 13, /* gt */ + 13, /* i_gt */ + 13, /* le */ + 13, /* i_le */ + 13, /* ge */ + 13, /* i_ge */ + 13, /* eq */ + 13, /* i_eq */ + 13, /* ne */ + 13, /* i_ne */ + 13, /* ncmp */ + 13, /* i_ncmp */ + 13, /* slt */ + 13, /* sgt */ + 13, /* sle */ + 13, /* sge */ + 13, /* seq */ + 13, /* sne */ + 13, /* scmp */ + 106, /* bit_and */ + 106, /* bit_xor */ + 106, /* bit_or */ + 104, /* nbit_and */ + 104, /* nbit_xor */ + 104, /* nbit_or */ + 106, /* sbit_and */ + 106, /* sbit_xor */ + 106, /* sbit_or */ + 79, /* negate */ + 79, /* i_negate */ 0, /* not */ - 105, /* complement */ - 103, /* ncomplement */ - 78, /* scomplement */ - 12, /* smartmatch */ - 101, /* atan2 */ - 78, /* sin */ - 78, /* cos */ - 101, /* rand */ - 101, /* srand */ - 78, /* exp */ - 78, /* log */ - 78, /* sqrt */ - 78, /* int */ - 78, /* hex */ - 78, /* oct */ - 78, /* abs */ - 106, /* length */ - 109, /* substr */ - 112, /* vec */ - 114, /* index */ - 114, /* rindex */ - 55, /* sprintf */ - 55, /* formline */ - 78, /* ord */ - 78, /* chr */ - 101, /* crypt */ + 106, /* complement */ + 104, /* ncomplement */ + 79, /* scomplement */ + 13, /* smartmatch */ + 102, /* atan2 */ + 79, /* sin */ + 79, /* cos */ + 102, /* rand */ + 102, /* srand */ + 79, /* exp */ + 79, /* log */ + 79, /* sqrt */ + 79, /* int */ + 79, /* hex */ + 79, /* oct */ + 79, /* abs */ + 107, /* length */ + 110, /* substr */ + 113, /* vec */ + 115, /* index */ + 115, /* rindex */ + 56, /* sprintf */ + 56, /* formline */ + 79, /* ord */ + 79, /* chr */ + 102, /* crypt */ 0, /* ucfirst */ 0, /* lcfirst */ 0, /* uc */ 0, /* lc */ 0, /* quotemeta */ - 118, /* rv2av */ - 125, /* aelemfast */ - 125, /* aelemfast_lex */ - 125, /* aelemfastlex_store */ - 126, /* aelem */ - 131, /* aslice */ - 134, /* kvaslice */ + 119, /* rv2av */ + 126, /* aelemfast */ + 126, /* aelemfast_lex */ + 126, /* aelemfastlex_store */ + 127, /* aelem */ + 132, /* aslice */ + 135, /* kvaslice */ 0, /* aeach */ 0, /* avalues */ - 43, /* akeys */ + 44, /* akeys */ 0, /* each */ - 43, /* values */ - 43, /* keys */ - 135, /* delete */ - 139, /* exists */ - 141, /* rv2hv */ - 126, /* helem */ - 131, /* hslice */ - 134, /* kvhslice */ - 149, /* multideref */ - 55, /* unpack */ - 55, /* pack */ - 156, /* split */ - 55, /* join */ - 161, /* list */ - 12, /* lslice */ - 55, /* anonlist */ - 55, /* anonhash */ - 163, /* emptyavhv */ - 55, /* splice */ - 101, /* push */ + 44, /* values */ + 44, /* keys */ + 136, /* delete */ + 140, /* exists */ + 142, /* rv2hv */ + 127, /* helem */ + 132, /* hslice */ + 135, /* kvhslice */ + 150, /* multideref */ + 56, /* unpack */ + 56, /* pack */ + 157, /* split */ + 56, /* join */ + 162, /* list */ + 13, /* lslice */ + 56, /* anonlist */ + 56, /* anonhash */ + 164, /* emptyavhv */ + 56, /* splice */ + 102, /* push */ 0, /* pop */ 0, /* shift */ - 101, /* unshift */ - 168, /* sort */ - 173, /* reverse */ + 102, /* unshift */ + 169, /* sort */ + 174, /* reverse */ 0, /* grepstart */ - 175, /* grepwhile */ + 176, /* grepwhile */ 0, /* mapstart */ 0, /* mapwhile */ 0, /* range */ - 177, /* flip */ - 177, /* flop */ + 178, /* flip */ + 178, /* flop */ 0, /* and */ 0, /* or */ - 12, /* xor */ + 13, /* xor */ 0, /* dor */ - 179, /* cond_expr */ + 180, /* cond_expr */ 0, /* andassign */ 0, /* orassign */ 0, /* dorassign */ - 181, /* entersub */ - 188, /* leavesub */ - 188, /* leavesublv */ + 182, /* entersub */ + 189, /* leavesub */ + 189, /* leavesublv */ 0, /* argcheck */ - 190, /* argelem */ - 192, /* argdefelem */ - 195, /* caller */ - 55, /* warn */ - 55, /* die */ - 55, /* reset */ + 191, /* argelem */ + 193, /* argdefelem */ + 196, /* caller */ + 56, /* warn */ + 56, /* die */ + 56, /* reset */ -1, /* lineseq */ - 197, /* nextstate */ - 197, /* dbstate */ + 198, /* nextstate */ + 198, /* dbstate */ -1, /* unstack */ -1, /* enter */ - 198, /* leave */ + 199, /* leave */ -1, /* scope */ - 200, /* enteriter */ - 204, /* iter */ + 201, /* enteriter */ + 205, /* iter */ -1, /* enterloop */ - 205, /* leaveloop */ + 206, /* leaveloop */ -1, /* return */ - 207, /* last */ - 207, /* next */ - 207, /* redo */ - 207, /* dump */ - 207, /* goto */ - 55, /* exit */ - 0, /* method */ - 0, /* method_named */ - 0, /* method_super */ - 0, /* method_redir */ - 0, /* method_redir_super */ + 208, /* last */ + 208, /* next */ + 208, /* redo */ + 208, /* dump */ + 210, /* goto */ + 56, /* exit */ + 213, /* method */ + 213, /* method_named */ + 213, /* method_super */ + 213, /* method_redir */ + 213, /* method_redir_super */ 0, /* entergiven */ 0, /* leavegiven */ 0, /* enterwhen */ 0, /* leavewhen */ -1, /* break */ -1, /* continue */ - 209, /* open */ - 55, /* close */ - 55, /* pipe_op */ - 55, /* fileno */ - 55, /* umask */ - 55, /* binmode */ - 55, /* tie */ + 215, /* open */ + 56, /* close */ + 56, /* pipe_op */ + 56, /* fileno */ + 56, /* umask */ + 56, /* binmode */ + 56, /* tie */ 0, /* untie */ 0, /* tied */ - 55, /* dbmopen */ + 56, /* dbmopen */ 0, /* dbmclose */ - 55, /* sselect */ - 55, /* select */ - 55, /* getc */ - 55, /* read */ - 55, /* enterwrite */ - 188, /* leavewrite */ + 56, /* sselect */ + 56, /* select */ + 56, /* getc */ + 56, /* read */ + 56, /* enterwrite */ + 189, /* leavewrite */ -1, /* prtf */ -1, /* print */ -1, /* say */ - 55, /* sysopen */ - 55, /* sysseek */ - 55, /* sysread */ - 55, /* syswrite */ - 55, /* eof */ - 55, /* tell */ - 55, /* seek */ - 55, /* truncate */ - 55, /* fcntl */ - 55, /* ioctl */ - 101, /* flock */ - 55, /* send */ - 55, /* recv */ - 55, /* socket */ - 55, /* sockpair */ - 55, /* bind */ - 55, /* connect */ - 55, /* listen */ - 55, /* accept */ - 55, /* shutdown */ - 55, /* gsockopt */ - 55, /* ssockopt */ + 56, /* sysopen */ + 56, /* sysseek */ + 56, /* sysread */ + 56, /* syswrite */ + 56, /* eof */ + 56, /* tell */ + 56, /* seek */ + 56, /* truncate */ + 56, /* fcntl */ + 56, /* ioctl */ + 102, /* flock */ + 56, /* send */ + 56, /* recv */ + 56, /* socket */ + 56, /* sockpair */ + 56, /* bind */ + 56, /* connect */ + 56, /* listen */ + 56, /* accept */ + 56, /* shutdown */ + 56, /* gsockopt */ + 56, /* ssockopt */ 0, /* getsockname */ 0, /* getpeername */ 0, /* lstat */ 0, /* stat */ - 214, /* ftrread */ - 214, /* ftrwrite */ - 214, /* ftrexec */ - 214, /* fteread */ - 214, /* ftewrite */ - 214, /* fteexec */ - 219, /* ftis */ - 219, /* ftsize */ - 219, /* ftmtime */ - 219, /* ftatime */ - 219, /* ftctime */ - 219, /* ftrowned */ - 219, /* fteowned */ - 219, /* ftzero */ - 219, /* ftsock */ - 219, /* ftchr */ - 219, /* ftblk */ - 219, /* ftfile */ - 219, /* ftdir */ - 219, /* ftpipe */ - 219, /* ftsuid */ - 219, /* ftsgid */ - 219, /* ftsvtx */ - 219, /* ftlink */ - 219, /* fttty */ - 219, /* fttext */ - 219, /* ftbinary */ - 101, /* chdir */ - 101, /* chown */ - 78, /* chroot */ - 101, /* unlink */ - 101, /* chmod */ - 101, /* utime */ - 101, /* rename */ - 101, /* link */ - 101, /* symlink */ + 220, /* ftrread */ + 220, /* ftrwrite */ + 220, /* ftrexec */ + 220, /* fteread */ + 220, /* ftewrite */ + 220, /* fteexec */ + 225, /* ftis */ + 225, /* ftsize */ + 225, /* ftmtime */ + 225, /* ftatime */ + 225, /* ftctime */ + 225, /* ftrowned */ + 225, /* fteowned */ + 225, /* ftzero */ + 225, /* ftsock */ + 225, /* ftchr */ + 225, /* ftblk */ + 225, /* ftfile */ + 225, /* ftdir */ + 225, /* ftpipe */ + 225, /* ftsuid */ + 225, /* ftsgid */ + 225, /* ftsvtx */ + 225, /* ftlink */ + 225, /* fttty */ + 225, /* fttext */ + 225, /* ftbinary */ + 102, /* chdir */ + 102, /* chown */ + 79, /* chroot */ + 102, /* unlink */ + 102, /* chmod */ + 102, /* utime */ + 102, /* rename */ + 102, /* link */ + 102, /* symlink */ 0, /* readlink */ - 101, /* mkdir */ - 78, /* rmdir */ - 55, /* open_dir */ + 102, /* mkdir */ + 79, /* rmdir */ + 56, /* open_dir */ 0, /* readdir */ 0, /* telldir */ - 55, /* seekdir */ + 56, /* seekdir */ 0, /* rewinddir */ 0, /* closedir */ -1, /* fork */ - 223, /* wait */ - 101, /* waitpid */ - 101, /* system */ - 101, /* exec */ - 101, /* kill */ - 223, /* getppid */ - 101, /* getpgrp */ - 101, /* setpgrp */ - 101, /* getpriority */ - 101, /* setpriority */ - 223, /* time */ + 229, /* wait */ + 102, /* waitpid */ + 102, /* system */ + 102, /* exec */ + 102, /* kill */ + 229, /* getppid */ + 102, /* getpgrp */ + 102, /* setpgrp */ + 102, /* getpriority */ + 102, /* setpriority */ + 229, /* time */ -1, /* tms */ 0, /* localtime */ - 55, /* gmtime */ + 56, /* gmtime */ 0, /* alarm */ - 101, /* sleep */ - 55, /* shmget */ - 55, /* shmctl */ - 55, /* shmread */ - 55, /* shmwrite */ - 55, /* msgget */ - 55, /* msgctl */ - 55, /* msgsnd */ - 55, /* msgrcv */ - 55, /* semop */ - 55, /* semget */ - 55, /* semctl */ + 102, /* sleep */ + 56, /* shmget */ + 56, /* shmctl */ + 56, /* shmread */ + 56, /* shmwrite */ + 56, /* msgget */ + 56, /* msgctl */ + 56, /* msgsnd */ + 56, /* msgrcv */ + 56, /* semop */ + 56, /* semget */ + 56, /* semctl */ 0, /* require */ 0, /* dofile */ -1, /* hintseval */ - 224, /* entereval */ - 188, /* leaveeval */ + 230, /* entereval */ + 189, /* leaveeval */ 0, /* entertry */ -1, /* leavetry */ 0, /* ghbyname */ - 55, /* ghbyaddr */ + 56, /* ghbyaddr */ -1, /* ghostent */ 0, /* gnbyname */ - 55, /* gnbyaddr */ + 56, /* gnbyaddr */ -1, /* gnetent */ 0, /* gpbyname */ - 55, /* gpbynumber */ + 56, /* gpbynumber */ -1, /* gprotoent */ - 55, /* gsbyname */ - 55, /* gsbyport */ + 56, /* gsbyname */ + 56, /* gsbyport */ -1, /* gservent */ 0, /* shostent */ 0, /* snetent */ @@ -2937,44 +2955,45 @@ EXTCONST I16 PL_op_private_bitdef_ix[] -1, /* sgrent */ -1, /* egrent */ -1, /* getlogin */ - 55, /* syscall */ + 56, /* syscall */ 0, /* lock */ 0, /* once */ -1, /* custom */ - 231, /* coreargs */ - 235, /* avhvswitch */ + 237, /* coreargs */ + 241, /* avhvswitch */ 3, /* runcv */ 0, /* fc */ -1, /* padcv */ -1, /* introcv */ -1, /* clonecv */ - 237, /* padrange */ - 239, /* refassign */ - 245, /* lvref */ - 251, /* lvrefslice */ - 16, /* lvavref */ + 243, /* padrange */ + 245, /* refassign */ + 251, /* lvref */ + 257, /* lvrefslice */ + 17, /* lvavref */ 0, /* anonconst */ - 12, /* isa */ + 13, /* isa */ 0, /* cmpchain_and */ 0, /* cmpchain_dup */ 0, /* entertrycatch */ -1, /* leavetrycatch */ -1, /* poptry */ 0, /* catch */ - 252, /* pushdefer */ + 258, /* pushdefer */ 0, /* is_bool */ 0, /* is_weak */ 0, /* weaken */ 0, /* unweaken */ - 52, /* blessed */ - 78, /* refaddr */ - 78, /* reftype */ - 78, /* ceil */ - 78, /* floor */ + 53, /* blessed */ + 260, /* refaddr */ + 260, /* reftype */ + 260, /* ceil */ + 260, /* floor */ 0, /* is_tainted */ - 254, /* helemexistsor */ - 256, /* methstart */ - 258, /* initfield */ + 263, /* helemexistsor */ + 265, /* methstart */ + 267, /* initfield */ + -1, /* classname */ }; @@ -2993,85 +3012,88 @@ EXTCONST I16 PL_op_private_bitdef_ix[] */ EXTCONST U16 PL_op_private_bitdefs[] = { - 0x0003, /* scalar, prototype, refgen, srefgen, readline, regcmaybe, regcreset, regcomp, substcont, chop, schop, defined, study, preinc, i_preinc, predec, i_predec, postinc, i_postinc, postdec, i_postdec, negate, i_negate, not, ucfirst, lcfirst, uc, lc, quotemeta, aeach, avalues, each, pop, shift, grepstart, mapstart, mapwhile, range, and, or, dor, andassign, orassign, dorassign, argcheck, method, method_named, method_super, method_redir, method_redir_super, entergiven, leavegiven, enterwhen, leavewhen, untie, tied, dbmclose, getsockname, getpeername, lstat, stat, readlink, readdir, telldir, rewinddir, closedir, localtime, alarm, require, dofile, entertry, ghbyname, gnbyname, gpbyname, shostent, snetent, sprotoent, sservent, gpwnam, gpwuid, ggrnam, ggrgid, lock, once, fc, anonconst, cmpchain_and, cmpchain_dup, entertrycatch, catch, is_bool, is_weak, weaken, unweaken, is_tainted */ - 0x3abc, 0x4bb9, /* pushmark */ + 0x0003, /* scalar, prototype, refgen, srefgen, readline, regcmaybe, regcreset, regcomp, substcont, chop, schop, defined, study, preinc, i_preinc, predec, i_predec, postinc, i_postinc, postdec, i_postdec, not, ucfirst, lcfirst, uc, lc, quotemeta, aeach, avalues, each, pop, shift, grepstart, mapstart, mapwhile, range, and, or, dor, andassign, orassign, dorassign, argcheck, entergiven, leavegiven, enterwhen, leavewhen, untie, tied, dbmclose, getsockname, getpeername, lstat, stat, readlink, readdir, telldir, rewinddir, closedir, localtime, alarm, require, dofile, entertry, ghbyname, gnbyname, gpbyname, shostent, snetent, sprotoent, sservent, gpwnam, gpwuid, ggrnam, ggrgid, lock, once, fc, anonconst, cmpchain_and, cmpchain_dup, entertrycatch, catch, is_bool, is_weak, weaken, unweaken, is_tainted */ + 0x3bfc, 0x4fd9, /* pushmark */ 0x00bd, /* wantarray, runcv */ - 0x0558, 0x1b70, 0x4c6c, 0x4808, 0x3fe5, /* const */ - 0x3abc, 0x4139, /* gvsv */ + 0x065e, 0x0554, 0x1b70, 0x508c, 0x4c28, 0x4125, /* const */ + 0x3bfc, 0x4459, /* gvsv */ 0x19d5, /* gv */ 0x0067, /* gelem, lt, i_lt, gt, i_gt, le, i_le, ge, i_ge, eq, i_eq, ne, i_ne, ncmp, i_ncmp, slt, sgt, sle, sge, seq, sne, scmp, smartmatch, lslice, xor, isa */ - 0x3abc, 0x4bb8, 0x03d7, /* padsv */ - 0x3abc, 0x4bb8, 0x0003, /* padsv_store, lvavref */ - 0x3abc, 0x4bb8, 0x06d4, 0x3bac, 0x4989, /* padav */ - 0x3abc, 0x4bb8, 0x06d4, 0x0770, 0x3bac, 0x4988, 0x3621, /* padhv */ - 0x3abc, 0x1e38, 0x03d6, 0x3bac, 0x3f08, 0x4c64, 0x0003, /* rv2gv */ - 0x3abc, 0x4138, 0x03d6, 0x4c64, 0x0003, /* rv2sv */ - 0x3bac, 0x0003, /* av2arylen, akeys, values, keys */ - 0x3e7c, 0x1198, 0x0ef4, 0x014c, 0x4f68, 0x4c64, 0x0003, /* rv2cv */ + 0x3bfc, 0x4fd8, 0x03d7, /* padsv */ + 0x3bfc, 0x4fd8, 0x0003, /* padsv_store, lvavref */ + 0x3bfc, 0x4fd8, 0x06d4, 0x3cec, 0x4da9, /* padav */ + 0x3bfc, 0x4fd8, 0x06d4, 0x0770, 0x3cec, 0x4da8, 0x36c1, /* padhv */ + 0x3bfc, 0x1e38, 0x03d6, 0x3cec, 0x4048, 0x5084, 0x0003, /* rv2gv */ + 0x3bfc, 0x4458, 0x03d6, 0x5084, 0x0003, /* rv2sv */ + 0x3cec, 0x0003, /* av2arylen, akeys, values, keys */ + 0x3fbc, 0x1198, 0x0ef4, 0x014c, 0x5388, 0x5084, 0x0003, /* rv2cv */ 0x06d4, 0x0770, 0x0003, /* ref, blessed */ 0x018f, /* bless, glob, sprintf, formline, unpack, pack, join, anonlist, anonhash, splice, warn, die, reset, exit, close, pipe_op, fileno, umask, binmode, tie, dbmopen, sselect, select, getc, read, enterwrite, sysopen, sysseek, sysread, syswrite, eof, tell, seek, truncate, fcntl, ioctl, send, recv, socket, sockpair, bind, connect, listen, accept, shutdown, gsockopt, ssockopt, open_dir, seekdir, gmtime, shmget, shmctl, shmread, shmwrite, msgget, msgctl, msgsnd, msgrcv, semop, semget, semctl, ghbyaddr, gnbyaddr, gpbynumber, gsbyname, gsbyport, syscall */ - 0x431c, 0x4238, 0x2dd4, 0x2d10, 0x0003, /* backtick */ + 0x463c, 0x4558, 0x2e74, 0x2db0, 0x0003, /* backtick */ 0x06d5, /* subst */ - 0x129c, 0x24b8, 0x0ad4, 0x4acc, 0x2848, 0x5244, 0x08e1, /* trans, transr */ + 0x129c, 0x2558, 0x0ad4, 0x4eec, 0x28e8, 0x5724, 0x08e1, /* trans, transr */ 0x10dc, 0x05f8, 0x0067, /* sassign */ - 0x0d98, 0x0c94, 0x0b90, 0x3bac, 0x06c8, 0x0067, /* aassign */ - 0x5010, 0x0003, /* chomp, schomp, scomplement, sin, cos, exp, log, sqrt, int, hex, oct, abs, ord, chr, chroot, rmdir, refaddr, reftype, ceil, floor */ - 0x3abc, 0x4bb8, 0x3534, 0x5010, 0x0003, /* undef */ - 0x06d4, 0x3bac, 0x0003, /* pos */ - 0x5010, 0x0067, /* pow, multiply, i_multiply, divide, i_divide, modulo, i_modulo, add, i_add, subtract, i_subtract */ + 0x0d98, 0x0c94, 0x0b90, 0x3cec, 0x06c8, 0x0067, /* aassign */ + 0x5430, 0x0003, /* chomp, schomp, negate, i_negate, scomplement, sin, cos, exp, log, sqrt, int, hex, oct, abs, ord, chr, chroot, rmdir */ + 0x3bfc, 0x4fd8, 0x35d4, 0x5430, 0x0003, /* undef */ + 0x06d4, 0x3cec, 0x0003, /* pos */ + 0x5430, 0x0067, /* pow, multiply, i_multiply, divide, i_divide, modulo, i_modulo, add, i_add, subtract, i_subtract */ 0x1658, 0x0067, /* repeat */ - 0x3d98, 0x5010, 0x0067, /* concat */ - 0x3abc, 0x0338, 0x1e34, 0x5010, 0x4d4c, 0x0003, /* multiconcat */ - 0x5010, 0x018f, /* stringify, atan2, rand, srand, crypt, push, unshift, flock, chdir, chown, unlink, chmod, utime, rename, link, symlink, mkdir, waitpid, system, exec, kill, getpgrp, setpgrp, getpriority, setpriority, sleep */ - 0x5010, 0x5169, /* left_shift, right_shift, nbit_and, nbit_xor, nbit_or, ncomplement */ - 0x5169, /* bit_and, bit_xor, bit_or, sbit_and, sbit_xor, sbit_or, complement */ - 0x06d4, 0x5010, 0x0003, /* length */ - 0x4570, 0x3bac, 0x012b, /* substr */ - 0x3bac, 0x0067, /* vec */ - 0x3d18, 0x06d4, 0x5010, 0x018f, /* index, rindex */ - 0x3abc, 0x4138, 0x06d4, 0x3bac, 0x4988, 0x4c64, 0x0003, /* rv2av */ + 0x3ed8, 0x5430, 0x0067, /* concat */ + 0x3bfc, 0x0338, 0x1e34, 0x5430, 0x516c, 0x0003, /* multiconcat */ + 0x5430, 0x018f, /* stringify, atan2, rand, srand, crypt, push, unshift, flock, chdir, chown, unlink, chmod, utime, rename, link, symlink, mkdir, waitpid, system, exec, kill, getpgrp, setpgrp, getpriority, setpriority, sleep */ + 0x5430, 0x5649, /* left_shift, right_shift, nbit_and, nbit_xor, nbit_or, ncomplement */ + 0x5649, /* bit_and, bit_xor, bit_or, sbit_and, sbit_xor, sbit_or, complement */ + 0x06d4, 0x5430, 0x0003, /* length */ + 0x4990, 0x3cec, 0x012b, /* substr */ + 0x3cec, 0x0067, /* vec */ + 0x3e58, 0x06d4, 0x5430, 0x018f, /* index, rindex */ + 0x3bfc, 0x4458, 0x06d4, 0x3cec, 0x4da8, 0x5084, 0x0003, /* rv2av */ 0x025f, /* aelemfast, aelemfast_lex, aelemfastlex_store */ - 0x3abc, 0x39b8, 0x03d6, 0x3bac, 0x0067, /* aelem, helem */ - 0x3abc, 0x3bac, 0x4989, /* aslice, hslice */ - 0x3bad, /* kvaslice, kvhslice */ - 0x3abc, 0x48d8, 0x36d4, 0x0003, /* delete */ - 0x4e98, 0x0003, /* exists */ - 0x3abc, 0x4138, 0x06d4, 0x0770, 0x3bac, 0x4988, 0x4c64, 0x3621, /* rv2hv */ - 0x3abc, 0x39b8, 0x1314, 0x1d50, 0x3bac, 0x4c64, 0x0003, /* multideref */ - 0x3abc, 0x4138, 0x0410, 0x37cc, 0x2b49, /* split */ - 0x3abc, 0x2579, /* list */ - 0x3abc, 0x4bb8, 0x0214, 0x5010, 0x018f, /* emptyavhv */ - 0x15b0, 0x330c, 0x4668, 0x3404, 0x40a1, /* sort */ - 0x330c, 0x0003, /* reverse */ + 0x3bfc, 0x3af8, 0x03d6, 0x3cec, 0x0067, /* aelem, helem */ + 0x3bfc, 0x3cec, 0x4da9, /* aslice, hslice */ + 0x3ced, /* kvaslice, kvhslice */ + 0x3bfc, 0x4cf8, 0x3774, 0x0003, /* delete */ + 0x52b8, 0x0003, /* exists */ + 0x3bfc, 0x4458, 0x06d4, 0x0770, 0x3cec, 0x4da8, 0x5084, 0x36c1, /* rv2hv */ + 0x3bfc, 0x3af8, 0x1314, 0x1d50, 0x3cec, 0x5084, 0x0003, /* multideref */ + 0x3bfc, 0x4458, 0x0410, 0x386c, 0x2be9, /* split */ + 0x3bfc, 0x2619, /* list */ + 0x3bfc, 0x4fd8, 0x0214, 0x5430, 0x018f, /* emptyavhv */ + 0x15b0, 0x33ac, 0x4a88, 0x34a4, 0x43c1, /* sort */ + 0x33ac, 0x0003, /* reverse */ 0x06d4, 0x0003, /* grepwhile */ - 0x3858, 0x0003, /* flip, flop */ - 0x3abc, 0x0003, /* cond_expr */ - 0x3abc, 0x1198, 0x03d6, 0x014c, 0x4f68, 0x4c64, 0x2c21, /* entersub */ - 0x43d8, 0x0003, /* leavesub, leavesublv, leavewrite, leaveeval */ + 0x3998, 0x0003, /* flip, flop */ + 0x3bfc, 0x0003, /* cond_expr */ + 0x3bfc, 0x1198, 0x03d6, 0x014c, 0x5388, 0x5084, 0x2cc1, /* entersub */ + 0x47f8, 0x0003, /* leavesub, leavesublv, leavewrite, leaveeval */ 0x02aa, 0x0003, /* argelem */ - 0x2a3c, 0x2918, 0x0003, /* argdefelem */ + 0x2adc, 0x29b8, 0x0003, /* argdefelem */ 0x00bc, 0x018f, /* caller */ - 0x2755, /* nextstate, dbstate */ - 0x395c, 0x43d9, /* leave */ - 0x3abc, 0x4138, 0x120c, 0x46e5, /* enteriter */ - 0x46e5, /* iter */ - 0x395c, 0x0067, /* leaveloop */ - 0x537c, 0x0003, /* last, next, redo, dump, goto */ - 0x431c, 0x4238, 0x2dd4, 0x2d10, 0x018f, /* open */ - 0x20f0, 0x234c, 0x2208, 0x1fc4, 0x0003, /* ftrread, ftrwrite, ftrexec, fteread, ftewrite, fteexec */ - 0x20f0, 0x234c, 0x2208, 0x0003, /* ftis, ftsize, ftmtime, ftatime, ftctime, ftrowned, fteowned, ftzero, ftsock, ftchr, ftblk, ftfile, ftdir, ftpipe, ftsuid, ftsgid, ftsvtx, ftlink, fttty, fttext, ftbinary */ - 0x5011, /* wait, getppid, time */ - 0x1c78, 0x4474, 0x0fb0, 0x082c, 0x50e8, 0x2664, 0x0003, /* entereval */ - 0x3c7c, 0x0018, 0x14c4, 0x13e1, /* coreargs */ - 0x3bac, 0x00c7, /* avhvswitch */ - 0x3abc, 0x01fb, /* padrange */ - 0x3abc, 0x4bb8, 0x04f6, 0x348c, 0x1ac8, 0x0067, /* refassign */ - 0x3abc, 0x4bb8, 0x04f6, 0x348c, 0x1ac8, 0x0003, /* lvref */ - 0x3abd, /* lvrefslice */ - 0x1edc, 0x0003, /* pushdefer */ + 0x27f5, /* nextstate, dbstate */ + 0x3a9c, 0x47f9, /* leave */ + 0x3bfc, 0x4458, 0x120c, 0x4b05, /* enteriter */ + 0x4b05, /* iter */ + 0x3a9c, 0x0067, /* leaveloop */ + 0x585c, 0x0003, /* last, next, redo, dump */ + 0x585c, 0x5388, 0x0003, /* goto */ + 0x41e4, 0x0003, /* method, method_named, method_super, method_redir, method_redir_super */ + 0x463c, 0x4558, 0x2e74, 0x2db0, 0x018f, /* open */ + 0x2190, 0x23ec, 0x22a8, 0x2064, 0x0003, /* ftrread, ftrwrite, ftrexec, fteread, ftewrite, fteexec */ + 0x2190, 0x23ec, 0x22a8, 0x0003, /* ftis, ftsize, ftmtime, ftatime, ftctime, ftrowned, fteowned, ftzero, ftsock, ftchr, ftblk, ftfile, ftdir, ftpipe, ftsuid, ftsgid, ftsvtx, ftlink, fttty, fttext, ftbinary */ + 0x5431, /* wait, getppid, time */ + 0x1c78, 0x4894, 0x0fb0, 0x082c, 0x55c8, 0x2704, 0x0003, /* entereval */ + 0x3dbc, 0x0018, 0x14c4, 0x13e1, /* coreargs */ + 0x3cec, 0x00c7, /* avhvswitch */ + 0x3bfc, 0x01fb, /* padrange */ + 0x3bfc, 0x4fd8, 0x04f6, 0x352c, 0x1ac8, 0x0067, /* refassign */ + 0x3bfc, 0x4fd8, 0x04f6, 0x352c, 0x1ac8, 0x0003, /* lvref */ + 0x3bfd, /* lvrefslice */ + 0x1f7c, 0x0003, /* pushdefer */ + 0x5430, 0x5388, 0x0003, /* refaddr, reftype, ceil, floor */ 0x131c, 0x0003, /* helemexistsor */ - 0x2e7c, 0x0003, /* methstart */ - 0x3168, 0x2fc4, 0x0003, /* initfield */ + 0x2f1c, 0x0003, /* methstart */ + 0x3208, 0x3064, 0x0003, /* initfield */ }; @@ -3085,7 +3107,7 @@ EXTCONST U8 PL_op_private_valid[] = { /* SCALAR */ (OPpARG1_MASK), /* PUSHMARK */ (OPpPAD_STATE|OPpLVAL_INTRO), /* WANTARRAY */ (OPpOFFBYONE), - /* CONST */ (OPpCONST_NOVER|OPpCONST_SHORTCIRCUIT|OPpCONST_STRICT|OPpCONST_ENTERED|OPpCONST_BARE), + /* CONST */ (OPpCONST_NOVER|OPpCONST_SHORTCIRCUIT|OPpCONST_STRICT|OPpCONST_ENTERED|OPpCONST_BARE|OPpCONST_TOKEN_MASK), /* GVSV */ (OPpOUR_INTRO|OPpLVAL_INTRO), /* GV */ (OPpEARLY_CV), /* GELEM */ (OPpARG2_MASK), @@ -3182,8 +3204,8 @@ EXTCONST U8 PL_op_private_valid[] = { /* SBIT_AND */ (OPpUSEINT), /* SBIT_XOR */ (OPpUSEINT), /* SBIT_OR */ (OPpUSEINT), - /* NEGATE */ (OPpARG1_MASK), - /* I_NEGATE */ (OPpARG1_MASK), + /* NEGATE */ (OPpARG1_MASK|OPpTARGET_MY), + /* I_NEGATE */ (OPpARG1_MASK|OPpTARGET_MY), /* NOT */ (OPpARG1_MASK), /* COMPLEMENT */ (OPpUSEINT), /* NCOMPLEMENT */ (OPpUSEINT|OPpTARGET_MY), @@ -3293,13 +3315,13 @@ EXTCONST U8 PL_op_private_valid[] = { /* NEXT */ (OPpARG1_MASK|OPpPV_IS_UTF8), /* REDO */ (OPpARG1_MASK|OPpPV_IS_UTF8), /* DUMP */ (OPpARG1_MASK|OPpPV_IS_UTF8), - /* GOTO */ (OPpARG1_MASK|OPpPV_IS_UTF8), + /* GOTO */ (OPpARG1_MASK|OPpENTERSUB_HASTARG|OPpPV_IS_UTF8), /* EXIT */ (OPpARG4_MASK), - /* METHOD */ (OPpARG1_MASK), - /* METHOD_NAMED */ (OPpARG1_MASK), - /* METHOD_SUPER */ (OPpARG1_MASK), - /* METHOD_REDIR */ (OPpARG1_MASK), - /* METHOD_REDIR_SUPER */ (OPpARG1_MASK), + /* METHOD */ (OPpARG1_MASK|OPpMETH_NO_BAREWORD_IO), + /* METHOD_NAMED */ (OPpARG1_MASK|OPpMETH_NO_BAREWORD_IO), + /* METHOD_SUPER */ (OPpARG1_MASK|OPpMETH_NO_BAREWORD_IO), + /* METHOD_REDIR */ (OPpARG1_MASK|OPpMETH_NO_BAREWORD_IO), + /* METHOD_REDIR_SUPER */ (OPpARG1_MASK|OPpMETH_NO_BAREWORD_IO), /* ENTERGIVEN */ (OPpARG1_MASK), /* LEAVEGIVEN */ (OPpARG1_MASK), /* ENTERWHEN */ (OPpARG1_MASK), @@ -3493,14 +3515,15 @@ EXTCONST U8 PL_op_private_valid[] = { /* WEAKEN */ (OPpARG1_MASK), /* UNWEAKEN */ (OPpARG1_MASK), /* BLESSED */ (OPpARG1_MASK|OPpMAYBE_TRUEBOOL|OPpTRUEBOOL), - /* REFADDR */ (OPpARG1_MASK|OPpTARGET_MY), - /* REFTYPE */ (OPpARG1_MASK|OPpTARGET_MY), - /* CEIL */ (OPpARG1_MASK|OPpTARGET_MY), - /* FLOOR */ (OPpARG1_MASK|OPpTARGET_MY), + /* REFADDR */ (OPpARG1_MASK|OPpENTERSUB_HASTARG|OPpTARGET_MY), + /* REFTYPE */ (OPpARG1_MASK|OPpENTERSUB_HASTARG|OPpTARGET_MY), + /* CEIL */ (OPpARG1_MASK|OPpENTERSUB_HASTARG|OPpTARGET_MY), + /* FLOOR */ (OPpARG1_MASK|OPpENTERSUB_HASTARG|OPpTARGET_MY), /* IS_TAINTED */ (OPpARG1_MASK), /* HELEMEXISTSOR */ (OPpARG1_MASK|OPpHELEMEXISTSOR_DELETE), /* METHSTART */ (OPpARG1_MASK|OPpINITFIELDS), /* INITFIELD */ (OPpARG1_MASK|OPpINITFIELD_AV|OPpINITFIELD_HV), + /* CLASSNAME */ (0), }; Index: gnu/usr.bin/perl/opnames.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/opnames.h,v diff -u -p -a -u -p -r1.6 opnames.h --- gnu/usr.bin/perl/opnames.h 14 May 2024 19:38:54 -0000 1.6 +++ gnu/usr.bin/perl/opnames.h 22 Jan 2025 00:37:44 -0000 @@ -435,10 +435,11 @@ typedef enum opcode { OP_HELEMEXISTSOR = 418, OP_METHSTART = 419, OP_INITFIELD = 420, + OP_CLASSNAME = 421, OP_max } opcode; -#define MAXO 421 +#define MAXO 422 #define OP_FREED MAXO /* the OP_IS_* macros are optimized to a simple range check because Index: gnu/usr.bin/perl/pad.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/pad.c,v diff -u -p -a -u -p -r1.7 pad.c --- gnu/usr.bin/perl/pad.c 14 May 2024 19:38:54 -0000 1.7 +++ gnu/usr.bin/perl/pad.c 22 Jan 2025 00:37:44 -0000 @@ -229,7 +229,9 @@ Perl_pad_new(pTHX_ int flags) if (flags & padnew_CLONE) { AV * const a0 = newAV(); /* will be @_ */ AvARRAY(pad)[0] = MUTABLE_SV(a0); +#ifndef PERL_RC_STACK AvREIFY_only(a0); +#endif PadnamelistREFCNT(padname = PL_comppad_name)++; } @@ -370,9 +372,7 @@ Perl_cv_undef_flags(pTHX_ CV *cv, U32 fl else CvGV_set(cv, NULL); } - /* This statement and the subsequence if block was pad_undef(). */ - pad_peg("pad_undef"); - + /* This 'if' block used to be a separate function, pad_undef(). */ if (!CvISXSUB(&cvbody) && CvPADLIST(&cvbody)) { PADOFFSET ix; const PADLIST *padlist = CvPADLIST(&cvbody); @@ -401,9 +401,12 @@ Perl_cv_undef_flags(pTHX_ CV *cv, U32 fl SV ** const curpad = AvARRAY(comppad); for (ix = PadnamelistMAX(comppad_name); ix > 0; ix--) { PADNAME * const name = namepad[ix]; - if (name && PadnamePV(name) && *PadnamePV(name) == '&') - { - CV * const innercv = MUTABLE_CV(curpad[ix]); + if (name && PadnamePV(name) && *PadnamePV(name) == '&') { + CV * const innercv = MUTABLE_CV(curpad[ix]); + if (PadnameIsOUR(name) && CvCLONED(&cvbody)) { + assert(!innercv); + } + else { U32 inner_rc; assert(innercv); assert(SvTYPE(innercv) != SVt_PVFM); @@ -433,6 +436,7 @@ Perl_cv_undef_flags(pTHX_ CV *cv, U32 fl } } } + } } } @@ -535,8 +539,8 @@ pad (via L) and then stores a name for that entry. C is adopted and becomes the name entry; it must already contain the name string. C and C and the C -flag get added to C. None of the other -processing of L +flag gets added to C. +None of the other processing of L is done. Returns the offset of the allocated pad slot. =cut @@ -584,7 +588,8 @@ variable. Stores the name and other met pad, and makes preparations to manage the variable's lexical scoping. Returns the offset of the allocated pad slot. -C/C specify the variable's name, including leading sigil. +C/C specify the variable's name in UTF-8, including +leading sigil. If C is non-null, the name is for a typed lexical, and this identifies the type. If C is non-null, it's a lexical reference to a package variable, and this identifies the package. The following @@ -613,7 +618,7 @@ Perl_pad_add_name_pvn(pTHX_ const char * name = newPADNAMEpvn(namepv, namelen); - if ((flags & padadd_NO_DUP_CHECK) == 0) { + if ((flags & (padadd_NO_DUP_CHECK)) == 0) { ENTER; SAVEFREEPADNAME(name); /* in case of fatal warnings */ /* check for duplicate declaration */ @@ -812,7 +817,6 @@ Perl_pad_add_anon(pTHX_ CV* func, I32 op PERL_ARGS_ASSERT_PAD_ADD_ANON; assert (SvTYPE(func) == SVt_PVCV); - pad_peg("add_anon"); /* These two aren't used; just make sure they're not equal to * PERL_PADSEQ_INTRO. They should be 0 by default. */ assert(COP_SEQ_RANGE_LOW (name) != PERL_PADSEQ_INTRO); @@ -964,8 +968,6 @@ Perl_pad_findmy_pvn(pTHX_ const char *na PERL_ARGS_ASSERT_PAD_FINDMY_PVN; - pad_peg("pad_findmy_pvn"); - if (flags) Perl_croak(aTHX_ "panic: pad_findmy_pvn illegal flag bits 0x%" UVxf, (UV)flags); @@ -1679,7 +1681,6 @@ Perl_pad_tidy(pTHX_ padtidy_type type) "Pad clone on cv=0x%" UVxf "\n", PTR2UV(cv))); CvCLONE_on(cv); } - CvHASEVAL_on(cv); } } @@ -1714,7 +1715,9 @@ Perl_pad_tidy(pTHX_ padtidy_type type) else if (type == padtidy_SUB) { AV * const av = newAV(); /* Will be @_ */ av_store(PL_comppad, 0, MUTABLE_SV(av)); +#ifndef PERL_RC_STACK AvREIFY_only(av); +#endif } if (type == padtidy_SUB || type == padtidy_FORMAT) { @@ -1969,8 +1972,7 @@ S_cv_clone_pad(pTHX_ CV *proto, CV *cv, PL_compcv = cv; if (newcv) SAVEFREESV(cv); /* in case of fatal warnings */ - if (CvHASEVAL(cv)) - CvOUTSIDE(cv) = MUTABLE_CV(SvREFCNT_inc_simple(outside)); + CvOUTSIDE(cv) = MUTABLE_CV(SvREFCNT_inc_simple(outside)); SAVESPTR(PL_comppad_name); PL_comppad_name = protopad_name; @@ -2233,7 +2235,7 @@ S_cv_clone(pTHX_ CV *proto, CV *cv, CV * if (UNLIKELY(CvISXSUB(proto))) { CvXSUB(cv) = CvXSUB(proto); CvXSUBANY(cv) = CvXSUBANY(proto); - if (CvREFCOUNTED_ANYSV(cv)) + if (CvREFCOUNTED_ANYSV(cv) || CvCONST(cv)) SvREFCNT_inc(CvXSUBANY(cv).any_sv); } else { @@ -2445,8 +2447,19 @@ Perl_pad_push(pTHX_ PADLIST *padlist, in || PadnameIsSTATE(names[ix]) || sigil == '&') { - /* outer lexical or anon code */ - sv = SvREFCNT_inc(oldpad[ix]); + SV *tmp = oldpad[ix]; + if (sigil == '&' && SvTYPE(tmp) == SVt_PVCV + && !PadnameOUTER(names[ix]) + && CvLEXICAL(tmp) && CvCLONED(tmp) + && !PadnameIsOUR(names[ix]) + && !PadnameIsSTATE(names[ix])) { + /* lexical sub that needs cloning */ + sv = newSV_type(SVt_PVCV); + } + else { + /* outer non-cloning lexical or anon code */ + sv = SvREFCNT_inc(tmp); + } } else { /* our own lexical */ if (sigil == '@') @@ -2469,7 +2482,9 @@ Perl_pad_push(pTHX_ PADLIST *padlist, in } av = newAV(); AvARRAY(newpad)[0] = MUTABLE_SV(av); +#ifndef PERL_RC_STACK AvREIFY_only(av); +#endif padlist_store(padlist, depth, newpad); } @@ -2582,7 +2597,9 @@ Perl_padlist_dup(pTHX_ PADLIST *srcpad, if (oldpad[0]) { args = newAV(); /* Will be @_ */ +#ifndef PERL_RC_STACK AvREIFY_only(args); +#endif pad1a[0] = (SV *)args; } } @@ -2915,8 +2932,8 @@ block. suspend_compcv(&buffer); LEAVE; -Once suspended, the C or C function can -later be used to continue the parsing from the point this stopped. +Once suspended, the C or C +function can later be used to continue the parsing from the point this stopped. =cut */ Index: gnu/usr.bin/perl/pad.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/pad.h,v diff -u -p -a -u -p -r1.6 pad.h --- gnu/usr.bin/perl/pad.h 14 May 2024 19:38:54 -0000 1.6 +++ gnu/usr.bin/perl/pad.h 22 Jan 2025 00:37:44 -0000 @@ -155,18 +155,14 @@ typedef enum { * whether PL_comppad and PL_curpad are consistent and whether they have * active values */ -# define pad_peg(label) - #ifdef DEBUGGING # define ASSERT_CURPAD_LEGAL(label) \ - pad_peg(label); \ if (PL_comppad ? (AvARRAY(PL_comppad) != PL_curpad) : (PL_curpad != 0)) \ Perl_croak(aTHX_ "panic: illegal pad in %s: 0x%" UVxf "[0x%" UVxf "]",\ label, PTR2UV(PL_comppad), PTR2UV(PL_curpad)); # define ASSERT_CURPAD_ACTIVE(label) \ - pad_peg(label); \ if (!PL_comppad || (AvARRAY(PL_comppad) != PL_curpad)) \ Perl_croak(aTHX_ "panic: invalid pad in %s: 0x%" UVxf "[0x%" UVxf "]",\ label, PTR2UV(PL_comppad), PTR2UV(PL_curpad)); @@ -359,15 +355,15 @@ Restore the old pad saved into the local #define PadnameLVALUE(pn) (PadnameFLAGS(pn) & PADNAMEf_LVALUE) #define PadnameIsFIELD(pn) (PadnameFLAGS(pn) & PADNAMEf_FIELD) -#define PadnameLVALUE_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_LVALUE) -#define PadnameIsSTATE_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_STATE) +#define PadnameLVALUE_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_LVALUE) +#define PadnameIsSTATE_on(pn) (PadnameFLAGS(pn) |= PADNAMEf_STATE) -#define PADNAMEf_OUTER 0x01 /* outer lexical var */ -#define PADNAMEf_STATE 0x02 /* state var */ -#define PADNAMEf_LVALUE 0x04 /* used as lvalue */ -#define PADNAMEf_TYPED 0x08 /* for B; unused by core */ -#define PADNAMEf_OUR 0x10 /* for B; unused by core */ -#define PADNAMEf_FIELD 0x20 /* field var */ +#define PADNAMEf_OUTER 0x01 /* outer lexical var */ +#define PADNAMEf_STATE 0x02 /* state var */ +#define PADNAMEf_LVALUE 0x04 /* used as lvalue */ +#define PADNAMEf_TYPED 0x08 /* for B; unused by core */ +#define PADNAMEf_OUR 0x10 /* for B; unused by core */ +#define PADNAMEf_FIELD 0x20 /* field var */ /* backward compatibility */ #ifndef PERL_CORE Index: gnu/usr.bin/perl/patchlevel.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/patchlevel.h,v diff -u -p -a -u -p -r1.55 patchlevel.h --- gnu/usr.bin/perl/patchlevel.h 14 May 2024 19:38:54 -0000 1.55 +++ gnu/usr.bin/perl/patchlevel.h 22 Jan 2025 00:37:44 -0000 @@ -38,8 +38,8 @@ Instead use one of the version compariso * exactly on the third column */ #define PERL_REVISION 5 /* age */ -#define PERL_VERSION 38 /* epoch */ -#define PERL_SUBVERSION 2 /* generation */ +#define PERL_VERSION 40 /* epoch */ +#define PERL_SUBVERSION 1 /* generation */ /* The following numbers describe the earliest compatible version of Perl ("compatibility" here being defined as sufficient binary/API @@ -59,7 +59,7 @@ Instead use one of the version compariso changing them should not be necessary. */ #define PERL_API_REVISION 5 -#define PERL_API_VERSION 38 +#define PERL_API_VERSION 40 #define PERL_API_SUBVERSION 0 /* XXX Note: The selection of non-default Configure options, such @@ -149,9 +149,6 @@ hunk. #if !defined(PERL_PATCHLEVEL_H_IMPLICIT) && !defined(LOCAL_PATCH_COUNT) # if defined(PERL_IS_MINIPERL) # define PERL_PATCHNUM "UNKNOWN-miniperl" -# define PERL_GIT_UNPUSHED_COMMITS /*leave-this-comment*/ -# elif defined(PERL_MICRO) -# define PERL_PATCHNUM "UNKNOWN-microperl" # define PERL_GIT_UNPUSHED_COMMITS /*leave-this-comment*/ # else # include "git_version.h" Index: gnu/usr.bin/perl/peep.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/peep.c,v diff -u -p -a -u -p -r1.1.1.1 peep.c --- gnu/usr.bin/perl/peep.c 14 May 2024 19:36:27 -0000 1.1.1.1 +++ gnu/usr.bin/perl/peep.c 22 Jan 2025 00:37:44 -0000 @@ -997,6 +997,23 @@ S_maybe_multiconcat(pTHX_ OP *o) o->op_type = OP_MULTICONCAT; o->op_ppaddr = PL_ppaddr[OP_MULTICONCAT]; cUNOP_AUXo->op_aux = aux; + + + /* add some PADTMPs, as needed, for the 'fallback to OP_CONCAT + * behaviour if magic / overloaded etc present' code path */ + + /* general PADTMP for the target of each concat */ + aux[PERL_MULTICONCAT_IX_PADTMP0].pad_offset = + pad_alloc(OP_MULTICONCAT, SVs_PADTMP); + + /* PADTMP for recreating OP_CONST return values */ + aux[PERL_MULTICONCAT_IX_PADTMP1].pad_offset = + (is_sprintf || nconst) ? pad_alloc(OP_MULTICONCAT, SVs_PADTMP) : 0; + + /* PADTMP for stringifying the result */ + aux[PERL_MULTICONCAT_IX_PADTMP2].pad_offset = + (o->op_private &OPpMULTICONCAT_STRINGIFY) + ? pad_alloc(OP_MULTICONCAT, SVs_PADTMP) : 0; } @@ -3151,62 +3168,6 @@ Perl_rpeep(pTHX_ OP *o) } } - /* If the pushmark is associated with an empty anonhash - * or anonlist, null out the pushmark and swap in a - * specialised op for the parent. - * 4 <@> anonhash sK* ->5 - * 3 <0> pushmark s ->4 - * becomes: - * 3 <@> emptyavhv sK* ->4 - * - <0> pushmark s ->3 - */ - if (!OpHAS_SIBLING(o) && (o->op_next == o->op_sibparent) && ( - (o->op_next->op_type == OP_ANONHASH) || - (o->op_next->op_type == OP_ANONLIST) ) && - (o->op_next->op_flags & OPf_SPECIAL) ) { - - OP* anon = o->op_next; - /* These next two are _potentially_ a padsv and an sassign */ - OP* padsv = anon->op_next; - OP* sassign = (padsv) ? padsv->op_next: NULL; - - anon->op_private = (anon->op_type == OP_ANONLIST) ? - 0 : OPpEMPTYAVHV_IS_HV; - OpTYPE_set(anon, OP_EMPTYAVHV); - op_null(o); - o = anon; - if (oldop) /* A previous optimization may have NULLED it */ - oldop->op_next = anon; - - /* Further optimise scalar assignment of an empty anonhash - * or anonlist by subsuming the padsv & sassign OPs. */ - if ((padsv->op_type == OP_PADSV) && - !(padsv->op_private & OPpDEREF) && - sassign && (sassign->op_type == OP_SASSIGN) ){ - - /* Take some public flags from the sassign */ - anon->op_flags = OPf_KIDS | OPf_SPECIAL | - (anon->op_flags & OPf_PARENS) | - (sassign->op_flags & (OPf_WANT|OPf_PARENS)); - - /* Take some private flags from the padsv */ - anon->op_private |= OPpTARGET_MY | - (padsv->op_private & (OPpLVAL_INTRO|OPpPAD_STATE)); - - /* Take the targ slot from the padsv*/ - anon->op_targ = padsv->op_targ; - padsv->op_targ = 0; - - /* Clean up */ - anon->op_next = sassign->op_next; - op_null(padsv); - op_null(sassign); - } - break; - - } - - /* Convert a series of PAD ops for my vars plus support into a * single padrange op. Basically * @@ -4019,6 +3980,11 @@ Perl_rpeep(pTHX_ OP *o) if (!(o->op_private & (OPpASSIGN_BACKWARDS|OPpASSIGN_CV_TO_GV)) && (lval->op_type == OP_NULL) && (lval->op_private == 2) && (cBINOPx(lval)->op_first->op_type == OP_AELEMFAST_LEX) + /* For efficiency, pp_aelemfastlex_store() doesn't push its + * result onto the stack. For the relatively rare case of + * the array assignment not in void context, we just do it + * the old slow way. */ + && OP_GIMME(o,0) == G_VOID ) { OP * lex = cBINOPx(lval)->op_first; /* SASSIGN's bitfield flags, such as op_moresib and Index: gnu/usr.bin/perl/perl.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/perl.c,v diff -u -p -a -u -p -r1.47 perl.c --- gnu/usr.bin/perl/perl.c 14 May 2024 19:39:39 -0000 1.47 +++ gnu/usr.bin/perl/perl.c 22 Jan 2025 00:37:44 -0000 @@ -4,6 +4,7 @@ * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 * 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 * 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 + * 2024, 2025 * by Larry Wall and others * * You may distribute under the terms of either the GNU General Public @@ -408,11 +409,9 @@ perl_construct(pTHXx) Zero(PL_sv_consts, SV_CONSTS_COUNT, SV*); -#ifndef PERL_MICRO -# ifdef USE_ENVIRON_ARRAY +#ifdef USE_ENVIRON_ARRAY if (!PL_origenviron) PL_origenviron = environ; -# endif #endif /* Use sysconf(_SC_CLK_TCK) if available, if not @@ -1128,7 +1127,7 @@ perl_destruct(pTHXx) PL_curlocales[i] = NULL; } #endif -#ifdef USE_POSIX_2008_LOCALE +#if defined(USE_POSIX_2008_LOCALE) && defined(MULTIPLICITY) { /* This also makes sure we aren't using a locale object that gets freed * below */ @@ -1160,15 +1159,6 @@ perl_destruct(pTHXx) freelocale(PL_scratch_locale_obj); PL_scratch_locale_obj = NULL; } -# ifdef USE_LOCALE_NUMERIC - if (PL_underlying_numeric_obj) { - DEBUG_Lv(PerlIO_printf(Perl_debug_log, - "%s:%d: Freeing %p\n", __FILE__, __LINE__, - PL_underlying_numeric_obj)); - freelocale(PL_underlying_numeric_obj); - PL_underlying_numeric_obj = (locale_t) NULL; - } -# endif #endif #ifdef USE_LOCALE_NUMERIC Safefree(PL_numeric_name); @@ -1188,15 +1178,17 @@ perl_destruct(pTHXx) PL_setlocale_buf = NULL; } - if (PL_langinfo_buf) { - Safefree(PL_langinfo_buf); - PL_langinfo_buf = NULL; - } - - if (PL_stdize_locale_buf) { - Safefree(PL_stdize_locale_buf); - PL_stdize_locale_buf = NULL; + SvREFCNT_dec(PL_langinfo_sv); + PL_langinfo_sv = NULL; + SvREFCNT_dec(PL_scratch_langinfo); + PL_scratch_langinfo = NULL; + +#if defined(USE_LOCALE_THREADS) && ! defined(USE_THREAD_SAFE_LOCALE) + if (PL_less_dicey_locale_buf) { + Safefree(PL_less_dicey_locale_buf); + PL_less_dicey_locale_buf = NULL; } +#endif #ifdef USE_LOCALE_CTYPE SvREFCNT_dec(PL_warn_locale); @@ -1903,10 +1895,9 @@ perl_parse(pTHXx_ XSINIT_t xsinit, int a return 0; } - if (PL_main_root) { - op_free(PL_main_root); - PL_main_root = NULL; - } + op_free(PL_main_root); + PL_main_root = NULL; + PL_main_start = NULL; SvREFCNT_dec(PL_main_cv); PL_main_cv = NULL; @@ -2043,6 +2034,9 @@ S_Internals_V(pTHX_ CV *cv) # ifdef PERL_PRESERVE_IVUV " PERL_PRESERVE_IVUV" # endif +# ifdef PERL_RC_STACK + " PERL_RC_STACK" +# endif # ifdef PERL_RELOCATABLE_INCPUSH " PERL_RELOCATABLE_INCPUSH" # endif @@ -2128,6 +2122,56 @@ S_Internals_V(pTHX_ CV *cv) XSRETURN(entries); } +static const char * +S_moreswitch_m(pTHX_ char option, const char *s) +{ + const char *start; + const char *end; + SV *sv; + const char *use = "use "; + bool colon = FALSE; + /* -M-foo == 'no foo' */ + /* Leading space on " no " is deliberate, to make both + possibilities the same length. */ + if (*s == '-') { use = " no "; ++s; } + sv = newSVpvn(use,4); + start = s; + /* We allow -M'Module qw(Foo Bar)' */ + while(isWORDCHAR(*s) || *s==':') { + if( *s++ == ':' ) { + if( *s == ':' ) + s++; + else + colon = TRUE; + } + } + if (s == start) + Perl_croak(aTHX_ "Module name required with -%c option", + option); + if (colon) + Perl_croak(aTHX_ "Invalid module name %.*s with -%c option: " + "contains single ':'", + (int)(s - start), start, option); + end = s + strlen(s); + if (*s != '=') { + sv_catpvn(sv, start, end - start); + if (option == 'm') { + if (*s != '\0') + Perl_croak(aTHX_ "Can't use '%c' after -mname", *s); + sv_catpvs( sv, " ()"); + } + } else { + sv_catpvn(sv, start, s-start); + /* Use NUL as q''-delimiter. */ + sv_catpvs(sv, " split(/,/,q\0"); + ++s; + sv_catpvn(sv, s, end - s); + sv_catpvs(sv, "\0)"); + } + Perl_av_create_and_push(aTHX_ &PL_preambleav, sv); + return end; +} + #define INCPUSH_UNSHIFT 0x01 #define INCPUSH_ADD_OLD_VERS 0x02 #define INCPUSH_ADD_VERSIONED_SUB_DIRS 0x04 @@ -2184,8 +2228,6 @@ S_parse_body(pTHX_ char **env, XSINIT_t case 'h': case 'i': case 'l': - case 'M': - case 'm': case 'n': case 'p': case 's': @@ -2199,6 +2241,21 @@ S_parse_body(pTHX_ char **env, XSINIT_t goto reswitch; break; + case 'M': + forbid_setid('M', FALSE); /* XXX ? */ + /* FALLTHROUGH */ + case 'm': + forbid_setid('m', FALSE); /* XXX ? */ + if (*++s) /* -MModule */ + s = S_moreswitch_m(aTHX_ c, s); + else if(argc && argv[1]) { /* -M Module */ + argc--; argv++; + s = S_moreswitch_m(aTHX_ c, *argv); + } + else + croak("Missing argument to -%c", c); + break; + case 't': #if defined(SILENT_NO_TAINT_SUPPORT) /* silently ignore */ @@ -2479,12 +2536,11 @@ S_parse_body(pTHX_ char **env, XSINIT_t validate_suid(rsfp); -#ifndef PERL_MICRO -# if defined(SIGCHLD) || defined(SIGCLD) +#if defined(SIGCHLD) || defined(SIGCLD) { -# ifndef SIGCHLD -# define SIGCHLD SIGCLD -# endif +#ifndef SIGCHLD +# define SIGCHLD SIGCLD +#endif Sighandler_t sigstate = rsignal_state(SIGCHLD); if (sigstate == (Sighandler_t) SIG_IGN) { Perl_ck_warner(aTHX_ packWARN(WARN_SIGNAL), @@ -2492,7 +2548,6 @@ S_parse_body(pTHX_ char **env, XSINIT_t (void)rsignal(SIGCHLD, (Sighandler_t)SIG_DFL); } } -# endif #endif if (doextract) { @@ -2525,11 +2580,9 @@ S_parse_body(pTHX_ char **env, XSINIT_t if (xsinit) (*xsinit)(aTHX); /* in case linked C routines want magical variables */ -#ifndef PERL_MICRO #if defined(VMS) || defined(WIN32) || defined(__CYGWIN__) init_os_extras(); #endif -#endif #ifdef USE_SOCKS # ifdef HAS_SOCKS5_INIT @@ -2975,22 +3028,29 @@ Approximate Perl equivalent: C<&{"$sub_n =cut */ -I32 +SSize_t Perl_call_argv(pTHX_ const char *sub_name, I32 flags, char **argv) /* See G_* flags in cop.h */ /* null terminated arg list */ { - dSP; - PERL_ARGS_ASSERT_CALL_ARGV; - PUSHMARK(SP); + bool is_rc = +#ifdef PERL_RC_STACK + rpp_stack_is_rc(); +#else + 0; +#endif + PUSHMARK(PL_stack_sp); while (*argv) { - mXPUSHs(newSVpv(*argv,0)); + SV *newsv = newSVpv(*argv,0); + rpp_extend(1); + *++PL_stack_sp = newsv; + if (!is_rc) + sv_2mortal(newsv); argv++; } - PUTBACK; return call_pv(sub_name, flags); } @@ -3002,7 +3062,7 @@ Performs a callback to the specified Per =cut */ -I32 +SSize_t Perl_call_pv(pTHX_ const char *sub_name, I32 flags) /* name of the subroutine */ /* See G_* flags in cop.h */ @@ -3021,7 +3081,7 @@ be on the stack. See L. =cut */ -I32 +SSize_t Perl_call_method(pTHX_ const char *methname, I32 flags) /* name of the subroutine */ /* See G_* flags in cop.h */ @@ -3065,17 +3125,21 @@ See L. =cut */ -I32 -Perl_call_sv(pTHX_ SV *sv, volatile I32 flags) +SSize_t +Perl_call_sv(pTHX_ SV *sv, I32 arg_flags) /* See G_* flags in cop.h */ { LOGOP myop; /* fake syntax tree node */ METHOP method_op; - I32 oldmark; - volatile I32 retval = 0; + SSize_t oldmark; + volatile SSize_t retval = 0; bool oldcatch = CATCH_GET; int ret; OP* const oldop = PL_op; + /* Since we don't modify flags after setjmp() we don't really need to make + flags volatile, but gcc complains that it could be clobbered anyway. + */ + volatile I32 flags = arg_flags; dJMPENV; PERL_ARGS_ASSERT_CALL_SV; @@ -3100,10 +3164,12 @@ Perl_call_sv(pTHX_ SV *sv, volatile I32 PL_op = (OP*)&myop; if (!(flags & G_METHOD_NAMED)) { - dSP; - EXTEND(SP, 1); - PUSHs(sv); - PUTBACK; + rpp_extend(1); + *++PL_stack_sp = sv; +#ifdef PERL_RC_STACK + if (rpp_stack_is_rc()) + SvREFCNT_inc_simple_void_NN(sv); +#endif } oldmark = TOPMARK; @@ -3141,7 +3207,7 @@ Perl_call_sv(pTHX_ SV *sv, volatile I32 myop.op_other = (OP*)&myop; (void)POPMARK; old_cxix = cxstack_ix; - create_eval_scope(NULL, flags|G_FAKINGEVAL); + create_eval_scope( NULL, PL_stack_base + oldmark, flags|G_FAKINGEVAL); INCMARK; JMPENV_PUSH(ret); @@ -3172,6 +3238,11 @@ Perl_call_sv(pTHX_ SV *sv, volatile I32 PL_restartop = 0; goto redo_body; } + /* Should be nothing left in stack frame apart from a possible + * scalar context undef. Assert it's safe to reset the stack */ + assert( PL_stack_sp == PL_stack_base + oldmark + || (PL_stack_sp == PL_stack_base + oldmark + 1 + && *PL_stack_sp == &PL_sv_undef)); PL_stack_sp = PL_stack_base + oldmark; if ((flags & G_WANT) == G_LIST) retval = 0; @@ -3193,7 +3264,12 @@ Perl_call_sv(pTHX_ SV *sv, volatile I32 } if (flags & G_DISCARD) { - PL_stack_sp = PL_stack_base + oldmark; +#ifdef PERL_RC_STACK + if (rpp_stack_is_rc()) + rpp_popfree_to(PL_stack_base + oldmark); + else +#endif + PL_stack_sp = PL_stack_base + oldmark; retval = 0; FREETMPS; LEAVE; @@ -3213,18 +3289,23 @@ as C, with the obvious exceptio The C flag can be used if you only need eval_sv() to execute code specified by a string, but not catch any errors. +By default the code is compiled and executed with the default hints, +such as strict and features. Set C in flags to use the +current hints from C. + =for apidoc Amnh||G_RETHROW +=for apidoc Amnh||G_USEHINTS =cut */ -I32 +SSize_t Perl_eval_sv(pTHX_ SV *sv, I32 flags) /* See G_* flags in cop.h */ { UNOP myop; /* fake syntax tree node */ - volatile I32 oldmark; - volatile I32 retval = 0; + volatile SSize_t oldmark; + volatile SSize_t retval = 0; int ret; OP* const oldop = PL_op; dJMPENV; @@ -3242,13 +3323,13 @@ Perl_eval_sv(pTHX_ SV *sv, I32 flags) myop.op_ppaddr = PL_ppaddr[OP_ENTEREVAL]; myop.op_type = OP_ENTEREVAL; - { - dSP; - oldmark = SP - PL_stack_base; - EXTEND(SP, 1); - PUSHs(sv); - PUTBACK; - } + oldmark = PL_stack_sp - PL_stack_base; + rpp_extend(1); + *++PL_stack_sp = sv; +#ifdef PERL_RC_STACK + if (rpp_stack_is_rc()) + SvREFCNT_inc_simple_void_NN(sv); +#endif if (!(flags & G_NOARGS)) myop.op_flags = OPf_STACKED; @@ -3261,6 +3342,9 @@ Perl_eval_sv(pTHX_ SV *sv, I32 flags) if (flags & G_RE_REPARSING) myop.op_private |= (OPpEVAL_COPHH | OPpEVAL_RE_REPARSING); + if (flags & G_USEHINTS) + myop.op_private |= OPpEVAL_COPHH; + /* fail now; otherwise we could fail after the JMPENV_PUSH but * before a cx_pusheval(), which corrupts the stack after a croak */ TAINT_PROPER("eval_sv()"); @@ -3329,7 +3413,12 @@ Perl_eval_sv(pTHX_ SV *sv, I32 flags) JMPENV_POP; if (flags & G_DISCARD) { - PL_stack_sp = PL_stack_base + oldmark; +#ifdef PERL_RC_STACK + if (rpp_stack_is_rc()) + rpp_popfree_to(PL_stack_base + oldmark); + else +#endif + PL_stack_sp = PL_stack_base + oldmark; retval = 0; FREETMPS; LEAVE; @@ -3362,11 +3451,16 @@ Perl_eval_pv(pTHX_ const char *p, I32 cr SvREFCNT_dec(sv); } - { - dSP; - sv = POPs; - PUTBACK; + sv = *PL_stack_sp; + +#ifdef PERL_RC_STACK + if (rpp_stack_is_rc()) { + SvREFCNT_inc_NN(sv_2mortal(sv)); + rpp_popfree_1(); } + else +#endif + PL_stack_sp--; return sv; } @@ -3759,53 +3853,8 @@ Perl_moreswitches(pTHX_ const char *s) /* FALLTHROUGH */ case 'm': forbid_setid('m', FALSE); /* XXX ? */ - if (*++s) { - const char *start; - const char *end; - SV *sv; - const char *use = "use "; - bool colon = FALSE; - /* -M-foo == 'no foo' */ - /* Leading space on " no " is deliberate, to make both - possibilities the same length. */ - if (*s == '-') { use = " no "; ++s; } - sv = newSVpvn(use,4); - start = s; - /* We allow -M'Module qw(Foo Bar)' */ - while(isWORDCHAR(*s) || *s==':') { - if( *s++ == ':' ) { - if( *s == ':' ) - s++; - else - colon = TRUE; - } - } - if (s == start) - Perl_croak(aTHX_ "Module name required with -%c option", - option); - if (colon) - Perl_croak(aTHX_ "Invalid module name %.*s with -%c option: " - "contains single ':'", - (int)(s - start), start, option); - end = s + strlen(s); - if (*s != '=') { - sv_catpvn(sv, start, end - start); - if (option == 'm') { - if (*s != '\0') - Perl_croak(aTHX_ "Can't use '%c' after -mname", *s); - sv_catpvs( sv, " ()"); - } - } else { - sv_catpvn(sv, start, s-start); - /* Use NUL as q''-delimiter. */ - sv_catpvs(sv, " split(/,/,q\0"); - ++s; - sv_catpvn(sv, s, end - s); - sv_catpvs(sv, "\0)"); - } - s = end; - Perl_av_create_and_push(aTHX_ &PL_preambleav, sv); - } + if (*++s) + s = S_moreswitch_m(aTHX_ option, s); else Perl_croak(aTHX_ "Missing argument to -%c", option); return s; @@ -3947,7 +3996,7 @@ S_minus_v(pTHX) #endif PerlIO_printf(PIO_stdout, - "\n\nCopyright 1987-2023, Larry Wall\n"); + "\n\nCopyright 1987-2025, Larry Wall\n"); #ifdef OS2 PerlIO_printf(PIO_stdout, "\n\nOS/2 port Copyright (c) 1990, 1991, Raymond Chen, Kai Uwe Rommel\n" @@ -4457,11 +4506,17 @@ Perl_init_stacks(pTHX) { SSize_t size; +#ifdef PERL_RC_STACK + const UV make_real = 1; +#else + const UV make_real = 0; +#endif /* start with 128-item stack and 8K cxstack */ - PL_curstackinfo = new_stackinfo(REASONABLE(128), - REASONABLE(8192/sizeof(PERL_CONTEXT) - 1)); + PL_curstackinfo = new_stackinfo_flags(REASONABLE(128), + REASONABLE(8192/sizeof(PERL_CONTEXT) - 1), + make_real); PL_curstackinfo->si_type = PERLSI_MAIN; -#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY +#ifdef PERL_USE_HWM PL_curstackinfo->si_stack_hwm = 0; #endif PL_curstack = PL_curstackinfo->si_stack; @@ -4476,7 +4531,7 @@ Perl_init_stacks(pTHX) PL_tmps_ix = -1; PL_tmps_max = REASONABLE(128); - Newxz(PL_markstack,REASONABLE(32),I32); + Newxz(PL_markstack, REASONABLE(32), Stack_off_t); PL_markstack_ptr = PL_markstack; PL_markstack_max = PL_markstack + REASONABLE(32); @@ -4686,7 +4741,6 @@ S_init_postdump_symbols(pTHX_ int argc, GvMULTI_on(PL_envgv); hv = GvHVn(PL_envgv); hv_magic(hv, NULL, PERL_MAGIC_env); -#ifndef PERL_MICRO #if defined(USE_ENVIRON_ARRAY) || defined(WIN32) /* Note that if the supplied env parameter is actually a copy of the global environ then it may now point to free'd memory @@ -4799,7 +4853,6 @@ S_init_postdump_symbols(pTHX_ int argc, SvREFCNT_dec_NN(dups); } #endif /* USE_ENVIRON_ARRAY */ -#endif /* !PERL_MICRO */ } TAINT_NOT; @@ -5442,8 +5495,8 @@ S_my_exit_jump(pTHX) POPSTACK_TO(PL_mainstack); if (cxstack_ix >= 0) { dounwind(-1); - cx_popblock(cxstack); } + rpp_obliterate_stack_to(0); LEAVE_SCOPE(0); JMPENV_JUMP(2); @@ -5471,7 +5524,7 @@ read_e_script(pTHX_ int idx, SV *buf_sv, /* removes boilerplate code at the end of each boot_Module xsub */ void -Perl_xs_boot_epilog(pTHX_ const I32 ax) +Perl_xs_boot_epilog(pTHX_ const SSize_t ax) { if (PL_unitcheckav) call_list(PL_scopestack_ix, PL_unitcheckav); Index: gnu/usr.bin/perl/perl.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/perl.h,v diff -u -p -a -u -p -r1.29 perl.h --- gnu/usr.bin/perl/perl.h 14 May 2024 19:38:54 -0000 1.29 +++ gnu/usr.bin/perl/perl.h 22 Jan 2025 00:37:44 -0000 @@ -38,10 +38,30 @@ #define USE_STDIO #endif /* PERL_FOR_X2P */ -#ifdef PERL_MICRO -# include "uconfig.h" -#else -# include "config.h" +/* Treat the SVs on the argument stack as having been reference counted. + * (Experimental). + */ +/* #define PERL_RC_STACK */ + +#include "config.h" + +/* This fakes up using Mingw for locale handling. In order to not define WIN32 + * in this file (and hence throughout the code that isn't expecting it), this + * doesn't define that, but defines the appropriate things that would otherwise + * be defined later in the file. Hence those and here must be kept in sync */ +#ifdef WIN32_USE_FAKE_OLD_MINGW_LOCALES +# define UINT unsigned int +# undef USE_THREAD_SAFE_LOCALE +# define NO_POSIX_2008_LOCALE +# undef HAS_NL_LANGINFO +# undef HAS_NL_LANGINFO_L +# undef _UCRT +# ifdef USE_LOCALE +# define TS_W32_BROKEN_LOCALECONV +# ifdef USE_THREADS +# define EMULATE_THREAD_SAFE_LOCALES +# endif +# endif #endif /* @@ -93,14 +113,14 @@ no normal arguments, and used by L for detailed notes on * MULTIPLICITY and PERL_IMPLICIT_SYS */ -/* XXX NOTE that from here --> to <-- the same logic is - * repeated in makedef.pl, so be certain to update - * both places when editing. */ - -#ifdef USE_ITHREADS +#ifdef USE_THREADS # if !defined(MULTIPLICITY) # define MULTIPLICITY # endif @@ -129,11 +149,12 @@ no normal arguments, and used by L #endif @@ -1097,6 +1142,13 @@ violations are fatal. # include #endif +/* Even if not using locales, this header should be #included so as to #define + * some symbols which avoid #ifdefs to get things to compile. But make sure + * the macro it calls does nothing */ +#undef PERL_LOCALE_TABLE_ENTRY +#define PERL_LOCALE_TABLE_ENTRY(name, call_back) +#include "locale_table.h" + #include "perl_langinfo.h" /* Needed for _NL_LOCALE_NAME */ /* ========================================================================= @@ -1108,7 +1160,6 @@ violations are fatal. * repeated in t/loc_tools.pl and makedef.pl; The three should be kept in * sync. */ #if ! defined(NO_LOCALE) - # if ! defined(NO_POSIX_2008_LOCALE) \ && defined(HAS_NEWLOCALE) \ && defined(HAS_USELOCALE) \ @@ -1127,174 +1178,104 @@ violations are fatal. # endif #endif +/* end of makedef.pl logic duplication. But there are other groups below. + * ========================================================================= */ + #ifdef USE_LOCALE # define HAS_SKIP_LOCALE_INIT /* Solely for XS code to test for this #define */ -# if !defined(NO_LOCALE_COLLATE) && defined(LC_COLLATE) \ - && defined(HAS_STRXFRM) -# define USE_LOCALE_COLLATE -# endif -# if !defined(NO_LOCALE_CTYPE) && defined(LC_CTYPE) -# define USE_LOCALE_CTYPE -# endif -# if !defined(NO_LOCALE_NUMERIC) && defined(LC_NUMERIC) -# define USE_LOCALE_NUMERIC -# endif -# if !defined(NO_LOCALE_MESSAGES) && defined(LC_MESSAGES) -# define USE_LOCALE_MESSAGES -# endif -# if !defined(NO_LOCALE_MONETARY) && defined(LC_MONETARY) -# define USE_LOCALE_MONETARY -# endif -# if !defined(NO_LOCALE_TIME) && defined(LC_TIME) -# define USE_LOCALE_TIME -# endif -# if !defined(NO_LOCALE_ADDRESS) && defined(LC_ADDRESS) -# define USE_LOCALE_ADDRESS -# endif -# if !defined(NO_LOCALE_IDENTIFICATION) && defined(LC_IDENTIFICATION) -# define USE_LOCALE_IDENTIFICATION -# endif -# if !defined(NO_LOCALE_MEASUREMENT) && defined(LC_MEASUREMENT) -# define USE_LOCALE_MEASUREMENT -# endif -# if !defined(NO_LOCALE_PAPER) && defined(LC_PAPER) -# define USE_LOCALE_PAPER -# endif -# if !defined(NO_LOCALE_TELEPHONE) && defined(LC_TELEPHONE) -# define USE_LOCALE_TELEPHONE -# endif -# if !defined(NO_LOCALE_NAME) && defined(LC_NAME) -# define USE_LOCALE_NAME -# endif -# if !defined(NO_LOCALE_SYNTAX) && defined(LC_SYNTAX) -# define USE_LOCALE_SYNTAX -# endif -# if !defined(NO_LOCALE_TOD) && defined(LC_TOD) -# define USE_LOCALE_TOD -# endif +#endif -/* Now create LC_foo_INDEX_ #defines for just those categories on this system */ -# ifdef USE_LOCALE_CTYPE -# define LC_CTYPE_INDEX_ 0 -# define PERL_DUMMY_CTYPE_ LC_CTYPE_INDEX_ -# else -# define PERL_DUMMY_CTYPE_ -1 -# endif -# ifdef USE_LOCALE_NUMERIC -# define LC_NUMERIC_INDEX_ PERL_DUMMY_CTYPE_ + 1 -# define PERL_DUMMY_NUMERIC_ LC_NUMERIC_INDEX_ -# else -# define PERL_DUMMY_NUMERIC_ PERL_DUMMY_CTYPE_ -# endif -# ifdef USE_LOCALE_COLLATE -# define LC_COLLATE_INDEX_ PERL_DUMMY_NUMERIC_ + 1 -# define PERL_DUMMY_COLLATE_ LC_COLLATE_INDEX_ -# else -# define PERL_DUMMY_COLLATE_ PERL_DUMMY_NUMERIC_ -# endif -# ifdef USE_LOCALE_TIME -# define LC_TIME_INDEX_ PERL_DUMMY_COLLATE_ + 1 -# define PERL_DUMMY_TIME_ LC_TIME_INDEX_ -# else -# define PERL_DUMMY_TIME_ PERL_DUMMY_COLLATE_ -# endif -# ifdef USE_LOCALE_MESSAGES -# define LC_MESSAGES_INDEX_ PERL_DUMMY_TIME_ + 1 -# define PERL_DUMMY_MESSAGES_ LC_MESSAGES_INDEX_ -# else -# define PERL_DUMMY_MESSAGES_ PERL_DUMMY_TIME_ -# endif -# ifdef USE_LOCALE_MONETARY -# define LC_MONETARY_INDEX_ PERL_DUMMY_MESSAGES_ + 1 -# define PERL_DUMMY_MONETARY_ LC_MONETARY_INDEX_ -# else -# define PERL_DUMMY_MONETARY_ PERL_DUMMY_MESSAGES_ -# endif -# ifdef USE_LOCALE_ADDRESS -# define LC_ADDRESS_INDEX_ PERL_DUMMY_MONETARY_ + 1 -# define PERL_DUMMY_ADDRESS_ LC_ADDRESS_INDEX_ -# else -# define PERL_DUMMY_ADDRESS_ PERL_DUMMY_MONETARY_ -# endif -# ifdef USE_LOCALE_IDENTIFICATION -# define LC_IDENTIFICATION_INDEX_ PERL_DUMMY_ADDRESS_ + 1 -# define PERL_DUMMY_IDENTIFICATION_ LC_IDENTIFICATION_INDEX_ -# else -# define PERL_DUMMY_IDENTIFICATION_ PERL_DUMMY_ADDRESS_ -# endif -# ifdef USE_LOCALE_MEASUREMENT -# define LC_MEASUREMENT_INDEX_ PERL_DUMMY_IDENTIFICATION_ + 1 -# define PERL_DUMMY_MEASUREMENT_ LC_MEASUREMENT_INDEX_ -# else -# define PERL_DUMMY_MEASUREMENT_ PERL_DUMMY_IDENTIFICATION_ -# endif -# ifdef USE_LOCALE_PAPER -# define LC_PAPER_INDEX_ PERL_DUMMY_MEASUREMENT_ + 1 -# define PERL_DUMMY_PAPER_ LC_PAPER_INDEX_ -# else -# define PERL_DUMMY_PAPER_ PERL_DUMMY_MEASUREMENT_ -# endif -# ifdef USE_LOCALE_TELEPHONE -# define LC_TELEPHONE_INDEX_ PERL_DUMMY_PAPER_ + 1 -# define PERL_DUMMY_TELEPHONE_ LC_TELEPHONE_INDEX_ -# else -# define PERL_DUMMY_TELEPHONE_ PERL_DUMMY_PAPER_ -# endif -# ifdef USE_LOCALE_NAME -# define LC_NAME_INDEX_ PERL_DUMMY_TELEPHONE_ + 1 -# define PERL_DUMMY_NAME_ LC_NAME_INDEX_ -# else -# define PERL_DUMMY_NAME_ PERL_DUMMY_TELEPHONE_ -# endif -# ifdef USE_LOCALE_SYNTAX -# define LC_SYNTAX_INDEX_ PERL_DUMMY_NAME + 1 -# define PERL_DUMMY_SYNTAX_ LC_SYNTAX_INDEX_ -# else -# define PERL_DUMMY_SYNTAX_ PERL_DUMMY_NAME_ -# endif -# ifdef USE_LOCALE_TOD -# define LC_TOD_INDEX_ PERL_DUMMY_SYNTAX_ + 1 -# define PERL_DUMMY_TOD_ LC_TOD_INDEX_ -# else -# define PERL_DUMMY_TOD_ PERL_DUMMY_SYNTAX_ -# endif -# ifdef LC_ALL -# define LC_ALL_INDEX_ PERL_DUMMY_TOD_ + 1 -# endif +/* XXX The Configure probe for categories must be updated when adding new + * categories here */ + +/* Create an enum that allows translation between the arbitrary locale category + * integers that a platform has, and our desired values that range from 0..n + * which makes array indexing feasible. + * + * In locale.c, there are a bunch of parallel arrays corresponding to this + * enum. The first element of each corresponds with the first enum value here, + * and so on. That means this enum must be in identical order with those + * arrays. This is guaranteed by using locale_table.h in all instances. + * (There are also asserts in locale.c that should fail if this gets + * out-of-sync.) So, if the platform doesn't have LC_CTYPE, but does have + * LC_NUMERIC, the code below will cause LC_NUMERIC_INDEX_ to be defined to be + * 0. That way the foo_INDEX_ values are contiguous non-negative integers, + * regardless of how the platform defines the actual locale categories. + * + * It is possible to tell perl it is not to pay attention to certain categories + * that exist on a platform (which means they are always kept in the "C" + * locale). For the ones perl is supposed to pay attention to, The hdr file + * creates a 'USE_LOCALE_foo' #define. If any are to be ignored by perl, it + * #defines HAS_IGNORED_LOCALE_CATEGORIES_ */ +typedef enum { + +#ifdef USE_LOCALE +# undef PERL_LOCALE_TABLE_ENTRY +# define PERL_LOCALE_TABLE_ENTRY(name, call_back) LC_ ## name ## _INDEX_, +# include "locale_table.h" +#endif /* USE_LOCALE */ + + LC_ALL_INDEX_ /* Always defined, even if no LC_ALL on system */ +} locale_category_index; -# if defined(USE_ITHREADS) && ! defined(NO_LOCALE_THREADS) +#ifdef USE_LOCALE + +/* And a count of all the locale categories, mainly for use in array + * declarations */ +# define LOCALE_CATEGORIES_COUNT_ (LC_ALL_INDEX_ + 1) + +/* As a development aid for platforms that have LC_ALL name=value notation, + * setting -Accflags=-DUSE_FAKE_LC_ALL_POSITIONAL_NOTATION, simulates a + * platform that instead uses positional notation. By doing this, you can find + * many bugs without trying it out on a real such platform. It would be + * possible to create the reverse definitions for people who have ready access + * to a posiional notation box, but harder to get a name=value box */ +# if defined(USE_FAKE_LC_ALL_POSITIONAL_NOTATION) \ + && defined(PERL_LC_ALL_USES_NAME_VALUE_PAIRS) +# undef PERL_LC_ALL_USES_NAME_VALUE_PAIRS + +# define PERL_LC_ALL_CATEGORY_POSITIONS_INIT /* Assumes glibc cateories */\ + { 12, 11, 10, 9, 8, 7, 5, 4, 3, 2, 1, 0 } +# define PERL_LC_ALL_SEPARATOR "/ = /" +# endif +/* ========================================================================= + * The defines from here to the following ===== line are unfortunately + * duplicated in makedef.pl, and changes here MUST also be made there */ + +# if defined(USE_THREADS) && ! defined(NO_LOCALE_THREADS) # define USE_LOCALE_THREADS # endif /* Use POSIX 2008 locales if available, and no alternative exists * ('setlocale()' is the alternative); or is threaded and not forbidden to * use them */ -# if defined(HAS_POSIX_2008_LOCALE) && ( ! defined(HAS_SETLOCALE) \ - || ( defined(USE_LOCALE_THREADS) \ - && ! defined(NO_POSIX_2008_LOCALE))) +# if ( defined(HAS_POSIX_2008_LOCALE) \ + && ( ! defined(HAS_SETLOCALE) \ + || ( defined(USE_LOCALE_THREADS) \ + && ! defined(NO_POSIX_2008_LOCALE))) \ + && ! defined(NO_THREAD_SAFE_LOCALE)) # define USE_POSIX_2008_LOCALE # endif /* On threaded builds, use thread-safe locales if they are available and not * forbidden. Availability is when we are using POSIX 2008 locales, or - * Windows for quite a few releases now. */ + * Windows for any vintage recent enough to have _MSC_VER defined, or are + * using UCRT (principally MINGW in this latter case) */ # if defined(USE_LOCALE_THREADS) && ! defined(NO_THREAD_SAFE_LOCALE) -# if defined(USE_POSIX_2008_LOCALE) || (defined(WIN32) && defined(_MSC_VER)) +# if defined(USE_POSIX_2008_LOCALE) \ + || (defined(WIN32) && (defined(_MSC_VER) || (defined(_UCRT)))) # define USE_THREAD_SAFE_LOCALE # endif # endif -# include "perl_langinfo.h" /* Needed for _NL_LOCALE_NAME */ - # ifdef USE_POSIX_2008_LOCALE # if defined(HAS_QUERYLOCALE) \ /* Use querylocale if has it, or has the glibc internal \ - * undocumented equivalent. */ \ + * undocumented equivalent (if not forbidden). */ \ || ( defined(_NL_LOCALE_NAME) \ - /* And asked for */ \ - && defined(USE_NL_LOCALE_NAME) \ + && ! defined(NO_USE_NL_LOCALE_NAME) \ /* nl_langinfo_l almost certainly will exist on systems that \ * have _NL_LOCALE_NAME, so there is nothing lost by \ * requiring it instead of also allowing plain nl_langinfo(). \ @@ -1303,7 +1284,7 @@ violations are fatal. && defined(HAS_NL_LANGINFO_L) \ /* On systems that accept any locale name, the real \ * underlying locale is often returned by this internal \ - * item, so we can't use it */ \ + * langinfo item, so we can't use it */ \ && ! defined(SETLOCALE_ACCEPTS_ANY_LOCALE_NAME)) # define USE_QUERYLOCALE # endif @@ -1313,22 +1294,20 @@ violations are fatal. * querylocale; so must keep track of it ourselves */ # if (defined(USE_POSIX_2008_LOCALE) && ! defined(USE_QUERYLOCALE)) # define USE_PL_CURLOCALES -# define USE_PL_CUR_LC_ALL # endif -# if defined(WIN32) && defined(USE_THREAD_SAFE_LOCALE) +# if defined(WIN32) - /* We need to be able to map the current value of what the tTHX context - * thinks LC_ALL is so as to inform the Windows libc when switching - * contexts. */ -# define USE_PL_CUR_LC_ALL - - /* Microsoft documentation reads in the change log for VS 2015: "The - * localeconv function declared in locale.h now works correctly when - * per-thread locale is enabled. In previous versions of the library, this - * function would return the lconv data for the global locale, not the - * thread's locale." */ -# if _MSC_VER < 1900 + /* We need to be able to map the current value of what the tTHX context + * thinks LC_ALL is so as to inform the Windows libc when switching + * contexts. */ +# if defined(USE_THREAD_SAFE_LOCALE) +# define USE_PL_CUR_LC_ALL +# endif + + /* Assume MingW without UCRT has the broken localeconv() that Microsoft + * fixed in VS 2015 */ +# if ! defined(_MSC_VER) && ! defined(_UCRT) # define TS_W32_BROKEN_LOCALECONV # endif # endif @@ -1341,25 +1320,15 @@ violations are fatal. && defined(USE_THREAD_SAFE_LOCALE))) # define USE_PERL_SWITCH_LOCALE_CONTEXT # endif -#endif +#endif /* End of USE_LOCALE */ /* end of makedef.pl logic duplication * ========================================================================= */ #ifdef PERL_CORE -/* Both typedefs are used in locale.c only, but defined here so that embed.fnc - * can generate the proper prototypes. */ - -typedef enum { - DONT_RECALC_LC_ALL, - YES_RECALC_LC_ALL, - - /* Used in tight loops through all sub-categories, where LC_ALL won't be - * fully known until all subcategories are handled. */ - RECALCULATE_LC_ALL_ON_FINAL_INTERATION -} recalc_lc_all_t; - +/* These typedefs are used in locale.c only (and documented there), but defined + * here so that embed.fnc can generate the proper prototypes. */ typedef enum { /* Is the locale UTF8? */ LOCALE_NOT_UTF8, @@ -1372,6 +1341,30 @@ typedef struct { size_t offset; } lconv_offset_t; +typedef enum { + INTERNAL_FORMAT, + EXTERNAL_FORMAT_FOR_SET, + EXTERNAL_FORMAT_FOR_QUERY +} calc_LC_ALL_format; + +typedef enum { + WANT_VOID, + WANT_TEMP_PV, + WANT_PL_setlocale_buf, +} calc_LC_ALL_return; + +typedef enum { + no_override, + override_if_ignored, + check_that_overridden +} parse_LC_ALL_STRING_action; + +typedef enum { + invalid, + no_array, + only_element_0, + full_array +} parse_LC_ALL_string_return; #endif @@ -1625,8 +1618,11 @@ Use L to declare variables of the m #define PERL_MULTICONCAT_IX_PLAIN_LEN 2 /* non-utf8 constant string length */ #define PERL_MULTICONCAT_IX_UTF8_PV 3 /* utf8 constant string */ #define PERL_MULTICONCAT_IX_UTF8_LEN 4 /* utf8 constant string length */ -#define PERL_MULTICONCAT_IX_LENGTHS 5 /* first of nargs+1 const segment lens */ -#define PERL_MULTICONCAT_HEADER_SIZE 5 /* The number of fields of a +#define PERL_MULTICONCAT_IX_PADTMP0 5 /* up to 3 pad indexes for PADTMPs */ +#define PERL_MULTICONCAT_IX_PADTMP1 6 +#define PERL_MULTICONCAT_IX_PADTMP2 7 +#define PERL_MULTICONCAT_IX_LENGTHS 8 /* first of nargs+1 const segment lens */ +#define PERL_MULTICONCAT_HEADER_SIZE 8 /* The number of fields of a multiconcat header */ /* We no longer default to creating a new SV for GvSV. @@ -1921,6 +1917,12 @@ was saved by C or C is like C, but it has a benefit in a release build. It is a @@ -4963,15 +4974,15 @@ Gid_t getegid (void); * #define DEBUG_POST_STMTS RESTORE_ERRNO; * * Other potential things include displaying timestamps, location information, - * which thread, etc. Heres an example with both errno and location info: + * which thread, etc. Here's an example with both errno and location info: * * #define DEBUG_PRE_STMTS dSAVE_ERRNO; \ * PerlIO_printf(Perl_debug_log, "%s:%d: ", __FILE__, __LINE__); * #define DEBUG_POST RESTORE_ERRNO; * - * All DEBUG statements in the compiled scope will be have these extra - * statements compiled in; they will be executed only for the DEBUG statements - * whose flags are turned on. + * All DEBUG statements in the compiled scope will have these extra statements + * compiled in; they will be executed only for the DEBUG statements whose flags + * are turned on. */ #ifndef DEBUG_PRE_STMTS # define DEBUG_PRE_STMTS @@ -5213,7 +5224,7 @@ typedef Sighandler_t Sigsave_t; #define SCAN_TR 1 #define SCAN_REPL 2 -#ifdef DEBUGGING +#if defined DEBUGGING || defined PERL_USE_HWM # ifndef register # define register # endif @@ -5224,7 +5235,7 @@ typedef Sighandler_t Sigsave_t; #if defined(USE_PERLIO) EXTERN_C void PerlIO_teardown(void); -# ifdef USE_ITHREADS +# ifdef USE_THREADS # define PERLIO_INIT MUTEX_INIT(&PL_perlio_mutex) # define PERLIO_TERM \ STMT_START { \ @@ -5402,8 +5413,6 @@ EXTCONST char PL_no_helem_sv[] INIT("Modification of non-creatable hash value attempted, subscript \"%" SVf "\""); EXTCONST char PL_no_modify[] INIT("Modification of a read-only value attempted"); -EXTCONST char PL_no_mem[sizeof("Out of memory!\n")] - INIT("Out of memory!\n"); EXTCONST char PL_no_security[] INIT("Insecure dependency in %s%s"); EXTCONST char PL_no_sock_func[] @@ -5485,18 +5494,10 @@ EXTCONST char PL_isa_DOES[] #ifdef DOINIT EXTCONST char PL_uudmap[256] = -# ifdef PERL_MICRO -# include "uuudmap.h" -# else -# include "uudmap.h" -# endif +# include "uudmap.h" ; EXTCONST char PL_bitcount[256] = -# ifdef PERL_MICRO -# include "ubitcount.h" -#else -# include "bitcount.h" -# endif +# include "bitcount.h" ; EXTCONST char* const PL_sig_name[] = { SIG_NAME }; EXTCONST int PL_sig_num[] = { SIG_NUM }; @@ -5760,9 +5761,6 @@ EXTCONST char PL_bincompat_options[] = # ifdef PERL_IMPLICIT_SYS " PERL_IMPLICIT_SYS" # endif -# ifdef PERL_MICRO - " PERL_MICRO" -# endif # ifdef PERL_POISON " PERL_POISON" # endif @@ -6287,11 +6285,7 @@ EXTCONST runops_proc_t PL_runops_dbg #ifdef DOINIT EXTCONST U8 PL_magic_data[256] = -# ifdef PERL_MICRO -# include "umg_data.h" -# else -# include "mg_data.h" -# endif +# include "mg_data.h" ; #else EXTCONST U8 PL_magic_data[256]; @@ -6365,21 +6359,21 @@ EXTCONST U8 PL_deBruijn_bitpos_tab64[] #ifdef USE_PERL_SWITCH_LOCALE_CONTEXT # define PERL_SET_LOCALE_CONTEXT(i) \ STMT_START { \ - if (UNLIKELY(PL_veto_switch_non_tTHX_context)) \ - Perl_switch_locale_context(); \ + if (LIKELY(! PL_veto_switch_non_tTHX_context)) \ + Perl_switch_locale_context(i); \ } STMT_END + + /* In some Configurations there may be per-thread information that is + * carried in a library instead of perl's tTHX structure. This macro is to + * be used to handle those when tTHX is changed. Only locale handling is + * currently known to be affected. */ +# define PERL_SET_NON_tTHX_CONTEXT(i) \ + STMT_START { if (i) PERL_SET_LOCALE_CONTEXT(i); } STMT_END #else -# define PERL_SET_LOCALE_CONTEXT(i) NOOP +# define PERL_SET_LOCALE_CONTEXT(i) NOOP +# define PERL_SET_NON_tTHX_CONTEXT(i) NOOP #endif -/* In some Configurations there may be per-thread information that is carried - * in a library instead of perl's tTHX structure. This macro is to be used to - * handle those when tTHX is changed. Only locale handling is currently known - * to be affected. */ -#define PERL_SET_NON_tTHX_CONTEXT(i) \ - STMT_START { PERL_SET_LOCALE_CONTEXT(i); } STMT_END - - #ifndef PERL_GET_CONTEXT # define PERL_GET_CONTEXT PERL_GET_INTERP #endif @@ -6392,6 +6386,93 @@ EXTCONST U8 PL_deBruijn_bitpos_tab64[] # define PERL_SET_THX(t) NOOP #endif +#ifdef WIN32 + /* Windows mutexes are all general semaphores; we don't currently bother + * with reproducing the same panic behavior as on other systems */ +# define PERL_REENTRANT_LOCK(name, mutex, counter, \ + cond_to_panic_if_already_locked) \ + MUTEX_LOCK(mutex) +# define PERL_REENTRANT_UNLOCK(name, mutex, counter) MUTEX_UNLOCK(mutex) +#else + + /* Simulate a general (or recursive) semaphore on 'mutex' whose name will + * be displayed as 'name' in any messages. There must be a per-thread + * variable 'counter', initialized to 0 upon thread creation that this + * macro otherwise controls and keeps set to the recursion depth of the + * mutex. 'cond_to_panic_if_already_locked' should be set to '0' for a + * fully reentrant semaphore. Otherwise set it to a bit of code which will + * be evaluated if the macro is called recursively. If it evaluates to + * 'true', it means something is seriously wrong, and the process panics. + * + * It locks the mutex if the 'counter' is zero, and then increments + * 'counter'. Each corresponding UNLOCK decrements 'counter' until it is + * 0, at which point it actually unlocks the mutex. Since the variable is + * per-thread, initialized to 0, there is no race with other threads. + * + * Clang improperly gives warnings for this, if not silenced: + * https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#conditional-locks + */ +# define PERL_REENTRANT_LOCK(name, mutex, counter, \ + cond_to_panic_if_already_locked) \ + STMT_START { \ + CLANG_DIAG_IGNORE(-Wthread-safety) \ + if (LIKELY(counter <= 0)) { \ + UNLESS_PERL_MEM_LOG(DEBUG_Lv(PerlIO_printf(Perl_debug_log, \ + "%s: %d: locking " name "; lock depth=1\n", \ + __FILE__, __LINE__)); \ + ) \ + MUTEX_LOCK(mutex); \ + counter = 1; \ + UNLESS_PERL_MEM_LOG(DEBUG_Lv(PerlIO_printf(Perl_debug_log, \ + "%s: %d: " name " locked; lock depth=1\n", \ + __FILE__, __LINE__)); \ + ) \ + } \ + else { \ + counter++; \ + UNLESS_PERL_MEM_LOG(DEBUG_Lv(PerlIO_printf(Perl_debug_log, \ + "%s: %d: avoided locking " name "; new lock" \ + " depth=%d, but will panic if '%s' is true\n", \ + __FILE__, __LINE__, counter, \ + STRINGIFY(cond_to_panic_if_already_locked))); \ + ) \ + if (cond_to_panic_if_already_locked) { \ + Perl_croak_nocontext("panic: %s: %d: attempting to lock" \ + name " incompatibly: %s\n", \ + __FILE__, __LINE__, \ + STRINGIFY(cond_to_panic_if_already_locked));\ + } \ + } \ + CLANG_DIAG_RESTORE \ + } STMT_END + +# define PERL_REENTRANT_UNLOCK(name, mutex, counter) \ + STMT_START { \ + if (LIKELY(counter == 1)) { \ + UNLESS_PERL_MEM_LOG(DEBUG_Lv(PerlIO_printf(Perl_debug_log, \ + "%s: %d: unlocking " name "; new lock depth=0\n", \ + __FILE__, __LINE__)); \ + ) \ + counter = 0; \ + MUTEX_UNLOCK(mutex); \ + } \ + else if (counter <= 0) { \ + Perl_croak_nocontext("panic: %s: %d: attempting to unlock" \ + " already unlocked " name "; depth was" \ + " %d\n", __FILE__, __LINE__, \ + counter); \ + } \ + else { \ + counter--; \ + UNLESS_PERL_MEM_LOG(DEBUG_Lv(PerlIO_printf(Perl_debug_log, \ + "%s: %d: avoided unlocking " name "; new lock depth=%d\n", \ + __FILE__, __LINE__, counter)); \ + ) \ + } \ + } STMT_END + +#endif + #ifndef EBCDIC /* The tables below are adapted from @@ -6929,7 +7010,7 @@ typedef struct am_table_short AMTS; #define PERLDB_LINE_OR_SAVESRC (PL_perldb & (PERLDBf_LINE | PERLDBf_SAVESRC)) -#ifdef USE_ITHREADS +#ifdef USE_THREADS # define KEYWORD_PLUGIN_MUTEX_INIT MUTEX_INIT(&PL_keyword_plugin_mutex) # define KEYWORD_PLUGIN_MUTEX_LOCK MUTEX_LOCK(&PL_keyword_plugin_mutex) # define KEYWORD_PLUGIN_MUTEX_UNLOCK MUTEX_UNLOCK(&PL_keyword_plugin_mutex) @@ -6949,30 +7030,397 @@ typedef struct am_table_short AMTS; # define USER_PROP_MUTEX_TERM NOOP #endif -#ifdef USE_LOCALE /* These locale things are all subject to change */ - - /* Returns TRUE if the plain locale pragma without a parameter is in effect. - * */ -# define IN_LOCALE_RUNTIME (PL_curcop \ - && CopHINTS_get(PL_curcop) & HINT_LOCALE) - - /* Returns TRUE if either form of the locale pragma is in effect */ -# define IN_SOME_LOCALE_FORM_RUNTIME \ - cBOOL(CopHINTS_get(PL_curcop) & (HINT_LOCALE|HINT_LOCALE_PARTIAL)) +#ifdef USE_THREADS +# define ENV_LOCK PERL_WRITE_LOCK(&PL_env_mutex) +# define ENV_UNLOCK PERL_WRITE_UNLOCK(&PL_env_mutex) +# define ENV_READ_LOCK PERL_READ_LOCK(&PL_env_mutex) +# define ENV_READ_UNLOCK PERL_READ_UNLOCK(&PL_env_mutex) +# define ENV_INIT PERL_RW_MUTEX_INIT(&PL_env_mutex) +# define ENV_TERM PERL_RW_MUTEX_DESTROY(&PL_env_mutex) -# define IN_LOCALE_COMPILETIME cBOOL(PL_hints & HINT_LOCALE) -# define IN_SOME_LOCALE_FORM_COMPILETIME \ - cBOOL(PL_hints & (HINT_LOCALE|HINT_LOCALE_PARTIAL)) + /* On platforms where the static buffer contained in getenv() is per-thread + * rather than process-wide, another thread executing a getenv() at the same + * time won't destroy ours before we have copied the result safely away and + * unlocked the mutex. On such platforms (which is most), we can have many + * readers of the environment at the same time. */ +# ifdef GETENV_PRESERVES_OTHER_THREAD +# define GETENV_LOCK ENV_READ_LOCK +# define GETENV_UNLOCK ENV_READ_UNLOCK +# else + /* If, on the other hand, another thread could zap our getenv() return, we + * need to keep them from executing until we are done */ +# define GETENV_LOCK ENV_LOCK +# define GETENV_UNLOCK ENV_UNLOCK +# endif +#else +# define ENV_LOCK NOOP +# define ENV_UNLOCK NOOP +# define ENV_READ_LOCK NOOP +# define ENV_READ_UNLOCK NOOP +# define ENV_INIT NOOP +# define ENV_TERM NOOP +# define GETENV_LOCK NOOP +# define GETENV_UNLOCK NOOP +#endif -/* -=for apidoc_section $locale +/* Locale/thread synchronization macros. */ +#if ! defined(USE_LOCALE_THREADS) /* No threads, or no locales */ +# define LOCALE_LOCK_(cond) NOOP +# define LOCALE_UNLOCK_ NOOP +# define LOCALE_LOCK NOOP +# define LOCALE_UNLOCK NOOP +#else /* Below: Threaded, and locales are supported */ -=for apidoc Amn|bool|IN_LOCALE + /* A locale mutex is required on all such threaded builds for at least + * situations where there is a global static buffer. This base lock that + * handles these has a trailing underscore in the name */ +# define LOCALE_LOCK_(cond_to_panic_if_already_locked) \ + PERL_REENTRANT_LOCK("locale", \ + &PL_locale_mutex, PL_locale_mutex_depth, \ + cond_to_panic_if_already_locked) +# define LOCALE_UNLOCK_ \ + PERL_REENTRANT_UNLOCK("locale", \ + &PL_locale_mutex, PL_locale_mutex_depth) +# ifdef USE_THREAD_SAFE_LOCALE + /* But for most situations, we use the macro name without a trailing + * underscore. + * + * In locale thread-safe Configurations, typical operations don't need + * locking */ +# define LOCALE_LOCK NOOP +# define LOCALE_UNLOCK NOOP +# else + /* Whereas, thread-unsafe Configurations always requires locking */ +# define LOCALE_LOCK_DOES_SOMETHING_ +# define LOCALE_LOCK LOCALE_LOCK_(0) +# define LOCALE_UNLOCK LOCALE_UNLOCK_ +# ifdef USE_LOCALE_NUMERIC +# define LC_NUMERIC_LOCK(cond_to_panic_if_already_locked) \ + LOCALE_LOCK_(cond_to_panic_if_already_locked) +# define LC_NUMERIC_UNLOCK LOCALE_UNLOCK_ +# endif +# endif +#endif -Evaluates to TRUE if the plain locale pragma without a parameter (S>) is in effect. +/* There are some locale-related functions which may need locking only because + * they share some common memory across threads, and hence there is the + * potential for a race in accessing that space. Most are because their return + * points to a global static buffer, but some just use some common space + * internally. All functions accessing a given space need to have a critical + * section to prevent any other thread from accessing it at the same time. + * Ideally, there would be a separate mutex for each such space, so that + * another thread isn't unnecessarily blocked. But, most of them need to be + * locked against the locale changing while accessing that space, and it is not + * expected that any will be called frequently, and the locked interval should + * be short, and modern platforms will have reentrant versions (which don't + * lock) for almost all of them, so khw thinks a single mutex should suffice. + * Having a single mutex facilitates that, avoiding potential deadlock + * situations. + * + * This will be a no-op iff the perl is unthreaded. 'gw' stands for 'global + * write', to indicate the caller wants to be able to access memory that isn't + * thread specific, either to write to itself, or to prevent anyone else from + * writing. */ +#define gwLOCALE_LOCK LOCALE_LOCK_(0) +#define gwLOCALE_UNLOCK LOCALE_UNLOCK_ -=for apidoc Amn|bool|IN_LOCALE_COMPILETIME +/* Similar to gwLOCALE_LOCK, there are functions that require both the locale + * and environment to be constant during their execution, and don't change + * either of those things, but do write to some sort of shared global space. + * They require some sort of exclusive lock against similar functions, and a + * read lock on both the locale and environment. However, on systems which + * have per-thread locales, the locale is constant during the execution of + * these functions, and so no locale lock is necssary. For such systems, an + * exclusive ENV lock is necessary and sufficient. On systems where the locale + * could change out from under us, we use an exclusive LOCALE lock to prevent + * that, and a read ENV lock to prevent other threads that have nothing to do + * with locales here from changing the environment. */ +#ifdef LOCALE_LOCK_DOES_SOMETHING +# define gwENVr_LOCALEr_LOCK \ + STMT_START { LOCALE_LOCK; ENV_READ_LOCK; } STMT_END +# define gwENVr_LOCALEr_UNLOCK \ + STMT_START { ENV_READ_UNLOCK; LOCALE_UNLOCK; } STMT_END +#else +# define gwENVr_LOCALEr_LOCK ENV_LOCK +# define gwENVr_LOCALEr_UNLOCK ENV_UNLOCK +#endif + + /* On systems that don't have per-thread locales, even though we don't + * think we are changing the locale ourselves, behind the scenes it does + * get changed to whatever the thread's should be, so it has to be an + * exclusive lock. By defining it here with this name, we can, for the + * most part, hide this detail from the rest of the code */ +/* Currently, the read lock is an exclusive lock */ +#define LOCALE_READ_LOCK LOCALE_LOCK +#define LOCALE_READ_UNLOCK LOCALE_UNLOCK + +/* setlocale() generally returns in a global static buffer, but not on Windows + * when operating in thread-safe mode */ +#if defined(WIN32) && defined(USE_THREAD_SAFE_LOCALE) +# define POSIX_SETLOCALE_LOCK \ + STMT_START { \ + if (_configthreadlocale(0) == _DISABLE_PER_THREAD_LOCALE) \ + gwLOCALE_LOCK; \ + } STMT_END +# define POSIX_SETLOCALE_UNLOCK \ + STMT_START { \ + if (_configthreadlocale(0) == _DISABLE_PER_THREAD_LOCALE) \ + gwLOCALE_UNLOCK; \ + } STMT_END +#else +# define POSIX_SETLOCALE_LOCK gwLOCALE_LOCK +# define POSIX_SETLOCALE_UNLOCK gwLOCALE_UNLOCK +#endif + +/* It handles _wsetlocale() as well */ +#define WSETLOCALE_LOCK POSIX_SETLOCALE_LOCK +#define WSETLOCALE_UNLOCK POSIX_SETLOCALE_UNLOCK + + +#ifndef LC_NUMERIC_LOCK +# define LC_NUMERIC_LOCK(cond) NOOP +# define LC_NUMERIC_UNLOCK NOOP +#endif + + /* These non-reentrant versions use global space */ +# define MBLEN_LOCK_ gwLOCALE_LOCK +# define MBLEN_UNLOCK_ gwLOCALE_UNLOCK + +# define MBTOWC_LOCK_ gwLOCALE_LOCK +# define MBTOWC_UNLOCK_ gwLOCALE_UNLOCK + +# define WCTOMB_LOCK_ gwLOCALE_LOCK +# define WCTOMB_UNLOCK_ gwLOCALE_UNLOCK + + /* Whereas the reentrant versions don't (assuming they are called with a + * per-thread buffer; some have the capability of being called with a NULL + * parameter, which defeats the reentrancy) */ +# define MBRLEN_LOCK_ NOOP +# define MBRLEN_UNLOCK_ NOOP +# define MBRTOWC_LOCK_ NOOP +# define MBRTOWC_UNLOCK_ NOOP +# define WCRTOMB_LOCK_ NOOP +# define WCRTOMB_UNLOCK_ NOOP + +# define LC_COLLATE_LOCK LOCALE_LOCK +# define LC_COLLATE_UNLOCK LOCALE_UNLOCK + +/* Some critical sections need to lock both the locale and the environment from + * changing, while allowing for any number of readers. To avoid deadlock, this + * is always done in the same order. These should always be invoked, like all + * locks really, at such a low level that its just a libc call that is wrapped, + * so as to prevent recursive calls which could deadlock. */ +#define ENVr_LOCALEr_LOCK \ + STMT_START { LOCALE_READ_LOCK; ENV_READ_LOCK; } STMT_END +#define ENVr_LOCALEr_UNLOCK \ + STMT_START { ENV_READ_UNLOCK; LOCALE_READ_UNLOCK; } STMT_END + +#define STRFTIME_LOCK ENVr_LOCALEr_LOCK +#define STRFTIME_UNLOCK ENVr_LOCALEr_UNLOCK + +/* These time-related functions all requre that the environment and locale + * don't change while they are executing (at least in glibc; this appears to be + * contrary to the POSIX standard). tzset() writes global variables, so + * always needs to have write locking. ctime, localtime, mktime, and strftime + * effectively call it, so they too need exclusive access. The rest need to + * have exclusive locking as well so that they can copy the contents of the + * returned static buffer before releasing the lock. That leaves asctime and + * gmtime. There may be reentrant versions of these available on the platform + * which don't require write locking. + */ +#ifdef PERL_REENTR_USING_ASCTIME_R +# define ASCTIME_LOCK ENVr_LOCALEr_LOCK +# define ASCTIME_UNLOCK ENVr_LOCALEr_UNLOCK +#else +# define ASCTIME_LOCK gwENVr_LOCALEr_LOCK +# define ASCTIME_UNLOCK gwENVr_LOCALEr_UNLOCK +#endif + +#define CTIME_LOCK gwENVr_LOCALEr_LOCK +#define CTIME_UNLOCK gwENVr_LOCALEr_UNLOCK + +#ifdef PERL_REENTR_USING_GMTIME_R +# define GMTIME_LOCK ENVr_LOCALEr_LOCK +# define GMTIME_UNLOCK ENVr_LOCALEr_UNLOCK +#else +# define GMTIME_LOCK gwENVr_LOCALEr_LOCK +# define GMTIME_UNLOCK gwENVr_LOCALEr_UNLOCK +#endif + +#define LOCALTIME_LOCK gwENVr_LOCALEr_LOCK +#define LOCALTIME_UNLOCK gwENVr_LOCALEr_UNLOCK +#define MKTIME_LOCK gwENVr_LOCALEr_LOCK +#define MKTIME_UNLOCK gwENVr_LOCALEr_UNLOCK +#define TZSET_LOCK gwENVr_LOCALEr_LOCK +#define TZSET_UNLOCK gwENVr_LOCALEr_UNLOCK + +/* Similiarly, these functions need a constant environment and/or locale. And + * some have a buffer that is shared with another thread executing the same or + * a related call. A mutex could be created for each class, but for now, share + * the ENV mutex with everything, as none probably gets called so much that + * performance would suffer by a thread being locked out by another thread that + * could have used a different mutex. + * + * But, create a different macro name just to indicate the ones that don't + * actually depend on the environment, but are using its mutex for want of a + * better one */ +#define gwLOCALEr_LOCK gwENVr_LOCALEr_LOCK +#define gwLOCALEr_UNLOCK gwENVr_LOCALEr_UNLOCK + +#ifdef PERL_REENTR_USING_GETHOSTBYADDR_R +# define GETHOSTBYADDR_LOCK ENVr_LOCALEr_LOCK +# define GETHOSTBYADDR_UNLOCK ENVr_LOCALEr_UNLOCK +#else +# define GETHOSTBYADDR_LOCK gwENVr_LOCALEr_LOCK +# define GETHOSTBYADDR_UNLOCK gwENVr_LOCALEr_UNLOCK +#endif +#ifdef PERL_REENTR_USING_GETHOSTBYNAME_R +# define GETHOSTBYNAME_LOCK ENVr_LOCALEr_LOCK +# define GETHOSTBYNAME_UNLOCK ENVr_LOCALEr_UNLOCK +#else +# define GETHOSTBYNAME_LOCK gwENVr_LOCALEr_LOCK +# define GETHOSTBYNAME_UNLOCK gwENVr_LOCALEr_UNLOCK +#endif +#ifdef PERL_REENTR_USING_GETNETBYADDR_R +# define GETNETBYADDR_LOCK LOCALE_READ_LOCK +# define GETNETBYADDR_UNLOCK LOCALE_READ_UNLOCK +#else +# define GETNETBYADDR_LOCK gwLOCALEr_LOCK +# define GETNETBYADDR_UNLOCK gwLOCALEr_UNLOCK +#endif +#ifdef PERL_REENTR_USING_GETNETBYNAME_R +# define GETNETBYNAME_LOCK LOCALE_READ_LOCK +# define GETNETBYNAME_UNLOCK LOCALE_READ_UNLOCK +#else +# define GETNETBYNAME_LOCK gwLOCALEr_LOCK +# define GETNETBYNAME_UNLOCK gwLOCALEr_UNLOCK +#endif +#ifdef PERL_REENTR_USING_GETPROTOBYNAME_R +# define GETPROTOBYNAME_LOCK LOCALE_READ_LOCK +# define GETPROTOBYNAME_UNLOCK LOCALE_READ_UNLOCK +#else +# define GETPROTOBYNAME_LOCK gwLOCALEr_LOCK +# define GETPROTOBYNAME_UNLOCK gwLOCALEr_UNLOCK +#endif +#ifdef PERL_REENTR_USING_GETPROTOBYNUMBER_R +# define GETPROTOBYNUMBER_LOCK LOCALE_READ_LOCK +# define GETPROTOBYNUMBER_UNLOCK LOCALE_READ_UNLOCK +#else +# define GETPROTOBYNUMBER_LOCK gwLOCALEr_LOCK +# define GETPROTOBYNUMBER_UNLOCK gwLOCALEr_UNLOCK +#endif +#ifdef PERL_REENTR_USING_GETPROTOENT_R +# define GETPROTOENT_LOCK LOCALE_READ_LOCK +# define GETPROTOENT_UNLOCK LOCALE_READ_UNLOCK +#else +# define GETPROTOENT_LOCK gwLOCALEr_LOCK +# define GETPROTOENT_UNLOCK gwLOCALEr_UNLOCK +#endif +#ifdef PERL_REENTR_USING_GETPWNAM_R +# define GETPWNAM_LOCK LOCALE_READ_LOCK +# define GETPWNAM_UNLOCK LOCALE_READ_UNLOCK +#else +# define GETPWNAM_LOCK gwLOCALEr_LOCK +# define GETPWNAM_UNLOCK gwLOCALEr_UNLOCK +#endif +#ifdef PERL_REENTR_USING_GETPWUID_R +# define GETPWUID_LOCK LOCALE_READ_LOCK +# define GETPWUID_UNLOCK LOCALE_READ_UNLOCK +#else +# define GETPWUID_LOCK gwLOCALEr_LOCK +# define GETPWUID_UNLOCK gwLOCALEr_UNLOCK +#endif +#ifdef PERL_REENTR_USING_GETSERVBYNAME_R +# define GETSERVBYNAME_LOCK LOCALE_READ_LOCK +# define GETSERVBYNAME_UNLOCK LOCALE_READ_UNLOCK +#else +# define GETSERVBYNAME_LOCK gwLOCALEr_LOCK +# define GETSERVBYNAME_UNLOCK gwLOCALEr_UNLOCK +#endif +#ifdef PERL_REENTR_USING_GETSERVBYPORT_R +# define GETSERVBYPORT_LOCK LOCALE_READ_LOCK +# define GETSERVBYPORT_UNLOCK LOCALE_READ_UNLOCK +#else +# define GETSERVBYPORT_LOCK gwLOCALEr_LOCK +# define GETSERVBYPORT_UNLOCK gwLOCALEr_UNLOCK +#endif +#ifdef PERL_REENTR_USING_GETSERVENT_R +# define GETSERVENT_LOCK LOCALE_READ_LOCK +# define GETSERVENT_UNLOCK LOCALE_READ_UNLOCK +#else +# define GETSERVENT_LOCK gwLOCALEr_LOCK +# define GETSERVENT_UNLOCK gwLOCALEr_UNLOCK +#endif +#ifdef PERL_REENTR_USING_GETSPNAM_R +# define GETSPNAM_LOCK LOCALE_READ_LOCK +# define GETSPNAM_UNLOCK LOCALE_READ_UNLOCK +#else +# define GETSPNAM_LOCK gwLOCALEr_LOCK +# define GETSPNAM_UNLOCK gwLOCALEr_UNLOCK +#endif + +#define STRFMON_LOCK LC_MONETARY_LOCK +#define STRFMON_UNLOCK LC_MONETARY_UNLOCK + +/* End of locale/env synchronization */ + +#if ! defined(USE_LOCALE_THREADS) +# define LOCALE_INIT +# define LOCALE_TERM +#else +# ifdef WIN32_USE_FAKE_OLD_MINGW_LOCALES + /* This function is coerced by this Configure option into cleaning up + * memory that is static to locale.c. So we call it at termination. Doing + * it this way is kludgy but confines having to deal with this + * Configuration to a bare minimum number of places. */ +# define LOCALE_TERM_POSIX_2008_ Perl_thread_locale_term(NULL) +# elif ! defined(USE_POSIX_2008_LOCALE) +# define LOCALE_TERM_POSIX_2008_ NOOP +# else + /* We have a locale object holding the 'C' locale for Posix 2008 */ +# define LOCALE_TERM_POSIX_2008_ \ + STMT_START { \ + if (PL_C_locale_obj) { \ + /* Make sure we aren't using the locale \ + * space we are about to free */ \ + uselocale(LC_GLOBAL_LOCALE); \ + freelocale(PL_C_locale_obj); \ + PL_C_locale_obj = (locale_t) NULL; \ + } \ + } STMT_END +# endif + +# define LOCALE_INIT MUTEX_INIT(&PL_locale_mutex) +# define LOCALE_TERM STMT_START { \ + LOCALE_TERM_POSIX_2008_; \ + MUTEX_DESTROY(&PL_locale_mutex); \ + } STMT_END +#endif + +#ifdef USE_LOCALE /* These locale things are all subject to change */ + + /* Returns TRUE if the plain locale pragma without a parameter is in effect. + * */ +# define IN_LOCALE_RUNTIME (PL_curcop \ + && CopHINTS_get(PL_curcop) & HINT_LOCALE) + + /* Returns TRUE if either form of the locale pragma is in effect */ +# define IN_SOME_LOCALE_FORM_RUNTIME \ + cBOOL(CopHINTS_get(PL_curcop) & (HINT_LOCALE|HINT_LOCALE_PARTIAL)) + +# define IN_LOCALE_COMPILETIME cBOOL(PL_hints & HINT_LOCALE) +# define IN_SOME_LOCALE_FORM_COMPILETIME \ + cBOOL(PL_hints & (HINT_LOCALE|HINT_LOCALE_PARTIAL)) + +/* +=for apidoc_section $locale + +=for apidoc Amn|bool|IN_LOCALE + +Evaluates to TRUE if the plain locale pragma without a parameter (S>) is in effect. + +=for apidoc Amn|bool|IN_LOCALE_COMPILETIME Evaluates to TRUE if, when compiling a perl program (including an C) if the plain locale pragma without a parameter (S>) is in effect. @@ -7008,7 +7456,7 @@ the plain locale pragma without a parame # define IN_LC(category) \ (IN_LC_COMPILETIME(category) || IN_LC_RUNTIME(category)) -# if defined (PERL_CORE) || defined (PERL_IN_XSUB_RE) +# if defined (PERL_CORE) || defined (PERL_IN_XSUB_RE) || defined(PERL_EXT_POSIX) /* This internal macro should be called from places that operate under * locale rules. If there is a problem with the current locale that @@ -7020,7 +7468,7 @@ the plain locale pragma without a parame # define CHECK_AND_WARN_PROBLEMATIC_LOCALE_ \ STMT_START { \ if (UNLIKELY(PL_warn_locale)) { \ - Perl__warn_problematic_locale(); \ + Perl_warn_problematic_locale(); \ } \ } STMT_END # else @@ -7033,270 +7481,49 @@ the plain locale pragma without a parame * argument; the 2nd, is a pointer to the first byte of the UTF-8 encoded * string, and an end position which it won't try to read past */ # define _CHECK_AND_OUTPUT_WIDE_LOCALE_CP_MSG(cp) \ - STMT_START { \ - if (! IN_UTF8_CTYPE_LOCALE && ckWARN(WARN_LOCALE)) { \ - Perl_warner(aTHX_ packWARN(WARN_LOCALE), \ - "Wide character (U+%" UVXf ") in %s",\ - (UV) cp, OP_DESC(PL_op)); \ - } \ - } STMT_END - -# define _CHECK_AND_OUTPUT_WIDE_LOCALE_UTF8_MSG(s, send) \ - STMT_START { /* Check if to warn before doing the conversion work */\ - if (! IN_UTF8_CTYPE_LOCALE && ckWARN(WARN_LOCALE)) { \ - UV cp = utf8_to_uvchr_buf((U8 *) (s), (U8 *) (send), NULL); \ - Perl_warner(aTHX_ packWARN(WARN_LOCALE), \ - "Wide character (U+%" UVXf ") in %s", \ - (cp == 0) \ - ? UNICODE_REPLACEMENT \ - : (UV) cp, \ - OP_DESC(PL_op)); \ - } \ - } STMT_END - -# endif /* PERL_CORE or PERL_IN_XSUB_RE */ -#else /* No locale usage */ -# define IN_LOCALE_RUNTIME 0 -# define IN_SOME_LOCALE_FORM_RUNTIME 0 -# define IN_LOCALE_COMPILETIME 0 -# define IN_SOME_LOCALE_FORM_COMPILETIME 0 -# define IN_LOCALE 0 -# define IN_SOME_LOCALE_FORM 0 -# define IN_LC_ALL_COMPILETIME 0 -# define IN_LC_ALL_RUNTIME 0 -# define IN_LC_PARTIAL_COMPILETIME 0 -# define IN_LC_PARTIAL_RUNTIME 0 -# define IN_LC_COMPILETIME(category) 0 -# define IN_LC_RUNTIME(category) 0 -# define IN_LC(category) 0 -# define CHECK_AND_WARN_PROBLEMATIC_LOCALE_ -# define _CHECK_AND_OUTPUT_WIDE_LOCALE_UTF8_MSG(s, send) -# define _CHECK_AND_OUTPUT_WIDE_LOCALE_CP_MSG(c) -#endif - -#define locale_panic_(m) Perl_locale_panic((m), __FILE__, __LINE__, errno) - -/* Locale/thread synchronization macros. */ -#if ! defined(USE_LOCALE) || ! defined(USE_LOCALE_THREADS) -# define LOCALE_LOCK_(cond) NOOP -# define LOCALE_UNLOCK_ NOOP -# define LOCALE_INIT -# define LOCALE_TERM - -#else /* Below: Threaded, and locales are supported */ - - /* A locale mutex is required on all such threaded builds. - * - * This mutex simulates a general (or recursive) semaphore. The current - * thread will lock the mutex if the per-thread variable is zero, and then - * increments that variable. Each corresponding UNLOCK decrements the - * variable until it is 0, at which point it actually unlocks the mutex. - * Since the variable is per-thread, initialized to 0, there is no race - * with other threads. - * - * The single argument is a condition to test for, and if true, to panic. - * Call it with the constant 0 to suppress the check. - * - * Clang improperly gives warnings for this, if not silenced: - * https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#conditional-locks - */ -# define LOCALE_LOCK_(cond_to_panic_if_already_locked) \ - STMT_START { \ - CLANG_DIAG_IGNORE(-Wthread-safety) \ - if (LIKELY(PL_locale_mutex_depth <= 0)) { \ - DEBUG_Lv(PerlIO_printf(Perl_debug_log, \ - "%s: %d: locking locale; depth=1\n", \ - __FILE__, __LINE__)); \ - MUTEX_LOCK(&PL_locale_mutex); \ - PL_locale_mutex_depth = 1; \ - } \ - else { \ - PL_locale_mutex_depth++; \ - DEBUG_Lv(PerlIO_printf(Perl_debug_log, \ - "%s: %d: avoided locking locale; new depth=%d\n", \ - __FILE__, __LINE__, PL_locale_mutex_depth)); \ - if (cond_to_panic_if_already_locked) { \ - locale_panic_("Trying to lock locale incompatibly: " \ - STRINGIFY(cond_to_panic_if_already_locked)); \ - } \ - } \ - CLANG_DIAG_RESTORE \ - } STMT_END - -# define LOCALE_UNLOCK_ \ - STMT_START { \ - if (LIKELY(PL_locale_mutex_depth == 1)) { \ - DEBUG_Lv(PerlIO_printf(Perl_debug_log, \ - "%s: %d: unlocking locale; new depth=0\n", \ - __FILE__, __LINE__)); \ - PL_locale_mutex_depth = 0; \ - MUTEX_UNLOCK(&PL_locale_mutex); \ - } \ - else if (PL_locale_mutex_depth <= 0) { \ - DEBUG_L(PerlIO_printf(Perl_debug_log, \ - "%s: %d: ignored attempt to unlock already" \ - " unlocked locale; depth unchanged at %d\n", \ - __FILE__, __LINE__, PL_locale_mutex_depth)); \ - } \ - else { \ - PL_locale_mutex_depth--; \ - DEBUG_Lv(PerlIO_printf(Perl_debug_log, \ - "%s: %d: avoided unlocking locale; new depth=%d\n", \ - __FILE__, __LINE__, PL_locale_mutex_depth)); \ - } \ - } STMT_END - -# if defined(USE_THREADS) && ! defined(USE_THREAD_SAFE_LOCALE) - - /* By definition, a thread-unsafe locale means we need a critical - * section. */ -# define SETLOCALE_LOCK LOCALE_LOCK_(0) -# define SETLOCALE_UNLOCK LOCALE_UNLOCK_ -# ifdef USE_LOCALE_NUMERIC -# define LC_NUMERIC_LOCK(cond_to_panic_if_already_locked) \ - LOCALE_LOCK_(cond_to_panic_if_already_locked) -# define LC_NUMERIC_UNLOCK LOCALE_UNLOCK_ -# endif -# endif - -# ifndef USE_POSIX_2008_LOCALE -# define LOCALE_TERM_POSIX_2008_ NOOP -# else - /* We have a locale object holding the 'C' locale for Posix 2008 */ -# define LOCALE_TERM_POSIX_2008_ \ - STMT_START { \ - if (PL_C_locale_obj) { \ - /* Make sure we aren't using the locale \ - * space we are about to free */ \ - uselocale(LC_GLOBAL_LOCALE); \ - freelocale(PL_C_locale_obj); \ - PL_C_locale_obj = (locale_t) NULL; \ - } \ - } STMT_END -# endif - -# define LOCALE_INIT MUTEX_INIT(&PL_locale_mutex) -# define LOCALE_TERM STMT_START { \ - LOCALE_TERM_POSIX_2008_; \ - MUTEX_DESTROY(&PL_locale_mutex); \ - } STMT_END -#endif - -/* There are some locale-related functions which may need locking only because - * they share some common memory across threads, and hence there is the - * potential for a race in accessing that space. Most are because their return - * points to a global static buffer, but some just use some common space - * internally. All functions accessing a given space need to have a critical - * section to prevent any other thread from accessing it at the same time. - * Ideally, there would be a separate mutex for each such space, so that - * another thread isn't unnecessarily blocked. But, most of them need to be - * locked against the locale changing while accessing that space, and it is not - * expected that any will be called frequently, and the locked interval should - * be short, and modern platforms will have reentrant versions (which don't - * lock) for almost all of them, so khw thinks a single mutex should suffice. - * Having a single mutex facilitates that, avoiding potential deadlock - * situations. - * - * This will be a no-op iff the perl is unthreaded. 'gw' stands for 'global - * write', to indicate the caller wants to be able to access memory that isn't - * thread specific, either to write to itself, or to prevent anyone else from - * writing. */ -#define gwLOCALE_LOCK LOCALE_LOCK_(0) -#define gwLOCALE_UNLOCK LOCALE_UNLOCK_ - -/* setlocale() generally returns in a global static buffer, but not on Windows - * when operating in thread-safe mode */ -#if defined(WIN32) && defined(USE_THREAD_SAFE_LOCALE) -# define POSIX_SETLOCALE_LOCK \ - STMT_START { \ - if (_configthreadlocale(0) == _DISABLE_PER_THREAD_LOCALE) \ - gwLOCALE_LOCK; \ - } STMT_END -# define POSIX_SETLOCALE_UNLOCK \ - STMT_START { \ - if (_configthreadlocale(0) == _DISABLE_PER_THREAD_LOCALE) \ - gwLOCALE_UNLOCK; \ - } STMT_END -#else -# define POSIX_SETLOCALE_LOCK gwLOCALE_LOCK -# define POSIX_SETLOCALE_UNLOCK gwLOCALE_UNLOCK -#endif - -/* It handles _wsetlocale() as well */ -#define WSETLOCALE_LOCK POSIX_SETLOCALE_LOCK -#define WSETLOCALE_UNLOCK POSIX_SETLOCALE_UNLOCK - -/* Similar to gwLOCALE_LOCK, there are functions that require both the locale - * and environment to be constant during their execution, and don't change - * either of those things, but do write to some sort of shared global space. - * They require some sort of exclusive lock against similar functions, and a - * read lock on both the locale and environment. However, on systems which - * have per-thread locales, the locale is constant during the execution of - * these functions, and so no locale lock is necssary. For such systems, an - * exclusive ENV lock is necessary and sufficient. On systems where the locale - * could change out from under us, we use an exclusive LOCALE lock to prevent - * that, and a read ENV lock to prevent other threads that have nothing to do - * with locales here from changing the environment. */ -#ifdef SETLOCALE_LOCK -# define gwENVr_LOCALEr_LOCK \ - STMT_START { SETLOCALE_LOCK; ENV_READ_LOCK; } STMT_END -# define gwENVr_LOCALEr_UNLOCK \ - STMT_START { ENV_READ_UNLOCK; SETLOCALE_UNLOCK; } STMT_END -#else -# define gwENVr_LOCALEr_LOCK ENV_LOCK -# define gwENVr_LOCALEr_UNLOCK ENV_UNLOCK -#endif - -/* Now that we have defined gwENVr_LOCALEr_LOCK, we can finish defining - * SETLOCALE_LOCK, which we kept undefined until here on a thread-safe system - * so that we could use that fact to calculate what gwENVr_LOCALEr_LOCK should - * be */ -#ifndef SETLOCALE_LOCK -# define SETLOCALE_LOCK NOOP -# define SETLOCALE_UNLOCK NOOP -#endif - - - /* On systems that don't have per-thread locales, even though we don't - * think we are changing the locale ourselves, behind the scenes it does - * get changed to whatever the thread's should be, so it has to be an - * exclusive lock. By defining it here with this name, we can, for the - * most part, hide this detail from the rest of the code */ -/* Currently, the read lock is an exclusive lock */ -#define LOCALE_READ_LOCK SETLOCALE_LOCK -#define LOCALE_READ_UNLOCK SETLOCALE_UNLOCK - - -#ifndef LC_NUMERIC_LOCK -# define LC_NUMERIC_LOCK(cond) NOOP -# define LC_NUMERIC_UNLOCK NOOP -#endif - - /* These non-reentrant versions use global space */ -# define MBLEN_LOCK_ gwLOCALE_LOCK -# define MBLEN_UNLOCK_ gwLOCALE_UNLOCK - -# define MBTOWC_LOCK_ gwLOCALE_LOCK -# define MBTOWC_UNLOCK_ gwLOCALE_UNLOCK - -# define WCTOMB_LOCK_ gwLOCALE_LOCK -# define WCTOMB_UNLOCK_ gwLOCALE_UNLOCK + STMT_START { \ + if (! IN_UTF8_CTYPE_LOCALE && ckWARN(WARN_LOCALE)) { \ + Perl_warner(aTHX_ packWARN(WARN_LOCALE), \ + "Wide character (U+%" UVXf ") in %s",\ + (UV) cp, OP_DESC(PL_op)); \ + } \ + } STMT_END - /* Whereas the reentrant versions don't (assuming they are called with a - * per-thread buffer; some have the capability of being called with a NULL - * parameter, which defeats the reentrancy) */ -# define MBRLEN_LOCK_ NOOP -# define MBRLEN_UNLOCK_ NOOP -# define MBRTOWC_LOCK_ NOOP -# define MBRTOWC_UNLOCK_ NOOP -# define WCRTOMB_LOCK_ NOOP -# define WCRTOMB_UNLOCK_ NOOP +# define _CHECK_AND_OUTPUT_WIDE_LOCALE_UTF8_MSG(s, send) \ + STMT_START { /* Check if to warn before doing the conversion work */\ + if (! IN_UTF8_CTYPE_LOCALE && ckWARN(WARN_LOCALE)) { \ + UV cp = utf8_to_uvchr_buf((U8 *) (s), (U8 *) (send), NULL); \ + Perl_warner(aTHX_ packWARN(WARN_LOCALE), \ + "Wide character (U+%" UVXf ") in %s", \ + (cp == 0) \ + ? UNICODE_REPLACEMENT \ + : (UV) cp, \ + OP_DESC(PL_op)); \ + } \ + } STMT_END -# define LC_COLLATE_LOCK SETLOCALE_LOCK -# define LC_COLLATE_UNLOCK SETLOCALE_UNLOCK +# endif /* PERL_CORE or PERL_IN_XSUB_RE */ +#else /* No locale usage */ +# define IN_LOCALE_RUNTIME 0 +# define IN_SOME_LOCALE_FORM_RUNTIME 0 +# define IN_LOCALE_COMPILETIME 0 +# define IN_SOME_LOCALE_FORM_COMPILETIME 0 +# define IN_LOCALE 0 +# define IN_SOME_LOCALE_FORM 0 +# define IN_LC_ALL_COMPILETIME 0 +# define IN_LC_ALL_RUNTIME 0 +# define IN_LC_PARTIAL_COMPILETIME 0 +# define IN_LC_PARTIAL_RUNTIME 0 +# define IN_LC_COMPILETIME(category) 0 +# define IN_LC_RUNTIME(category) 0 +# define IN_LC(category) 0 +# define CHECK_AND_WARN_PROBLEMATIC_LOCALE_ +# define _CHECK_AND_OUTPUT_WIDE_LOCALE_UTF8_MSG(s, send) +# define _CHECK_AND_OUTPUT_WIDE_LOCALE_CP_MSG(c) +#endif -# define STRFTIME_LOCK ENV_LOCK -# define STRFTIME_UNLOCK ENV_UNLOCK +#define locale_panic_via_(m, f, l) Perl_locale_panic((m), __LINE__, f, l) +#define locale_panic_(m) locale_panic_via_((m), __FILE__, __LINE__) #ifdef USE_LOCALE_NUMERIC @@ -7456,14 +7683,17 @@ cannot have changed since the precalcula # define NOT_IN_NUMERIC_STANDARD_ (! PL_numeric_standard) -/* We can lock the category to stay in the C locale, making requests to the - * contrary be noops, in the dynamic scope by setting PL_numeric_standard to 2. - * */ +/* This macro is designed to be a helper macro when we think an operation needs + * to take place in the underlying numeric locale category. When 'true', the + * caller will attempt to toggle to that category. But a later addition was an + * override that prevents that toggle when PL_numeric_standard >= 2. The name + * of the macro was not changed when this was added. */ # define NOT_IN_NUMERIC_UNDERLYING_ \ (! PL_numeric_underlying && PL_numeric_standard < 2) # define DECLARATION_FOR_LC_NUMERIC_MANIPULATION \ - void (*_restore_LC_NUMERIC_function)(pTHX) = NULL + void (*_restore_LC_NUMERIC_function)(pTHX_ const char * const file, \ + const line_t line) = NULL # define STORE_LC_NUMERIC_SET_TO_NEEDED_IN(in) \ STMT_START { \ @@ -7473,14 +7703,14 @@ cannot have changed since the precalcula || (! _in_lc_numeric && NOT_IN_NUMERIC_STANDARD_))); \ if (_in_lc_numeric) { \ if (NOT_IN_NUMERIC_UNDERLYING_) { \ - Perl_set_numeric_underlying(aTHX); \ + Perl_set_numeric_underlying(aTHX_ __FILE__, __LINE__); \ _restore_LC_NUMERIC_function \ = &Perl_set_numeric_standard; \ } \ } \ else { \ if (NOT_IN_NUMERIC_STANDARD_) { \ - Perl_set_numeric_standard(aTHX); \ + Perl_set_numeric_standard(aTHX_ __FILE__, __LINE__); \ _restore_LC_NUMERIC_function \ = &Perl_set_numeric_underlying; \ } \ @@ -7493,7 +7723,7 @@ cannot have changed since the precalcula # define RESTORE_LC_NUMERIC() \ STMT_START { \ if (_restore_LC_NUMERIC_function) { \ - _restore_LC_NUMERIC_function(aTHX); \ + _restore_LC_NUMERIC_function(aTHX_ __FILE__, __LINE__); \ } \ LC_NUMERIC_UNLOCK; \ } STMT_END @@ -7506,7 +7736,7 @@ cannot have changed since the precalcula "%s: %d: lc_numeric standard=%d\n", \ __FILE__, __LINE__, PL_numeric_standard)); \ if (UNLIKELY(NOT_IN_NUMERIC_STANDARD_)) { \ - Perl_set_numeric_standard(aTHX); \ + Perl_set_numeric_standard(aTHX_ __FILE__, __LINE__); \ } \ DEBUG_Lv(PerlIO_printf(Perl_debug_log, \ "%s: %d: lc_numeric standard=%d\n", \ @@ -7517,7 +7747,7 @@ cannot have changed since the precalcula STMT_START { \ /*assert(PL_locale_mutex_depth > 0);*/ \ if (NOT_IN_NUMERIC_UNDERLYING_) { \ - Perl_set_numeric_underlying(aTHX); \ + Perl_set_numeric_underlying(aTHX_ __FILE__, __LINE__); \ } \ } STMT_END @@ -7528,7 +7758,7 @@ cannot have changed since the precalcula LC_NUMERIC_LOCK(NOT_IN_NUMERIC_STANDARD_); \ if (NOT_IN_NUMERIC_STANDARD_) { \ _restore_LC_NUMERIC_function = &Perl_set_numeric_underlying;\ - Perl_set_numeric_standard(aTHX); \ + Perl_set_numeric_standard(aTHX_ __FILE__, __LINE__); \ } \ } STMT_END @@ -7538,23 +7768,27 @@ cannot have changed since the precalcula STMT_START { \ LC_NUMERIC_LOCK(NOT_IN_NUMERIC_UNDERLYING_); \ if (NOT_IN_NUMERIC_UNDERLYING_) { \ - Perl_set_numeric_underlying(aTHX); \ + Perl_set_numeric_underlying(aTHX_ __FILE__, __LINE__); \ _restore_LC_NUMERIC_function = &Perl_set_numeric_standard; \ } \ } STMT_END -/* Lock/unlock to the C locale until unlock is called. This needs to be - * recursively callable. [perl #128207] */ -# define LOCK_LC_NUMERIC_STANDARD() \ +/* Lock/unlock changes to LC_NUMERIC. This needs to be recursively callable. + * The highest level caller is responsible for making sure that LC_NUMERIC is + * set to a locale with a dot radix character. These deliberately don't check + * for the internal state being so, as they can be called from code that is not + * party to the internal conventions, namely 'version' (vutil.c). + * PL_numeric_standard changing doesn't affect anything about what locale is in + * effect, etc. [perl #128207] */ +# define DISABLE_LC_NUMERIC_CHANGES() \ STMT_START { \ DEBUG_Lv(PerlIO_printf(Perl_debug_log, \ "%s: %d: lc_numeric_standard now locked to depth %d\n", \ __FILE__, __LINE__, PL_numeric_standard)); \ - __ASSERT_(PL_numeric_standard) \ PL_numeric_standard++; \ } STMT_END -# define UNLOCK_LC_NUMERIC_STANDARD() \ +# define REENABLE_LC_NUMERIC_CHANGES() \ STMT_START { \ if (PL_numeric_standard > 1) { \ PL_numeric_standard--; \ @@ -7572,13 +7806,24 @@ cannot have changed since the precalcula PL_numeric_standard););\ } STMT_END +/* Essentially synonyms for the above. The LOCK asserts at the top level that + * we are in a locale equivalent to C. By including the top level, this can be + * recursively called from chains which include DISABLE_LC_NUMERIC_CHANGES(). + * */ +# define LOCK_LC_NUMERIC_STANDARD() \ + STMT_START { \ + assert(PL_numeric_standard > 0 || PL_numeric_standard); \ + DISABLE_LC_NUMERIC_CHANGES(); \ + } STMT_END +# define UNLOCK_LC_NUMERIC_STANDARD() REENABLE_LC_NUMERIC_CHANGES() + # define WITH_LC_NUMERIC_SET_TO_NEEDED_IN(in_lc_numeric, block) \ STMT_START { \ DECLARATION_FOR_LC_NUMERIC_MANIPULATION; \ STORE_LC_NUMERIC_SET_TO_NEEDED_IN(in_lc_numeric); \ block; \ RESTORE_LC_NUMERIC(); \ - } STMT_END; + } STMT_END # define WITH_LC_NUMERIC_SET_TO_NEEDED(block) \ WITH_LC_NUMERIC_SET_TO_NEEDED_IN(IN_LC(LC_NUMERIC), block) @@ -7596,6 +7841,8 @@ cannot have changed since the precalcula # define RESTORE_LC_NUMERIC() # define LOCK_LC_NUMERIC_STANDARD() # define UNLOCK_LC_NUMERIC_STANDARD() +# define DISABLE_LC_NUMERIC_CHANGES() +# define REENABLE_LC_NUMERIC_CHANGES() # define WITH_LC_NUMERIC_SET_TO_NEEDED_IN(in_lc_numeric, block) \ STMT_START { block; } STMT_END # define WITH_LC_NUMERIC_SET_TO_NEEDED(block) \ @@ -7603,195 +7850,6 @@ cannot have changed since the precalcula #endif /* !USE_LOCALE_NUMERIC */ -#ifdef USE_LOCALE_THREADS -# define ENV_LOCK PERL_WRITE_LOCK(&PL_env_mutex) -# define ENV_UNLOCK PERL_WRITE_UNLOCK(&PL_env_mutex) -# define ENV_READ_LOCK PERL_READ_LOCK(&PL_env_mutex) -# define ENV_READ_UNLOCK PERL_READ_UNLOCK(&PL_env_mutex) -# define ENV_INIT PERL_RW_MUTEX_INIT(&PL_env_mutex) -# define ENV_TERM PERL_RW_MUTEX_DESTROY(&PL_env_mutex) - - /* On platforms where the static buffer contained in getenv() is per-thread - * rather than process-wide, another thread executing a getenv() at the same - * time won't destroy ours before we have copied the result safely away and - * unlocked the mutex. On such platforms (which is most), we can have many - * readers of the environment at the same time. */ -# ifdef GETENV_PRESERVES_OTHER_THREAD -# define GETENV_LOCK ENV_READ_LOCK -# define GETENV_UNLOCK ENV_READ_UNLOCK -# else - /* If, on the other hand, another thread could zap our getenv() return, we - * need to keep them from executing until we are done */ -# define GETENV_LOCK ENV_LOCK -# define GETENV_UNLOCK ENV_UNLOCK -# endif -#else -# define ENV_LOCK NOOP -# define ENV_UNLOCK NOOP -# define ENV_READ_LOCK NOOP -# define ENV_READ_UNLOCK NOOP -# define ENV_INIT NOOP -# define ENV_TERM NOOP -# define GETENV_LOCK NOOP -# define GETENV_UNLOCK NOOP -#endif - -/* Some critical sections need to lock both the locale and the environment from - * changing, while allowing for any number of readers. To avoid deadlock, this - * is always done in the same order. These should always be invoked, like all - * locks really, at such a low level that its just a libc call that is wrapped, - * so as to prevent recursive calls which could deadlock. */ -#define ENVr_LOCALEr_LOCK \ - STMT_START { LOCALE_READ_LOCK; ENV_READ_LOCK; } STMT_END -#define ENVr_LOCALEr_UNLOCK \ - STMT_START { ENV_READ_UNLOCK; LOCALE_READ_UNLOCK; } STMT_END - -/* These time-related functions all requre that the environment and locale - * don't change while they are executing (at least in glibc; this appears to be - * contrary to the POSIX standard). tzset() writes global variables, so - * always needs to have write locking. ctime, localtime, mktime, and strftime - * effectively call it, so they too need exclusive access. The rest need to - * have exclusive locking as well so that they can copy the contents of the - * returned static buffer before releasing the lock. That leaves asctime and - * gmtime. There may be reentrant versions of these available on the platform - * which don't require write locking. - */ -#ifdef PERL_REENTR_USING_ASCTIME_R -# define ASCTIME_LOCK ENVr_LOCALEr_LOCK -# define ASCTIME_UNLOCK ENVr_LOCALEr_UNLOCK -#else -# define ASCTIME_LOCK gwENVr_LOCALEr_LOCK -# define ASCTIME_UNLOCK gwENVr_LOCALEr_UNLOCK -#endif - -#define CTIME_LOCK gwENVr_LOCALEr_LOCK -#define CTIME_UNLOCK gwENVr_LOCALEr_UNLOCK - -#ifdef PERL_REENTR_USING_GMTIME_R -# define GMTIME_LOCK ENVr_LOCALEr_LOCK -# define GMTIME_UNLOCK ENVr_LOCALEr_UNLOCK -#else -# define GMTIME_LOCK gwENVr_LOCALEr_LOCK -# define GMTIME_UNLOCK gwENVr_LOCALEr_UNLOCK -#endif - -#define LOCALTIME_LOCK gwENVr_LOCALEr_LOCK -#define LOCALTIME_UNLOCK gwENVr_LOCALEr_UNLOCK -#define MKTIME_LOCK gwENVr_LOCALEr_LOCK -#define MKTIME_UNLOCK gwENVr_LOCALEr_UNLOCK -#define TZSET_LOCK gwENVr_LOCALEr_LOCK -#define TZSET_UNLOCK gwENVr_LOCALEr_UNLOCK - -/* Similiarly, these functions need a constant environment and/or locale. And - * some have a buffer that is shared with another thread executing the same or - * a related call. A mutex could be created for each class, but for now, share - * the ENV mutex with everything, as none probably gets called so much that - * performance would suffer by a thread being locked out by another thread that - * could have used a different mutex. - * - * But, create a different macro name just to indicate the ones that don't - * actually depend on the environment, but are using its mutex for want of a - * better one */ -#define gwLOCALEr_LOCK gwENVr_LOCALEr_LOCK -#define gwLOCALEr_UNLOCK gwENVr_LOCALEr_UNLOCK - -#ifdef PERL_REENTR_USING_GETHOSTBYADDR_R -# define GETHOSTBYADDR_LOCK ENVr_LOCALEr_LOCK -# define GETHOSTBYADDR_UNLOCK ENVr_LOCALEr_UNLOCK -#else -# define GETHOSTBYADDR_LOCK gwENVr_LOCALEr_LOCK -# define GETHOSTBYADDR_UNLOCK gwENVr_LOCALEr_UNLOCK -#endif -#ifdef PERL_REENTR_USING_GETHOSTBYNAME_R -# define GETHOSTBYNAME_LOCK ENVr_LOCALEr_LOCK -# define GETHOSTBYNAME_UNLOCK ENVr_LOCALEr_UNLOCK -#else -# define GETHOSTBYNAME_LOCK gwENVr_LOCALEr_LOCK -# define GETHOSTBYNAME_UNLOCK gwENVr_LOCALEr_UNLOCK -#endif -#ifdef PERL_REENTR_USING_GETNETBYADDR_R -# define GETNETBYADDR_LOCK LOCALE_READ_LOCK -# define GETNETBYADDR_UNLOCK LOCALE_READ_UNLOCK -#else -# define GETNETBYADDR_LOCK gwLOCALEr_LOCK -# define GETNETBYADDR_UNLOCK gwLOCALEr_UNLOCK -#endif -#ifdef PERL_REENTR_USING_GETNETBYNAME_R -# define GETNETBYNAME_LOCK LOCALE_READ_LOCK -# define GETNETBYNAME_UNLOCK LOCALE_READ_UNLOCK -#else -# define GETNETBYNAME_LOCK gwLOCALEr_LOCK -# define GETNETBYNAME_UNLOCK gwLOCALEr_UNLOCK -#endif -#ifdef PERL_REENTR_USING_GETPROTOBYNAME_R -# define GETPROTOBYNAME_LOCK LOCALE_READ_LOCK -# define GETPROTOBYNAME_UNLOCK LOCALE_READ_UNLOCK -#else -# define GETPROTOBYNAME_LOCK gwLOCALEr_LOCK -# define GETPROTOBYNAME_UNLOCK gwLOCALEr_UNLOCK -#endif -#ifdef PERL_REENTR_USING_GETPROTOBYNUMBER_R -# define GETPROTOBYNUMBER_LOCK LOCALE_READ_LOCK -# define GETPROTOBYNUMBER_UNLOCK LOCALE_READ_UNLOCK -#else -# define GETPROTOBYNUMBER_LOCK gwLOCALEr_LOCK -# define GETPROTOBYNUMBER_UNLOCK gwLOCALEr_UNLOCK -#endif -#ifdef PERL_REENTR_USING_GETPROTOENT_R -# define GETPROTOENT_LOCK LOCALE_READ_LOCK -# define GETPROTOENT_UNLOCK LOCALE_READ_UNLOCK -#else -# define GETPROTOENT_LOCK gwLOCALEr_LOCK -# define GETPROTOENT_UNLOCK gwLOCALEr_UNLOCK -#endif -#ifdef PERL_REENTR_USING_GETPWNAM_R -# define GETPWNAM_LOCK LOCALE_READ_LOCK -# define GETPWNAM_UNLOCK LOCALE_READ_UNLOCK -#else -# define GETPWNAM_LOCK gwLOCALEr_LOCK -# define GETPWNAM_UNLOCK gwLOCALEr_UNLOCK -#endif -#ifdef PERL_REENTR_USING_GETPWUID_R -# define GETPWUID_LOCK LOCALE_READ_LOCK -# define GETPWUID_UNLOCK LOCALE_READ_UNLOCK -#else -# define GETPWUID_LOCK gwLOCALEr_LOCK -# define GETPWUID_UNLOCK gwLOCALEr_UNLOCK -#endif -#ifdef PERL_REENTR_USING_GETSERVBYNAME_R -# define GETSERVBYNAME_LOCK LOCALE_READ_LOCK -# define GETSERVBYNAME_UNLOCK LOCALE_READ_UNLOCK -#else -# define GETSERVBYNAME_LOCK gwLOCALEr_LOCK -# define GETSERVBYNAME_UNLOCK gwLOCALEr_UNLOCK -#endif -#ifdef PERL_REENTR_USING_GETSERVBYPORT_R -# define GETSERVBYPORT_LOCK LOCALE_READ_LOCK -# define GETSERVBYPORT_UNLOCK LOCALE_READ_UNLOCK -#else -# define GETSERVBYPORT_LOCK gwLOCALEr_LOCK -# define GETSERVBYPORT_UNLOCK gwLOCALEr_UNLOCK -#endif -#ifdef PERL_REENTR_USING_GETSERVENT_R -# define GETSERVENT_LOCK LOCALE_READ_LOCK -# define GETSERVENT_UNLOCK LOCALE_READ_UNLOCK -#else -# define GETSERVENT_LOCK gwLOCALEr_LOCK -# define GETSERVENT_UNLOCK gwLOCALEr_UNLOCK -#endif -#ifdef PERL_REENTR_USING_GETSPNAM_R -# define GETSPNAM_LOCK LOCALE_READ_LOCK -# define GETSPNAM_UNLOCK LOCALE_READ_UNLOCK -#else -# define GETSPNAM_LOCK gwLOCALEr_LOCK -# define GETSPNAM_UNLOCK gwLOCALEr_UNLOCK -#endif - -#define STRFMON_LOCK LC_MONETARY_LOCK -#define STRFMON_UNLOCK LC_MONETARY_UNLOCK - -/* End of locale/env synchronization */ - #ifndef PERL_NO_INLINE_FUNCTIONS /* Static inline funcs that depend on includes and declarations above. Some of these reference functions in the perl object files, and some @@ -7932,14 +7990,8 @@ C. * massively. */ -#ifndef PERL_MICRO -# ifndef PERL_ASYNC_CHECK -# define PERL_ASYNC_CHECK() if (UNLIKELY(PL_sig_pending)) PL_signalhook(aTHX) -# endif -#endif - #ifndef PERL_ASYNC_CHECK -# define PERL_ASYNC_CHECK() NOOP +#define PERL_ASYNC_CHECK() if (UNLIKELY(PL_sig_pending)) PL_signalhook(aTHX) #endif /* @@ -9127,6 +9179,33 @@ END_EXTERN_C #endif #define PERL_PARSE_ERROR_COUNT(f) (f) + + +/* Work around + + https://github.com/Perl/perl5/issues/21313 + + Where gcc when generating code for 32-bit windows assumes the stack + is 16 byte aligned, where the system doesn't guarantee that. + + The code generated by gcc itself does maintain 16 byte alignment, + but callbacks from the CRT or Windows APIs don't, so calls to + code that is generated to SSE instructions (like the quadmath code + by default), crashes when called from a callback. + + Since other code other than quadmath might use SSE instructions, + also enable this outside of quadmath builds. + + This change is a little risky: if an XS module uses callbacks + and those callbacks may also produce alignment errors, if that + becomes a problem we'll need to use the nuclear option: building + 32-bit perl with -mstackrealign. +*/ +#if defined(WIN32) && !defined(WIN64) && defined(__GNUC__) +# define PERL_STACK_REALIGN __attribute__((force_align_arg_pointer)) +#else +# define PERL_STACK_REALIGN +#endif /* Index: gnu/usr.bin/perl/perl_langinfo.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/perl_langinfo.h,v diff -u -p -a -u -p -r1.1.1.1 perl_langinfo.h --- gnu/usr.bin/perl/perl_langinfo.h 13 Feb 2019 21:10:45 -0000 1.1.1.1 +++ gnu/usr.bin/perl/perl_langinfo.h 22 Jan 2025 00:37:44 -0000 @@ -6,8 +6,12 @@ #include "config.h" -#if defined(HAS_NL_LANGINFO) && defined(I_LANGINFO) +#if defined(I_LANGINFO) # include +#else + +typedef int nl_item; /* Substitute 'int' for emulated nl_langinfo() */ + #endif /* NOTE that this file is parsed by ext/XS-APItest/t/locale.t, so be careful @@ -17,174 +21,317 @@ #ifndef CODESET # define CODESET -1 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef D_T_FMT # define D_T_FMT -2 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef D_FMT # define D_FMT -3 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef T_FMT # define T_FMT -4 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef T_FMT_AMPM # define T_FMT_AMPM -5 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef AM_STR # define AM_STR -6 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef PM_STR # define PM_STR -7 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef DAY_1 # define DAY_1 -8 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef DAY_2 # define DAY_2 -9 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef DAY_3 # define DAY_3 -10 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef DAY_4 # define DAY_4 -11 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef DAY_5 # define DAY_5 -12 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef DAY_6 # define DAY_6 -13 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef DAY_7 # define DAY_7 -14 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABDAY_1 # define ABDAY_1 -15 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABDAY_2 # define ABDAY_2 -16 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABDAY_3 # define ABDAY_3 -17 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABDAY_4 # define ABDAY_4 -18 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABDAY_5 # define ABDAY_5 -19 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABDAY_6 # define ABDAY_6 -20 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABDAY_7 # define ABDAY_7 -21 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef MON_1 # define MON_1 -22 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef MON_2 # define MON_2 -23 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef MON_3 # define MON_3 -24 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef MON_4 # define MON_4 -25 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef MON_5 # define MON_5 -26 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef MON_6 # define MON_6 -27 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef MON_7 # define MON_7 -28 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef MON_8 # define MON_8 -29 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef MON_9 # define MON_9 -30 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef MON_10 # define MON_10 -31 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef MON_11 # define MON_11 -32 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef MON_12 # define MON_12 -33 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABMON_1 # define ABMON_1 -34 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABMON_2 # define ABMON_2 -35 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABMON_3 # define ABMON_3 -36 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABMON_4 # define ABMON_4 -37 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABMON_5 # define ABMON_5 -38 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABMON_6 # define ABMON_6 -39 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABMON_7 # define ABMON_7 -40 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABMON_8 # define ABMON_8 -41 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABMON_9 # define ABMON_9 -42 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABMON_10 # define ABMON_10 -43 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABMON_11 # define ABMON_11 -44 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ABMON_12 # define ABMON_12 -45 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ERA # define ERA -46 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ERA_D_FMT # define ERA_D_FMT -47 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ERA_D_T_FMT # define ERA_D_T_FMT -48 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ERA_T_FMT # define ERA_T_FMT -49 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef ALT_DIGITS # define ALT_DIGITS -50 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef RADIXCHAR # define RADIXCHAR -51 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef THOUSEP # define THOUSEP -52 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef YESEXPR # define YESEXPR -53 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef YESSTR # define YESSTR -54 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef NOEXPR # define NOEXPR -55 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef NOSTR # define NOSTR -56 +# define HAS_MISSING_LANGINFO_ITEM_ #endif #ifndef CRNCYSTR # define CRNCYSTR -57 +# define HAS_MISSING_LANGINFO_ITEM_ +#endif + +/* The rest of the items are gnu extensions, and are not #defined by its + * langinfo.h. There is a slight possibility that one of these numbers could + * conflict with some other value, in which case after much gnashing of teeth + * you will find this comment, and end up having to adjust the numbers. But + * glibc values are not (so far) negative */ +#if ! defined(HAS_NL_LANGINFO) || ! defined(LC_ADDRESS) +# define _NL_ADDRESS_POSTAL_FMT -58 +# define _NL_ADDRESS_COUNTRY_NAME -59 +# define _NL_ADDRESS_COUNTRY_POST -60 +# define _NL_ADDRESS_COUNTRY_AB2 -61 +# define _NL_ADDRESS_COUNTRY_AB3 -62 +# define _NL_ADDRESS_COUNTRY_CAR -63 +# define _NL_ADDRESS_COUNTRY_NUM -64 +# define _NL_ADDRESS_COUNTRY_ISBN -65 +# define _NL_ADDRESS_LANG_NAME -66 +# define _NL_ADDRESS_LANG_AB -67 +# define _NL_ADDRESS_LANG_TERM -68 +# define _NL_ADDRESS_LANG_LIB -69 + +# define HAS_MISSING_LANGINFO_ITEM_ +#endif +#if ! defined(HAS_NL_LANGINFO) || ! defined(LC_IDENTIFICATION) +# define _NL_IDENTIFICATION_TITLE -70 +# define _NL_IDENTIFICATION_SOURCE -71 +# define _NL_IDENTIFICATION_ADDRESS -72 +# define _NL_IDENTIFICATION_CONTACT -73 +# define _NL_IDENTIFICATION_EMAIL -74 +# define _NL_IDENTIFICATION_TEL -75 +# define _NL_IDENTIFICATION_FAX -76 +# define _NL_IDENTIFICATION_LANGUAGE -77 +# define _NL_IDENTIFICATION_TERRITORY -78 +# define _NL_IDENTIFICATION_AUDIENCE -79 +# define _NL_IDENTIFICATION_APPLICATION -80 +# define _NL_IDENTIFICATION_ABBREVIATION -81 +# define _NL_IDENTIFICATION_REVISION -82 +# define _NL_IDENTIFICATION_DATE -83 +# define _NL_IDENTIFICATION_CATEGORY -84 + +# define HAS_MISSING_LANGINFO_ITEM_ +#endif +#if ! defined(HAS_NL_LANGINFO) || ! defined(LC_MEASUREMENT) +# define _NL_MEASUREMENT_MEASUREMENT -85 + +# define HAS_MISSING_LANGINFO_ITEM_ #endif +#if ! defined(HAS_NL_LANGINFO) || ! defined(LC_NAME) +# define _NL_NAME_NAME_FMT -86 +# define _NL_NAME_NAME_GEN -87 +# define _NL_NAME_NAME_MR -88 +# define _NL_NAME_NAME_MRS -89 +# define _NL_NAME_NAME_MISS -90 +# define _NL_NAME_NAME_MS -91 +# define HAS_MISSING_LANGINFO_ITEM_ #endif +#if ! defined(HAS_NL_LANGINFO) || ! defined(LC_PAPER) +# define _NL_PAPER_HEIGHT -92 +# define _NL_PAPER_WIDTH -93 + +# define HAS_MISSING_LANGINFO_ITEM_ +#endif +#if ! defined(HAS_NL_LANGINFO) || ! defined(LC_TELEPHONE) +# define _NL_TELEPHONE_TEL_INT_FMT -94 +# define _NL_TELEPHONE_TEL_DOM_FMT -95 +# define _NL_TELEPHONE_INT_SELECT -96 +# define _NL_TELEPHONE_INT_PREFIX -97 + +# define HAS_MISSING_LANGINFO_ITEM_ +#endif + +/* All these categories have to be emulated if not available on the platform */ +#if ! LC_CTYPE_AVAIL_ \ + || ! LC_MESSAGES_AVAIL_ \ + || ! LC_MONETARY_AVAIL_ \ + || ! LC_NUMERIC_AVAIL_ \ + || ! LC_TIME_AVAIL_ \ + || ! LC_ADDRESS_AVAIL_ \ + || ! LC_IDENTIFICATION_AVAIL_ \ + || ! LC_MEASUREMENT_AVAIL_ \ + || ! LC_NAME_AVAIL_ \ + || ! LC_PAPER_AVAIL_ \ + || ! LC_TELEPHONE_AVAIL_ + +# define HAS_MISSING_LANGINFO_ITEM_ +#endif + +#endif /* PERL_LANGINFO_H */ Index: gnu/usr.bin/perl/perlio.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/perlio.c,v diff -u -p -a -u -p -r1.23 perlio.c --- gnu/usr.bin/perl/perlio.c 14 May 2024 19:38:54 -0000 1.23 +++ gnu/usr.bin/perl/perlio.c 22 Jan 2025 00:37:44 -0000 @@ -232,14 +232,12 @@ PerlIO_binmode(pTHX_ PerlIO *fp, int iot PerlIO * PerlIO_fdupopen(pTHX_ PerlIO *f, CLONE_PARAMS *param, int flags) { -# if defined(PERL_MICRO) - return NULL; -# elif defined(PERL_IMPLICIT_SYS) +#if defined(PERL_IMPLICIT_SYS) return PerlSIO_fdupopen(f); -# else -# ifdef WIN32 +#else +# ifdef WIN32 return win32_fdupopen(f); -# else +# else if (f) { const int fd = PerlLIO_dup_cloexec(PerlIO_fileno(f)); if (fd >= 0) { @@ -254,9 +252,9 @@ PerlIO_fdupopen(pTHX_ PerlIO *f, CLONE_P else { SETERRNO(EBADF, SS_IVCHAN); } -# endif - return NULL; # endif + return NULL; +#endif } @@ -1053,6 +1051,439 @@ PERLIO_FUNCS_DECL(PerlIO_remove) = { NULL, /* set_ptrcnt */ }; +static const char code_point_warning[] = + "Strings with code points over 0xFF may not be mapped into in-memory file handles\n"; + +typedef struct { + struct _PerlIO base; /* Base "class" info */ + SV *var; + Off_t posn; +} PerlIOScalar; + +IV +PerlIOScalar_eof(pTHX_ PerlIO * f) +{ + if (PerlIOBase(f)->flags & PERLIO_F_CANREAD) { + PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar); + STRLEN len; + (void)SvPV(s->var, len); + return len - (STRLEN)(s->posn) <= 0; + } + return 1; +} + +static IV +PerlIOScalar_pushed(pTHX_ PerlIO * f, const char *mode, SV * arg, + PerlIO_funcs * tab) +{ + IV code; + PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar); + /* If called (normally) via open() then arg is ref to scalar we are + * using, otherwise arg (from binmode presumably) is either NULL + * or the _name_ of the scalar + */ + if (arg && SvOK(arg)) { + if (SvROK(arg)) { + if (SvREADONLY(SvRV(arg)) && !SvIsCOW(SvRV(arg)) + && mode && *mode != 'r') { + if (ckWARN(WARN_LAYER)) + Perl_warner(aTHX_ packWARN(WARN_LAYER), "%s", PL_no_modify); + SETERRNO(EACCES, RMS_PRV); + return -1; + } + s->var = SvREFCNT_inc(SvRV(arg)); + SvGETMAGIC(s->var); + if (!SvPOK(s->var) && SvOK(s->var)) + (void)SvPV_nomg_const_nolen(s->var); + } + else { + s->var = + SvREFCNT_inc(get_sv + (SvPV_nolen(arg), GV_ADD | GV_ADDMULTI)); + } + SvUPGRADE(s->var, SVt_PV); + } + else { + s->var = newSVpvs(""); + } + + code = PerlIOBase_pushed(aTHX_ f, mode, NULL, tab); + if (!SvOK(s->var) || (PerlIOBase(f)->flags) & PERLIO_F_TRUNCATE) + { + sv_force_normal(s->var); + SvCUR_set(s->var, 0); + if (SvPOK(s->var)) *SvPVX(s->var) = 0; + } + if (SvUTF8(s->var) && !sv_utf8_downgrade(s->var, TRUE)) { + if (ckWARN(WARN_UTF8)) + Perl_warner(aTHX_ packWARN(WARN_UTF8), code_point_warning); + SETERRNO(EINVAL, SS_IVCHAN); + SvREFCNT_dec(s->var); + s->var = NULL; + return -1; + } + if ((PerlIOBase(f)->flags) & PERLIO_F_APPEND) + s->posn = SvOK(s->var) ? sv_len(s->var) : 0; + else + s->posn = 0; + SvSETMAGIC(s->var); + return code; +} + +static IV +PerlIOScalar_popped(pTHX_ PerlIO * f) +{ + PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar); + if (s->var) { + SvREFCNT_dec(s->var); + s->var = NULL; + } + return 0; +} + +static IV +PerlIOScalar_close(pTHX_ PerlIO * f) +{ + IV code = PerlIOBase_close(aTHX_ f); + PerlIOBase(f)->flags &= ~(PERLIO_F_RDBUF | PERLIO_F_WRBUF); + return code; +} + +static IV +PerlIOScalar_fileno(pTHX_ PerlIO * f) +{ + PERL_UNUSED_ARG(f); + return -1; +} + +static IV +PerlIOScalar_seek(pTHX_ PerlIO * f, Off_t offset, int whence) +{ + PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar); + Off_t new_posn; + + switch (whence) { + case SEEK_SET: + new_posn = offset; + break; + case SEEK_CUR: + new_posn = offset + s->posn; + break; + case SEEK_END: + { + STRLEN oldcur; + (void)SvPV(s->var, oldcur); + new_posn = offset + oldcur; + break; + } + default: + SETERRNO(EINVAL, SS_IVCHAN); + return -1; + } + if (new_posn < 0) { + if (ckWARN(WARN_LAYER)) + Perl_warner(aTHX_ packWARN(WARN_LAYER), "Offset outside string"); + SETERRNO(EINVAL, SS_IVCHAN); + return -1; + } + s->posn = new_posn; + return 0; +} + +static Off_t +PerlIOScalar_tell(pTHX_ PerlIO * f) +{ + PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar); + return s->posn; +} + + +static SSize_t +PerlIOScalar_read(pTHX_ PerlIO *f, void *vbuf, Size_t count) +{ + if (!f) + return 0; + if (!(PerlIOBase(f)->flags & PERLIO_F_CANREAD)) { + PerlIOBase(f)->flags |= PERLIO_F_ERROR; + SETERRNO(EBADF, SS_IVCHAN); + Perl_PerlIO_save_errno(aTHX_ f); + return 0; + } + { + PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar); + SV *sv = s->var; + char *p; + STRLEN len; + STRLEN got; + p = SvPV(sv, len); + if (SvUTF8(sv)) { + if (sv_utf8_downgrade(sv, TRUE)) { + p = SvPV_nomg(sv, len); + } + else { + if (ckWARN(WARN_UTF8)) + Perl_warner(aTHX_ packWARN(WARN_UTF8), code_point_warning); + SETERRNO(EINVAL, SS_IVCHAN); + return -1; + } + } + /* I assume that Off_t is at least as large as len (which + * seems safe) and that the size of the buffer in our SV is + * always less than half the size of the address space + * + * Which turns out not to be the case on 64-bit Windows, since + * a build with USE_LARGE_FILES=undef defines Off_t as long, + * which is 32-bits on 64-bit Windows. This doesn't appear to + * be the case on other 64-bit platforms. + */ +#if Off_t_size >= Size_t_size + assert(len < ((~(STRLEN)0) >> 1)); + if ((Off_t)len <= s->posn) + return 0; +#else + if (len <= (STRLEN)s->posn) + return 0; +#endif + got = len - (STRLEN)(s->posn); + if ((STRLEN)got > (STRLEN)count) + got = (STRLEN)count; + Copy(p + (STRLEN)(s->posn), vbuf, got, STDCHAR); + s->posn += (Off_t)got; + return (SSize_t)got; + } +} + +static SSize_t +PerlIOScalar_write(pTHX_ PerlIO * f, const void *vbuf, Size_t count) +{ + if (PerlIOBase(f)->flags & PERLIO_F_CANWRITE) { + Off_t offset; + PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar); + SV *sv = s->var; + char *dst; + SvGETMAGIC(sv); + if (!SvROK(sv)) sv_force_normal(sv); + if (SvOK(sv)) SvPV_force_nomg_nolen(sv); + if (SvUTF8(sv) && !sv_utf8_downgrade(sv, TRUE)) { + if (ckWARN(WARN_UTF8)) + Perl_warner(aTHX_ packWARN(WARN_UTF8), code_point_warning); + SETERRNO(EINVAL, SS_IVCHAN); + return 0; + } + if ((PerlIOBase(f)->flags) & PERLIO_F_APPEND) { + dst = SvGROW(sv, SvCUR(sv) + count + 1); + offset = SvCUR(sv); + s->posn = offset + count; + } + else { + STRLEN const cur = SvCUR(sv); + + /* ensure we don't try to create ridiculously large + * SVs on small platforms + */ +#if Size_t_size < Off_t_size + if (s->posn > SSize_t_MAX) { +#ifdef EFBIG + SETERRNO(EFBIG, SS_BUFFEROVF); +#else + SETERRNO(ENOSPC, SS_BUFFEROVF); +#endif + return 0; + } +#endif + + if ((STRLEN)s->posn > cur) { + dst = SvGROW(sv, (STRLEN)s->posn + count + 1); + Zero(SvPVX(sv) + cur, (STRLEN)s->posn - cur, char); + } + else if ((s->posn + count) >= cur) + dst = SvGROW(sv, (STRLEN)s->posn + count + 1); + else + dst = SvPVX(sv); + offset = s->posn; + s->posn += count; + } + Move(vbuf, dst + offset, count, char); + if ((STRLEN) s->posn > SvCUR(sv)) { + SvCUR_set(sv, (STRLEN)s->posn); + dst[(STRLEN) s->posn] = 0; + } + SvPOK_on(sv); + SvSETMAGIC(sv); + return count; + } + else + return 0; +} + +static IV +PerlIOScalar_fill(pTHX_ PerlIO * f) +{ + PERL_UNUSED_ARG(f); + return -1; +} + +static IV +PerlIOScalar_flush(pTHX_ PerlIO * f) +{ + PERL_UNUSED_ARG(f); + return 0; +} + +static STDCHAR * +PerlIOScalar_get_base(pTHX_ PerlIO * f) +{ + PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar); + if (PerlIOBase(f)->flags & PERLIO_F_CANREAD) { + SvGETMAGIC(s->var); + return (STDCHAR *) SvPV_nolen(s->var); + } + return (STDCHAR *) NULL; +} + +static STDCHAR * +PerlIOScalar_get_ptr(pTHX_ PerlIO * f) +{ + if (PerlIOBase(f)->flags & PERLIO_F_CANREAD) { + PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar); + return PerlIOScalar_get_base(aTHX_ f) + s->posn; + } + return (STDCHAR *) NULL; +} + +static SSize_t +PerlIOScalar_get_cnt(pTHX_ PerlIO * f) +{ + if (PerlIOBase(f)->flags & PERLIO_F_CANREAD) { + PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar); + STRLEN len; + (void)SvPV(s->var,len); + if ((Off_t)len > s->posn) + return len - (STRLEN)s->posn; + else + return 0; + } + return 0; +} + +static Size_t +PerlIOScalar_bufsiz(pTHX_ PerlIO * f) +{ + if (PerlIOBase(f)->flags & PERLIO_F_CANREAD) { + PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar); + SvGETMAGIC(s->var); + return SvCUR(s->var); + } + return 0; +} + +static void +PerlIOScalar_set_ptrcnt(pTHX_ PerlIO * f, STDCHAR * ptr, SSize_t cnt) +{ + PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar); + STRLEN len; + PERL_UNUSED_ARG(ptr); + (void)SvPV(s->var,len); + s->posn = len - cnt; +} + +static PerlIO * +PerlIOScalar_open(pTHX_ PerlIO_funcs * self, PerlIO_list_t * layers, IV n, + const char *mode, int fd, int imode, int perm, + PerlIO * f, int narg, SV ** args) +{ + SV *arg = (narg > 0) ? *args : PerlIOArg; + PERL_UNUSED_ARG(fd); + PERL_UNUSED_ARG(imode); + PERL_UNUSED_ARG(perm); + if (SvROK(arg) || SvPOK(arg)) { + if (!f) { + f = PerlIO_allocate(aTHX); + } + if ( (f = PerlIO_push(aTHX_ f, self, mode, arg)) ) { + PerlIOBase(f)->flags |= PERLIO_F_OPEN; + } + return f; + } + return NULL; +} + +static SV * +PerlIOScalar_arg(pTHX_ PerlIO * f, CLONE_PARAMS * param, int flags) +{ + PerlIOScalar *s = PerlIOSelf(f, PerlIOScalar); + SV *var = s->var; + if (flags & PERLIO_DUP_CLONE) + var = PerlIO_sv_dup(aTHX_ var, param); + else if (flags & PERLIO_DUP_FD) { + /* Equivalent (guesses NI-S) of dup() is to create a new scalar */ + var = newSVsv(var); + } + else { + var = SvREFCNT_inc(var); + } + return newRV_noinc(var); +} + +static PerlIO * +PerlIOScalar_dup(pTHX_ PerlIO * f, PerlIO * o, CLONE_PARAMS * param, + int flags) +{ + /* Duplication causes the scalar layer to be pushed on to clone, caus- + ing the cloned scalar to be set to the empty string by + PerlIOScalar_pushed. So set aside our scalar temporarily. */ + PerlIOScalar * const os = PerlIOSelf(o, PerlIOScalar); + PerlIOScalar *fs = NULL; /* avoid "may be used uninitialized" warning */ + SV * const var = os->var; + os->var = newSVpvs(""); + if ((f = PerlIOBase_dup(aTHX_ f, o, param, flags))) { + fs = PerlIOSelf(f, PerlIOScalar); + /* var has been set by implicit push, so replace it */ + SvREFCNT_dec(fs->var); + } + SvREFCNT_dec(os->var); + os->var = var; + if (f) { + SV * const rv = PerlIOScalar_arg(aTHX_ o, param, flags); + fs->var = SvREFCNT_inc(SvRV(rv)); + SvREFCNT_dec(rv); + fs->posn = os->posn; + } + return f; +} + +static PERLIO_FUNCS_DECL(PerlIO_scalar) = { + sizeof(PerlIO_funcs), + "scalar", + sizeof(PerlIOScalar), + PERLIO_K_BUFFERED | PERLIO_K_RAW, + PerlIOScalar_pushed, + PerlIOScalar_popped, + PerlIOScalar_open, + PerlIOBase_binmode, + PerlIOScalar_arg, + PerlIOScalar_fileno, + PerlIOScalar_dup, + PerlIOScalar_read, + NULL, /* unread */ + PerlIOScalar_write, + PerlIOScalar_seek, + PerlIOScalar_tell, + PerlIOScalar_close, + PerlIOScalar_flush, + PerlIOScalar_fill, + PerlIOScalar_eof, + PerlIOBase_error, + PerlIOBase_clearerr, + PerlIOBase_setlinebuf, + PerlIOScalar_get_base, + PerlIOScalar_bufsiz, + PerlIOScalar_get_ptr, + PerlIOScalar_get_cnt, + PerlIOScalar_set_ptrcnt, +}; + + PerlIO_list_t * PerlIO_default_layers(pTHX) { @@ -1068,6 +1499,7 @@ PerlIO_default_layers(pTHX) PerlIO_define_layer(aTHX_ PERLIO_FUNCS_CAST(&PerlIO_utf8)); PerlIO_define_layer(aTHX_ PERLIO_FUNCS_CAST(&PerlIO_remove)); PerlIO_define_layer(aTHX_ PERLIO_FUNCS_CAST(&PerlIO_byte)); + PerlIO_define_layer(aTHX_ PERLIO_FUNCS_CAST(&PerlIO_scalar)); PerlIO_list_push(aTHX_ PL_def_layerlist, (PerlIO_funcs *)osLayer, &PL_sv_undef); if (s) { @@ -1396,15 +1828,8 @@ PerlIO_layer_from_ref(pTHX_ SV *sv) /* * For any scalar type load the handler which is bundled with perl */ - if (SvTYPE(sv) < SVt_PVAV && (!isGV_with_GP(sv) || SvFAKE(sv))) { - PerlIO_funcs *f = PerlIO_find_layer(aTHX_ STR_WITH_LEN("scalar"), 1); - /* This isn't supposed to happen, since PerlIO::scalar is core, - * but could happen anyway in smaller installs or with PAR */ - if (!f) - /* diag_listed_as: Unknown PerlIO layer "%s" */ - Perl_ck_warner(aTHX_ packWARN(WARN_LAYER), "Unknown PerlIO layer \"scalar\""); - return f; - } + if (SvTYPE(sv) < SVt_PVAV && (!isGV_with_GP(sv) || SvFAKE(sv))) + return (PerlIO_funcs*) &PerlIO_scalar; /* * For other types allow if layer is known but don't try and load it @@ -2272,7 +2697,7 @@ S_more_refcounted_fds(pTHX_ const int ne if (!new_array) { MUTEX_UNLOCK(&PL_perlio_mutex); - croak_no_mem(); + croak_no_mem_ext(STR_WITH_LEN("perlio:more_refcounted_fds")); } PL_perlio_fd_refcnt_size = new_max; @@ -3169,7 +3594,7 @@ PerlIOStdio_invalidate_fileno(pTHX_ FILE #elif defined(__GLIBC__) /* There may be a better way for GLIBC: - libio.h defines a flag to not close() on cleanup - */ + */ f->_fileno = -1; return 1; #elif defined(__sun) @@ -3573,7 +3998,7 @@ PerlIOStdio_set_ptrcnt(pTHX_ PerlIO *f, * problem is that one cannot know the signedness of char, and * more precisely the signedness of FILE._ptr. The following * things have been tried, and they have all failed (across - * different compilers (remember that core needs to to build + * different compilers (remember that core needs to build * also with c++) and compiler options: * * - casting the RHS to (void*) -- works in *some* places @@ -3906,7 +4331,7 @@ PerlIOBuf_open(pTHX_ PerlIO_funcs *self, Stat_t st; if (PerlLIO_fstat(fd, &st) == 0 && S_ISREG(st.st_mode) - && (st.st_fab_rfm == FAB$C_VAR + && (st.st_fab_rfm == FAB$C_VAR || st.st_fab_rfm == FAB$C_VFC)) { PerlIOBase(f)->flags |= PERLIO_F_LINEBUF; } @@ -4146,7 +4571,7 @@ PerlIOBuf_write(pTHX_ PerlIO *f, const v if (PerlIO_flush(f) != 0) { return 0; } - } + } if (PerlIOBase(f)->flags & PERLIO_F_LINEBUF) { flushptr = buf + count; while (flushptr > buf && *(flushptr - 1) != '\n') @@ -4205,9 +4630,9 @@ PerlIOBuf_tell(pTHX_ PerlIO *f) #if 1 /* As O_APPEND files are normally shared in some sense it is better to flush : - */ + */ PerlIO_flush(f); -#else +#else /* when file is NOT shared then this is sufficient */ PerlIO_seek(PerlIONext(f),0, SEEK_END); #endif Index: gnu/usr.bin/perl/perlvars.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/perlvars.h,v diff -u -p -a -u -p -r1.11 perlvars.h --- gnu/usr.bin/perl/perlvars.h 14 May 2024 19:38:54 -0000 1.11 +++ gnu/usr.bin/perl/perlvars.h 22 Jan 2025 00:37:44 -0000 @@ -65,7 +65,6 @@ PERLVARA(G, sig_defaulting, SIG_SIZE, in PERLVARI(G, sig_trapped, int, 0) #endif -#ifndef PERL_MICRO /* If Perl has to ignore SIGPFE, this is its saved state. * See perl.h macros PERL_FPU_INIT and PERL_FPU_{PRE,POST}_EXEC. */ PERLVAR(G, sigfpe_saved, Sighandler_t) @@ -76,7 +75,6 @@ PERLVAR(G, sigfpe_saved, Sighandler_t) PERLVARI(G, csighandlerp, Sighandler_t, Perl_csighandler) PERLVARI(G, csighandler1p, Sighandler1_t, Perl_csighandler1) PERLVARI(G, csighandler3p, Sighandler3_t, Perl_csighandler3) -#endif /* This is constant on most architectures, a global on OS/2 */ #ifdef OS2 Index: gnu/usr.bin/perl/perly.act =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/perly.act,v diff -u -p -a -u -p -r1.7 perly.act --- gnu/usr.bin/perl/perly.act 14 May 2024 19:38:54 -0000 1.7 +++ gnu/usr.bin/perl/perly.act 22 Jan 2025 00:37:44 -0000 @@ -4,18 +4,18 @@ Any changes made here will be lost! */ -case 2: +case 2: /* @1: %empty */ #line 161 "perly.y" - { + { parser->expect = XSTATE; (yyval.ival) = 0; } break; - case 3: + case 3: /* grammar: GRAMPROG @1 remember stmtseq */ #line 166 "perly.y" - { + { newPROG(block_end((ps[-1].val.ival),(ps[0].val.opval))); PL_compiling.cop_seq = 0; (yyval.ival) = 0; @@ -23,36 +23,36 @@ case 2: break; - case 4: + case 4: /* @2: %empty */ #line 172 "perly.y" - { + { parser->expect = XTERM; (yyval.ival) = 0; } break; - case 5: + case 5: /* grammar: GRAMEXPR @2 optexpr */ #line 177 "perly.y" - { + { PL_eval_root = (ps[0].val.opval); (yyval.ival) = 0; } break; - case 6: + case 6: /* @3: %empty */ #line 182 "perly.y" - { + { parser->expect = XBLOCK; (yyval.ival) = 0; } break; - case 7: + case 7: /* grammar: GRAMBLOCK @3 block */ #line 187 "perly.y" - { + { PL_pad_reset_pending = TRUE; PL_eval_root = (ps[0].val.opval); (yyval.ival) = 0; @@ -62,18 +62,18 @@ case 2: break; - case 8: + case 8: /* @4: %empty */ #line 195 "perly.y" - { + { parser->expect = XSTATE; (yyval.ival) = 0; } break; - case 9: + case 9: /* grammar: GRAMBARESTMT @4 barestmt */ #line 200 "perly.y" - { + { PL_pad_reset_pending = TRUE; PL_eval_root = (ps[0].val.opval); (yyval.ival) = 0; @@ -83,18 +83,18 @@ case 2: break; - case 10: + case 10: /* @5: %empty */ #line 208 "perly.y" - { + { parser->expect = XSTATE; (yyval.ival) = 0; } break; - case 11: + case 11: /* grammar: GRAMFULLSTMT @5 fullstmt */ #line 213 "perly.y" - { + { PL_pad_reset_pending = TRUE; PL_eval_root = (ps[0].val.opval); (yyval.ival) = 0; @@ -104,122 +104,122 @@ case 2: break; - case 12: + case 12: /* @6: %empty */ #line 221 "perly.y" - { + { parser->expect = XSTATE; (yyval.ival) = 0; } break; - case 13: + case 13: /* grammar: GRAMSTMTSEQ @6 stmtseq */ #line 226 "perly.y" - { + { PL_eval_root = (ps[0].val.opval); (yyval.ival) = 0; } break; - case 14: + case 14: /* @7: %empty */ #line 231 "perly.y" - { + { parser->expect = XSTATE; (yyval.ival) = 0; } break; - case 15: + case 15: /* grammar: GRAMSUBSIGNATURE @7 subsigguts */ #line 236 "perly.y" - { + { PL_eval_root = (ps[0].val.opval); (yyval.ival) = 0; } break; - case 16: + case 16: /* sigsub_or_method_named: KW_SUB_named_sig */ #line 245 "perly.y" - { (yyval.ival) = KW_SUB_named_sig; } + { (yyval.ival) = KW_SUB_named_sig; } break; - case 17: + case 17: /* sigsub_or_method_named: KW_METHOD_named */ #line 247 "perly.y" - { (yyval.ival) = KW_METHOD_named; } + { (yyval.ival) = KW_METHOD_named; } break; - case 18: + case 18: /* block: PERLY_BRACE_OPEN remember stmtseq PERLY_BRACE_CLOSE */ #line 252 "perly.y" - { if (parser->copline > (line_t)(ps[-3].val.ival)) + { if (parser->copline > (line_t)(ps[-3].val.ival)) parser->copline = (line_t)(ps[-3].val.ival); (yyval.opval) = block_end((ps[-2].val.ival), (ps[-1].val.opval)); } break; - case 19: + case 19: /* empty: %empty */ #line 259 "perly.y" - { (yyval.opval) = NULL; } + { (yyval.opval) = NULL; } break; - case 20: + case 20: /* formblock: PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERLY_SEMICOLON PERLY_DOT */ #line 264 "perly.y" - { if (parser->copline > (line_t)(ps[-6].val.ival)) + { if (parser->copline > (line_t)(ps[-6].val.ival)) parser->copline = (line_t)(ps[-6].val.ival); (yyval.opval) = block_end((ps[-5].val.ival), (ps[-2].val.opval)); } break; - case 21: + case 21: /* remember: %empty */ #line 271 "perly.y" - { (yyval.ival) = block_start(TRUE); + { (yyval.ival) = block_start(TRUE); parser->parsed_sub = 0; } break; - case 22: + case 22: /* mblock: PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE */ #line 276 "perly.y" - { if (parser->copline > (line_t)(ps[-3].val.ival)) + { if (parser->copline > (line_t)(ps[-3].val.ival)) parser->copline = (line_t)(ps[-3].val.ival); (yyval.opval) = block_end((ps[-2].val.ival), (ps[-1].val.opval)); } break; - case 23: + case 23: /* mremember: %empty */ #line 283 "perly.y" - { (yyval.ival) = block_start(FALSE); + { (yyval.ival) = block_start(FALSE); parser->parsed_sub = 0; } break; - case 25: + case 25: /* $@8: %empty */ #line 292 "perly.y" - { parser->in_my = 1; } + { parser->in_my = 1; } break; - case 26: + case 26: /* $@9: %empty */ #line 294 "perly.y" - { parser->in_my = 0; intro_my(); } + { parser->in_my = 0; intro_my(); } break; - case 27: + case 27: /* catch_paren: PERLY_PAREN_OPEN $@8 scalar $@9 PERLY_PAREN_CLOSE */ #line 296 "perly.y" - { (yyval.opval) = (ps[-2].val.opval); } + { (yyval.opval) = (ps[-2].val.opval); } break; - case 29: + case 29: /* stmtseq: stmtseq fullstmt */ #line 303 "perly.y" - { (yyval.opval) = op_append_list(OP_LINESEQ, (ps[-1].val.opval), (ps[0].val.opval)); + { (yyval.opval) = op_append_list(OP_LINESEQ, (ps[-1].val.opval), (ps[0].val.opval)); PL_pad_reset_pending = TRUE; if ((ps[-1].val.opval) && (ps[0].val.opval)) PL_hints |= HINT_BLOCK_SCOPE; @@ -227,9 +227,9 @@ case 2: break; - case 31: + case 31: /* formstmtseq: formstmtseq formline */ #line 314 "perly.y" - { (yyval.opval) = op_append_list(OP_LINESEQ, (ps[-1].val.opval), (ps[0].val.opval)); + { (yyval.opval) = op_append_list(OP_LINESEQ, (ps[-1].val.opval), (ps[0].val.opval)); PL_pad_reset_pending = TRUE; if ((ps[-1].val.opval) && (ps[0].val.opval)) PL_hints |= HINT_BLOCK_SCOPE; @@ -237,23 +237,23 @@ case 2: break; - case 32: + case 32: /* fullstmt: barestmt */ #line 323 "perly.y" - { + { (yyval.opval) = (ps[0].val.opval) ? newSTATEOP(0, NULL, (ps[0].val.opval)) : NULL; } break; - case 33: + case 33: /* fullstmt: labfullstmt */ #line 327 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + { (yyval.opval) = (ps[0].val.opval); } break; - case 34: + case 34: /* labfullstmt: LABEL barestmt */ #line 331 "perly.y" - { + { SV *label = cSVOPx_sv((ps[-1].val.opval)); (yyval.opval) = newSTATEOP(SvFLAGS(label) & SVf_UTF8, savepv(SvPVX_const(label)), (ps[0].val.opval)); @@ -262,9 +262,9 @@ case 2: break; - case 35: + case 35: /* labfullstmt: LABEL labfullstmt */ #line 338 "perly.y" - { + { SV *label = cSVOPx_sv((ps[-1].val.opval)); (yyval.opval) = newSTATEOP(SvFLAGS(label) & SVf_UTF8, savepv(SvPVX_const(label)), (ps[0].val.opval)); @@ -273,15 +273,15 @@ case 2: break; - case 36: + case 36: /* barestmt: PLUGSTMT */ #line 348 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + { (yyval.opval) = (ps[0].val.opval); } break; - case 37: + case 37: /* barestmt: KW_FORMAT startformsub formname formblock */ #line 350 "perly.y" - { + { CV *fmtcv = PL_compcv; newFORM((ps[-2].val.ival), (ps[-1].val.opval), (ps[0].val.opval)); (yyval.opval) = NULL; @@ -293,9 +293,9 @@ case 2: break; - case 38: + case 38: /* $@10: %empty */ #line 362 "perly.y" - { + { init_named_cv(PL_compcv, (ps[-1].val.opval)); parser->in_my = 0; parser->in_my_stash = NULL; @@ -303,9 +303,9 @@ case 2: break; - case 39: + case 39: /* barestmt: KW_SUB_named subname startsub $@10 proto subattrlist optsubbody */ #line 368 "perly.y" - { + { SvREFCNT_inc_simple_void(PL_compcv); (ps[-5].val.opval)->op_type == OP_CONST ? newATTRSUB((ps[-4].val.ival), (ps[-5].val.opval), (ps[-2].val.opval), (ps[-1].val.opval), (ps[0].val.opval)) @@ -318,9 +318,9 @@ case 2: break; - case 40: + case 40: /* $@11: %empty */ #line 383 "perly.y" - { + { init_named_cv(PL_compcv, (ps[-1].val.opval)); if((ps[-2].val.ival) == KW_METHOD_named) { croak_kw_unless_class("method"); @@ -332,9 +332,9 @@ case 2: break; - case 41: + case 41: /* barestmt: sigsub_or_method_named subname startsub $@11 subattrlist optsigsubbody */ #line 393 "perly.y" - { + { OP *body = (ps[0].val.opval); SvREFCNT_inc_simple_void(PL_compcv); @@ -349,9 +349,9 @@ case 2: break; - case 42: + case 42: /* $@12: %empty */ #line 406 "perly.y" - { + { switch((ps[-1].val.ival)) { case KEY_ADJUST: croak_kw_unless_class("ADJUST"); @@ -364,9 +364,9 @@ case 2: break; - case 43: + case 43: /* barestmt: PHASER startsub $@12 optsubbody */ #line 417 "perly.y" - { + { OP *body = (ps[0].val.opval); SvREFCNT_inc_simple_void(PL_compcv); @@ -383,9 +383,9 @@ case 2: break; - case 44: + case 44: /* barestmt: KW_PACKAGE BAREWORD BAREWORD PERLY_SEMICOLON */ #line 436 "perly.y" - { + { package((ps[-1].val.opval)); if ((ps[-2].val.opval)) package_version((ps[-2].val.opval)); @@ -394,9 +394,9 @@ case 2: break; - case 45: + case 45: /* barestmt: KW_CLASS BAREWORD BAREWORD subattrlist PERLY_SEMICOLON */ #line 443 "perly.y" - { + { package((ps[-2].val.opval)); if ((ps[-3].val.opval)) package_version((ps[-3].val.opval)); @@ -409,15 +409,15 @@ case 2: break; - case 46: + case 46: /* $@13: %empty */ #line 454 "perly.y" - { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ } + { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ } break; - case 47: + case 47: /* barestmt: KW_USE_or_NO startsub $@13 BAREWORD BAREWORD optlistexpr PERLY_SEMICOLON */ #line 458 "perly.y" - { + { SvREFCNT_inc_simple_void(PL_compcv); utilize((ps[-6].val.ival), (ps[-5].val.ival), (ps[-3].val.opval), (ps[-2].val.opval), (ps[-1].val.opval)); parser->parsed_sub = 1; @@ -426,9 +426,9 @@ case 2: break; - case 48: + case 48: /* barestmt: KW_IF PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else */ #line 465 "perly.y" - { + { (yyval.opval) = block_end((ps[-4].val.ival), newCONDOP(0, (ps[-3].val.opval), op_scope((ps[-1].val.opval)), (ps[0].val.opval))); parser->copline = (line_t)(ps[-6].val.ival); @@ -436,9 +436,9 @@ case 2: break; - case 49: + case 49: /* barestmt: KW_UNLESS PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else */ #line 471 "perly.y" - { + { (yyval.opval) = block_end((ps[-4].val.ival), newCONDOP(0, (ps[-3].val.opval), (ps[0].val.opval), op_scope((ps[-1].val.opval)))); parser->copline = (line_t)(ps[-6].val.ival); @@ -446,30 +446,30 @@ case 2: break; - case 50: + case 50: /* barestmt: KW_GIVEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock */ #line 477 "perly.y" - { + { (yyval.opval) = block_end((ps[-3].val.ival), newGIVENOP((ps[-2].val.opval), op_scope((ps[0].val.opval)), 0)); parser->copline = (line_t)(ps[-5].val.ival); } break; - case 51: + case 51: /* barestmt: KW_WHEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock */ #line 482 "perly.y" - { (yyval.opval) = block_end((ps[-3].val.ival), newWHENOP((ps[-2].val.opval), op_scope((ps[0].val.opval)))); } + { (yyval.opval) = block_end((ps[-3].val.ival), newWHENOP((ps[-2].val.opval), op_scope((ps[0].val.opval)))); } break; - case 52: + case 52: /* barestmt: KW_DEFAULT block */ #line 484 "perly.y" - { (yyval.opval) = newWHENOP(0, op_scope((ps[0].val.opval))); } + { (yyval.opval) = newWHENOP(0, op_scope((ps[0].val.opval))); } break; - case 53: + case 53: /* barestmt: KW_WHILE PERLY_PAREN_OPEN remember texpr PERLY_PAREN_CLOSE mintro mblock cont */ #line 486 "perly.y" - { + { (yyval.opval) = block_end((ps[-5].val.ival), newWHILEOP(0, 1, NULL, (ps[-4].val.opval), (ps[-1].val.opval), (ps[0].val.opval), (ps[-2].val.ival))); @@ -478,9 +478,9 @@ case 2: break; - case 54: + case 54: /* barestmt: KW_UNTIL PERLY_PAREN_OPEN remember iexpr PERLY_PAREN_CLOSE mintro mblock cont */ #line 493 "perly.y" - { + { (yyval.opval) = block_end((ps[-5].val.ival), newWHILEOP(0, 1, NULL, (ps[-4].val.opval), (ps[-1].val.opval), (ps[0].val.opval), (ps[-2].val.ival))); @@ -489,21 +489,21 @@ case 2: break; - case 55: + case 55: /* $@14: %empty */ #line 500 "perly.y" - { parser->expect = XTERM; } + { parser->expect = XTERM; } break; - case 56: + case 56: /* $@15: %empty */ #line 502 "perly.y" - { parser->expect = XTERM; } + { parser->expect = XTERM; } break; - case 57: + case 57: /* barestmt: KW_FOR PERLY_PAREN_OPEN remember mnexpr PERLY_SEMICOLON $@14 texpr PERLY_SEMICOLON $@15 mintro mnexpr PERLY_PAREN_CLOSE mblock */ #line 505 "perly.y" - { + { OP *initop = (ps[-9].val.opval); OP *forop = newWHILEOP(0, 1, NULL, scalar((ps[-6].val.opval)), (ps[0].val.opval), (ps[-2].val.opval), (ps[-3].val.ival)); @@ -520,18 +520,18 @@ case 2: break; - case 58: + case 58: /* barestmt: KW_FOR KW_MY remember my_scalar PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont */ #line 520 "perly.y" - { + { (yyval.opval) = block_end((ps[-6].val.ival), newFOROP(0, (ps[-5].val.opval), (ps[-3].val.opval), (ps[-1].val.opval), (ps[0].val.opval))); parser->copline = (line_t)(ps[-8].val.ival); } break; - case 59: + case 59: /* barestmt: KW_FOR KW_MY remember PERLY_PAREN_OPEN my_list_of_scalars PERLY_PAREN_CLOSE PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont */ #line 525 "perly.y" - { + { if ((ps[-6].val.opval)->op_type == OP_PADSV) /* degenerate case of 1 var: for my ($x) .... Flag it so it can be special-cased in newFOROP */ @@ -542,9 +542,9 @@ case 2: break; - case 60: + case 60: /* barestmt: KW_FOR scalar PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont */ #line 534 "perly.y" - { + { (yyval.opval) = block_end((ps[-4].val.ival), newFOROP(0, op_lvalue((ps[-6].val.opval), OP_ENTERLOOP), (ps[-3].val.opval), (ps[-1].val.opval), (ps[0].val.opval))); parser->copline = (line_t)(ps[-7].val.ival); @@ -552,15 +552,15 @@ case 2: break; - case 61: + case 61: /* @16: %empty */ #line 540 "perly.y" - { parser->in_my = 0; (yyval.opval) = my((ps[0].val.opval)); } + { parser->in_my = 0; (yyval.opval) = my((ps[0].val.opval)); } break; - case 62: + case 62: /* barestmt: KW_FOR my_refgen remember my_var @16 PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont */ #line 542 "perly.y" - { + { (yyval.opval) = block_end( (ps[-7].val.ival), newFOROP(0, @@ -575,9 +575,9 @@ case 2: break; - case 63: + case 63: /* barestmt: KW_FOR REFGEN refgen_topic PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont */ #line 555 "perly.y" - { + { (yyval.opval) = block_end((ps[-4].val.ival), newFOROP( 0, op_lvalue(newUNOP(OP_REFGEN, 0, (ps[-6].val.opval)), @@ -587,9 +587,9 @@ case 2: break; - case 64: + case 64: /* barestmt: KW_FOR PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont */ #line 563 "perly.y" - { + { (yyval.opval) = block_end((ps[-4].val.ival), newFOROP(0, NULL, (ps[-3].val.opval), (ps[-1].val.opval), (ps[0].val.opval))); parser->copline = (line_t)(ps[-6].val.ival); @@ -597,9 +597,9 @@ case 2: break; - case 65: + case 65: /* $@17: %empty */ #line 569 "perly.y" - { + { if(!(ps[0].val.opval)) { yyerror("catch block requires a (VAR)"); YYERROR; @@ -608,9 +608,9 @@ case 2: break; - case 66: + case 66: /* barestmt: KW_TRY mblock KW_CATCH remember catch_paren $@17 mblock finally */ #line 576 "perly.y" - { + { (yyval.opval) = newTRYCATCHOP(0, (ps[-6].val.opval), (ps[-3].val.opval), block_end((ps[-4].val.ival), op_scope((ps[-1].val.opval)))); if((ps[0].val.opval)) @@ -620,9 +620,9 @@ case 2: break; - case 67: + case 67: /* barestmt: block cont */ #line 584 "perly.y" - { + { /* a block is a loop that happens once */ (yyval.opval) = newWHILEOP(0, 1, NULL, NULL, (ps[-1].val.opval), (ps[0].val.opval), 0); @@ -630,9 +630,9 @@ case 2: break; - case 68: + case 68: /* $@18: %empty */ #line 590 "perly.y" - { + { package((ps[-2].val.opval)); if ((ps[-3].val.opval)) { package_version((ps[-3].val.opval)); @@ -641,9 +641,9 @@ case 2: break; - case 69: + case 69: /* barestmt: KW_PACKAGE BAREWORD BAREWORD PERLY_BRACE_OPEN remember $@18 stmtseq PERLY_BRACE_CLOSE */ #line 597 "perly.y" - { + { /* a block is a loop that happens once */ (yyval.opval) = newWHILEOP(0, 1, NULL, NULL, block_end((ps[-3].val.ival), (ps[-1].val.opval)), NULL, 0); @@ -653,9 +653,9 @@ case 2: break; - case 70: + case 70: /* $@19: %empty */ #line 605 "perly.y" - { + { package((ps[-3].val.opval)); if ((ps[-4].val.opval)) { @@ -669,9 +669,9 @@ case 2: break; - case 71: + case 71: /* barestmt: KW_CLASS BAREWORD BAREWORD subattrlist PERLY_BRACE_OPEN remember $@19 stmtseq PERLY_BRACE_CLOSE */ #line 617 "perly.y" - { + { /* a block is a loop that happens once */ (yyval.opval) = newWHILEOP(0, 1, NULL, NULL, block_end((ps[-3].val.ival), (ps[-1].val.opval)), NULL, 0); @@ -681,33 +681,33 @@ case 2: break; - case 72: + case 72: /* barestmt: fielddecl PERLY_SEMICOLON */ #line 625 "perly.y" - { + { (yyval.opval) = (ps[-1].val.opval); } break; - case 73: + case 73: /* barestmt: sideff PERLY_SEMICOLON */ #line 629 "perly.y" - { + { (yyval.opval) = (ps[-1].val.opval); } break; - case 74: + case 74: /* barestmt: KW_DEFER mblock */ #line 633 "perly.y" - { + { (yyval.opval) = newDEFEROP(0, op_scope((ps[0].val.opval))); } break; - case 75: + case 75: /* barestmt: YADAYADA PERLY_SEMICOLON */ #line 637 "perly.y" - { + { /* diag_listed_as: Unimplemented */ (yyval.opval) = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0), newSVOP(OP_CONST, 0, newSVpvs("Unimplemented"))); @@ -715,18 +715,18 @@ case 2: break; - case 76: + case 76: /* barestmt: PERLY_SEMICOLON */ #line 643 "perly.y" - { + { (yyval.opval) = NULL; parser->copline = NOLINE; } break; - case 77: + case 77: /* formline: THING formarg */ #line 651 "perly.y" - { OP *list; + { OP *list; if ((ps[0].val.opval)) { OP *term = (ps[0].val.opval); list = op_append_elem(OP_LIST, (ps[-1].val.opval), term); @@ -743,73 +743,73 @@ case 2: break; - case 79: + case 79: /* formarg: FORMLBRACK stmtseq FORMRBRACK */ #line 670 "perly.y" - { (yyval.opval) = op_unscope((ps[-1].val.opval)); } + { (yyval.opval) = op_unscope((ps[-1].val.opval)); } break; - case 81: + case 81: /* sideff: error */ #line 678 "perly.y" - { (yyval.opval) = NULL; } + { (yyval.opval) = NULL; } break; - case 82: + case 82: /* sideff: expr */ #line 680 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + { (yyval.opval) = (ps[0].val.opval); } break; - case 83: + case 83: /* sideff: expr KW_IF condition */ #line 682 "perly.y" - { (yyval.opval) = newLOGOP(OP_AND, 0, (ps[0].val.opval), (ps[-2].val.opval)); } + { (yyval.opval) = newLOGOP(OP_AND, 0, (ps[0].val.opval), (ps[-2].val.opval)); } break; - case 84: + case 84: /* sideff: expr KW_UNLESS condition */ #line 684 "perly.y" - { (yyval.opval) = newLOGOP(OP_OR, 0, (ps[0].val.opval), (ps[-2].val.opval)); } + { (yyval.opval) = newLOGOP(OP_OR, 0, (ps[0].val.opval), (ps[-2].val.opval)); } break; - case 85: + case 85: /* sideff: expr KW_WHILE condition */ #line 686 "perly.y" - { (yyval.opval) = newLOOPOP(OPf_PARENS, 1, scalar((ps[0].val.opval)), (ps[-2].val.opval)); } + { (yyval.opval) = newLOOPOP(OPf_PARENS, 1, scalar((ps[0].val.opval)), (ps[-2].val.opval)); } break; - case 86: + case 86: /* sideff: expr KW_UNTIL iexpr */ #line 688 "perly.y" - { (yyval.opval) = newLOOPOP(OPf_PARENS, 1, (ps[0].val.opval), (ps[-2].val.opval)); } + { (yyval.opval) = newLOOPOP(OPf_PARENS, 1, (ps[0].val.opval), (ps[-2].val.opval)); } break; - case 87: + case 87: /* sideff: expr KW_FOR condition */ #line 690 "perly.y" - { (yyval.opval) = newFOROP(0, NULL, (ps[0].val.opval), (ps[-2].val.opval), NULL); + { (yyval.opval) = newFOROP(0, NULL, (ps[0].val.opval), (ps[-2].val.opval), NULL); parser->copline = (line_t)(ps[-1].val.ival); } break; - case 88: + case 88: /* sideff: expr KW_WHEN condition */ #line 693 "perly.y" - { (yyval.opval) = newWHENOP((ps[0].val.opval), op_scope((ps[-2].val.opval))); } + { (yyval.opval) = newWHENOP((ps[0].val.opval), op_scope((ps[-2].val.opval))); } break; - case 90: + case 90: /* else: KW_ELSE mblock */ #line 700 "perly.y" - { + { ((ps[0].val.opval))->op_flags |= OPf_PARENS; (yyval.opval) = op_scope((ps[0].val.opval)); } break; - case 91: + case 91: /* else: KW_ELSIF PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock else */ #line 705 "perly.y" - { parser->copline = (line_t)(ps[-5].val.ival); + { parser->copline = (line_t)(ps[-5].val.ival); (yyval.opval) = newCONDOP(0, newSTATEOP(OPf_SPECIAL,NULL,(ps[-3].val.opval)), op_scope((ps[-1].val.opval)), (ps[0].val.opval)); @@ -818,95 +818,95 @@ case 2: break; - case 93: + case 93: /* cont: KW_CONTINUE block */ #line 717 "perly.y" - { (yyval.opval) = op_scope((ps[0].val.opval)); } + { (yyval.opval) = op_scope((ps[0].val.opval)); } break; - case 94: + case 94: /* finally: %empty */ #line 722 "perly.y" - { (yyval.opval) = NULL; } + { (yyval.opval) = NULL; } break; - case 95: + case 95: /* finally: KW_FINALLY block */ #line 724 "perly.y" - { (yyval.opval) = op_scope((ps[0].val.opval)); } + { (yyval.opval) = op_scope((ps[0].val.opval)); } break; - case 96: + case 96: /* mintro: %empty */ #line 729 "perly.y" - { (yyval.ival) = (PL_min_intro_pending && + { (yyval.ival) = (PL_min_intro_pending && PL_max_intro_pending >= PL_min_intro_pending); intro_my(); } break; - case 99: + case 99: /* texpr: %empty */ #line 741 "perly.y" - { YYSTYPE tmplval; + { YYSTYPE tmplval; (void)scan_num("1", &tmplval); (yyval.opval) = tmplval.opval; } break; - case 101: + case 101: /* iexpr: expr */ #line 749 "perly.y" - { (yyval.opval) = invert(scalar((ps[0].val.opval))); } + { (yyval.opval) = invert(scalar((ps[0].val.opval))); } break; - case 102: + case 102: /* mexpr: expr */ #line 754 "perly.y" - { (yyval.opval) = (ps[0].val.opval); intro_my(); } + { (yyval.opval) = (ps[0].val.opval); intro_my(); } break; - case 103: + case 103: /* mnexpr: nexpr */ #line 758 "perly.y" - { (yyval.opval) = (ps[0].val.opval); intro_my(); } + { (yyval.opval) = (ps[0].val.opval); intro_my(); } break; - case 104: + case 104: /* formname: BAREWORD */ #line 761 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + { (yyval.opval) = (ps[0].val.opval); } break; - case 106: + case 106: /* startsub: %empty */ #line 766 "perly.y" - { (yyval.ival) = start_subparse(FALSE, 0); + { (yyval.ival) = start_subparse(FALSE, 0); SAVEFREESV(PL_compcv); } break; - case 107: + case 107: /* startanonsub: %empty */ #line 772 "perly.y" - { (yyval.ival) = start_subparse(FALSE, CVf_ANON); + { (yyval.ival) = start_subparse(FALSE, CVf_ANON); SAVEFREESV(PL_compcv); } break; - case 108: + case 108: /* startanonmethod: %empty */ #line 777 "perly.y" - { (yyval.ival) = start_subparse(FALSE, CVf_ANON|CVf_IsMETHOD); + { (yyval.ival) = start_subparse(FALSE, CVf_ANON|CVf_IsMETHOD); SAVEFREESV(PL_compcv); } break; - case 109: + case 109: /* startformsub: %empty */ #line 782 "perly.y" - { (yyval.ival) = start_subparse(TRUE, 0); + { (yyval.ival) = start_subparse(TRUE, 0); SAVEFREESV(PL_compcv); } break; - case 115: + case 115: /* subattrlist: COLONATTR THING */ #line 801 "perly.y" - { + { OP *attrlist = (ps[0].val.opval); if(attrlist && !PL_parser->sig_seen) attrlist = apply_builtin_cv_attributes(PL_compcv, attrlist); @@ -915,51 +915,51 @@ case 2: break; - case 116: + case 116: /* subattrlist: COLONATTR */ #line 808 "perly.y" - { (yyval.opval) = NULL; } + { (yyval.opval) = NULL; } break; - case 117: + case 117: /* myattrlist: COLONATTR THING */ #line 813 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + { (yyval.opval) = (ps[0].val.opval); } break; - case 118: + case 118: /* myattrlist: COLONATTR */ #line 815 "perly.y" - { (yyval.opval) = NULL; } + { (yyval.opval) = NULL; } break; - case 119: + case 119: /* sigvarname: %empty */ #line 826 "perly.y" - { parser->in_my = 0; (yyval.opval) = NULL; } + { parser->in_my = 0; (yyval.opval) = NULL; } break; - case 120: + case 120: /* sigvarname: PRIVATEREF */ #line 828 "perly.y" - { parser->in_my = 0; (yyval.opval) = (ps[0].val.opval); } + { parser->in_my = 0; (yyval.opval) = (ps[0].val.opval); } break; - case 121: + case 121: /* sigslurpsigil: PERLY_SNAIL */ #line 833 "perly.y" - { (yyval.ival) = '@'; } + { (yyval.ival) = '@'; } break; - case 122: + case 122: /* sigslurpsigil: PERLY_PERCENT_SIGN */ #line 835 "perly.y" - { (yyval.ival) = '%'; } + { (yyval.ival) = '%'; } break; - case 123: + case 123: /* sigslurpelem: sigslurpsigil sigvarname sigdefault */ #line 839 "perly.y" - { + { I32 sigil = (ps[-2].val.ival); OP *var = (ps[-1].val.opval); OP *defop = (ps[0].val.opval); @@ -977,15 +977,15 @@ case 2: break; - case 125: + case 125: /* sigdefault: ASSIGNOP */ #line 860 "perly.y" - { (yyval.opval) = newARGDEFELEMOP(0, newOP(OP_NULL, 0), parser->sig_elems); } + { (yyval.opval) = newARGDEFELEMOP(0, newOP(OP_NULL, 0), parser->sig_elems); } break; - case 126: + case 126: /* sigdefault: ASSIGNOP term */ #line 862 "perly.y" - { + { I32 flags = 0; if ((ps[-1].val.ival) == OP_DORASSIGN) flags |= OPpARG_IF_UNDEF << 8; @@ -996,9 +996,9 @@ case 2: break; - case 127: + case 127: /* sigscalarelem: PERLY_DOLLAR sigvarname sigdefault */ #line 875 "perly.y" - { + { OP *var = (ps[-1].val.opval); OP *defop = (ps[0].val.opval); @@ -1056,47 +1056,47 @@ case 2: break; - case 128: + case 128: /* sigelem: sigscalarelem */ #line 935 "perly.y" - { parser->in_my = KEY_sigvar; (yyval.opval) = (ps[0].val.opval); } + { parser->in_my = KEY_sigvar; (yyval.opval) = (ps[0].val.opval); } break; - case 129: + case 129: /* sigelem: sigslurpelem */ #line 937 "perly.y" - { parser->in_my = KEY_sigvar; (yyval.opval) = (ps[0].val.opval); } + { parser->in_my = KEY_sigvar; (yyval.opval) = (ps[0].val.opval); } break; - case 130: + case 130: /* siglist: siglist PERLY_COMMA */ #line 943 "perly.y" - { (yyval.opval) = (ps[-1].val.opval); } + { (yyval.opval) = (ps[-1].val.opval); } break; - case 131: + case 131: /* siglist: siglist PERLY_COMMA sigelem */ #line 945 "perly.y" - { + { (yyval.opval) = op_append_list(OP_LINESEQ, (ps[-2].val.opval), (ps[0].val.opval)); } break; - case 132: + case 132: /* siglist: sigelem */ #line 949 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + { (yyval.opval) = (ps[0].val.opval); } break; - case 137: + case 137: /* subsignature: PERLY_PAREN_OPEN subsigguts PERLY_PAREN_CLOSE */ #line 966 "perly.y" - { (yyval.opval) = (ps[-1].val.opval); } + { (yyval.opval) = (ps[-1].val.opval); } break; - case 138: + case 138: /* $@20: %empty */ #line 969 "perly.y" - { + { ENTER; SAVEIV(parser->sig_elems); SAVEIV(parser->sig_optelems); @@ -1109,9 +1109,9 @@ case 2: break; - case 139: + case 139: /* subsigguts: $@20 optsiglist */ #line 980 "perly.y" - { + { OP *sigops = (ps[0].val.opval); struct op_argcheck_aux *aux; OP *check; @@ -1166,15 +1166,15 @@ case 2: break; - case 141: + case 141: /* optsubbody: PERLY_SEMICOLON */ #line 1037 "perly.y" - { (yyval.opval) = NULL; } + { (yyval.opval) = NULL; } break; - case 142: + case 142: /* subbody: remember PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE */ #line 1043 "perly.y" - { + { if (parser->copline > (line_t)(ps[-2].val.ival)) parser->copline = (line_t)(ps[-2].val.ival); (yyval.opval) = block_end((ps[-3].val.ival), (ps[-1].val.opval)); @@ -1182,81 +1182,87 @@ case 2: break; - case 144: + case 144: /* optsigsubbody: PERLY_SEMICOLON */ #line 1055 "perly.y" - { (yyval.opval) = NULL; } + { (yyval.opval) = NULL; } break; - case 145: + case 145: /* $@21: %empty */ #line 1060 "perly.y" - { - if (parser->copline > (line_t)(ps[-2].val.ival)) - parser->copline = (line_t)(ps[-2].val.ival); - (yyval.opval) = block_end((ps[-4].val.ival), - op_append_list(OP_LINESEQ, (ps[-3].val.opval), (ps[-1].val.opval))); - } + { PL_parser->sig_seen = FALSE; } break; - case 146: -#line 1071 "perly.y" - { (yyval.opval) = newLOGOP(OP_AND, 0, (ps[-2].val.opval), (ps[0].val.opval)); } + case 146: /* sigsubbody: remember optsubsignature PERLY_BRACE_OPEN $@21 stmtseq PERLY_BRACE_CLOSE */ +#line 1062 "perly.y" + { + if (parser->copline > (line_t)(ps[-3].val.ival)) + parser->copline = (line_t)(ps[-3].val.ival); + (yyval.opval) = block_end((ps[-5].val.ival), + op_append_list(OP_LINESEQ, (ps[-4].val.opval), (ps[-1].val.opval))); + } break; - case 147: + case 147: /* expr: expr ANDOP expr */ #line 1073 "perly.y" - { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } + { (yyval.opval) = newLOGOP(OP_AND, 0, (ps[-2].val.opval), (ps[0].val.opval)); } break; - case 148: + case 148: /* expr: expr PLUGIN_LOGICAL_AND_LOW_OP expr */ #line 1075 "perly.y" - { (yyval.opval) = newLOGOP((ps[-1].val.ival), 0, (ps[-2].val.opval), (ps[0].val.opval)); } + { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } break; - case 149: + case 149: /* expr: expr OROP expr */ #line 1077 "perly.y" - { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } + { (yyval.opval) = newLOGOP((ps[-1].val.ival), 0, (ps[-2].val.opval), (ps[0].val.opval)); } break; - case 151: -#line 1083 "perly.y" - { (yyval.opval) = (ps[-1].val.opval); } + case 150: /* expr: expr PLUGIN_LOGICAL_OR_LOW_OP expr */ +#line 1079 "perly.y" + { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } break; - case 152: + case 152: /* listexpr: listexpr PERLY_COMMA */ #line 1085 "perly.y" - { + { (yyval.opval) = (ps[-1].val.opval); } + + break; + + case 153: /* listexpr: listexpr PERLY_COMMA term */ +#line 1087 "perly.y" + { OP* term = (ps[0].val.opval); (yyval.opval) = op_append_elem(OP_LIST, (ps[-2].val.opval), term); } break; - case 154: -#line 1094 "perly.y" - { (yyval.opval) = op_convert_list((ps[-2].val.ival), OPf_STACKED, + case 155: /* listop: LSTOP indirob listexpr */ +#line 1096 "perly.y" + { (yyval.opval) = op_convert_list((ps[-2].val.ival), OPf_STACKED, op_prepend_elem(OP_LIST, newGVREF((ps[-2].val.ival),(ps[-1].val.opval)), (ps[0].val.opval)) ); } break; - case 155: -#line 1098 "perly.y" - { (yyval.opval) = op_convert_list((ps[-4].val.ival), OPf_STACKED, + case 156: /* listop: FUNC PERLY_PAREN_OPEN indirob expr PERLY_PAREN_CLOSE */ +#line 1100 "perly.y" + { (yyval.opval) = op_convert_list((ps[-4].val.ival), OPf_STACKED, op_prepend_elem(OP_LIST, newGVREF((ps[-4].val.ival),(ps[-2].val.opval)), (ps[-1].val.opval)) ); } break; - case 156: -#line 1102 "perly.y" - { (yyval.opval) = op_convert_list(OP_ENTERSUB, OPf_STACKED, + case 157: /* listop: term ARROW methodname PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE */ +#line 1104 "perly.y" + { (yyval.opval) = op_convert_list(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, op_prepend_elem(OP_LIST, scalar((ps[-5].val.opval)), (ps[-1].val.opval)), newMETHOP(OP_METHOD, 0, (ps[-3].val.opval)))); @@ -1264,18 +1270,18 @@ case 2: break; - case 157: -#line 1108 "perly.y" - { (yyval.opval) = op_convert_list(OP_ENTERSUB, OPf_STACKED, + case 158: /* listop: term ARROW methodname */ +#line 1110 "perly.y" + { (yyval.opval) = op_convert_list(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, scalar((ps[-2].val.opval)), newMETHOP(OP_METHOD, 0, (ps[0].val.opval)))); } break; - case 158: -#line 1113 "perly.y" - { (yyval.opval) = op_convert_list(OP_ENTERSUB, OPf_STACKED, + case 159: /* listop: METHCALL0 indirob optlistexpr */ +#line 1115 "perly.y" + { (yyval.opval) = op_convert_list(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, op_prepend_elem(OP_LIST, (ps[-1].val.opval), (ps[0].val.opval)), newMETHOP(OP_METHOD, 0, (ps[-2].val.opval)))); @@ -1283,9 +1289,9 @@ case 2: break; - case 159: -#line 1119 "perly.y" - { (yyval.opval) = op_convert_list(OP_ENTERSUB, OPf_STACKED, + case 160: /* listop: METHCALL indirob PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE */ +#line 1121 "perly.y" + { (yyval.opval) = op_convert_list(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, op_prepend_elem(OP_LIST, (ps[-3].val.opval), (ps[-1].val.opval)), newMETHOP(OP_METHOD, 0, (ps[-4].val.opval)))); @@ -1293,97 +1299,100 @@ case 2: break; - case 160: -#line 1125 "perly.y" - { (yyval.opval) = op_convert_list((ps[-1].val.ival), 0, (ps[0].val.opval)); } - - break; - - case 161: + case 161: /* listop: LSTOP optlistexpr */ #line 1127 "perly.y" - { (yyval.opval) = op_convert_list((ps[-3].val.ival), 0, (ps[-1].val.opval)); } + { (yyval.opval) = op_convert_list((ps[-1].val.ival), 0, (ps[0].val.opval)); } break; - case 162: + case 162: /* listop: FUNC PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE */ #line 1129 "perly.y" - { (yyval.opval) = op_convert_list((ps[-3].val.ival), 0, (ps[-1].val.opval)); } + { (yyval.opval) = op_convert_list((ps[-3].val.ival), 0, (ps[-1].val.opval)); } break; - case 163: + case 163: /* listop: FUNC SUBLEXSTART optexpr SUBLEXEND */ #line 1131 "perly.y" - { SvREFCNT_inc_simple_void(PL_compcv); - (yyval.opval) = newANONATTRSUB((ps[-1].val.ival), 0, NULL, (ps[0].val.opval)); } + { (yyval.opval) = op_convert_list((ps[-3].val.ival), 0, (ps[-1].val.opval)); } break; - case 164: -#line 1134 "perly.y" - { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, + case 164: /* @22: %empty */ +#line 1133 "perly.y" + { SvREFCNT_inc_simple_void(PL_compcv); + (yyval.opval) = newANONATTRSUB((ps[-1].val.ival), 0, NULL, (ps[0].val.opval)); + /* prevent double op_free() if the following fails to parse */ + (ps[0].val.opval) = NULL; + } + + break; + + case 165: /* listop: LSTOPSUB startanonsub block @22 optlistexpr */ +#line 1139 "perly.y" + { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, op_prepend_elem(OP_LIST, (ps[-1].val.opval), (ps[0].val.opval)), (ps[-4].val.opval))); } break; - case 167: -#line 1149 "perly.y" - { (yyval.opval) = newBINOP(OP_GELEM, 0, (ps[-4].val.opval), scalar((ps[-2].val.opval))); } + case 168: /* subscripted: gelem PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE */ +#line 1154 "perly.y" + { (yyval.opval) = newBINOP(OP_GELEM, 0, (ps[-4].val.opval), scalar((ps[-2].val.opval))); } break; - case 168: -#line 1151 "perly.y" - { (yyval.opval) = newBINOP(OP_AELEM, 0, oopsAV((ps[-3].val.opval)), scalar((ps[-1].val.opval))); + case 169: /* subscripted: scalar PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE */ +#line 1156 "perly.y" + { (yyval.opval) = newBINOP(OP_AELEM, 0, oopsAV((ps[-3].val.opval)), scalar((ps[-1].val.opval))); } break; - case 169: -#line 1154 "perly.y" - { (yyval.opval) = newBINOP(OP_AELEM, 0, + case 170: /* subscripted: term ARROW PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE */ +#line 1159 "perly.y" + { (yyval.opval) = newBINOP(OP_AELEM, 0, ref(newAVREF((ps[-4].val.opval)),OP_RV2AV), scalar((ps[-1].val.opval))); } break; - case 170: -#line 1159 "perly.y" - { (yyval.opval) = newBINOP(OP_AELEM, 0, + case 171: /* subscripted: subscripted PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE */ +#line 1164 "perly.y" + { (yyval.opval) = newBINOP(OP_AELEM, 0, ref(newAVREF((ps[-3].val.opval)),OP_RV2AV), scalar((ps[-1].val.opval))); } break; - case 171: -#line 1164 "perly.y" - { (yyval.opval) = newBINOP(OP_HELEM, 0, oopsHV((ps[-4].val.opval)), jmaybe((ps[-2].val.opval))); + case 172: /* subscripted: scalar PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE */ +#line 1169 "perly.y" + { (yyval.opval) = newBINOP(OP_HELEM, 0, oopsHV((ps[-4].val.opval)), jmaybe((ps[-2].val.opval))); } break; - case 172: -#line 1167 "perly.y" - { (yyval.opval) = newBINOP(OP_HELEM, 0, + case 173: /* subscripted: term ARROW PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE */ +#line 1172 "perly.y" + { (yyval.opval) = newBINOP(OP_HELEM, 0, ref(newHVREF((ps[-5].val.opval)),OP_RV2HV), jmaybe((ps[-2].val.opval))); } break; - case 173: -#line 1171 "perly.y" - { (yyval.opval) = newBINOP(OP_HELEM, 0, + case 174: /* subscripted: subscripted PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE */ +#line 1176 "perly.y" + { (yyval.opval) = newBINOP(OP_HELEM, 0, ref(newHVREF((ps[-4].val.opval)),OP_RV2HV), jmaybe((ps[-2].val.opval))); } break; - case 174: -#line 1175 "perly.y" - { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, + case 175: /* subscripted: term ARROW PERLY_PAREN_OPEN PERLY_PAREN_CLOSE */ +#line 1180 "perly.y" + { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, newCVREF(0, scalar((ps[-3].val.opval)))); if (parser->expect == XBLOCK) parser->expect = XOPERATOR; @@ -1391,9 +1400,9 @@ case 2: break; - case 175: -#line 1181 "perly.y" - { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, + case 176: /* subscripted: term ARROW PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE */ +#line 1186 "perly.y" + { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, (ps[-1].val.opval), newCVREF(0, scalar((ps[-4].val.opval))))); if (parser->expect == XBLOCK) @@ -1402,9 +1411,9 @@ case 2: break; - case 176: -#line 1189 "perly.y" - { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, + case 177: /* subscripted: subscripted PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE */ +#line 1194 "perly.y" + { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, (ps[-1].val.opval), newCVREF(0, scalar((ps[-3].val.opval))))); if (parser->expect == XBLOCK) @@ -1413,9 +1422,9 @@ case 2: break; - case 177: -#line 1196 "perly.y" - { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, + case 178: /* subscripted: subscripted PERLY_PAREN_OPEN PERLY_PAREN_CLOSE */ +#line 1201 "perly.y" + { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, newCVREF(0, scalar((ps[-2].val.opval)))); if (parser->expect == XBLOCK) parser->expect = XOPERATOR; @@ -1423,278 +1432,278 @@ case 2: break; - case 178: -#line 1202 "perly.y" - { (yyval.opval) = newSLICEOP(0, (ps[-1].val.opval), (ps[-4].val.opval)); } + case 179: /* subscripted: PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE */ +#line 1207 "perly.y" + { (yyval.opval) = newSLICEOP(0, (ps[-1].val.opval), (ps[-4].val.opval)); } break; - case 179: -#line 1204 "perly.y" - { (yyval.opval) = newSLICEOP(0, (ps[-1].val.opval), (ps[-3].val.opval)); } + case 180: /* subscripted: QWLIST PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE */ +#line 1209 "perly.y" + { (yyval.opval) = newSLICEOP(0, (ps[-1].val.opval), (ps[-3].val.opval)); } break; - case 180: -#line 1206 "perly.y" - { (yyval.opval) = newSLICEOP(0, (ps[-1].val.opval), NULL); } + case 181: /* subscripted: PERLY_PAREN_OPEN PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE */ +#line 1211 "perly.y" + { (yyval.opval) = newSLICEOP(0, (ps[-1].val.opval), NULL); } break; - case 181: -#line 1211 "perly.y" - { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } + case 182: /* termbinop: term PLUGIN_HIGH_OP term */ +#line 1216 "perly.y" + { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } break; - case 182: -#line 1213 "perly.y" - { (yyval.opval) = newASSIGNOP(OPf_STACKED, (ps[-2].val.opval), (ps[-1].val.ival), (ps[0].val.opval)); } + case 183: /* termbinop: term ASSIGNOP term */ +#line 1218 "perly.y" + { (yyval.opval) = newASSIGNOP(OPf_STACKED, (ps[-2].val.opval), (ps[-1].val.ival), (ps[0].val.opval)); } break; - case 183: -#line 1215 "perly.y" - { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } + case 184: /* termbinop: term PLUGIN_ASSIGN_OP term */ +#line 1220 "perly.y" + { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } break; - case 184: -#line 1217 "perly.y" - { (yyval.opval) = newBINOP((ps[-1].val.ival), 0, scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } + case 185: /* termbinop: term POWOP term */ +#line 1222 "perly.y" + { (yyval.opval) = newBINOP((ps[-1].val.ival), 0, scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } break; - case 185: -#line 1219 "perly.y" - { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } + case 186: /* termbinop: term PLUGIN_POW_OP term */ +#line 1224 "perly.y" + { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } break; - case 186: -#line 1221 "perly.y" - { if ((ps[-1].val.ival) != OP_REPEAT) + case 187: /* termbinop: term MULOP term */ +#line 1226 "perly.y" + { if ((ps[-1].val.ival) != OP_REPEAT) scalar((ps[-2].val.opval)); (yyval.opval) = newBINOP((ps[-1].val.ival), 0, (ps[-2].val.opval), scalar((ps[0].val.opval))); } break; - case 187: -#line 1226 "perly.y" - { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } + case 188: /* termbinop: term PLUGIN_MUL_OP term */ +#line 1231 "perly.y" + { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } break; - case 188: -#line 1228 "perly.y" - { (yyval.opval) = newBINOP((ps[-1].val.ival), 0, scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } + case 189: /* termbinop: term ADDOP term */ +#line 1233 "perly.y" + { (yyval.opval) = newBINOP((ps[-1].val.ival), 0, scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } break; - case 189: -#line 1230 "perly.y" - { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } + case 190: /* termbinop: term PLUGIN_ADD_OP term */ +#line 1235 "perly.y" + { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } break; - case 190: -#line 1232 "perly.y" - { (yyval.opval) = newBINOP((ps[-1].val.ival), 0, scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } + case 191: /* termbinop: term SHIFTOP term */ +#line 1237 "perly.y" + { (yyval.opval) = newBINOP((ps[-1].val.ival), 0, scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } break; - case 191: -#line 1234 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 192: /* termbinop: termrelop */ +#line 1239 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 192: -#line 1236 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 193: /* termbinop: termeqop */ +#line 1241 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 193: -#line 1238 "perly.y" - { (yyval.opval) = newBINOP((ps[-1].val.ival), 0, scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } + case 194: /* termbinop: term BITANDOP term */ +#line 1243 "perly.y" + { (yyval.opval) = newBINOP((ps[-1].val.ival), 0, scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } break; - case 194: -#line 1240 "perly.y" - { (yyval.opval) = newBINOP((ps[-1].val.ival), 0, scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } + case 195: /* termbinop: term BITOROP term */ +#line 1245 "perly.y" + { (yyval.opval) = newBINOP((ps[-1].val.ival), 0, scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } break; - case 195: -#line 1242 "perly.y" - { (yyval.opval) = newRANGE((ps[-1].val.ival), scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } + case 196: /* termbinop: term DOTDOT term */ +#line 1247 "perly.y" + { (yyval.opval) = newRANGE((ps[-1].val.ival), scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } break; - case 196: -#line 1244 "perly.y" - { (yyval.opval) = newLOGOP(OP_AND, 0, (ps[-2].val.opval), (ps[0].val.opval)); } + case 197: /* termbinop: term ANDAND term */ +#line 1249 "perly.y" + { (yyval.opval) = newLOGOP(OP_AND, 0, (ps[-2].val.opval), (ps[0].val.opval)); } break; - case 197: -#line 1246 "perly.y" - { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } + case 198: /* termbinop: term PLUGIN_LOGICAL_AND_OP term */ +#line 1251 "perly.y" + { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } break; - case 198: -#line 1248 "perly.y" - { (yyval.opval) = newLOGOP(OP_OR, 0, (ps[-2].val.opval), (ps[0].val.opval)); } + case 199: /* termbinop: term OROR term */ +#line 1253 "perly.y" + { (yyval.opval) = newLOGOP((ps[-1].val.ival), 0, (ps[-2].val.opval), (ps[0].val.opval)); } break; - case 199: -#line 1250 "perly.y" - { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } + case 200: /* termbinop: term PLUGIN_LOGICAL_OR_OP term */ +#line 1255 "perly.y" + { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } break; - case 200: -#line 1252 "perly.y" - { (yyval.opval) = newLOGOP(OP_DOR, 0, (ps[-2].val.opval), (ps[0].val.opval)); } + case 201: /* termbinop: term DORDOR term */ +#line 1257 "perly.y" + { (yyval.opval) = newLOGOP(OP_DOR, 0, (ps[-2].val.opval), (ps[0].val.opval)); } break; - case 201: -#line 1254 "perly.y" - { (yyval.opval) = bind_match((ps[-1].val.ival), (ps[-2].val.opval), (ps[0].val.opval)); } + case 202: /* termbinop: term MATCHOP term */ +#line 1259 "perly.y" + { (yyval.opval) = bind_match((ps[-1].val.ival), (ps[-2].val.opval), (ps[0].val.opval)); } break; - case 202: -#line 1256 "perly.y" - { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } + case 203: /* termbinop: term PLUGIN_LOW_OP term */ +#line 1261 "perly.y" + { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } break; - case 203: -#line 1260 "perly.y" - { (yyval.opval) = cmpchain_finish((ps[0].val.opval)); } + case 204: /* termrelop: relopchain */ +#line 1265 "perly.y" + { (yyval.opval) = cmpchain_finish((ps[0].val.opval)); } break; - case 204: -#line 1262 "perly.y" - { (yyval.opval) = newBINOP((ps[-1].val.ival), 0, scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } + case 205: /* termrelop: term NCRELOP term */ +#line 1267 "perly.y" + { (yyval.opval) = newBINOP((ps[-1].val.ival), 0, scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } break; - case 205: -#line 1264 "perly.y" - { yyerror("syntax error"); YYERROR; } + case 206: /* termrelop: termrelop NCRELOP */ +#line 1269 "perly.y" + { yyerror("syntax error"); YYERROR; } break; - case 206: -#line 1266 "perly.y" - { yyerror("syntax error"); YYERROR; } + case 207: /* termrelop: termrelop CHRELOP */ +#line 1271 "perly.y" + { yyerror("syntax error"); YYERROR; } break; - case 207: -#line 1268 "perly.y" - { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } + case 208: /* termrelop: term PLUGIN_REL_OP term */ +#line 1273 "perly.y" + { (yyval.opval) = build_infix_plugin((ps[-2].val.opval), (ps[0].val.opval), (ps[-1].val.pval)); } break; - case 208: -#line 1272 "perly.y" - { (yyval.opval) = cmpchain_start((ps[-1].val.ival), (ps[-2].val.opval), (ps[0].val.opval)); } + case 209: /* relopchain: term CHRELOP term */ +#line 1277 "perly.y" + { (yyval.opval) = cmpchain_start((ps[-1].val.ival), (ps[-2].val.opval), (ps[0].val.opval)); } break; - case 209: -#line 1274 "perly.y" - { (yyval.opval) = cmpchain_extend((ps[-1].val.ival), (ps[-2].val.opval), (ps[0].val.opval)); } + case 210: /* relopchain: relopchain CHRELOP term */ +#line 1279 "perly.y" + { (yyval.opval) = cmpchain_extend((ps[-1].val.ival), (ps[-2].val.opval), (ps[0].val.opval)); } break; - case 210: -#line 1278 "perly.y" - { (yyval.opval) = cmpchain_finish((ps[0].val.opval)); } + case 211: /* termeqop: eqopchain */ +#line 1283 "perly.y" + { (yyval.opval) = cmpchain_finish((ps[0].val.opval)); } break; - case 211: -#line 1280 "perly.y" - { (yyval.opval) = newBINOP((ps[-1].val.ival), 0, scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } + case 212: /* termeqop: term NCEQOP term */ +#line 1285 "perly.y" + { (yyval.opval) = newBINOP((ps[-1].val.ival), 0, scalar((ps[-2].val.opval)), scalar((ps[0].val.opval))); } break; - case 212: -#line 1282 "perly.y" - { yyerror("syntax error"); YYERROR; } + case 213: /* termeqop: termeqop NCEQOP */ +#line 1287 "perly.y" + { yyerror("syntax error"); YYERROR; } break; - case 213: -#line 1284 "perly.y" - { yyerror("syntax error"); YYERROR; } + case 214: /* termeqop: termeqop CHEQOP */ +#line 1289 "perly.y" + { yyerror("syntax error"); YYERROR; } break; - case 214: -#line 1288 "perly.y" - { (yyval.opval) = cmpchain_start((ps[-1].val.ival), (ps[-2].val.opval), (ps[0].val.opval)); } + case 215: /* eqopchain: term CHEQOP term */ +#line 1293 "perly.y" + { (yyval.opval) = cmpchain_start((ps[-1].val.ival), (ps[-2].val.opval), (ps[0].val.opval)); } break; - case 215: -#line 1290 "perly.y" - { (yyval.opval) = cmpchain_extend((ps[-1].val.ival), (ps[-2].val.opval), (ps[0].val.opval)); } + case 216: /* eqopchain: eqopchain CHEQOP term */ +#line 1295 "perly.y" + { (yyval.opval) = cmpchain_extend((ps[-1].val.ival), (ps[-2].val.opval), (ps[0].val.opval)); } break; - case 216: -#line 1295 "perly.y" - { (yyval.opval) = newUNOP(OP_NEGATE, 0, scalar((ps[0].val.opval))); } + case 217: /* termunop: PERLY_MINUS term */ +#line 1300 "perly.y" + { (yyval.opval) = newUNOP(OP_NEGATE, 0, scalar((ps[0].val.opval))); } break; - case 217: -#line 1297 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 218: /* termunop: PERLY_PLUS term */ +#line 1302 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 218: -#line 1300 "perly.y" - { (yyval.opval) = newUNOP(OP_NOT, 0, scalar((ps[0].val.opval))); } + case 219: /* termunop: PERLY_EXCLAMATION_MARK term */ +#line 1305 "perly.y" + { (yyval.opval) = newUNOP(OP_NOT, 0, scalar((ps[0].val.opval))); } break; - case 219: -#line 1302 "perly.y" - { (yyval.opval) = newUNOP((ps[-1].val.ival), 0, scalar((ps[0].val.opval))); } + case 220: /* termunop: PERLY_TILDE term */ +#line 1307 "perly.y" + { (yyval.opval) = newUNOP((ps[-1].val.ival), 0, scalar((ps[0].val.opval))); } break; - case 220: -#line 1304 "perly.y" - { (yyval.opval) = newUNOP(OP_POSTINC, 0, + case 221: /* termunop: term POSTINC */ +#line 1309 "perly.y" + { (yyval.opval) = newUNOP(OP_POSTINC, 0, op_lvalue(scalar((ps[-1].val.opval)), OP_POSTINC)); } break; - case 221: -#line 1307 "perly.y" - { (yyval.opval) = newUNOP(OP_POSTDEC, 0, + case 222: /* termunop: term POSTDEC */ +#line 1312 "perly.y" + { (yyval.opval) = newUNOP(OP_POSTDEC, 0, op_lvalue(scalar((ps[-1].val.opval)), OP_POSTDEC));} break; - case 222: -#line 1310 "perly.y" - { (yyval.opval) = op_convert_list(OP_JOIN, 0, + case 223: /* termunop: term POSTJOIN */ +#line 1315 "perly.y" + { (yyval.opval) = op_convert_list(OP_JOIN, 0, op_append_elem( OP_LIST, newSVREF(scalar( @@ -1707,148 +1716,148 @@ case 2: break; - case 223: -#line 1321 "perly.y" - { (yyval.opval) = newUNOP(OP_PREINC, 0, + case 224: /* termunop: PREINC term */ +#line 1326 "perly.y" + { (yyval.opval) = newUNOP(OP_PREINC, 0, op_lvalue(scalar((ps[0].val.opval)), OP_PREINC)); } break; - case 224: -#line 1324 "perly.y" - { (yyval.opval) = newUNOP(OP_PREDEC, 0, + case 225: /* termunop: PREDEC term */ +#line 1329 "perly.y" + { (yyval.opval) = newUNOP(OP_PREDEC, 0, op_lvalue(scalar((ps[0].val.opval)), OP_PREDEC)); } break; - case 225: -#line 1332 "perly.y" - { (yyval.opval) = newANONLIST((ps[-1].val.opval)); } + case 226: /* anonymous: PERLY_BRACKET_OPEN optexpr PERLY_BRACKET_CLOSE */ +#line 1337 "perly.y" + { (yyval.opval) = newANONLIST((ps[-1].val.opval)); } break; - case 226: -#line 1334 "perly.y" - { (yyval.opval) = newANONHASH((ps[-2].val.opval)); } + case 227: /* anonymous: HASHBRACK optexpr PERLY_SEMICOLON PERLY_BRACE_CLOSE */ +#line 1339 "perly.y" + { (yyval.opval) = newANONHASH((ps[-2].val.opval)); } break; - case 227: -#line 1336 "perly.y" - { SvREFCNT_inc_simple_void(PL_compcv); + case 228: /* anonymous: KW_SUB_anon startanonsub proto subattrlist subbody */ +#line 1341 "perly.y" + { SvREFCNT_inc_simple_void(PL_compcv); (yyval.opval) = newANONATTRSUB((ps[-3].val.ival), (ps[-2].val.opval), (ps[-1].val.opval), (ps[0].val.opval)); } break; - case 228: -#line 1339 "perly.y" - { SvREFCNT_inc_simple_void(PL_compcv); + case 229: /* anonymous: KW_SUB_anon_sig startanonsub subattrlist sigsubbody */ +#line 1344 "perly.y" + { SvREFCNT_inc_simple_void(PL_compcv); (yyval.opval) = newANONATTRSUB((ps[-2].val.ival), NULL, (ps[-1].val.opval), (ps[0].val.opval)); } break; - case 229: -#line 1342 "perly.y" - { + case 230: /* anonymous: KW_METHOD_anon startanonmethod subattrlist sigsubbody */ +#line 1347 "perly.y" + { SvREFCNT_inc_simple_void(PL_compcv); (yyval.opval) = newANONATTRSUB((ps[-2].val.ival), NULL, (ps[-1].val.opval), (ps[0].val.opval)); } break; - case 230: -#line 1350 "perly.y" - { (yyval.opval) = dofile((ps[0].val.opval), (ps[-1].val.ival));} + case 231: /* termdo: KW_DO term */ +#line 1355 "perly.y" + { (yyval.opval) = dofile((ps[0].val.opval), (ps[-1].val.ival));} break; - case 231: -#line 1352 "perly.y" - { (yyval.opval) = newUNOP(OP_NULL, OPf_SPECIAL, op_scope((ps[0].val.opval)));} + case 232: /* termdo: KW_DO block */ +#line 1357 "perly.y" + { (yyval.opval) = newUNOP(OP_NULL, OPf_SPECIAL, op_scope((ps[0].val.opval)));} break; - case 236: -#line 1360 "perly.y" - { (yyval.opval) = newCONDOP(0, (ps[-4].val.opval), (ps[-2].val.opval), (ps[0].val.opval)); } + case 237: /* term: term PERLY_QUESTION_MARK term PERLY_COLON term */ +#line 1365 "perly.y" + { (yyval.opval) = newCONDOP(0, (ps[-4].val.opval), (ps[-2].val.opval), (ps[0].val.opval)); } break; - case 237: -#line 1362 "perly.y" - { (yyval.opval) = newUNOP(OP_REFGEN, 0, (ps[0].val.opval)); } + case 238: /* term: REFGEN term */ +#line 1367 "perly.y" + { (yyval.opval) = newUNOP(OP_REFGEN, 0, (ps[0].val.opval)); } break; - case 238: -#line 1364 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 239: /* term: myattrterm */ +#line 1369 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 239: -#line 1366 "perly.y" - { (yyval.opval) = localize((ps[0].val.opval),0); } + case 240: /* term: KW_LOCAL term */ +#line 1371 "perly.y" + { (yyval.opval) = localize((ps[0].val.opval),0); } break; - case 240: -#line 1368 "perly.y" - { (yyval.opval) = sawparens((ps[-1].val.opval)); } + case 241: /* term: PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE */ +#line 1373 "perly.y" + { (yyval.opval) = sawparens((ps[-1].val.opval)); } break; - case 241: -#line 1370 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 242: /* term: QWLIST */ +#line 1375 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 242: -#line 1372 "perly.y" - { (yyval.opval) = sawparens(newNULLLIST()); } + case 243: /* term: PERLY_PAREN_OPEN PERLY_PAREN_CLOSE */ +#line 1377 "perly.y" + { (yyval.opval) = sawparens(newNULLLIST()); } break; - case 243: -#line 1374 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 244: /* term: scalar */ +#line 1379 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 244: -#line 1376 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 245: /* term: star */ +#line 1381 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 245: -#line 1378 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 246: /* term: hsh */ +#line 1383 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 246: -#line 1380 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 247: /* term: ary */ +#line 1385 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 247: -#line 1382 "perly.y" - { (yyval.opval) = newUNOP(OP_AV2ARYLEN, 0, ref((ps[0].val.opval), OP_AV2ARYLEN));} + case 248: /* term: arylen */ +#line 1387 "perly.y" + { (yyval.opval) = newUNOP(OP_AV2ARYLEN, 0, ref((ps[0].val.opval), OP_AV2ARYLEN));} break; - case 248: -#line 1384 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 249: /* term: subscripted */ +#line 1389 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 249: -#line 1386 "perly.y" - { (yyval.opval) = op_prepend_elem(OP_ASLICE, + case 250: /* term: sliceme PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE */ +#line 1391 "perly.y" + { (yyval.opval) = op_prepend_elem(OP_ASLICE, newOP(OP_PUSHMARK, 0), newLISTOP(OP_ASLICE, 0, list((ps[-1].val.opval)), @@ -1860,9 +1869,9 @@ case 2: break; - case 250: -#line 1396 "perly.y" - { (yyval.opval) = op_prepend_elem(OP_KVASLICE, + case 251: /* term: kvslice PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE */ +#line 1401 "perly.y" + { (yyval.opval) = op_prepend_elem(OP_KVASLICE, newOP(OP_PUSHMARK, 0), newLISTOP(OP_KVASLICE, 0, list((ps[-1].val.opval)), @@ -1874,9 +1883,9 @@ case 2: break; - case 251: -#line 1406 "perly.y" - { (yyval.opval) = op_prepend_elem(OP_HSLICE, + case 252: /* term: sliceme PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE */ +#line 1411 "perly.y" + { (yyval.opval) = op_prepend_elem(OP_HSLICE, newOP(OP_PUSHMARK, 0), newLISTOP(OP_HSLICE, 0, list((ps[-2].val.opval)), @@ -1888,9 +1897,9 @@ case 2: break; - case 252: -#line 1416 "perly.y" - { (yyval.opval) = op_prepend_elem(OP_KVHSLICE, + case 253: /* term: kvslice PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE */ +#line 1421 "perly.y" + { (yyval.opval) = op_prepend_elem(OP_KVHSLICE, newOP(OP_PUSHMARK, 0), newLISTOP(OP_KVHSLICE, 0, list((ps[-2].val.opval)), @@ -1902,182 +1911,182 @@ case 2: break; - case 253: -#line 1426 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 254: /* term: THING */ +#line 1431 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 254: -#line 1428 "perly.y" - { (yyval.opval) = newUNOP(OP_ENTERSUB, 0, scalar((ps[0].val.opval))); } + case 255: /* term: amper */ +#line 1433 "perly.y" + { (yyval.opval) = newUNOP(OP_ENTERSUB, 0, scalar((ps[0].val.opval))); } break; - case 255: -#line 1430 "perly.y" - { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar((ps[-2].val.opval))); + case 256: /* term: amper PERLY_PAREN_OPEN PERLY_PAREN_CLOSE */ +#line 1435 "perly.y" + { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar((ps[-2].val.opval))); } break; - case 256: -#line 1433 "perly.y" - { + case 257: /* term: amper PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE */ +#line 1438 "perly.y" + { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, (ps[-1].val.opval), scalar((ps[-3].val.opval)))); } break; - case 257: -#line 1438 "perly.y" - { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, + case 258: /* term: NOAMP subname optlistexpr */ +#line 1443 "perly.y" + { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, (ps[0].val.opval), scalar((ps[-1].val.opval)))); } break; - case 258: -#line 1442 "perly.y" - { (yyval.opval) = newSVREF((ps[-3].val.opval)); } + case 259: /* term: term ARROW PERLY_DOLLAR PERLY_STAR */ +#line 1447 "perly.y" + { (yyval.opval) = newSVREF((ps[-3].val.opval)); } break; - case 259: -#line 1444 "perly.y" - { (yyval.opval) = newAVREF((ps[-3].val.opval)); } + case 260: /* term: term ARROW PERLY_SNAIL PERLY_STAR */ +#line 1449 "perly.y" + { (yyval.opval) = newAVREF((ps[-3].val.opval)); } break; - case 260: -#line 1446 "perly.y" - { (yyval.opval) = newHVREF((ps[-3].val.opval)); } + case 261: /* term: term ARROW PERLY_PERCENT_SIGN PERLY_STAR */ +#line 1451 "perly.y" + { (yyval.opval) = newHVREF((ps[-3].val.opval)); } break; - case 261: -#line 1448 "perly.y" - { (yyval.opval) = newUNOP(OP_ENTERSUB, 0, + case 262: /* term: term ARROW PERLY_AMPERSAND PERLY_STAR */ +#line 1453 "perly.y" + { (yyval.opval) = newUNOP(OP_ENTERSUB, 0, scalar(newCVREF((ps[-1].val.ival),(ps[-3].val.opval)))); } break; - case 262: -#line 1451 "perly.y" - { (yyval.opval) = newGVREF(0,(ps[-3].val.opval)); } + case 263: /* term: term ARROW PERLY_STAR PERLY_STAR */ +#line 1456 "perly.y" + { (yyval.opval) = newGVREF(0,(ps[-3].val.opval)); } break; - case 263: -#line 1453 "perly.y" - { (yyval.opval) = newOP((ps[0].val.ival), OPf_SPECIAL); + case 264: /* term: LOOPEX */ +#line 1458 "perly.y" + { (yyval.opval) = newOP((ps[0].val.ival), OPf_SPECIAL); PL_hints |= HINT_BLOCK_SCOPE; } break; - case 264: -#line 1456 "perly.y" - { (yyval.opval) = newLOOPEX((ps[-1].val.ival),(ps[0].val.opval)); } + case 265: /* term: LOOPEX term */ +#line 1461 "perly.y" + { (yyval.opval) = newLOOPEX((ps[-1].val.ival),(ps[0].val.opval)); } break; - case 265: -#line 1458 "perly.y" - { (yyval.opval) = newUNOP(OP_NOT, 0, scalar((ps[0].val.opval))); } + case 266: /* term: NOTOP listexpr */ +#line 1463 "perly.y" + { (yyval.opval) = newUNOP(OP_NOT, 0, scalar((ps[0].val.opval))); } break; - case 266: -#line 1460 "perly.y" - { (yyval.opval) = newOP((ps[0].val.ival), 0); } + case 267: /* term: UNIOP */ +#line 1465 "perly.y" + { (yyval.opval) = newOP((ps[0].val.ival), 0); } break; - case 267: -#line 1462 "perly.y" - { (yyval.opval) = newUNOP((ps[-1].val.ival), 0, (ps[0].val.opval)); } + case 268: /* term: UNIOP block */ +#line 1467 "perly.y" + { (yyval.opval) = newUNOP((ps[-1].val.ival), 0, (ps[0].val.opval)); } break; - case 268: -#line 1464 "perly.y" - { (yyval.opval) = newUNOP((ps[-1].val.ival), 0, (ps[0].val.opval)); } + case 269: /* term: UNIOP term */ +#line 1469 "perly.y" + { (yyval.opval) = newUNOP((ps[-1].val.ival), 0, (ps[0].val.opval)); } break; - case 269: -#line 1466 "perly.y" - { (yyval.opval) = newOP(OP_REQUIRE, (ps[0].val.ival) ? OPf_SPECIAL : 0); } + case 270: /* term: KW_REQUIRE */ +#line 1471 "perly.y" + { (yyval.opval) = newOP(OP_REQUIRE, (ps[0].val.ival) ? OPf_SPECIAL : 0); } break; - case 270: -#line 1468 "perly.y" - { (yyval.opval) = newUNOP(OP_REQUIRE, (ps[-1].val.ival) ? OPf_SPECIAL : 0, (ps[0].val.opval)); } + case 271: /* term: KW_REQUIRE term */ +#line 1473 "perly.y" + { (yyval.opval) = newUNOP(OP_REQUIRE, (ps[-1].val.ival) ? OPf_SPECIAL : 0, (ps[0].val.opval)); } break; - case 271: -#line 1470 "perly.y" - { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar((ps[0].val.opval))); } + case 272: /* term: UNIOPSUB */ +#line 1475 "perly.y" + { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar((ps[0].val.opval))); } break; - case 272: -#line 1472 "perly.y" - { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, + case 273: /* term: UNIOPSUB term */ +#line 1477 "perly.y" + { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, (ps[0].val.opval), scalar((ps[-1].val.opval)))); } break; - case 273: -#line 1475 "perly.y" - { (yyval.opval) = newOP((ps[0].val.ival), 0); } + case 274: /* term: FUNC0 */ +#line 1480 "perly.y" + { (yyval.opval) = newOP((ps[0].val.ival), 0); } break; - case 274: -#line 1477 "perly.y" - { (yyval.opval) = newOP((ps[-2].val.ival), 0);} + case 275: /* term: FUNC0 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE */ +#line 1482 "perly.y" + { (yyval.opval) = newOP((ps[-2].val.ival), 0);} break; - case 275: -#line 1479 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 276: /* term: FUNC0OP */ +#line 1484 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 276: -#line 1481 "perly.y" - { (yyval.opval) = (ps[-2].val.opval); } + case 277: /* term: FUNC0OP PERLY_PAREN_OPEN PERLY_PAREN_CLOSE */ +#line 1486 "perly.y" + { (yyval.opval) = (ps[-2].val.opval); } break; - case 277: -#line 1483 "perly.y" - { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar((ps[0].val.opval))); } + case 278: /* term: FUNC0SUB */ +#line 1488 "perly.y" + { (yyval.opval) = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar((ps[0].val.opval))); } break; - case 278: -#line 1485 "perly.y" - { (yyval.opval) = ((ps[-2].val.ival) == OP_NOT) + case 279: /* term: FUNC1 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE */ +#line 1490 "perly.y" + { (yyval.opval) = ((ps[-2].val.ival) == OP_NOT) ? newUNOP((ps[-2].val.ival), 0, newSVOP(OP_CONST, 0, newSViv(0))) : newOP((ps[-2].val.ival), OPf_SPECIAL); } break; - case 279: -#line 1489 "perly.y" - { (yyval.opval) = newUNOP((ps[-3].val.ival), 0, (ps[-1].val.opval)); } + case 280: /* term: FUNC1 PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE */ +#line 1494 "perly.y" + { (yyval.opval) = newUNOP((ps[-3].val.ival), 0, (ps[-1].val.opval)); } break; - case 280: -#line 1491 "perly.y" - { + case 281: /* @23: %empty */ +#line 1496 "perly.y" + { if ( (ps[0].val.opval)->op_type != OP_TRANS && (ps[0].val.opval)->op_type != OP_TRANSR && (((PMOP*)(ps[0].val.opval))->op_pmflags & PMf_HAS_CV)) @@ -2090,108 +2099,108 @@ case 2: break; - case 281: -#line 1502 "perly.y" - { (yyval.opval) = pmruntime((ps[-5].val.opval), (ps[-2].val.opval), (ps[-1].val.opval), 1, (ps[-4].val.ival)); } + case 282: /* term: PMFUNC @23 SUBLEXSTART listexpr optrepl SUBLEXEND */ +#line 1507 "perly.y" + { (yyval.opval) = pmruntime((ps[-5].val.opval), (ps[-2].val.opval), (ps[-1].val.opval), 1, (ps[-4].val.ival)); } break; - case 285: -#line 1511 "perly.y" - { (yyval.opval) = my_attrs((ps[-1].val.opval),(ps[0].val.opval)); } + case 286: /* myattrterm: KW_MY myterm myattrlist */ +#line 1516 "perly.y" + { (yyval.opval) = my_attrs((ps[-1].val.opval),(ps[0].val.opval)); } break; - case 286: -#line 1513 "perly.y" - { (yyval.opval) = localize((ps[0].val.opval),1); } + case 287: /* myattrterm: KW_MY myterm */ +#line 1518 "perly.y" + { (yyval.opval) = localize((ps[0].val.opval),1); } break; - case 287: -#line 1515 "perly.y" - { (yyval.opval) = newUNOP(OP_REFGEN, 0, my_attrs((ps[-1].val.opval),(ps[0].val.opval))); } + case 288: /* myattrterm: KW_MY REFGEN myterm myattrlist */ +#line 1520 "perly.y" + { (yyval.opval) = newUNOP(OP_REFGEN, 0, my_attrs((ps[-1].val.opval),(ps[0].val.opval))); } break; - case 288: -#line 1517 "perly.y" - { (yyval.opval) = newUNOP(OP_REFGEN, 0, localize((ps[0].val.opval),1)); } + case 289: /* myattrterm: KW_MY REFGEN term */ +#line 1522 "perly.y" + { (yyval.opval) = newUNOP(OP_REFGEN, 0, localize((ps[0].val.opval),1)); } break; - case 289: -#line 1522 "perly.y" - { (yyval.opval) = sawparens((ps[-1].val.opval)); } + case 290: /* myterm: PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE */ +#line 1527 "perly.y" + { (yyval.opval) = sawparens((ps[-1].val.opval)); } break; - case 290: -#line 1524 "perly.y" - { (yyval.opval) = sawparens(newNULLLIST()); } + case 291: /* myterm: PERLY_PAREN_OPEN PERLY_PAREN_CLOSE */ +#line 1529 "perly.y" + { (yyval.opval) = sawparens(newNULLLIST()); } break; - case 291: -#line 1527 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 292: /* myterm: scalar */ +#line 1532 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 292: -#line 1529 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 293: /* myterm: hsh */ +#line 1534 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 293: -#line 1531 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 294: /* myterm: ary */ +#line 1536 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 294: -#line 1536 "perly.y" - { + case 295: /* fieldvar: scalar */ +#line 1541 "perly.y" + { (yyval.pval) = PadnamelistARRAY(PL_comppad_name)[(ps[0].val.opval)->op_targ]; op_free((ps[0].val.opval)); } break; - case 295: -#line 1541 "perly.y" - { + case 296: /* fieldvar: hsh */ +#line 1546 "perly.y" + { (yyval.pval) = PadnamelistARRAY(PL_comppad_name)[(ps[0].val.opval)->op_targ]; op_free((ps[0].val.opval)); } break; - case 296: -#line 1546 "perly.y" - { + case 297: /* fieldvar: ary */ +#line 1551 "perly.y" + { (yyval.pval) = PadnamelistARRAY(PL_comppad_name)[(ps[0].val.opval)->op_targ]; op_free((ps[0].val.opval)); } break; - case 297: -#line 1554 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 298: /* optfieldattrlist: COLONATTR THING */ +#line 1559 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 298: -#line 1556 "perly.y" - { (yyval.opval) = NULL; } + case 299: /* optfieldattrlist: COLONATTR */ +#line 1561 "perly.y" + { (yyval.opval) = NULL; } break; - case 300: -#line 1562 "perly.y" - { + case 301: /* fielddecl: KW_FIELD fieldvar optfieldattrlist */ +#line 1567 "perly.y" + { parser->in_my = 0; if((ps[0].val.opval)) class_apply_field_attributes((PADNAME *)(ps[-1].val.pval), (ps[0].val.opval)); @@ -2200,9 +2209,9 @@ case 2: break; - case 301: -#line 1569 "perly.y" - { + case 302: /* $@24: %empty */ +#line 1574 "perly.y" + { parser->in_my = 0; if((ps[-1].val.opval)) class_apply_field_attributes((PADNAME *)(ps[-2].val.pval), (ps[-1].val.opval)); @@ -2212,9 +2221,9 @@ case 2: break; - case 302: -#line 1577 "perly.y" - { + case 303: /* fielddecl: KW_FIELD fieldvar optfieldattrlist ASSIGNOP $@24 term */ +#line 1582 "perly.y" + { class_set_field_defop((PADNAME *)(ps[-4].val.pval), (ps[-2].val.ival), (ps[0].val.opval)); LEAVE; (yyval.opval) = newOP(OP_NULL, 0); @@ -2222,132 +2231,133 @@ case 2: break; - case 308: -#line 1597 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 309: /* optrepl: PERLY_SLASH expr */ +#line 1602 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } break; - case 309: -#line 1603 "perly.y" - { parser->in_my = 0; (yyval.opval) = my((ps[0].val.opval)); } + case 310: /* my_scalar: scalar */ +#line 1608 "perly.y" + { parser->in_my = 0; (yyval.opval) = my((ps[0].val.opval)); } break; - case 310: -#line 1608 "perly.y" - { (yyval.opval) = (ps[-1].val.opval); } + case 311: /* list_of_scalars: list_of_scalars PERLY_COMMA */ +#line 1613 "perly.y" + { (yyval.opval) = (ps[-1].val.opval); } break; - case 311: -#line 1610 "perly.y" - { + case 312: /* list_of_scalars: list_of_scalars PERLY_COMMA scalar */ +#line 1615 "perly.y" + { (yyval.opval) = op_append_elem(OP_LIST, (ps[-2].val.opval), (ps[0].val.opval)); } break; - case 313: -#line 1617 "perly.y" - { parser->in_my = 0; (yyval.opval) = (ps[0].val.opval); } + case 314: /* my_list_of_scalars: list_of_scalars */ +#line 1622 "perly.y" + { parser->in_my = 0; (yyval.opval) = (ps[0].val.opval); } break; - case 321: -#line 1634 "perly.y" - { (yyval.opval) = newCVREF((ps[-1].val.ival),(ps[0].val.opval)); } + case 322: /* amper: PERLY_AMPERSAND indirob */ +#line 1639 "perly.y" + { (yyval.opval) = newCVREF((ps[-1].val.ival),(ps[0].val.opval)); } break; - case 322: -#line 1638 "perly.y" - { (yyval.opval) = newSVREF((ps[0].val.opval)); } + case 323: /* scalar: PERLY_DOLLAR indirob */ +#line 1643 "perly.y" + { (yyval.opval) = newSVREF((ps[0].val.opval)); } break; - case 323: -#line 1642 "perly.y" - { (yyval.opval) = newAVREF((ps[0].val.opval)); + case 324: /* ary: PERLY_SNAIL indirob */ +#line 1647 "perly.y" + { (yyval.opval) = newAVREF((ps[0].val.opval)); if ((yyval.opval)) (yyval.opval)->op_private |= (ps[-1].val.ival); } break; - case 324: -#line 1648 "perly.y" - { (yyval.opval) = newHVREF((ps[0].val.opval)); + case 325: /* hsh: PERLY_PERCENT_SIGN indirob */ +#line 1653 "perly.y" + { (yyval.opval) = newHVREF((ps[0].val.opval)); if ((yyval.opval)) (yyval.opval)->op_private |= (ps[-1].val.ival); } break; - case 325: -#line 1654 "perly.y" - { (yyval.opval) = newAVREF((ps[0].val.opval)); } + case 326: /* arylen: DOLSHARP indirob */ +#line 1659 "perly.y" + { (yyval.opval) = newAVREF((ps[0].val.opval)); } break; - case 326: -#line 1656 "perly.y" - { (yyval.opval) = newAVREF((ps[-3].val.opval)); } + case 327: /* arylen: term ARROW DOLSHARP PERLY_STAR */ +#line 1661 "perly.y" + { (yyval.opval) = newAVREF((ps[-3].val.opval)); } break; - case 327: -#line 1660 "perly.y" - { (yyval.opval) = newGVREF(0,(ps[0].val.opval)); } - - break; - - case 329: + case 328: /* star: PERLY_STAR indirob */ #line 1665 "perly.y" - { (yyval.opval) = newAVREF((ps[-2].val.opval)); } + { (yyval.opval) = newGVREF(0,(ps[0].val.opval)); } break; - case 331: + case 330: /* sliceme: term ARROW PERLY_SNAIL */ #line 1670 "perly.y" - { (yyval.opval) = newHVREF((ps[-2].val.opval)); } + { (yyval.opval) = newAVREF((ps[-2].val.opval)); } break; - case 333: + case 332: /* kvslice: term ARROW PERLY_PERCENT_SIGN */ #line 1675 "perly.y" - { (yyval.opval) = newGVREF(0,(ps[-2].val.opval)); } + { (yyval.opval) = newHVREF((ps[-2].val.opval)); } break; - case 334: + case 334: /* gelem: term ARROW PERLY_STAR */ #line 1680 "perly.y" - { (yyval.opval) = scalar((ps[0].val.opval)); } + { (yyval.opval) = newGVREF(0,(ps[-2].val.opval)); } break; - case 335: -#line 1682 "perly.y" - { (yyval.opval) = scalar((ps[0].val.opval)); } + case 335: /* indirob: BAREWORD */ +#line 1685 "perly.y" + { (yyval.opval) = scalar((ps[0].val.opval)); } break; - case 336: -#line 1684 "perly.y" - { (yyval.opval) = op_scope((ps[0].val.opval)); } + case 336: /* indirob: scalar */ +#line 1687 "perly.y" + { (yyval.opval) = scalar((ps[0].val.opval)); } break; - case 337: -#line 1687 "perly.y" - { (yyval.opval) = (ps[0].val.opval); } + case 337: /* indirob: block */ +#line 1689 "perly.y" + { (yyval.opval) = op_scope((ps[0].val.opval)); } break; + case 338: /* indirob: PRIVATEREF */ +#line 1692 "perly.y" + { (yyval.opval) = (ps[0].val.opval); } + + break; + + default: break; /* Generated from: - * 0a5fcd15cf0b7afb57ade6ceaf68037a38dd194acd9d60d3e4ad99c15233af75 perly.y + * 823630846fc59cc2a19502726ec723b568eabded55fdc5e9722c600e1098779e perly.y * acf1cbfd2545faeaaa58b1cf0cf9d7f98b5be0752eb7a54528ef904a9e2e1ca7 regen_perly.pl * ex: set ro ft=c: */ Index: gnu/usr.bin/perl/perly.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/perly.h,v diff -u -p -a -u -p -r1.15 perly.h --- gnu/usr.bin/perl/perly.h 14 May 2024 19:38:54 -0000 1.15 +++ gnu/usr.bin/perl/perly.h 22 Jan 2025 00:37:44 -0000 @@ -4,14 +4,14 @@ Any changes made here will be lost! */ -#define PERL_BISON_VERSION 30003 +#define PERL_BISON_VERSION 30007 #ifdef PERL_CORE -/* A Bison parser, made by GNU Bison 3.3. */ +/* A Bison parser, made by GNU Bison 3.7. */ /* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation, + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -40,8 +40,9 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ -/* Undocumented macros, especially those whose name start with YY_, - are private implementation details. Do not rely on them. */ +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ /* Debug traces. */ #ifndef YYDEBUG @@ -51,140 +52,145 @@ extern int yydebug; #endif -/* Token type. */ +/* Token kinds. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE enum yytokentype { - GRAMPROG = 258, - GRAMEXPR = 259, - GRAMBLOCK = 260, - GRAMBARESTMT = 261, - GRAMFULLSTMT = 262, - GRAMSTMTSEQ = 263, - GRAMSUBSIGNATURE = 264, - PERLY_AMPERSAND = 265, - PERLY_BRACE_OPEN = 266, - PERLY_BRACE_CLOSE = 267, - PERLY_BRACKET_OPEN = 268, - PERLY_BRACKET_CLOSE = 269, - PERLY_COMMA = 270, - PERLY_DOLLAR = 271, - PERLY_DOT = 272, - PERLY_EQUAL_SIGN = 273, - PERLY_MINUS = 274, - PERLY_PERCENT_SIGN = 275, - PERLY_PLUS = 276, - PERLY_SEMICOLON = 277, - PERLY_SLASH = 278, - PERLY_SNAIL = 279, - PERLY_STAR = 280, - KW_FORMAT = 281, - KW_PACKAGE = 282, - KW_CLASS = 283, - KW_LOCAL = 284, - KW_MY = 285, - KW_FIELD = 286, - KW_IF = 287, - KW_ELSE = 288, - KW_ELSIF = 289, - KW_UNLESS = 290, - KW_FOR = 291, - KW_UNTIL = 292, - KW_WHILE = 293, - KW_CONTINUE = 294, - KW_GIVEN = 295, - KW_WHEN = 296, - KW_DEFAULT = 297, - KW_TRY = 298, - KW_CATCH = 299, - KW_FINALLY = 300, - KW_DEFER = 301, - KW_REQUIRE = 302, - KW_DO = 303, - KW_USE_or_NO = 304, - KW_SUB_named = 305, - KW_SUB_named_sig = 306, - KW_SUB_anon = 307, - KW_SUB_anon_sig = 308, - KW_METHOD_named = 309, - KW_METHOD_anon = 310, - BAREWORD = 311, - METHCALL0 = 312, - METHCALL = 313, - THING = 314, - PMFUNC = 315, - PRIVATEREF = 316, - QWLIST = 317, - FUNC0OP = 318, - FUNC0SUB = 319, - UNIOPSUB = 320, - LSTOPSUB = 321, - PLUGEXPR = 322, - PLUGSTMT = 323, - LABEL = 324, - LOOPEX = 325, - DOTDOT = 326, - YADAYADA = 327, - FUNC0 = 328, - FUNC1 = 329, - FUNC = 330, - UNIOP = 331, - LSTOP = 332, - POWOP = 333, - MULOP = 334, - ADDOP = 335, - DOLSHARP = 336, - HASHBRACK = 337, - NOAMP = 338, - COLONATTR = 339, - FORMLBRACK = 340, - FORMRBRACK = 341, - SUBLEXSTART = 342, - SUBLEXEND = 343, - PHASER = 344, - PREC_LOW = 345, - PLUGIN_LOW_OP = 346, - OROP = 347, - PLUGIN_LOGICAL_OR_LOW_OP = 348, - ANDOP = 349, - PLUGIN_LOGICAL_AND_LOW_OP = 350, - NOTOP = 351, - ASSIGNOP = 352, - PLUGIN_ASSIGN_OP = 353, - PERLY_QUESTION_MARK = 354, - PERLY_COLON = 355, - OROR = 356, - DORDOR = 357, - PLUGIN_LOGICAL_OR_OP = 358, - ANDAND = 359, - PLUGIN_LOGICAL_AND_OP = 360, - BITOROP = 361, - BITANDOP = 362, - CHEQOP = 363, - NCEQOP = 364, - CHRELOP = 365, - NCRELOP = 366, - PLUGIN_REL_OP = 367, - SHIFTOP = 368, - PLUGIN_ADD_OP = 369, - PLUGIN_MUL_OP = 370, - MATCHOP = 371, - PERLY_EXCLAMATION_MARK = 372, - PERLY_TILDE = 373, - UMINUS = 374, - REFGEN = 375, - PLUGIN_POW_OP = 376, - PREINC = 377, - PREDEC = 378, - POSTINC = 379, - POSTDEC = 380, - POSTJOIN = 381, - PLUGIN_HIGH_OP = 382, - ARROW = 383, - PERLY_PAREN_CLOSE = 384, - PERLY_PAREN_OPEN = 385 + YYEMPTY = -2, + YYEOF = 0, /* "end of file" */ + YYerror = 256, /* error */ + YYUNDEF = 257, /* "invalid token" */ + GRAMPROG = 258, /* GRAMPROG */ + GRAMEXPR = 259, /* GRAMEXPR */ + GRAMBLOCK = 260, /* GRAMBLOCK */ + GRAMBARESTMT = 261, /* GRAMBARESTMT */ + GRAMFULLSTMT = 262, /* GRAMFULLSTMT */ + GRAMSTMTSEQ = 263, /* GRAMSTMTSEQ */ + GRAMSUBSIGNATURE = 264, /* GRAMSUBSIGNATURE */ + PERLY_AMPERSAND = 265, /* PERLY_AMPERSAND */ + PERLY_BRACE_OPEN = 266, /* PERLY_BRACE_OPEN */ + PERLY_BRACE_CLOSE = 267, /* PERLY_BRACE_CLOSE */ + PERLY_BRACKET_OPEN = 268, /* PERLY_BRACKET_OPEN */ + PERLY_BRACKET_CLOSE = 269, /* PERLY_BRACKET_CLOSE */ + PERLY_COMMA = 270, /* PERLY_COMMA */ + PERLY_DOLLAR = 271, /* PERLY_DOLLAR */ + PERLY_DOT = 272, /* PERLY_DOT */ + PERLY_EQUAL_SIGN = 273, /* PERLY_EQUAL_SIGN */ + PERLY_MINUS = 274, /* PERLY_MINUS */ + PERLY_PERCENT_SIGN = 275, /* PERLY_PERCENT_SIGN */ + PERLY_PLUS = 276, /* PERLY_PLUS */ + PERLY_SEMICOLON = 277, /* PERLY_SEMICOLON */ + PERLY_SLASH = 278, /* PERLY_SLASH */ + PERLY_SNAIL = 279, /* PERLY_SNAIL */ + PERLY_STAR = 280, /* PERLY_STAR */ + KW_FORMAT = 281, /* KW_FORMAT */ + KW_PACKAGE = 282, /* KW_PACKAGE */ + KW_CLASS = 283, /* KW_CLASS */ + KW_LOCAL = 284, /* KW_LOCAL */ + KW_MY = 285, /* KW_MY */ + KW_FIELD = 286, /* KW_FIELD */ + KW_IF = 287, /* KW_IF */ + KW_ELSE = 288, /* KW_ELSE */ + KW_ELSIF = 289, /* KW_ELSIF */ + KW_UNLESS = 290, /* KW_UNLESS */ + KW_FOR = 291, /* KW_FOR */ + KW_UNTIL = 292, /* KW_UNTIL */ + KW_WHILE = 293, /* KW_WHILE */ + KW_CONTINUE = 294, /* KW_CONTINUE */ + KW_GIVEN = 295, /* KW_GIVEN */ + KW_WHEN = 296, /* KW_WHEN */ + KW_DEFAULT = 297, /* KW_DEFAULT */ + KW_TRY = 298, /* KW_TRY */ + KW_CATCH = 299, /* KW_CATCH */ + KW_FINALLY = 300, /* KW_FINALLY */ + KW_DEFER = 301, /* KW_DEFER */ + KW_REQUIRE = 302, /* KW_REQUIRE */ + KW_DO = 303, /* KW_DO */ + KW_USE_or_NO = 304, /* KW_USE_or_NO */ + KW_SUB_named = 305, /* KW_SUB_named */ + KW_SUB_named_sig = 306, /* KW_SUB_named_sig */ + KW_SUB_anon = 307, /* KW_SUB_anon */ + KW_SUB_anon_sig = 308, /* KW_SUB_anon_sig */ + KW_METHOD_named = 309, /* KW_METHOD_named */ + KW_METHOD_anon = 310, /* KW_METHOD_anon */ + BAREWORD = 311, /* BAREWORD */ + METHCALL0 = 312, /* METHCALL0 */ + METHCALL = 313, /* METHCALL */ + THING = 314, /* THING */ + PMFUNC = 315, /* PMFUNC */ + PRIVATEREF = 316, /* PRIVATEREF */ + QWLIST = 317, /* QWLIST */ + FUNC0OP = 318, /* FUNC0OP */ + FUNC0SUB = 319, /* FUNC0SUB */ + UNIOPSUB = 320, /* UNIOPSUB */ + LSTOPSUB = 321, /* LSTOPSUB */ + PLUGEXPR = 322, /* PLUGEXPR */ + PLUGSTMT = 323, /* PLUGSTMT */ + LABEL = 324, /* LABEL */ + LOOPEX = 325, /* LOOPEX */ + DOTDOT = 326, /* DOTDOT */ + YADAYADA = 327, /* YADAYADA */ + FUNC0 = 328, /* FUNC0 */ + FUNC1 = 329, /* FUNC1 */ + FUNC = 330, /* FUNC */ + UNIOP = 331, /* UNIOP */ + LSTOP = 332, /* LSTOP */ + POWOP = 333, /* POWOP */ + MULOP = 334, /* MULOP */ + ADDOP = 335, /* ADDOP */ + DOLSHARP = 336, /* DOLSHARP */ + HASHBRACK = 337, /* HASHBRACK */ + NOAMP = 338, /* NOAMP */ + COLONATTR = 339, /* COLONATTR */ + FORMLBRACK = 340, /* FORMLBRACK */ + FORMRBRACK = 341, /* FORMRBRACK */ + SUBLEXSTART = 342, /* SUBLEXSTART */ + SUBLEXEND = 343, /* SUBLEXEND */ + PHASER = 344, /* PHASER */ + PREC_LOW = 345, /* PREC_LOW */ + PLUGIN_LOW_OP = 346, /* PLUGIN_LOW_OP */ + OROP = 347, /* OROP */ + PLUGIN_LOGICAL_OR_LOW_OP = 348, /* PLUGIN_LOGICAL_OR_LOW_OP */ + ANDOP = 349, /* ANDOP */ + PLUGIN_LOGICAL_AND_LOW_OP = 350, /* PLUGIN_LOGICAL_AND_LOW_OP */ + NOTOP = 351, /* NOTOP */ + ASSIGNOP = 352, /* ASSIGNOP */ + PLUGIN_ASSIGN_OP = 353, /* PLUGIN_ASSIGN_OP */ + PERLY_QUESTION_MARK = 354, /* PERLY_QUESTION_MARK */ + PERLY_COLON = 355, /* PERLY_COLON */ + OROR = 356, /* OROR */ + DORDOR = 357, /* DORDOR */ + PLUGIN_LOGICAL_OR_OP = 358, /* PLUGIN_LOGICAL_OR_OP */ + ANDAND = 359, /* ANDAND */ + PLUGIN_LOGICAL_AND_OP = 360, /* PLUGIN_LOGICAL_AND_OP */ + BITOROP = 361, /* BITOROP */ + BITANDOP = 362, /* BITANDOP */ + CHEQOP = 363, /* CHEQOP */ + NCEQOP = 364, /* NCEQOP */ + CHRELOP = 365, /* CHRELOP */ + NCRELOP = 366, /* NCRELOP */ + PLUGIN_REL_OP = 367, /* PLUGIN_REL_OP */ + SHIFTOP = 368, /* SHIFTOP */ + PLUGIN_ADD_OP = 369, /* PLUGIN_ADD_OP */ + PLUGIN_MUL_OP = 370, /* PLUGIN_MUL_OP */ + MATCHOP = 371, /* MATCHOP */ + PERLY_EXCLAMATION_MARK = 372, /* PERLY_EXCLAMATION_MARK */ + PERLY_TILDE = 373, /* PERLY_TILDE */ + UMINUS = 374, /* UMINUS */ + REFGEN = 375, /* REFGEN */ + PLUGIN_POW_OP = 376, /* PLUGIN_POW_OP */ + PREINC = 377, /* PREINC */ + PREDEC = 378, /* PREDEC */ + POSTINC = 379, /* POSTINC */ + POSTDEC = 380, /* POSTDEC */ + POSTJOIN = 381, /* POSTJOIN */ + PLUGIN_HIGH_OP = 382, /* PLUGIN_HIGH_OP */ + ARROW = 383, /* ARROW */ + PERLY_PAREN_CLOSE = 384, /* PERLY_PAREN_CLOSE */ + PERLY_PAREN_OPEN = 385 /* PERLY_PAREN_OPEN */ }; + typedef enum yytokentype yytoken_kind_t; #endif /* Value type. */ @@ -213,7 +219,6 @@ S_is_opval_token(int type) { #endif /* PERL_IN_TOKE_C */ #endif /* PERL_CORE */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED - union YYSTYPE { @@ -223,8 +228,8 @@ union YYSTYPE OP *opval; GV *gvval; -}; +}; typedef union YYSTYPE YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_DECLARED 1 @@ -236,6 +241,6 @@ int yyparse (void); /* Generated from: - * 0a5fcd15cf0b7afb57ade6ceaf68037a38dd194acd9d60d3e4ad99c15233af75 perly.y + * 823630846fc59cc2a19502726ec723b568eabded55fdc5e9722c600e1098779e perly.y * acf1cbfd2545faeaaa58b1cf0cf9d7f98b5be0752eb7a54528ef904a9e2e1ca7 regen_perly.pl * ex: set ro ft=c: */ Index: gnu/usr.bin/perl/perly.tab =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/perly.tab,v diff -u -p -a -u -p -r1.7 perly.tab --- gnu/usr.bin/perl/perly.tab 14 May 2024 19:38:54 -0000 1.7 +++ gnu/usr.bin/perl/perly.tab 22 Jan 2025 00:37:44 -0000 @@ -4,26 +4,284 @@ Any changes made here will be lost! */ +/* Symbol kind. */ +enum yysymbol_kind_t +{ + YYSYMBOL_YYEMPTY = -2, + YYSYMBOL_YYEOF = 0, /* "end of file" */ + YYSYMBOL_YYerror = 1, /* error */ + YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ + YYSYMBOL_GRAMPROG = 3, /* GRAMPROG */ + YYSYMBOL_GRAMEXPR = 4, /* GRAMEXPR */ + YYSYMBOL_GRAMBLOCK = 5, /* GRAMBLOCK */ + YYSYMBOL_GRAMBARESTMT = 6, /* GRAMBARESTMT */ + YYSYMBOL_GRAMFULLSTMT = 7, /* GRAMFULLSTMT */ + YYSYMBOL_GRAMSTMTSEQ = 8, /* GRAMSTMTSEQ */ + YYSYMBOL_GRAMSUBSIGNATURE = 9, /* GRAMSUBSIGNATURE */ + YYSYMBOL_PERLY_AMPERSAND = 10, /* PERLY_AMPERSAND */ + YYSYMBOL_PERLY_BRACE_OPEN = 11, /* PERLY_BRACE_OPEN */ + YYSYMBOL_PERLY_BRACE_CLOSE = 12, /* PERLY_BRACE_CLOSE */ + YYSYMBOL_PERLY_BRACKET_OPEN = 13, /* PERLY_BRACKET_OPEN */ + YYSYMBOL_PERLY_BRACKET_CLOSE = 14, /* PERLY_BRACKET_CLOSE */ + YYSYMBOL_PERLY_COMMA = 15, /* PERLY_COMMA */ + YYSYMBOL_PERLY_DOLLAR = 16, /* PERLY_DOLLAR */ + YYSYMBOL_PERLY_DOT = 17, /* PERLY_DOT */ + YYSYMBOL_PERLY_EQUAL_SIGN = 18, /* PERLY_EQUAL_SIGN */ + YYSYMBOL_PERLY_MINUS = 19, /* PERLY_MINUS */ + YYSYMBOL_PERLY_PERCENT_SIGN = 20, /* PERLY_PERCENT_SIGN */ + YYSYMBOL_PERLY_PLUS = 21, /* PERLY_PLUS */ + YYSYMBOL_PERLY_SEMICOLON = 22, /* PERLY_SEMICOLON */ + YYSYMBOL_PERLY_SLASH = 23, /* PERLY_SLASH */ + YYSYMBOL_PERLY_SNAIL = 24, /* PERLY_SNAIL */ + YYSYMBOL_PERLY_STAR = 25, /* PERLY_STAR */ + YYSYMBOL_KW_FORMAT = 26, /* KW_FORMAT */ + YYSYMBOL_KW_PACKAGE = 27, /* KW_PACKAGE */ + YYSYMBOL_KW_CLASS = 28, /* KW_CLASS */ + YYSYMBOL_KW_LOCAL = 29, /* KW_LOCAL */ + YYSYMBOL_KW_MY = 30, /* KW_MY */ + YYSYMBOL_KW_FIELD = 31, /* KW_FIELD */ + YYSYMBOL_KW_IF = 32, /* KW_IF */ + YYSYMBOL_KW_ELSE = 33, /* KW_ELSE */ + YYSYMBOL_KW_ELSIF = 34, /* KW_ELSIF */ + YYSYMBOL_KW_UNLESS = 35, /* KW_UNLESS */ + YYSYMBOL_KW_FOR = 36, /* KW_FOR */ + YYSYMBOL_KW_UNTIL = 37, /* KW_UNTIL */ + YYSYMBOL_KW_WHILE = 38, /* KW_WHILE */ + YYSYMBOL_KW_CONTINUE = 39, /* KW_CONTINUE */ + YYSYMBOL_KW_GIVEN = 40, /* KW_GIVEN */ + YYSYMBOL_KW_WHEN = 41, /* KW_WHEN */ + YYSYMBOL_KW_DEFAULT = 42, /* KW_DEFAULT */ + YYSYMBOL_KW_TRY = 43, /* KW_TRY */ + YYSYMBOL_KW_CATCH = 44, /* KW_CATCH */ + YYSYMBOL_KW_FINALLY = 45, /* KW_FINALLY */ + YYSYMBOL_KW_DEFER = 46, /* KW_DEFER */ + YYSYMBOL_KW_REQUIRE = 47, /* KW_REQUIRE */ + YYSYMBOL_KW_DO = 48, /* KW_DO */ + YYSYMBOL_KW_USE_or_NO = 49, /* KW_USE_or_NO */ + YYSYMBOL_KW_SUB_named = 50, /* KW_SUB_named */ + YYSYMBOL_KW_SUB_named_sig = 51, /* KW_SUB_named_sig */ + YYSYMBOL_KW_SUB_anon = 52, /* KW_SUB_anon */ + YYSYMBOL_KW_SUB_anon_sig = 53, /* KW_SUB_anon_sig */ + YYSYMBOL_KW_METHOD_named = 54, /* KW_METHOD_named */ + YYSYMBOL_KW_METHOD_anon = 55, /* KW_METHOD_anon */ + YYSYMBOL_BAREWORD = 56, /* BAREWORD */ + YYSYMBOL_METHCALL0 = 57, /* METHCALL0 */ + YYSYMBOL_METHCALL = 58, /* METHCALL */ + YYSYMBOL_THING = 59, /* THING */ + YYSYMBOL_PMFUNC = 60, /* PMFUNC */ + YYSYMBOL_PRIVATEREF = 61, /* PRIVATEREF */ + YYSYMBOL_QWLIST = 62, /* QWLIST */ + YYSYMBOL_FUNC0OP = 63, /* FUNC0OP */ + YYSYMBOL_FUNC0SUB = 64, /* FUNC0SUB */ + YYSYMBOL_UNIOPSUB = 65, /* UNIOPSUB */ + YYSYMBOL_LSTOPSUB = 66, /* LSTOPSUB */ + YYSYMBOL_PLUGEXPR = 67, /* PLUGEXPR */ + YYSYMBOL_PLUGSTMT = 68, /* PLUGSTMT */ + YYSYMBOL_LABEL = 69, /* LABEL */ + YYSYMBOL_LOOPEX = 70, /* LOOPEX */ + YYSYMBOL_DOTDOT = 71, /* DOTDOT */ + YYSYMBOL_YADAYADA = 72, /* YADAYADA */ + YYSYMBOL_FUNC0 = 73, /* FUNC0 */ + YYSYMBOL_FUNC1 = 74, /* FUNC1 */ + YYSYMBOL_FUNC = 75, /* FUNC */ + YYSYMBOL_UNIOP = 76, /* UNIOP */ + YYSYMBOL_LSTOP = 77, /* LSTOP */ + YYSYMBOL_POWOP = 78, /* POWOP */ + YYSYMBOL_MULOP = 79, /* MULOP */ + YYSYMBOL_ADDOP = 80, /* ADDOP */ + YYSYMBOL_DOLSHARP = 81, /* DOLSHARP */ + YYSYMBOL_HASHBRACK = 82, /* HASHBRACK */ + YYSYMBOL_NOAMP = 83, /* NOAMP */ + YYSYMBOL_COLONATTR = 84, /* COLONATTR */ + YYSYMBOL_FORMLBRACK = 85, /* FORMLBRACK */ + YYSYMBOL_FORMRBRACK = 86, /* FORMRBRACK */ + YYSYMBOL_SUBLEXSTART = 87, /* SUBLEXSTART */ + YYSYMBOL_SUBLEXEND = 88, /* SUBLEXEND */ + YYSYMBOL_PHASER = 89, /* PHASER */ + YYSYMBOL_PREC_LOW = 90, /* PREC_LOW */ + YYSYMBOL_PLUGIN_LOW_OP = 91, /* PLUGIN_LOW_OP */ + YYSYMBOL_OROP = 92, /* OROP */ + YYSYMBOL_PLUGIN_LOGICAL_OR_LOW_OP = 93, /* PLUGIN_LOGICAL_OR_LOW_OP */ + YYSYMBOL_ANDOP = 94, /* ANDOP */ + YYSYMBOL_PLUGIN_LOGICAL_AND_LOW_OP = 95, /* PLUGIN_LOGICAL_AND_LOW_OP */ + YYSYMBOL_NOTOP = 96, /* NOTOP */ + YYSYMBOL_ASSIGNOP = 97, /* ASSIGNOP */ + YYSYMBOL_PLUGIN_ASSIGN_OP = 98, /* PLUGIN_ASSIGN_OP */ + YYSYMBOL_PERLY_QUESTION_MARK = 99, /* PERLY_QUESTION_MARK */ + YYSYMBOL_PERLY_COLON = 100, /* PERLY_COLON */ + YYSYMBOL_OROR = 101, /* OROR */ + YYSYMBOL_DORDOR = 102, /* DORDOR */ + YYSYMBOL_PLUGIN_LOGICAL_OR_OP = 103, /* PLUGIN_LOGICAL_OR_OP */ + YYSYMBOL_ANDAND = 104, /* ANDAND */ + YYSYMBOL_PLUGIN_LOGICAL_AND_OP = 105, /* PLUGIN_LOGICAL_AND_OP */ + YYSYMBOL_BITOROP = 106, /* BITOROP */ + YYSYMBOL_BITANDOP = 107, /* BITANDOP */ + YYSYMBOL_CHEQOP = 108, /* CHEQOP */ + YYSYMBOL_NCEQOP = 109, /* NCEQOP */ + YYSYMBOL_CHRELOP = 110, /* CHRELOP */ + YYSYMBOL_NCRELOP = 111, /* NCRELOP */ + YYSYMBOL_PLUGIN_REL_OP = 112, /* PLUGIN_REL_OP */ + YYSYMBOL_SHIFTOP = 113, /* SHIFTOP */ + YYSYMBOL_PLUGIN_ADD_OP = 114, /* PLUGIN_ADD_OP */ + YYSYMBOL_PLUGIN_MUL_OP = 115, /* PLUGIN_MUL_OP */ + YYSYMBOL_MATCHOP = 116, /* MATCHOP */ + YYSYMBOL_PERLY_EXCLAMATION_MARK = 117, /* PERLY_EXCLAMATION_MARK */ + YYSYMBOL_PERLY_TILDE = 118, /* PERLY_TILDE */ + YYSYMBOL_UMINUS = 119, /* UMINUS */ + YYSYMBOL_REFGEN = 120, /* REFGEN */ + YYSYMBOL_PLUGIN_POW_OP = 121, /* PLUGIN_POW_OP */ + YYSYMBOL_PREINC = 122, /* PREINC */ + YYSYMBOL_PREDEC = 123, /* PREDEC */ + YYSYMBOL_POSTINC = 124, /* POSTINC */ + YYSYMBOL_POSTDEC = 125, /* POSTDEC */ + YYSYMBOL_POSTJOIN = 126, /* POSTJOIN */ + YYSYMBOL_PLUGIN_HIGH_OP = 127, /* PLUGIN_HIGH_OP */ + YYSYMBOL_ARROW = 128, /* ARROW */ + YYSYMBOL_PERLY_PAREN_CLOSE = 129, /* PERLY_PAREN_CLOSE */ + YYSYMBOL_PERLY_PAREN_OPEN = 130, /* PERLY_PAREN_OPEN */ + YYSYMBOL_YYACCEPT = 131, /* $accept */ + YYSYMBOL_grammar = 132, /* grammar */ + YYSYMBOL_133_1 = 133, /* @1 */ + YYSYMBOL_134_2 = 134, /* @2 */ + YYSYMBOL_135_3 = 135, /* @3 */ + YYSYMBOL_136_4 = 136, /* @4 */ + YYSYMBOL_137_5 = 137, /* @5 */ + YYSYMBOL_138_6 = 138, /* @6 */ + YYSYMBOL_139_7 = 139, /* @7 */ + YYSYMBOL_sigsub_or_method_named = 140, /* sigsub_or_method_named */ + YYSYMBOL_block = 141, /* block */ + YYSYMBOL_empty = 142, /* empty */ + YYSYMBOL_formblock = 143, /* formblock */ + YYSYMBOL_remember = 144, /* remember */ + YYSYMBOL_mblock = 145, /* mblock */ + YYSYMBOL_mremember = 146, /* mremember */ + YYSYMBOL_catch_paren = 147, /* catch_paren */ + YYSYMBOL_148_8 = 148, /* $@8 */ + YYSYMBOL_149_9 = 149, /* $@9 */ + YYSYMBOL_stmtseq = 150, /* stmtseq */ + YYSYMBOL_formstmtseq = 151, /* formstmtseq */ + YYSYMBOL_fullstmt = 152, /* fullstmt */ + YYSYMBOL_labfullstmt = 153, /* labfullstmt */ + YYSYMBOL_barestmt = 154, /* barestmt */ + YYSYMBOL_155_10 = 155, /* $@10 */ + YYSYMBOL_156_11 = 156, /* $@11 */ + YYSYMBOL_157_12 = 157, /* $@12 */ + YYSYMBOL_158_13 = 158, /* $@13 */ + YYSYMBOL_159_14 = 159, /* $@14 */ + YYSYMBOL_160_15 = 160, /* $@15 */ + YYSYMBOL_161_16 = 161, /* @16 */ + YYSYMBOL_162_17 = 162, /* $@17 */ + YYSYMBOL_163_18 = 163, /* $@18 */ + YYSYMBOL_164_19 = 164, /* $@19 */ + YYSYMBOL_formline = 165, /* formline */ + YYSYMBOL_formarg = 166, /* formarg */ + YYSYMBOL_condition = 167, /* condition */ + YYSYMBOL_sideff = 168, /* sideff */ + YYSYMBOL_else = 169, /* else */ + YYSYMBOL_cont = 170, /* cont */ + YYSYMBOL_finally = 171, /* finally */ + YYSYMBOL_mintro = 172, /* mintro */ + YYSYMBOL_nexpr = 173, /* nexpr */ + YYSYMBOL_texpr = 174, /* texpr */ + YYSYMBOL_iexpr = 175, /* iexpr */ + YYSYMBOL_mexpr = 176, /* mexpr */ + YYSYMBOL_mnexpr = 177, /* mnexpr */ + YYSYMBOL_formname = 178, /* formname */ + YYSYMBOL_startsub = 179, /* startsub */ + YYSYMBOL_startanonsub = 180, /* startanonsub */ + YYSYMBOL_startanonmethod = 181, /* startanonmethod */ + YYSYMBOL_startformsub = 182, /* startformsub */ + YYSYMBOL_subname = 183, /* subname */ + YYSYMBOL_proto = 184, /* proto */ + YYSYMBOL_subattrlist = 185, /* subattrlist */ + YYSYMBOL_myattrlist = 186, /* myattrlist */ + YYSYMBOL_sigvarname = 187, /* sigvarname */ + YYSYMBOL_sigslurpsigil = 188, /* sigslurpsigil */ + YYSYMBOL_sigslurpelem = 189, /* sigslurpelem */ + YYSYMBOL_sigdefault = 190, /* sigdefault */ + YYSYMBOL_sigscalarelem = 191, /* sigscalarelem */ + YYSYMBOL_sigelem = 192, /* sigelem */ + YYSYMBOL_siglist = 193, /* siglist */ + YYSYMBOL_optsiglist = 194, /* optsiglist */ + YYSYMBOL_optsubsignature = 195, /* optsubsignature */ + YYSYMBOL_subsignature = 196, /* subsignature */ + YYSYMBOL_subsigguts = 197, /* subsigguts */ + YYSYMBOL_198_20 = 198, /* $@20 */ + YYSYMBOL_optsubbody = 199, /* optsubbody */ + YYSYMBOL_subbody = 200, /* subbody */ + YYSYMBOL_optsigsubbody = 201, /* optsigsubbody */ + YYSYMBOL_sigsubbody = 202, /* sigsubbody */ + YYSYMBOL_203_21 = 203, /* $@21 */ + YYSYMBOL_expr = 204, /* expr */ + YYSYMBOL_listexpr = 205, /* listexpr */ + YYSYMBOL_listop = 206, /* listop */ + YYSYMBOL_207_22 = 207, /* @22 */ + YYSYMBOL_methodname = 208, /* methodname */ + YYSYMBOL_subscripted = 209, /* subscripted */ + YYSYMBOL_termbinop = 210, /* termbinop */ + YYSYMBOL_termrelop = 211, /* termrelop */ + YYSYMBOL_relopchain = 212, /* relopchain */ + YYSYMBOL_termeqop = 213, /* termeqop */ + YYSYMBOL_eqopchain = 214, /* eqopchain */ + YYSYMBOL_termunop = 215, /* termunop */ + YYSYMBOL_anonymous = 216, /* anonymous */ + YYSYMBOL_termdo = 217, /* termdo */ + YYSYMBOL_term = 218, /* term */ + YYSYMBOL_219_23 = 219, /* @23 */ + YYSYMBOL_myattrterm = 220, /* myattrterm */ + YYSYMBOL_myterm = 221, /* myterm */ + YYSYMBOL_fieldvar = 222, /* fieldvar */ + YYSYMBOL_optfieldattrlist = 223, /* optfieldattrlist */ + YYSYMBOL_fielddecl = 224, /* fielddecl */ + YYSYMBOL_225_24 = 225, /* $@24 */ + YYSYMBOL_optlistexpr = 226, /* optlistexpr */ + YYSYMBOL_optexpr = 227, /* optexpr */ + YYSYMBOL_optrepl = 228, /* optrepl */ + YYSYMBOL_my_scalar = 229, /* my_scalar */ + YYSYMBOL_list_of_scalars = 230, /* list_of_scalars */ + YYSYMBOL_my_list_of_scalars = 231, /* my_list_of_scalars */ + YYSYMBOL_my_var = 232, /* my_var */ + YYSYMBOL_refgen_topic = 233, /* refgen_topic */ + YYSYMBOL_my_refgen = 234, /* my_refgen */ + YYSYMBOL_amper = 235, /* amper */ + YYSYMBOL_scalar = 236, /* scalar */ + YYSYMBOL_ary = 237, /* ary */ + YYSYMBOL_hsh = 238, /* hsh */ + YYSYMBOL_arylen = 239, /* arylen */ + YYSYMBOL_star = 240, /* star */ + YYSYMBOL_sliceme = 241, /* sliceme */ + YYSYMBOL_kvslice = 242, /* kvslice */ + YYSYMBOL_gelem = 243, /* gelem */ + YYSYMBOL_indirob = 244 /* indirob */ +}; +typedef enum yysymbol_kind_t yysymbol_kind_t; + + + + #define YYFINAL 16 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 3664 +#define YYLAST 3705 /* YYNTOKENS -- Number of terminals. */ #define YYNTOKENS 131 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 113 +#define YYNNTS 114 /* YYNRULES -- Number of rules. */ -#define YYNRULES 337 +#define YYNRULES 338 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 669 +#define YYNSTATES 670 -#define YYUNDEFTOK 2 +/* YYMAXUTOK -- Last valid token kind. */ #define YYMAXUTOK 385 + /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM as returned by yylex, with out-of-bounds checking. */ -#define YYTRANSLATE(YYX) \ - ((unsigned) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) +#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : YYSYMBOL_YYUNDEF) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex. */ @@ -72,7 +330,7 @@ static const yytype_uint8 yytranslate[] #if YYDEBUG /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = +static const yytype_int16 yyrline[] = { 0, 161, 161, 160, 172, 171, 182, 181, 195, 194, 208, 207, 221, 220, 231, 230, 244, 246, 251, 259, @@ -88,45 +346,52 @@ static const yytype_uint16 yyrline[] = 787, 788, 793, 794, 799, 800, 807, 812, 814, 825, 827, 832, 834, 838, 858, 859, 861, 874, 934, 936, 942, 944, 948, 954, 955, 960, 961, 965, 969, 969, - 1036, 1037, 1042, 1054, 1055, 1059, 1070, 1072, 1074, 1076, - 1078, 1082, 1084, 1089, 1093, 1097, 1101, 1107, 1112, 1118, - 1124, 1126, 1128, 1131, 1130, 1141, 1142, 1146, 1150, 1153, - 1158, 1163, 1166, 1170, 1174, 1180, 1188, 1195, 1201, 1203, - 1205, 1210, 1212, 1214, 1216, 1218, 1220, 1225, 1227, 1229, - 1231, 1233, 1235, 1237, 1239, 1241, 1243, 1245, 1247, 1249, - 1251, 1253, 1255, 1259, 1261, 1263, 1265, 1267, 1271, 1273, - 1277, 1279, 1281, 1283, 1287, 1289, 1294, 1296, 1299, 1301, - 1303, 1306, 1309, 1320, 1323, 1331, 1333, 1335, 1338, 1341, - 1349, 1351, 1355, 1356, 1357, 1358, 1359, 1361, 1363, 1365, - 1367, 1369, 1371, 1373, 1375, 1377, 1379, 1381, 1383, 1385, - 1395, 1405, 1415, 1425, 1427, 1429, 1432, 1437, 1441, 1443, - 1445, 1447, 1450, 1452, 1455, 1457, 1459, 1461, 1463, 1465, - 1467, 1469, 1471, 1474, 1476, 1478, 1480, 1482, 1484, 1488, - 1491, 1490, 1503, 1504, 1505, 1510, 1512, 1514, 1516, 1521, - 1523, 1526, 1528, 1530, 1535, 1540, 1545, 1553, 1555, 1557, - 1561, 1569, 1568, 1586, 1587, 1591, 1592, 1596, 1597, 1602, - 1607, 1609, 1613, 1616, 1620, 1621, 1622, 1625, 1626, 1629, - 1630, 1633, 1637, 1641, 1647, 1653, 1655, 1659, 1663, 1664, - 1668, 1669, 1673, 1674, 1679, 1681, 1683, 1686 + 1036, 1037, 1042, 1054, 1055, 1060, 1059, 1072, 1074, 1076, + 1078, 1080, 1084, 1086, 1091, 1095, 1099, 1103, 1109, 1114, + 1120, 1126, 1128, 1130, 1133, 1132, 1146, 1147, 1151, 1155, + 1158, 1163, 1168, 1171, 1175, 1179, 1185, 1193, 1200, 1206, + 1208, 1210, 1215, 1217, 1219, 1221, 1223, 1225, 1230, 1232, + 1234, 1236, 1238, 1240, 1242, 1244, 1246, 1248, 1250, 1252, + 1254, 1256, 1258, 1260, 1264, 1266, 1268, 1270, 1272, 1276, + 1278, 1282, 1284, 1286, 1288, 1292, 1294, 1299, 1301, 1304, + 1306, 1308, 1311, 1314, 1325, 1328, 1336, 1338, 1340, 1343, + 1346, 1354, 1356, 1360, 1361, 1362, 1363, 1364, 1366, 1368, + 1370, 1372, 1374, 1376, 1378, 1380, 1382, 1384, 1386, 1388, + 1390, 1400, 1410, 1420, 1430, 1432, 1434, 1437, 1442, 1446, + 1448, 1450, 1452, 1455, 1457, 1460, 1462, 1464, 1466, 1468, + 1470, 1472, 1474, 1476, 1479, 1481, 1483, 1485, 1487, 1489, + 1493, 1496, 1495, 1508, 1509, 1510, 1515, 1517, 1519, 1521, + 1526, 1528, 1531, 1533, 1535, 1540, 1545, 1550, 1558, 1560, + 1562, 1566, 1574, 1573, 1591, 1592, 1596, 1597, 1601, 1602, + 1607, 1612, 1614, 1618, 1621, 1625, 1626, 1627, 1630, 1631, + 1634, 1635, 1638, 1642, 1646, 1652, 1658, 1660, 1664, 1668, + 1669, 1673, 1674, 1678, 1679, 1684, 1686, 1688, 1691 }; #endif -#if YYDEBUG || YYERROR_VERBOSE || 0 +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) + +#if YYDEBUG || 0 +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { - "$end", "error", "$undefined", "GRAMPROG", "GRAMEXPR", "GRAMBLOCK", - "GRAMBARESTMT", "GRAMFULLSTMT", "GRAMSTMTSEQ", "GRAMSUBSIGNATURE", - "PERLY_AMPERSAND", "PERLY_BRACE_OPEN", "PERLY_BRACE_CLOSE", - "PERLY_BRACKET_OPEN", "PERLY_BRACKET_CLOSE", "PERLY_COMMA", - "PERLY_DOLLAR", "PERLY_DOT", "PERLY_EQUAL_SIGN", "PERLY_MINUS", - "PERLY_PERCENT_SIGN", "PERLY_PLUS", "PERLY_SEMICOLON", "PERLY_SLASH", - "PERLY_SNAIL", "PERLY_STAR", "KW_FORMAT", "KW_PACKAGE", "KW_CLASS", - "KW_LOCAL", "KW_MY", "KW_FIELD", "KW_IF", "KW_ELSE", "KW_ELSIF", - "KW_UNLESS", "KW_FOR", "KW_UNTIL", "KW_WHILE", "KW_CONTINUE", "KW_GIVEN", - "KW_WHEN", "KW_DEFAULT", "KW_TRY", "KW_CATCH", "KW_FINALLY", "KW_DEFER", - "KW_REQUIRE", "KW_DO", "KW_USE_or_NO", "KW_SUB_named", + "\"end of file\"", "error", "\"invalid token\"", "GRAMPROG", "GRAMEXPR", + "GRAMBLOCK", "GRAMBARESTMT", "GRAMFULLSTMT", "GRAMSTMTSEQ", + "GRAMSUBSIGNATURE", "PERLY_AMPERSAND", "PERLY_BRACE_OPEN", + "PERLY_BRACE_CLOSE", "PERLY_BRACKET_OPEN", "PERLY_BRACKET_CLOSE", + "PERLY_COMMA", "PERLY_DOLLAR", "PERLY_DOT", "PERLY_EQUAL_SIGN", + "PERLY_MINUS", "PERLY_PERCENT_SIGN", "PERLY_PLUS", "PERLY_SEMICOLON", + "PERLY_SLASH", "PERLY_SNAIL", "PERLY_STAR", "KW_FORMAT", "KW_PACKAGE", + "KW_CLASS", "KW_LOCAL", "KW_MY", "KW_FIELD", "KW_IF", "KW_ELSE", + "KW_ELSIF", "KW_UNLESS", "KW_FOR", "KW_UNTIL", "KW_WHILE", "KW_CONTINUE", + "KW_GIVEN", "KW_WHEN", "KW_DEFAULT", "KW_TRY", "KW_CATCH", "KW_FINALLY", + "KW_DEFER", "KW_REQUIRE", "KW_DO", "KW_USE_or_NO", "KW_SUB_named", "KW_SUB_named_sig", "KW_SUB_anon", "KW_SUB_anon_sig", "KW_METHOD_named", "KW_METHOD_anon", "BAREWORD", "METHCALL0", "METHCALL", "THING", "PMFUNC", "PRIVATEREF", "QWLIST", "FUNC0OP", "FUNC0SUB", "UNIOPSUB", "LSTOPSUB", @@ -153,21 +418,27 @@ static const char *const yytname[] = "proto", "subattrlist", "myattrlist", "sigvarname", "sigslurpsigil", "sigslurpelem", "sigdefault", "sigscalarelem", "sigelem", "siglist", "optsiglist", "optsubsignature", "subsignature", "subsigguts", "$@20", - "optsubbody", "subbody", "optsigsubbody", "sigsubbody", "expr", - "listexpr", "listop", "@21", "methodname", "subscripted", "termbinop", + "optsubbody", "subbody", "optsigsubbody", "sigsubbody", "$@21", "expr", + "listexpr", "listop", "@22", "methodname", "subscripted", "termbinop", "termrelop", "relopchain", "termeqop", "eqopchain", "termunop", - "anonymous", "termdo", "term", "@22", "myattrterm", "myterm", "fieldvar", - "optfieldattrlist", "fielddecl", "$@23", "optlistexpr", "optexpr", + "anonymous", "termdo", "term", "@23", "myattrterm", "myterm", "fieldvar", + "optfieldattrlist", "fielddecl", "$@24", "optlistexpr", "optexpr", "optrepl", "my_scalar", "list_of_scalars", "my_list_of_scalars", "my_var", "refgen_topic", "my_refgen", "amper", "scalar", "ary", "hsh", "arylen", "star", "sliceme", "kvslice", "gelem", "indirob", YY_NULLPTR }; + +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +} #endif -# ifdef YYPRINT +#ifdef YYPRINT /* YYTOKNUM[NUM] -- (External) token number corresponding to the (internal) symbol number NUM (which must be that of a token). */ -static const yytype_uint16 yytoknum[] = +static const yytype_int16 yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, @@ -184,180 +455,180 @@ static const yytype_uint16 yytoknum[] = 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385 }; -# endif +#endif -#define YYPACT_NINF -551 +#define YYPACT_NINF (-544) -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-551))) +#define yypact_value_is_default(Yyn) \ + ((Yyn) == YYPACT_NINF) -#define YYTABLE_NINF -336 +#define YYTABLE_NINF (-337) -#define yytable_value_is_error(Yytable_value) \ - (!!((Yytable_value) == (-336))) +#define yytable_value_is_error(Yyn) \ + ((Yyn) == YYTABLE_NINF) /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ static const yytype_int16 yypact[] = { - 926, -551, -551, -551, -551, -551, -551, -551, 34, -551, - 2909, 41, 1877, 1762, -551, -551, -551, -551, 46, 2909, - 46, 2909, 46, 2909, 46, 46, 2909, 12, 2909, 2198, - -551, -551, -551, -551, 46, 46, -551, -551, 42, -66, - -551, 2909, -551, -551, 2909, -41, -38, -64, 2198, 2119, - 46, 2909, -23, 2909, 2909, 2909, 2909, 2909, 2909, 2277, - -551, 680, 101, -551, 4, -551, -42, 10, 63, 22, - -551, -551, -551, 3152, -551, -551, 18, 185, 200, 212, - -551, 151, 219, 229, 192, -551, -551, -551, -551, -551, - 160, 177, 129, 82, 111, 13, 127, 134, 175, 180, - 41, 300, 300, -551, -23, -551, -551, -551, 292, -551, - -23, 276, -551, 303, 432, 313, 1762, -551, -551, -551, - -551, 660, -551, 384, 832, -551, -551, -551, -551, -551, - 323, -551, 329, -551, 329, -551, -551, 317, 2988, 2356, - 255, -551, -551, -551, 317, -551, 317, 281, 261, 261, - 2909, 216, 266, 2909, 230, 317, 41, 3152, 232, 2435, - 2909, 2119, -551, 317, 3067, -551, 101, -551, 2514, 2909, - -551, 326, -551, -551, 2909, 101, 329, 329, 329, 642, - 642, 350, 262, 2909, 2909, 2909, 2909, 2909, 2909, 2909, - 2593, -551, -551, 2909, -551, -551, 2909, 2909, 2909, 2909, - 2909, 2909, 2909, 2909, 2909, 2909, 2909, 2909, 2909, 2909, - 2909, 2909, 2909, 2909, 2909, 2909, 2909, 2909, 2909, 2909, - 2909, 2909, -551, -551, -551, 2909, 84, 2672, 2909, 2909, - 2909, 2909, 2909, 2909, 2909, -551, 318, 324, 325, 289, - -551, -551, -551, -551, -551, 259, 741, -551, -551, 258, - -551, -551, -551, -551, -551, -551, 341, -551, -551, -551, - -551, -551, -551, 41, -551, -551, -551, 2909, 2909, 2909, - 2909, 2909, 2909, -551, -551, -551, -551, 332, -551, -551, - -551, 332, -551, -551, -551, 372, -551, -551, 2751, 329, - 255, 40, 250, 278, -551, 273, 340, -551, -551, -551, - 261, 342, -551, -551, -551, -551, 2909, 2909, 96, -551, - -551, -551, -551, 390, 315, 282, 2909, 101, 398, -551, - 2909, 399, 161, 161, -551, -551, 3254, 66, 100, -551, - 411, 3517, 3497, 3356, 329, 492, 3220, 3203, 3254, 3254, - 3101, 3395, 3395, 3395, 3418, 3418, 3457, 3478, 3497, 3497, - 3517, 3517, 3536, 459, 3220, 492, 329, 329, 146, 392, - 2909, 2909, 322, 393, 400, 401, -551, 410, 2830, 294, - -551, -551, 417, 89, 115, 236, 142, 249, 159, 257, - 947, -551, -551, 418, 54, 261, 380, -551, 343, 2909, - 2909, -551, 6, -551, -551, 316, -551, -551, -551, -551, - 1961, 129, -551, 2909, 2909, 2909, 2909, -551, -551, 403, - -551, 426, -551, -551, -551, 680, -551, -551, -551, 680, - -551, -551, -551, 352, 352, 384, -12, 449, -551, -551, - -551, -551, -551, 330, -551, -551, 334, 103, -551, 2909, - -551, -551, -551, 500, -551, 173, 2909, 453, -551, -551, - 2909, -551, 277, 214, -551, -551, -551, -551, -551, -551, - 652, 2909, -551, 454, -551, 460, -551, 462, -551, 463, - -551, -551, -551, -551, -551, 156, -551, -551, 347, 680, - 349, 455, 358, -551, -551, -551, -551, -551, 351, 457, - 183, -551, 2909, 361, 363, 680, 365, 366, 1072, 367, - 442, 281, -551, 490, -551, -551, 261, 2909, -551, -551, - -551, -551, 37, -551, -551, -551, 491, -551, -551, 2909, - -551, 419, -551, -551, -551, 224, -551, 3305, 502, -551, - -551, 386, -551, -551, -551, -551, 494, -551, -551, -551, - 2909, 300, 300, 503, 391, -551, 2909, 2909, 300, -551, - 415, 404, -551, -551, 300, 300, -551, -551, -551, -551, - 2909, 261, -551, 506, 3152, 423, -551, 680, -551, -551, - -551, -551, 436, -551, -551, 3152, 247, 247, 455, 424, - 428, 429, 276, 2909, 2909, 300, 300, 300, -551, -551, - 455, 300, 507, 426, 1187, -551, -551, -551, -551, 1302, - -551, 1417, -551, 300, 431, -551, -551, -551, -551, 2909, - 300, 300, -551, 525, 430, 276, 276, 276, -551, 519, - -551, -551, -551, -551, -551, 20, -551, 1532, -551, 2909, - 439, 276, 276, -551, 300, -551, -551, -551, 440, 41, - -551, 548, 486, -551, -551, 447, 300, -551, -551, -551, - 276, -551, -551, -551, -551, -551, -551, 300, 276, 2040, - -551, 1647, 247, -551, 448, -551, -551, 300, -551 + 775, -544, -544, -544, -544, -544, -544, -544, 62, -544, + 2930, 58, 1898, 1783, -544, -544, -544, -544, 41, 2930, + 41, 2930, 41, 2930, 41, 41, 2930, 3, 2930, 2219, + -544, -544, -544, -544, 41, 41, -544, -544, 86, -12, + -544, 2930, -544, -544, 2930, 11, 38, -58, 2219, 2140, + 41, 2930, 105, 2930, 2930, 2930, 2930, 2930, 2930, 2298, + -544, 255, 157, -544, 4, -544, -45, 68, -17, 8, + -544, -544, -544, 3173, -544, -544, 51, 94, 183, 217, + -544, 173, 229, 244, 187, -544, -544, -544, -544, -544, + 162, 169, 147, 73, 103, 12, 111, 126, 138, 140, + 58, 260, 260, -544, 105, -544, -544, -544, 267, -544, + 105, 253, -544, 284, 432, 285, 1783, -544, -544, -544, + -544, 681, -544, 163, 853, -544, -544, -544, -544, -544, + 298, -544, 416, -544, 416, -544, -544, 3577, 3009, 2377, + 231, -544, -544, -544, 3577, -544, 3577, 261, 237, 237, + 2930, 193, 238, 2930, 195, 3577, 58, 3173, 204, 2456, + 2930, 2140, -544, 3577, 3088, -544, 157, -544, 2535, 2930, + -544, 312, -544, -544, 2930, 157, 416, 416, 416, 647, + 647, 322, 251, 2930, 2930, 2930, 2930, 2930, 2930, 2930, + 2614, -544, -544, 2930, -544, -544, 2930, 2930, 2930, 2930, + 2930, 2930, 2930, 2930, 2930, 2930, 2930, 2930, 2930, 2930, + 2930, 2930, 2930, 2930, 2930, 2930, 2930, 2930, 2930, 2930, + 2930, 2930, -544, -544, -544, 2930, 101, 2693, 2930, 2930, + 2930, 2930, 2930, 2930, 2930, -544, 281, 282, 299, 272, + -544, -544, -544, -544, -544, 239, 455, -544, -544, 227, + -544, -544, -544, -544, -544, -544, 318, -544, -544, -544, + -544, -544, -544, 58, -544, -544, -544, 2930, 2930, 2930, + 2930, 2930, 2930, -544, -544, -544, -544, 302, -544, -544, + -544, 302, -544, -544, -544, 358, -544, -544, 2772, 416, + 231, 63, 69, 76, -544, 355, 319, -544, -544, -544, + 237, 320, -544, -544, -544, -544, 2930, 2930, 96, -544, + -544, -544, -544, 409, 286, 252, 2930, 157, 373, -544, + 2930, 375, 54, 54, -544, -544, 3275, 122, 116, -544, + 466, 3538, 3518, 3377, 416, 315, 503, 3224, 3275, 3275, + 3122, 3416, 3416, 3416, 3439, 3439, 3478, 3499, 3518, 3518, + 3538, 3538, 3557, 3344, 503, 315, 416, 416, 65, 372, + 2930, 2930, 39, 374, 376, 378, -544, 379, 2851, 256, + -544, -544, 481, 185, 129, 236, 142, 259, 159, 277, + 968, -544, -544, 382, 27, 237, 348, -544, 311, 2930, + 2930, -544, 6, -544, -544, 287, -544, -544, -544, -544, + 1982, 147, -544, 2930, 2930, 2930, 2930, -544, -544, 356, + -544, 396, -544, -544, -544, 255, -544, -544, -544, 255, + -544, -544, -544, 327, 327, 163, 20, 569, -544, -544, + -544, -544, -544, 295, -544, -544, 297, 83, -544, 2930, + -544, -544, -544, 575, -544, 181, 2930, 420, -544, -544, + 2930, -544, 361, 224, -544, -544, -544, -544, -544, -544, + 673, 2930, -544, 421, -544, 423, -544, 433, -544, 445, + -544, -544, -544, -544, -544, 29, -544, -544, 330, 255, + 331, 428, 333, -544, -544, -544, -544, -544, 337, 450, + 273, -544, 2930, 345, 347, 255, 349, 351, 1093, 352, + 427, 261, -544, 477, -544, -544, 237, 2930, -544, -544, + -544, -544, 75, -544, -544, -544, 479, -544, -544, 2930, + -544, 404, -544, -544, -544, 247, -544, 3326, 483, -544, + -544, 368, -544, -544, -544, -544, 476, -544, -544, -544, + 2930, 260, 260, 490, 377, -544, 2930, 2930, 260, -544, + 380, 383, -544, -544, 260, 260, -544, -544, -544, -544, + 2930, 237, -544, 485, 3173, 385, -544, 255, -544, -544, + -544, -544, 425, -544, -544, 3173, 179, 179, 428, 386, + 389, 390, 253, 2930, 2930, 260, 260, 260, -544, -544, + 428, 260, 487, 396, 1208, -544, -544, -544, -544, -544, + -544, 1323, -544, 260, 392, -544, -544, -544, -544, 2930, + 260, 260, -544, 493, 391, 253, 253, 253, -544, 484, + -544, -544, -544, 1438, -544, 31, -544, 1553, -544, 2930, + 399, 253, 253, -544, 260, -544, -544, -544, 410, 58, + -544, -544, 516, 460, -544, -544, 418, 260, -544, -544, + -544, 253, -544, -544, -544, -544, -544, -544, 260, 253, + 2061, -544, 1668, 179, -544, 424, -544, -544, 260, -544 }; /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. Performed when YYTABLE does not specify something else to do. Zero means the default is an error. */ -static const yytype_uint16 yydefact[] = +static const yytype_int16 yydefact[] = { 0, 2, 4, 6, 8, 10, 12, 14, 0, 21, 19, 0, 0, 0, 19, 138, 1, 19, 0, 19, - 0, 0, 0, 0, 0, 0, 0, 0, 269, 0, - 107, 107, 108, 282, 0, 0, 253, 280, 241, 275, - 277, 271, 107, 284, 263, 273, 0, 0, 266, 19, + 0, 0, 0, 0, 0, 0, 0, 0, 270, 0, + 107, 107, 108, 283, 0, 0, 254, 281, 242, 276, + 278, 272, 107, 285, 264, 274, 0, 0, 267, 19, 0, 19, 0, 0, 0, 0, 0, 0, 0, 0, - 305, 306, 150, 283, 248, 232, 191, 203, 192, 210, - 233, 234, 235, 153, 238, 5, 254, 243, 246, 245, - 247, 244, 0, 0, 0, 21, 7, 81, 76, 109, + 306, 307, 151, 284, 249, 233, 192, 204, 193, 211, + 234, 235, 236, 154, 239, 5, 255, 244, 247, 246, + 248, 245, 0, 0, 0, 21, 7, 81, 76, 109, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 106, 0, 16, 17, 36, 0, 106, 0, 19, 9, 0, 82, 0, 0, 11, 33, 32, - 28, 0, 15, 19, 0, 334, 337, 336, 335, 321, - 0, 322, 216, 324, 217, 323, 327, 239, 0, 0, - 286, 291, 293, 292, 270, 231, 230, 19, 19, 19, - 19, 0, 0, 0, 0, 272, 0, 264, 0, 0, - 19, 19, 267, 268, 282, 303, 304, 160, 243, 0, - 325, 0, 110, 111, 19, 265, 218, 219, 237, 223, - 224, 242, 0, 0, 0, 0, 0, 151, 0, 0, - 0, 206, 205, 0, 213, 212, 0, 0, 0, 0, + 28, 0, 15, 19, 0, 335, 338, 337, 336, 322, + 0, 323, 217, 325, 218, 324, 328, 240, 0, 0, + 287, 292, 294, 293, 271, 232, 231, 19, 19, 19, + 19, 0, 0, 0, 0, 273, 0, 265, 0, 0, + 19, 19, 268, 269, 283, 304, 305, 161, 244, 0, + 326, 0, 110, 111, 19, 266, 219, 220, 238, 224, + 225, 243, 0, 0, 0, 0, 0, 152, 0, 0, + 0, 207, 206, 0, 214, 213, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 220, 221, 222, 0, 0, 0, 0, 0, + 0, 0, 221, 222, 223, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 19, 0, 0, 19, - 294, 296, 295, 21, 21, 21, 0, 21, 21, 0, + 295, 297, 296, 21, 21, 21, 0, 21, 21, 0, 21, 21, 21, 21, 52, 23, 0, 74, 46, 106, 75, 42, 106, 0, 92, 67, 73, 0, 0, 0, 0, 0, 0, 72, 35, 34, 29, 119, 122, 121, - 133, 119, 129, 128, 132, 134, 139, 225, 0, 288, - 0, 243, 246, 245, 290, 0, 118, 285, 113, 112, - 19, 116, 114, 21, 21, 158, 19, 0, 0, 276, - 163, 274, 278, 0, 0, 0, 0, 154, 0, 257, - 0, 240, 148, 149, 146, 147, 152, 0, 0, 177, - 0, 209, 215, 195, 184, 186, 188, 202, 182, 183, - 0, 198, 200, 199, 196, 197, 194, 193, 214, 211, - 208, 204, 207, 190, 189, 187, 201, 185, 181, 0, - 0, 0, 0, 331, 329, 333, 165, 0, 0, 157, - 166, 255, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 104, 105, 0, 0, 19, 298, 299, 300, 0, - 0, 319, 0, 320, 317, 0, 318, 314, 315, 316, + 133, 119, 129, 128, 132, 134, 139, 226, 0, 289, + 0, 244, 247, 246, 291, 0, 118, 286, 113, 112, + 19, 116, 114, 21, 21, 159, 19, 0, 0, 277, + 164, 275, 279, 0, 0, 0, 0, 155, 0, 258, + 0, 241, 149, 150, 147, 148, 153, 0, 0, 178, + 0, 210, 216, 196, 185, 187, 189, 203, 183, 184, + 0, 199, 201, 200, 197, 198, 195, 194, 215, 212, + 209, 205, 208, 191, 190, 188, 202, 186, 182, 0, + 0, 0, 0, 332, 330, 334, 166, 0, 0, 158, + 167, 256, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 104, 105, 0, 0, 19, 299, 300, 301, 0, + 0, 320, 0, 321, 318, 0, 319, 315, 316, 317, 0, 0, 21, 0, 99, 0, 0, 19, 21, 0, 38, 21, 40, 93, 83, 80, 84, 87, 86, 101, - 85, 88, 120, 19, 19, 130, 242, 0, 287, 289, - 117, 21, 115, 19, 228, 229, 0, 19, 179, 19, - 279, 162, 161, 0, 226, 0, 0, 0, 170, 176, - 0, 261, 0, 0, 258, 260, 259, 262, 326, 174, - 0, 19, 256, 0, 168, 0, 249, 0, 250, 0, - 18, 21, 37, 21, 44, 0, 297, 301, 0, 102, - 0, 0, 0, 309, 21, 97, 98, 103, 0, 0, + 85, 88, 120, 19, 19, 130, 243, 0, 288, 290, + 117, 21, 115, 19, 229, 230, 0, 19, 180, 19, + 280, 163, 162, 0, 227, 0, 0, 0, 171, 177, + 0, 262, 0, 0, 259, 261, 260, 263, 327, 175, + 0, 19, 257, 0, 169, 0, 250, 0, 251, 0, + 18, 21, 37, 21, 44, 0, 298, 302, 0, 102, + 0, 0, 0, 310, 21, 97, 98, 103, 0, 0, 82, 61, 0, 0, 0, 100, 0, 0, 0, 19, 0, 19, 141, 0, 43, 140, 19, 125, 124, 127, - 123, 131, 240, 227, 138, 135, 0, 136, 159, 0, - 307, 0, 164, 155, 180, 0, 173, 236, 0, 169, - 175, 0, 171, 251, 252, 167, 0, 68, 21, 45, - 0, 0, 0, 313, 0, 312, 0, 0, 0, 55, + 123, 131, 241, 228, 138, 135, 0, 136, 160, 0, + 308, 0, 165, 156, 181, 0, 174, 237, 0, 170, + 176, 0, 172, 252, 253, 168, 0, 68, 21, 45, + 0, 0, 0, 314, 0, 313, 0, 0, 0, 55, 0, 0, 96, 96, 0, 0, 22, 25, 24, 65, - 19, 19, 19, 21, 126, 0, 19, 308, 281, 178, - 172, 156, 0, 19, 70, 302, 19, 19, 310, 0, + 19, 19, 19, 21, 126, 0, 145, 309, 282, 179, + 173, 157, 0, 19, 70, 303, 19, 19, 311, 0, 0, 0, 19, 99, 0, 0, 0, 0, 50, 51, - 0, 0, 0, 21, 0, 144, 41, 143, 137, 0, - 19, 0, 19, 0, 0, 89, 48, 49, 311, 0, + 0, 0, 0, 21, 0, 144, 41, 143, 137, 19, + 19, 0, 19, 0, 0, 89, 48, 49, 312, 0, 0, 0, 64, 0, 0, 19, 19, 19, 26, 94, - 47, 39, 142, 145, 30, 0, 69, 0, 90, 0, + 47, 39, 142, 0, 30, 0, 69, 0, 90, 0, 0, 19, 19, 56, 0, 60, 54, 53, 0, 0, - 66, 0, 19, 31, 71, 0, 0, 58, 63, 96, - 19, 27, 95, 20, 19, 78, 77, 0, 19, 0, - 62, 0, 19, 59, 0, 79, 91, 0, 57 + 66, 146, 0, 19, 31, 71, 0, 0, 58, 63, + 96, 19, 27, 95, 20, 19, 78, 77, 0, 19, + 0, 62, 0, 19, 59, 0, 79, 91, 0, 57 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int16 yypgoto[] = { - -551, -551, -551, -551, -551, -551, -551, -551, -551, -551, - -4, -10, -551, 50, -55, -551, -551, -551, -551, -13, - -551, 568, 466, 28, -551, -551, -551, -551, -551, -551, - -551, -551, -551, -551, -551, -551, 52, -390, -550, -533, - -551, -534, -551, 14, 193, -220, -61, -551, -96, 137, - -551, -551, -17, 102, -146, 311, 328, -551, -551, 186, - -551, 179, -551, -551, -551, -551, 97, -551, 30, 184, - -551, -293, 16, -47, -551, -551, -551, -551, -551, -551, - -551, -551, -551, -551, -551, -551, 610, -551, -551, 489, - -551, -551, -551, -551, -126, -14, -551, -551, -551, -551, - 223, -551, -551, 382, 36, -19, -15, -551, -551, -551, - -551, -551, 56 + -544, -544, -544, -544, -544, -544, -544, -544, -544, -544, + -4, -10, -544, 50, -55, -544, -544, -544, -544, -16, + -544, 536, 436, -1, -544, -544, -544, -544, -544, -544, + -544, -544, -544, -544, -544, -544, -5, -395, -543, -221, + -544, -521, -544, -29, 161, -220, -95, -544, -97, 37, + -544, -544, -67, 67, -146, 279, 289, -544, -544, 153, + -544, 146, -544, -544, -544, -544, 64, -544, -13, 154, + -544, -294, -544, 16, -47, -544, -544, -544, -544, -544, + -544, -544, -544, -544, -544, -544, -544, 631, -544, -544, + 446, -544, -544, -544, -544, -126, -15, -544, -544, -544, + -544, 186, -544, -544, 343, 36, -19, -14, -544, -544, + -544, -544, -544, 59 }; /* YYDEFGOTO[NTERM-NUM]. */ @@ -365,16 +636,16 @@ static const yytype_int16 yydefgoto[] = { -1, 8, 9, 10, 11, 12, 13, 14, 15, 110, 111, 120, 472, 433, 256, 407, 559, 590, 638, 121, - 625, 276, 118, 119, 501, 506, 411, 409, 583, 649, - 550, 591, 573, 602, 643, 656, 414, 113, 606, 265, + 625, 276, 118, 119, 501, 506, 411, 409, 583, 650, + 550, 591, 573, 602, 644, 657, 414, 113, 606, 265, 640, 586, 487, 494, 418, 478, 489, 383, 258, 147, 149, 236, 174, 300, 303, 297, 423, 281, 282, 509, 283, 284, 285, 286, 516, 517, 122, 123, 504, 505, - 596, 434, 114, 62, 63, 439, 369, 64, 65, 66, - 67, 68, 69, 70, 71, 72, 73, 152, 74, 140, - 239, 388, 115, 540, 167, 75, 521, 482, 543, 544, - 394, 395, 248, 76, 77, 78, 79, 80, 81, 82, - 83, 84, 131 + 596, 434, 599, 114, 62, 63, 439, 369, 64, 65, + 66, 67, 68, 69, 70, 71, 72, 73, 152, 74, + 140, 239, 388, 115, 540, 167, 75, 521, 482, 543, + 544, 394, 395, 248, 76, 77, 78, 79, 80, 81, + 82, 83, 84, 131 }; /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If @@ -382,227 +653,237 @@ static const yytype_int16 yydefgoto[] = number is the opposite. If YYTABLE_NINF, syntax error. */ static const yytype_int16 yytable[] = { - 60, 320, 166, 304, 124, 130, 175, 86, 142, 60, - 486, 435, 143, 261, 127, 188, 127, 189, 127, 587, - 127, 127, 20, 160, 305, 145, 61, 607, 20, 20, - 127, 127, 22, 172, 16, 61, 24, 171, 173, 165, - 112, 60, 641, 245, 162, 127, 127, 257, 319, 612, - 446, 228, 85, 229, 128, 153, 128, 85, 128, 17, - 128, 128, 20, 141, 154, 473, 161, 61, 191, 192, - 128, 128, -290, 241, 129, 182, 474, 242, 133, 642, - 135, 136, 635, 636, 637, 168, 128, 259, 447, 158, - 150, 151, 159, 262, 359, 360, 254, 361, 647, 648, - 362, 264, 125, 166, 363, 169, 170, 126, 364, 365, - 438, 463, 666, 280, 448, 659, 187, 660, 187, 292, - 193, -289, 317, 293, -291, 663, 519, 166, 240, 464, - 196, 249, 138, 246, 190, 235, 481, 299, 302, 302, - 165, 366, 139, 247, 275, 20, 314, 315, 227, 22, - 60, 60, 310, 24, 431, 295, 466, 127, 183, 184, - 185, 186, -332, 410, 165, 367, 412, 538, 148, 308, - 480, 194, 195, 468, 291, 313, 61, 61, 539, 156, - 488, 183, 184, 185, 186, 496, 497, 524, 183, 184, - 185, 186, 183, 184, 185, 186, 228, 168, 229, 322, - 323, 324, 325, 234, 327, 328, 330, 183, 184, 185, - 186, -328, 243, -328, 368, 267, 237, 316, 268, 269, - 270, 271, 380, -330, 272, -330, 382, 398, 529, 387, - 230, 399, 231, 238, 183, 184, 185, 186, 569, 475, - 232, 244, 233, 372, 373, 374, 375, 376, 377, 378, - 379, 183, 184, 185, 186, 185, 186, 250, 465, 413, - 437, -328, 370, -328, 251, 183, 184, 185, 186, 486, - 597, 467, 551, -336, 226, 183, 184, 185, 186, 469, - 603, 604, 397, 415, 415, 415, 419, 415, 415, -330, - 302, -330, 436, 389, 390, 392, 60, 400, 401, 528, - 403, 404, 405, 406, 427, 252, 183, 184, 185, 186, - 253, 255, -102, 522, 260, 263, 183, 184, 185, 186, - 416, 417, 61, 420, 421, 266, 580, 581, 183, 184, - 185, 186, 443, 85, -293, 273, 445, 287, 20, 296, - 298, 183, 184, 185, 186, 301, 306, 454, 318, 183, - 184, 185, 186, 307, 183, 184, 185, 186, 127, 309, - 563, 311, -292, 320, 614, 183, 184, 185, 186, 183, - 184, 185, 186, 386, 381, 302, 452, 453, 125, 391, - 384, 385, 398, 126, 460, 408, 399, 425, 402, 630, - 485, 321, 166, 422, 498, 198, 199, 200, 128, 430, - 277, 432, 429, 441, 278, 479, 479, 198, 279, 645, - 444, 442, 446, 508, 508, 593, 490, 451, 455, 419, - 495, 479, 479, 515, 461, 456, 457, 520, 483, 165, - 217, 218, 219, 220, 592, 458, 471, 397, 221, 476, - 477, 222, 223, 224, 225, 226, 484, 531, 502, 507, - 221, 60, 492, 222, 223, 224, 225, 226, 499, 500, - 514, 503, 525, 518, 267, 526, 532, 268, 269, 270, - 271, 20, 533, 272, 534, 535, 541, 61, 542, 549, - 548, 503, 183, 184, 185, 186, 576, 577, 546, 558, - 552, 299, 553, 582, 554, 555, 302, 557, 560, 588, - 589, 562, 566, 183, 184, 185, 186, 568, 479, 183, - 184, 185, 186, 166, 570, 571, 572, 545, 578, 440, - 579, 536, 600, 537, 183, 184, 185, 186, 595, 620, - 615, 616, 617, 585, 547, 567, 619, 198, 199, 200, - 449, 183, 184, 185, 186, 584, 462, 633, 628, 594, - 165, 302, 598, 599, 609, 631, 632, 610, 611, 634, - 601, 629, 479, 479, 639, 653, 605, 605, 646, 651, - 198, 654, 264, 218, 219, 220, 657, 667, 512, 650, - 221, 117, 274, 222, 223, 224, 225, 226, 574, 627, - 624, 658, 183, 184, 185, 186, 493, 613, 664, 495, - 479, 428, 662, 561, 511, 264, 264, 264, 220, 424, - 510, 565, 668, 221, 608, 513, 222, 223, 224, 225, - 226, 264, 264, 621, 491, 479, 618, 290, 396, 523, - 0, 132, 655, 134, 0, 652, 137, 0, 144, 146, - 264, 661, 0, 503, 0, 479, 0, 0, 264, 485, - 0, 155, 605, 0, 157, 0, 0, 0, 163, 0, - -13, 87, 0, 0, 176, 177, 178, 179, 180, 0, - 18, 85, 0, 19, 0, 0, 20, 0, 0, 21, - 22, 23, 88, 0, 24, 25, 89, 90, 91, 26, - 27, 92, 93, 0, 0, 94, 95, 96, 97, 0, - 98, 99, 100, 101, 0, 0, 102, 28, 29, 103, - 104, 105, 30, 31, 106, 32, 33, 34, 35, 36, - 37, 0, 38, 39, 40, 41, 42, 43, 107, 116, - 44, 0, 108, 45, 46, 47, 48, 49, 0, 0, - 0, 50, 51, 52, 183, 184, 185, 186, 289, 109, - 0, 18, 0, 0, 0, 0, 53, 20, 0, 0, - 0, 22, 0, 0, 0, 24, -336, -336, -336, 225, - 226, 393, 183, 184, 185, 186, 0, 54, 55, 0, - 56, 530, 57, 58, 0, 0, 0, 0, 0, 0, - 59, 0, 0, 0, 0, 0, 0, 326, 0, 0, - 0, 0, 0, 331, 0, 0, 332, 333, 334, 335, - 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, - 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, - 356, 357, -3, 87, 0, 358, 0, 0, 0, 0, - 0, 0, 18, 85, 0, 19, 0, 0, 20, 0, - 0, 21, 22, 23, 88, 0, 24, 25, 89, 90, - 91, 26, 27, 92, 93, 0, 0, 94, 95, 96, - 97, 0, 98, 99, 100, 101, 0, 0, 102, 28, - 29, 103, 104, 105, 30, 31, 106, 32, 33, 34, - 35, 36, 37, 0, 38, 39, 40, 41, 42, 43, - 107, 116, 44, 0, 108, 45, 46, 47, 48, 49, - 0, 0, 0, 50, 51, 52, 0, 0, 0, 0, - 0, 109, 0, 0, 0, 0, 0, 0, 53, 1, - 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 87, 54, - 55, 0, 56, 0, 57, 58, 0, 18, 85, 470, - 19, 0, 59, 20, 0, 0, 21, 22, 23, 88, - 0, 24, 25, 89, 90, 91, 26, 27, 92, 93, - 0, 0, 94, 95, 96, 97, 0, 98, 99, 100, - 101, 0, 0, 102, 28, 29, 103, 104, 105, 30, - 31, 106, 32, 33, 34, 35, 36, 37, 0, 38, - 39, 40, 41, 42, 43, 107, 116, 44, 0, 108, - 45, 46, 47, 48, 49, 0, 0, 0, 50, 51, - 52, 0, 0, 0, 0, 0, 109, 0, 0, 0, - 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, + 60, 124, 166, 304, 130, 486, 175, 86, 142, 60, + 435, 112, 261, 143, 127, 188, 127, 189, 127, 20, + 127, 127, 20, 22, 305, 145, 61, 24, 20, 160, + 127, 127, 587, 320, 607, 61, 171, 259, 473, 165, + 538, 60, 245, 262, 162, 127, 127, 257, 319, 474, + 85, 539, 85, 642, 128, 20, 128, 20, 128, 17, + 128, 128, 16, 141, 454, 191, 192, 61, 148, 85, + 128, 128, 161, 241, 228, 182, 229, 129, 242, 156, + -329, 133, -329, 135, 136, 168, 128, -331, 446, -331, + 643, 194, 195, 150, 151, 125, 254, 125, 187, 153, + 126, 264, 126, 166, -291, 228, 519, 229, 169, 170, + 438, 359, 360, 280, 361, 275, 196, 362, 154, 292, + 667, 363, 317, 138, 293, 364, 365, 166, 240, 660, + 448, 249, 246, 139, 190, 235, 481, 299, 302, 302, + 165, 158, 247, 464, 447, 314, 315, -292, 185, 186, + 60, 60, 310, -294, 431, 295, 466, 127, 366, -290, + -293, 172, 410, 20, 165, 412, 173, 22, 159, 308, + 480, 24, 187, 468, 291, 313, 61, 61, 193, 277, + 488, 227, 367, 278, -333, 496, 497, 279, 183, 184, + 185, 186, -337, 226, -329, 524, -329, 168, 234, 322, + 323, 324, 325, 243, 327, 328, 330, 463, 183, 184, + 185, 186, 603, 604, 183, 184, 185, 186, 237, 380, + 316, 183, 184, 185, 186, 238, 382, 398, -331, 387, + -331, 368, 399, 244, 183, 184, 185, 186, 529, 475, + 230, 250, 231, 372, 373, 374, 375, 376, 377, 378, + 379, 183, 184, 185, 186, 232, 251, 233, 465, 413, + 437, 569, 370, 416, 417, 486, 420, 421, 252, 597, + 253, 255, 551, 183, 184, 185, 186, 183, 184, 185, + 186, 467, 397, 415, 415, 415, 419, 415, 415, 260, + 302, 436, 263, 389, 390, 392, 60, 400, 401, 469, + 403, 404, 405, 406, 427, 267, 266, 273, 268, 269, + 270, 271, 287, 522, 272, 296, 183, 184, 185, 186, + 298, 301, 61, 306, 309, 307, 580, 581, 183, 184, + 185, 186, 443, 311, 318, 320, 445, 381, 384, 183, + 184, 185, 186, 183, 184, 185, 186, 183, 184, 185, + 186, 183, 184, 185, 186, 385, 386, 402, 127, 391, + 563, 612, 408, 422, 614, 183, 184, 185, 186, 183, + 184, 185, 186, 425, 441, 302, 452, 453, 430, 432, + 321, 442, 398, 528, 460, 444, 461, 399, 446, 630, + 485, 498, 166, 198, 635, 636, 637, 451, 128, 455, + 471, 456, -102, 457, 458, 479, 479, 476, 477, 646, + 648, 649, 500, 508, 508, 593, 490, 484, 502, 419, + 495, 479, 479, 515, 507, 514, 518, 520, 483, 165, + 661, 220, 526, 532, 592, 533, 221, 397, 664, 222, + 223, 224, 225, 226, 20, 534, 531, 183, 184, 185, + 186, 60, 492, 183, 184, 185, 186, 535, 499, 541, + 542, 503, 525, 546, 267, 18, 548, 268, 269, 270, + 271, 20, 549, 272, 552, 22, 553, 61, 554, 24, + 555, 503, 557, 560, 429, 393, 576, 577, 562, 558, + 566, 299, 568, 582, 198, 570, 302, 571, 572, 588, + 589, 183, 184, 185, 186, 578, 579, 595, 479, 620, + 584, 600, 585, 166, 598, 633, 609, 545, 610, 611, + 634, 536, 629, 537, 183, 184, 185, 186, 647, 639, + 615, 616, 617, 654, 547, 567, 619, 221, 440, 652, + 222, 223, 224, 225, 226, 655, 594, 658, 628, 117, + 165, 302, 274, 668, 613, 631, 632, 601, 183, 184, + 185, 186, 479, 479, 493, 665, 605, 605, 561, 428, + 424, 511, 264, 183, 184, 185, 186, 510, 565, 651, + 621, 198, 199, 623, 290, 513, 627, 491, 574, 396, + 624, 0, 659, 0, 0, 449, 0, 0, 0, 495, + 479, 0, 0, 663, 0, 264, 264, 264, 0, 0, + 462, 0, 0, 669, 608, 0, 0, 0, 219, 220, + 0, 264, 264, 0, 221, 479, 618, 222, 223, 224, + 225, 226, 0, 656, 0, 653, 0, 0, 0, 662, + 0, 264, 0, 503, 0, 479, 0, 0, 0, 264, + 485, 0, 132, 605, 134, 0, 0, 137, 0, 144, + 146, 183, 184, 185, 186, 0, 0, 183, 184, 185, + 186, 0, 155, 0, 0, 157, 0, 0, 0, 163, + 0, -13, 87, 0, 0, 176, 177, 178, 179, 180, + 0, 18, 85, 0, 19, 0, 0, 20, 512, 0, + 21, 22, 23, 88, 523, 24, 25, 89, 90, 91, + 26, 27, 92, 93, 0, 0, 94, 95, 96, 97, + 0, 98, 99, 100, 101, 0, 0, 102, 28, 29, + 103, 104, 105, 30, 31, 106, 32, 33, 34, 35, + 36, 37, 0, 38, 39, 40, 41, 42, 43, 107, + 116, 44, 0, 108, 45, 46, 47, 48, 49, 0, + 0, 0, 50, 51, 52, 183, 184, 185, 186, 289, + 109, -337, -337, -337, 225, 226, 0, 53, 1, 2, + 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 54, 55, + 0, 56, 530, 57, 58, 0, 0, 0, 0, 0, + 0, 59, 0, 0, 0, 0, 0, 0, 326, 0, + 0, 0, 0, 0, 331, 0, 0, 332, 333, 334, + 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, + 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, + 355, 356, 357, -3, 87, 0, 358, 0, 0, 0, + 0, 0, 0, 18, 85, 0, 19, 0, 0, 20, + 0, 0, 21, 22, 23, 88, 0, 24, 25, 89, + 90, 91, 26, 27, 92, 93, 0, 0, 94, 95, + 96, 97, 0, 98, 99, 100, 101, 0, 0, 102, + 28, 29, 103, 104, 105, 30, 31, 106, 32, 33, + 34, 35, 36, 37, 0, 38, 39, 40, 41, 42, + 43, 107, 116, 44, 0, 108, 45, 46, 47, 48, + 49, 0, 0, 0, 50, 51, 52, 0, 0, 0, + 0, 0, 109, 0, 0, 0, 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 527, 0, 0, 0, 54, 55, 0, 56, 0, 57, - 58, 0, 0, 87, 0, 0, 0, 59, 0, 0, - 0, 0, 18, 85, 556, 19, 0, 0, 20, 0, - 0, 21, 22, 23, 88, 0, 24, 25, 89, 90, - 91, 26, 27, 92, 93, 0, 0, 94, 95, 96, - 97, 0, 98, 99, 100, 101, 0, 564, 102, 28, - 29, 103, 104, 105, 30, 31, 106, 32, 33, 34, - 35, 36, 37, 0, 38, 39, 40, 41, 42, 43, - 107, 116, 44, 0, 108, 45, 46, 47, 48, 49, - 575, 0, 0, 50, 51, 52, 0, 0, 0, 0, - 0, 109, 0, 0, 0, 0, 0, 0, 53, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 87, + 54, 55, 0, 56, 0, 57, 58, 0, 18, 85, + 470, 19, 0, 59, 20, 0, 0, 21, 22, 23, + 88, 0, 24, 25, 89, 90, 91, 26, 27, 92, + 93, 0, 0, 94, 95, 96, 97, 0, 98, 99, + 100, 101, 0, 0, 102, 28, 29, 103, 104, 105, + 30, 31, 106, 32, 33, 34, 35, 36, 37, 0, + 38, 39, 40, 41, 42, 43, 107, 116, 44, 0, + 108, 45, 46, 47, 48, 49, 0, 0, 0, 50, + 51, 52, 0, 0, 0, 0, 0, 109, 0, 0, + 0, 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 87, 54, - 55, 0, 56, 0, 57, 58, 0, 18, 85, 622, - 19, 0, 59, 20, 0, 0, 21, 22, 23, 88, - 0, 24, 25, 89, 90, 91, 26, 27, 92, 93, - 0, 0, 94, 95, 96, 97, 0, 98, 99, 100, - 101, 0, 0, 102, 28, 29, 103, 104, 105, 30, - 31, 106, 32, 33, 34, 35, 36, 37, 0, 38, - 39, 40, 41, 42, 43, 107, 116, 44, 0, 108, - 45, 46, 47, 48, 49, 0, 0, 0, 50, 51, - 52, 0, 0, 0, 0, 0, 109, 0, 0, 0, - 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, + 0, 527, 0, 0, 0, 54, 55, 0, 56, 0, + 57, 58, 0, 0, 87, 0, 0, 0, 59, 0, + 0, 0, 0, 18, 85, 556, 19, 0, 0, 20, + 0, 0, 21, 22, 23, 88, 0, 24, 25, 89, + 90, 91, 26, 27, 92, 93, 0, 0, 94, 95, + 96, 97, 0, 98, 99, 100, 101, 0, 564, 102, + 28, 29, 103, 104, 105, 30, 31, 106, 32, 33, + 34, 35, 36, 37, 0, 38, 39, 40, 41, 42, + 43, 107, 116, 44, 0, 108, 45, 46, 47, 48, + 49, 575, 0, 0, 50, 51, 52, 0, 0, 0, + 0, 0, 109, 0, 0, 0, 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 87, 54, 55, 0, 56, 0, 57, - 58, 0, 18, 85, 623, 19, 0, 59, 20, 0, - 0, 21, 22, 23, 88, 0, 24, 25, 89, 90, - 91, 26, 27, 92, 93, 0, 0, 94, 95, 96, - 97, 0, 98, 99, 100, 101, 0, 0, 102, 28, - 29, 103, 104, 105, 30, 31, 106, 32, 33, 34, - 35, 36, 37, 0, 38, 39, 40, 41, 42, 43, - 107, 116, 44, 0, 108, 45, 46, 47, 48, 49, - 0, 0, 0, 50, 51, 52, 0, 0, 0, 0, - 0, 109, 0, 0, 0, 0, 0, 0, 53, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 87, + 54, 55, 0, 56, 0, 57, 58, 0, 18, 85, + 622, 19, 0, 59, 20, 0, 0, 21, 22, 23, + 88, 0, 24, 25, 89, 90, 91, 26, 27, 92, + 93, 0, 0, 94, 95, 96, 97, 0, 98, 99, + 100, 101, 0, 0, 102, 28, 29, 103, 104, 105, + 30, 31, 106, 32, 33, 34, 35, 36, 37, 0, + 38, 39, 40, 41, 42, 43, 107, 116, 44, 0, + 108, 45, 46, 47, 48, 49, 0, 0, 0, 50, + 51, 52, 0, 0, 0, 0, 0, 109, 0, 0, + 0, 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 87, 54, - 55, 0, 56, 0, 57, 58, 0, 18, 85, 626, - 19, 0, 59, 20, 0, 0, 21, 22, 23, 88, - 0, 24, 25, 89, 90, 91, 26, 27, 92, 93, - 0, 0, 94, 95, 96, 97, 0, 98, 99, 100, - 101, 0, 0, 102, 28, 29, 103, 104, 105, 30, - 31, 106, 32, 33, 34, 35, 36, 37, 0, 38, - 39, 40, 41, 42, 43, 107, 116, 44, 0, 108, - 45, 46, 47, 48, 49, 0, 0, 0, 50, 51, - 52, 0, 0, 0, 0, 0, 109, 0, 0, 0, - 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 87, 54, 55, 0, 56, 0, + 57, 58, 0, 18, 85, 626, 19, 0, 59, 20, + 0, 0, 21, 22, 23, 88, 0, 24, 25, 89, + 90, 91, 26, 27, 92, 93, 0, 0, 94, 95, + 96, 97, 0, 98, 99, 100, 101, 0, 0, 102, + 28, 29, 103, 104, 105, 30, 31, 106, 32, 33, + 34, 35, 36, 37, 0, 38, 39, 40, 41, 42, + 43, 107, 116, 44, 0, 108, 45, 46, 47, 48, + 49, 0, 0, 0, 50, 51, 52, 0, 0, 0, + 0, 0, 109, 0, 0, 0, 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 87, 54, 55, 0, 56, 0, 57, - 58, 0, 18, 85, 644, 19, 0, 59, 20, 0, - 0, 21, 22, 23, 88, 0, 24, 25, 89, 90, - 91, 26, 27, 92, 93, 0, 0, 94, 95, 96, - 97, 0, 98, 99, 100, 101, 0, 0, 102, 28, - 29, 103, 104, 105, 30, 31, 106, 32, 33, 34, - 35, 36, 37, 0, 38, 39, 40, 41, 42, 43, - 107, 116, 44, 0, 108, 45, 46, 47, 48, 49, - 0, 0, 0, 50, 51, 52, 0, 0, 0, 0, - 0, 109, 0, 0, 0, 0, 0, 0, 53, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 87, + 54, 55, 0, 56, 0, 57, 58, 0, 18, 85, + 641, 19, 0, 59, 20, 0, 0, 21, 22, 23, + 88, 0, 24, 25, 89, 90, 91, 26, 27, 92, + 93, 0, 0, 94, 95, 96, 97, 0, 98, 99, + 100, 101, 0, 0, 102, 28, 29, 103, 104, 105, + 30, 31, 106, 32, 33, 34, 35, 36, 37, 0, + 38, 39, 40, 41, 42, 43, 107, 116, 44, 0, + 108, 45, 46, 47, 48, 49, 0, 0, 0, 50, + 51, 52, 0, 0, 0, 0, 0, 109, 0, 0, + 0, 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 87, 54, - 55, 0, 56, 0, 57, 58, 0, 18, 85, 0, - 19, 0, 59, 20, 0, 0, 21, 22, 23, 88, - 0, 24, 25, 89, 90, 91, 26, 27, 92, 93, - 0, 0, 94, 95, 96, 97, 0, 98, 99, 100, - 101, 0, 0, 102, 28, 29, 103, 104, 105, 30, - 31, 106, 32, 33, 34, 35, 36, 37, 0, 38, - 39, 40, 41, 42, 43, 107, 116, 44, 0, 108, - 45, 46, 47, 48, 49, 0, 0, 0, 50, 51, - 52, 0, 0, 665, 0, 0, 109, 0, 0, 0, - 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 87, 54, 55, 0, 56, 0, + 57, 58, 0, 18, 85, 645, 19, 0, 59, 20, + 0, 0, 21, 22, 23, 88, 0, 24, 25, 89, + 90, 91, 26, 27, 92, 93, 0, 0, 94, 95, + 96, 97, 0, 98, 99, 100, 101, 0, 0, 102, + 28, 29, 103, 104, 105, 30, 31, 106, 32, 33, + 34, 35, 36, 37, 0, 38, 39, 40, 41, 42, + 43, 107, 116, 44, 0, 108, 45, 46, 47, 48, + 49, 0, 0, 0, 50, 51, 52, 0, 0, 0, + 0, 0, 109, 0, 0, 0, 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 87, 54, 55, 0, 56, 0, 57, - 58, 0, 18, 85, 0, 19, 0, 59, 20, 0, - 0, 21, 22, 23, 88, 0, 24, 25, 89, 90, - 91, 26, 27, 92, 93, 0, 0, 94, 95, 96, - 97, 0, 98, 99, 100, 101, 0, 0, 102, 28, - 29, 103, 104, 105, 30, 31, 106, 32, 33, 34, - 35, 36, 37, 0, 38, 39, 40, 41, 42, 43, - 107, 116, 44, 0, 108, 45, 46, 47, 48, 49, - 0, 0, 0, 50, 51, 52, 0, 0, 0, 0, - 0, 109, 0, 0, 0, 0, 0, 0, 53, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 87, + 54, 55, 0, 56, 0, 57, 58, 0, 18, 85, + 0, 19, 0, 59, 20, 0, 0, 21, 22, 23, + 88, 0, 24, 25, 89, 90, 91, 26, 27, 92, + 93, 0, 0, 94, 95, 96, 97, 0, 98, 99, + 100, 101, 0, 0, 102, 28, 29, 103, 104, 105, + 30, 31, 106, 32, 33, 34, 35, 36, 37, 0, + 38, 39, 40, 41, 42, 43, 107, 116, 44, 0, + 108, 45, 46, 47, 48, 49, 0, 0, 0, 50, + 51, 52, 0, 0, 666, 0, 0, 109, 0, 0, + 0, 0, 0, 0, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 87, 54, - 55, 0, 56, 0, 57, 58, 0, 18, 85, 0, - 19, 0, 59, 20, 0, 0, 21, 22, 23, 88, - 0, 24, 25, 89, 90, 91, 26, 27, 92, 93, - 0, 0, 94, 95, 96, 97, 0, 98, 99, 100, - 101, 0, 0, 102, 28, 29, 103, 104, 105, 30, - 31, 106, 32, 33, 34, 35, 36, 37, 0, 38, - 39, 40, 41, 42, 43, 107, 0, 44, 0, 108, - 45, 46, 47, 48, 49, 0, 0, 0, 50, 51, - 52, 0, 87, 0, 0, 0, 109, 0, 0, 0, - 0, 18, 0, 53, 19, 0, 0, 20, 0, 0, - 21, 22, 23, -19, 0, 24, 25, 0, 0, 0, - 26, 27, 0, 0, 54, 55, 0, 56, 0, 57, - 58, 0, 0, 0, 0, 0, 0, 59, 28, 29, - 0, 0, 0, 30, 31, 0, 32, 33, 34, 35, + 0, 0, 0, 0, 87, 54, 55, 0, 56, 0, + 57, 58, 0, 18, 85, 0, 19, 0, 59, 20, + 0, 0, 21, 22, 23, 88, 0, 24, 25, 89, + 90, 91, 26, 27, 92, 93, 0, 0, 94, 95, + 96, 97, 0, 98, 99, 100, 101, 0, 0, 102, + 28, 29, 103, 104, 105, 30, 31, 106, 32, 33, + 34, 35, 36, 37, 0, 38, 39, 40, 41, 42, + 43, 107, 116, 44, 0, 108, 45, 46, 47, 48, + 49, 0, 0, 0, 50, 51, 52, 0, 0, 0, + 0, 0, 109, 0, 0, 0, 0, 0, 0, 53, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 87, + 54, 55, 0, 56, 0, 57, 58, 0, 18, 85, + 0, 19, 0, 59, 20, 0, 0, 21, 22, 23, + 88, 0, 24, 25, 89, 90, 91, 26, 27, 92, + 93, 0, 0, 94, 95, 96, 97, 0, 98, 99, + 100, 101, 0, 0, 102, 28, 29, 103, 104, 105, + 30, 31, 106, 32, 33, 34, 35, 36, 37, 0, + 38, 39, 40, 41, 42, 43, 107, 0, 44, 0, + 108, 45, 46, 47, 48, 49, 0, 0, 0, 50, + 51, 52, 0, 87, 0, 0, 0, 109, 0, 0, + 0, 0, 18, 0, 53, 19, 0, 0, 20, 0, + 0, 21, 22, 23, -19, 0, 24, 25, 0, 0, + 0, 26, 27, 0, 0, 54, 55, 0, 56, 0, + 57, 58, 0, 0, 0, 0, 0, 0, 59, 28, + 29, 0, 0, 0, 30, 31, 0, 32, 33, 34, + 35, 36, 37, 0, 38, 39, 40, 41, 42, 43, + 0, 0, 44, 0, 0, 45, 46, 47, 48, 49, + 0, 0, 87, 50, 51, 52, 0, 0, 0, 0, + 0, 18, 0, 0, 19, 0, 0, 20, 53, 0, + 21, 22, 23, 0, 0, 24, 25, 0, 0, 0, + 26, 27, 0, 0, 0, 0, 0, 0, 0, 54, + 55, 0, 56, 0, 57, 58, 0, 0, 28, 29, + 0, 0, 59, 30, 31, 0, 32, 33, 34, 35, 36, 37, 0, 38, 39, 40, 41, 42, 43, 0, 0, 44, 0, 0, 45, 46, 47, 48, 49, 0, - 0, 87, 50, 51, 52, 0, 0, 0, 0, 0, - 18, 0, 0, 19, 0, 0, 20, 53, 0, 21, + 0, 0, 50, 51, 52, 0, 0, 0, 0, 0, + 18, 85, 0, 19, 0, 0, 20, 53, 0, 21, 22, 23, 0, 0, 24, 25, 0, 0, 0, 26, 27, 0, 0, 0, 0, 0, 0, 0, 54, 55, 0, 56, 0, 57, 58, 0, 0, 28, 29, 0, - 0, 59, 30, 31, 0, 32, 33, 34, 35, 36, - 37, 0, 38, 39, 40, 41, 42, 43, 0, 0, + -19, 59, 30, 31, 0, 32, 164, 34, 35, 36, + 37, 126, 38, 39, 40, 41, 42, 43, 0, 0, 44, 0, 0, 45, 46, 47, 48, 49, 0, 0, 0, 50, 51, 52, 0, 0, 0, 0, 0, 18, 85, 0, 19, 0, 0, 20, 53, 0, 21, 22, 23, 0, 0, 24, 25, 0, 0, 0, 26, 27, 0, 0, 0, 0, 0, 0, 0, 54, 55, 0, - 56, 0, 57, 58, 0, 0, 28, 29, 0, -19, - 59, 30, 31, 0, 32, 164, 34, 35, 36, 37, - 126, 38, 39, 40, 41, 42, 43, 0, 0, 44, + 56, 0, 57, 58, 0, 0, 28, 29, 0, 0, + 59, 30, 31, 0, 32, 33, 34, 35, 36, 37, + 0, 38, 39, 40, 41, 42, 43, 0, 0, 44, 0, 0, 45, 46, 47, 48, 49, 0, 0, 0, - 50, 51, 52, 0, 0, 0, 0, 0, 18, 85, + 50, 51, 52, 0, 0, 0, 0, 0, 18, 0, 0, 19, 0, 0, 20, 53, 0, 21, 22, 23, 0, 0, 24, 25, 0, 0, 0, 26, 27, 0, 0, 0, 0, 0, 0, 0, 54, 55, 0, 56, @@ -614,7 +895,7 @@ static const yytype_int16 yytable[] = 19, 0, 0, 20, 53, 0, 21, 22, 23, 0, 0, 24, 25, 0, 0, 0, 26, 27, 0, 0, 0, 0, 0, 0, 0, 54, 55, 0, 56, 0, - 57, 58, 0, 0, 28, 29, 0, 0, 59, 30, + 57, 58, 0, 0, 28, 29, 0, 181, 59, 30, 31, 0, 32, 33, 34, 35, 36, 37, 0, 38, 39, 40, 41, 42, 43, 0, 0, 44, 0, 0, 45, 46, 47, 48, 49, 0, 0, 0, 50, 51, @@ -622,31 +903,31 @@ static const yytype_int16 yytable[] = 0, 0, 20, 53, 0, 21, 22, 23, 0, 0, 24, 25, 0, 0, 0, 26, 27, 0, 0, 0, 0, 0, 0, 0, 54, 55, 0, 56, 0, 57, - 58, 0, 0, 28, 29, 0, 181, 59, 30, 31, + 58, 0, 0, 28, 29, 0, 294, 59, 30, 31, 0, 32, 33, 34, 35, 36, 37, 0, 38, 39, 40, 41, 42, 43, 0, 0, 44, 0, 0, 45, 46, 47, 48, 49, 0, 0, 0, 50, 51, 52, - 0, 0, 0, 0, 0, 18, 0, 0, 19, 0, - 0, 20, 53, 0, 21, 22, 23, 0, 0, 24, - 25, 0, 0, 0, 26, 27, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -336, 228, 0, 229, 0, + 0, -336, 53, 0, -336, -336, -336, 0, 0, -336, + -336, 0, 0, 0, -336, -336, 0, 0, 0, 0, 0, 0, 0, 54, 55, 0, 56, 0, 57, 58, - 0, 0, 28, 29, 0, 294, 59, 30, 31, 0, - 32, 33, 34, 35, 36, 37, 0, 38, 39, 40, - 41, 42, 43, 0, 0, 44, 0, 0, 45, 46, - 47, 48, 49, 0, 0, 0, 50, 51, 52, 0, - 0, 0, 0, 0, -335, 228, 0, 229, 0, 0, - -335, 53, 0, -335, -335, -335, 0, 0, -335, -335, - 0, 0, 0, -335, -335, 0, 0, 0, 0, 0, - 0, 0, 54, 55, 0, 56, 0, 57, 58, 0, - 0, -335, -335, 0, 312, 59, -335, -335, 0, -335, - -335, -335, -335, -335, -335, 0, -335, -335, -335, -335, - -335, -335, 0, 0, -335, 0, 0, -335, -335, -335, - -335, -335, 0, 0, 0, -335, -335, -335, 0, 0, + 0, 0, -336, -336, 0, 312, 59, -336, -336, 0, + -336, -336, -336, -336, -336, -336, 0, -336, -336, -336, + -336, -336, -336, 0, 0, -336, 0, 0, -336, -336, + -336, -336, -336, 0, 0, 0, -336, -336, -336, 0, + 0, 0, 0, 0, 18, 0, 0, 19, 0, 0, + 20, -336, 0, 21, 22, 23, 0, 0, 24, 25, + 0, 0, 0, 26, 27, 0, 0, 0, 0, 0, + 0, 0, -336, -336, 0, -336, 0, -336, -336, 0, + 0, 28, 29, 0, 0, -336, 30, 31, 0, 32, + 33, 34, 35, 36, 37, 0, 38, 39, 40, 41, + 42, 43, 0, 0, 44, 0, 0, 45, 46, 47, + 48, 49, 0, 0, 0, 50, 51, 52, 0, 0, 0, 0, 0, 18, 0, 0, 19, 0, 0, 20, - -335, 0, 21, 22, 23, 0, 0, 24, 25, 0, + 53, 0, 21, 22, 23, 0, 0, 24, 25, 0, 0, 0, 26, 27, 0, 0, 0, 0, 0, 0, - 0, -335, -335, 0, -335, 0, -335, -335, 0, 0, - 28, 29, 0, 0, -335, 30, 31, 0, 32, 33, + 0, 54, 55, 0, 56, 0, 57, 58, 0, 0, + 28, 29, 0, 329, 59, 30, 31, 0, 32, 33, 34, 35, 36, 37, 0, 38, 39, 40, 41, 42, 43, 0, 0, 44, 0, 0, 45, 46, 47, 48, 49, 0, 0, 0, 50, 51, 52, 0, 0, 0, @@ -654,7 +935,7 @@ static const yytype_int16 yytable[] = 0, 21, 22, 23, 0, 0, 24, 25, 0, 0, 0, 26, 27, 0, 0, 0, 0, 0, 0, 0, 54, 55, 0, 56, 0, 57, 58, 0, 0, 28, - 29, 0, 329, 59, 30, 31, 0, 32, 33, 34, + 29, 0, 371, 59, 30, 31, 0, 32, 33, 34, 35, 36, 37, 0, 38, 39, 40, 41, 42, 43, 0, 0, 44, 0, 0, 45, 46, 47, 48, 49, 0, 0, 0, 50, 51, 52, 0, 0, 0, 0, @@ -662,7 +943,7 @@ static const yytype_int16 yytable[] = 21, 22, 23, 0, 0, 24, 25, 0, 0, 0, 26, 27, 0, 0, 0, 0, 0, 0, 0, 54, 55, 0, 56, 0, 57, 58, 0, 0, 28, 29, - 0, 371, 59, 30, 31, 0, 32, 33, 34, 35, + 0, 426, 59, 30, 31, 0, 32, 33, 34, 35, 36, 37, 0, 38, 39, 40, 41, 42, 43, 0, 0, 44, 0, 0, 45, 46, 47, 48, 49, 0, 0, 0, 50, 51, 52, 0, 0, 0, 0, 0, @@ -670,310 +951,314 @@ static const yytype_int16 yytable[] = 22, 23, 0, 0, 24, 25, 0, 0, 0, 26, 27, 0, 0, 0, 0, 0, 0, 0, 54, 55, 0, 56, 0, 57, 58, 0, 0, 28, 29, 0, - 426, 59, 30, 31, 0, 32, 33, 34, 35, 36, + 459, 59, 30, 31, 0, 32, 33, 34, 35, 36, 37, 0, 38, 39, 40, 41, 42, 43, 0, 0, 44, 0, 0, 45, 46, 47, 48, 49, 0, 0, 0, 50, 51, 52, 0, 0, 0, 0, 0, 18, 0, 0, 19, 0, 0, 20, 53, 0, 21, 22, 23, 0, 0, 24, 25, 0, 0, 0, 26, 27, 0, 0, 0, 0, 0, 0, 0, 54, 55, 0, - 56, 0, 57, 58, 0, 0, 28, 29, 0, 459, + 56, 0, 57, 58, 0, 0, 28, 29, 0, 0, 59, 30, 31, 0, 32, 33, 34, 35, 36, 37, 0, 38, 39, 40, 41, 42, 43, 0, 0, 44, 0, 0, 45, 46, 47, 48, 49, 0, 0, 0, - 50, 51, 52, 0, 0, 0, 0, 0, 18, 0, - 0, 19, 0, 0, 20, 53, 0, 21, 22, 23, - 0, 0, 24, 25, 0, 0, 0, 26, 27, 0, + 50, 51, 52, 0, 0, 0, 0, 0, -335, 0, + 0, -335, 0, 0, -335, 53, 0, -335, -335, -335, + 0, 0, -335, -335, 0, 0, 0, -335, -335, 0, 0, 0, 0, 0, 0, 0, 54, 55, 0, 56, - 0, 57, 58, 0, 0, 28, 29, 0, 0, 59, - 30, 31, 0, 32, 33, 34, 35, 36, 37, 0, - 38, 39, 40, 41, 42, 43, 0, 0, 44, 0, - 0, 45, 46, 47, 48, 49, 0, 0, 0, 50, - 51, 52, 0, 0, 0, 0, 0, -334, 0, 0, - -334, 0, 0, -334, 53, 0, -334, -334, -334, 0, - 0, -334, -334, 0, 0, 0, -334, -334, 0, 0, - 0, 0, 0, 0, 0, 54, 55, 0, 56, 0, - 57, 58, 0, 0, -334, -334, 0, 0, 288, -334, - -334, 0, -334, -334, -334, -334, -334, -334, 0, -334, - -334, -334, -334, -334, -334, 0, 0, -334, 0, 0, - -334, -334, -334, -334, -334, 0, 0, 0, -334, -334, - -334, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, -334, 0, 0, 0, 0, 0, 0, - 0, 0, 197, 0, 0, 0, 0, 0, 0, 198, - 199, 200, 0, 0, -334, -334, 0, -334, 0, -334, - -334, 0, 201, 0, 0, 0, 0, -334, 202, 203, - 204, 450, 205, 206, 207, 208, 209, 210, 211, 212, - 213, 214, 215, 216, 217, 218, 219, 220, 0, 0, - 0, 0, 221, 197, 0, 222, 223, 224, 225, 226, - 198, 199, 200, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 201, 0, 0, 0, 0, 0, 202, - 203, 204, 0, 205, 206, 207, 208, 209, 210, 211, + 0, 57, 58, 0, 0, -335, -335, 0, 0, 288, + -335, -335, 0, -335, -335, -335, -335, -335, -335, 0, + -335, -335, -335, -335, -335, -335, 0, 0, -335, 0, + 0, -335, -335, -335, -335, -335, 0, 0, 0, -335, + -335, -335, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, -335, 0, 0, 0, 0, 0, + 0, 0, 0, 197, 0, 0, 0, 0, 0, 0, + 198, 199, 200, 0, 0, -335, -335, 0, -335, 0, + -335, -335, 0, 201, 0, 0, 0, 0, -335, 202, + 203, 204, 450, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 0, 0, 0, 0, 221, 197, 0, 222, 223, 224, 225, 226, 198, 199, 200, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, -336, 0, 0, 0, 198, 199, + 0, 0, 0, 0, 201, 0, 0, 0, 0, 0, 202, 203, 204, 0, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 0, 0, 0, 0, 221, 197, 0, 222, 223, 224, - 225, 226, 198, 199, 200, 219, 220, 0, 0, 0, - 0, 221, 0, 0, 222, 223, 224, 225, 226, 0, + 225, 226, 198, 199, 200, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, -337, 0, 0, 0, 0, 0, 202, 203, 204, 0, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 0, 0, 0, 0, 221, 197, 0, 222, 223, 224, 225, 226, 198, 199, 200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 204, 0, 205, 206, 207, 208, + 0, 0, 202, 203, 204, 0, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, - 219, 220, 0, 0, 0, 0, 221, -336, 0, 222, + 219, 220, 0, 0, 0, 0, 221, 197, 0, 222, 223, 224, 225, 226, 198, 199, 200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 205, 206, 207, + 0, 0, 198, 199, 200, 204, 0, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, - 218, 219, 220, 198, 199, 200, 0, 221, 0, 0, - 222, 223, 224, 225, 226, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 198, 199, 200, 208, - 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, - 219, 220, 0, 0, 0, 0, 221, 0, 0, 222, - 223, 224, 225, 226, 210, 211, 212, 213, 214, 215, + 218, 219, 220, 0, 0, 0, 0, 221, -337, 0, + 222, 223, 224, 225, 226, 198, 199, 200, 218, 219, + 220, 0, 0, 0, 0, 221, 0, 0, 222, 223, + 224, 225, 226, 0, 0, 0, 0, 0, 205, 206, + 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, + 217, 218, 219, 220, 198, 199, 200, 0, 221, 0, + 0, 222, 223, 224, 225, 226, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 198, 199, 200, + 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, + 218, 219, 220, 0, 0, 0, 0, 221, 0, 0, + 222, 223, 224, 225, 226, 210, 211, 212, 213, 214, + 215, 216, 217, 218, 219, 220, 198, 199, 200, 0, + 221, 0, 0, 222, 223, 224, 225, 226, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 198, 199, 200, + 0, 0, 0, 0, 0, 211, 212, 213, 214, 215, + 216, 217, 218, 219, 220, 0, 198, 199, 200, 221, + 0, 0, 222, 223, 224, 225, 226, 212, 213, 214, + 215, 216, 217, 218, 219, 220, 198, 199, 200, 0, + 221, 0, 0, 222, 223, 224, 225, 226, 214, 215, 216, 217, 218, 219, 220, 198, 199, 200, 0, 221, 0, 0, 222, 223, 224, 225, 226, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 198, 199, 200, 0, - 0, 0, 0, 0, 211, 212, 213, 214, 215, 216, - 217, 218, 219, 220, 0, 198, 199, 200, 221, 0, - 0, 222, 223, 224, 225, 226, 212, 213, 214, 215, 216, 217, 218, 219, 220, 198, 199, 200, 0, 221, - 0, 0, 222, 223, 224, 225, 226, 214, 215, 216, - 217, 218, 219, 220, 198, 199, 200, 0, 221, 0, - 0, 222, 223, 224, 225, 226, 0, 0, 0, 216, + 0, 0, 222, 223, 224, 225, 226, 0, 0, -337, 217, 218, 219, 220, 0, 0, 0, 0, 221, 0, - 0, 222, 223, 224, 225, 226, 0, 0, -336, 217, - 218, 219, 220, 0, 0, 0, 0, 221, 0, 0, - 222, 223, 224, 225, 226 + 0, 222, 223, 224, 225, 226, 0, 0, 0, 0, + 217, 218, 219, 220, 0, 0, 0, 0, 221, 0, + 0, 222, 223, 224, 225, 226 }; static const yytype_int16 yycheck[] = { - 10, 13, 49, 149, 17, 19, 53, 11, 27, 19, - 400, 304, 27, 109, 18, 11, 20, 13, 22, 553, - 24, 25, 16, 87, 150, 29, 10, 577, 16, 16, - 34, 35, 20, 56, 0, 19, 24, 51, 61, 49, - 12, 51, 22, 30, 48, 49, 50, 102, 174, 582, - 13, 11, 11, 13, 18, 13, 20, 11, 22, 9, - 24, 25, 16, 27, 130, 11, 130, 51, 110, 111, - 34, 35, 84, 92, 18, 59, 22, 92, 22, 59, - 24, 25, 615, 616, 617, 49, 50, 104, 22, 130, - 34, 35, 130, 110, 10, 11, 100, 13, 631, 632, - 16, 111, 56, 150, 20, 49, 50, 61, 24, 25, - 14, 22, 662, 123, 14, 649, 15, 650, 15, 138, - 110, 84, 169, 138, 84, 658, 23, 174, 92, 14, - 108, 95, 120, 120, 130, 85, 130, 147, 148, 149, - 150, 57, 130, 130, 116, 16, 160, 161, 130, 20, - 160, 161, 156, 24, 300, 139, 14, 161, 92, 93, - 94, 95, 11, 259, 174, 81, 262, 11, 31, 153, - 390, 108, 109, 14, 138, 159, 160, 161, 22, 42, - 400, 92, 93, 94, 95, 405, 406, 14, 92, 93, - 94, 95, 92, 93, 94, 95, 11, 161, 13, 183, - 184, 185, 186, 11, 188, 189, 190, 92, 93, 94, - 95, 11, 130, 13, 130, 32, 56, 161, 35, 36, - 37, 38, 235, 11, 41, 13, 236, 246, 14, 239, - 11, 246, 13, 56, 92, 93, 94, 95, 14, 385, + 10, 17, 49, 149, 19, 400, 53, 11, 27, 19, + 304, 12, 109, 27, 18, 11, 20, 13, 22, 16, + 24, 25, 16, 20, 150, 29, 10, 24, 16, 87, + 34, 35, 553, 13, 577, 19, 51, 104, 11, 49, + 11, 51, 30, 110, 48, 49, 50, 102, 174, 22, + 11, 22, 11, 22, 18, 16, 20, 16, 22, 9, + 24, 25, 0, 27, 25, 110, 111, 51, 31, 11, + 34, 35, 130, 92, 11, 59, 13, 18, 92, 42, + 11, 22, 13, 24, 25, 49, 50, 11, 13, 13, + 59, 108, 109, 34, 35, 56, 100, 56, 15, 13, + 61, 111, 61, 150, 84, 11, 23, 13, 49, 50, + 14, 10, 11, 123, 13, 116, 108, 16, 130, 138, + 663, 20, 169, 120, 138, 24, 25, 174, 92, 650, + 14, 95, 120, 130, 130, 85, 130, 147, 148, 149, + 150, 130, 130, 14, 22, 160, 161, 84, 94, 95, + 160, 161, 156, 84, 300, 139, 14, 161, 57, 84, + 84, 56, 259, 16, 174, 262, 61, 20, 130, 153, + 390, 24, 15, 14, 138, 159, 160, 161, 110, 16, + 400, 130, 81, 20, 11, 405, 406, 24, 92, 93, + 94, 95, 127, 128, 11, 14, 13, 161, 11, 183, + 184, 185, 186, 130, 188, 189, 190, 22, 92, 93, + 94, 95, 33, 34, 92, 93, 94, 95, 56, 235, + 161, 92, 93, 94, 95, 56, 236, 246, 11, 239, + 13, 130, 246, 130, 92, 93, 94, 95, 14, 385, 11, 130, 13, 227, 228, 229, 230, 231, 232, 233, - 234, 92, 93, 94, 95, 94, 95, 130, 22, 263, - 307, 11, 226, 13, 130, 92, 93, 94, 95, 659, - 563, 22, 492, 127, 128, 92, 93, 94, 95, 22, - 33, 34, 246, 267, 268, 269, 270, 271, 272, 11, - 300, 13, 306, 243, 244, 245, 306, 247, 248, 22, - 250, 251, 252, 253, 288, 130, 92, 93, 94, 95, - 130, 11, 129, 439, 22, 39, 92, 93, 94, 95, - 268, 269, 306, 271, 272, 22, 546, 547, 92, 93, - 94, 95, 316, 11, 84, 22, 320, 14, 16, 84, - 59, 92, 93, 94, 95, 84, 130, 25, 22, 92, - 93, 94, 95, 87, 92, 93, 94, 95, 362, 129, - 506, 129, 84, 13, 584, 92, 93, 94, 95, 92, - 93, 94, 95, 84, 56, 385, 360, 361, 56, 120, - 56, 56, 401, 61, 368, 44, 401, 15, 130, 609, - 400, 129, 439, 61, 407, 78, 79, 80, 362, 59, - 16, 59, 129, 88, 20, 389, 390, 78, 24, 629, - 12, 129, 13, 423, 424, 561, 400, 25, 25, 403, - 404, 405, 406, 433, 130, 25, 25, 437, 392, 439, - 113, 114, 115, 116, 560, 25, 18, 401, 121, 59, - 97, 124, 125, 126, 127, 128, 130, 461, 22, 97, - 121, 461, 402, 124, 125, 126, 127, 128, 408, 56, - 130, 411, 446, 129, 32, 12, 12, 35, 36, 37, - 38, 16, 12, 41, 12, 12, 129, 461, 129, 22, - 129, 431, 92, 93, 94, 95, 541, 542, 130, 499, - 129, 501, 129, 548, 129, 129, 506, 130, 56, 554, - 555, 11, 11, 92, 93, 94, 95, 88, 492, 92, - 93, 94, 95, 560, 12, 129, 22, 481, 15, 129, - 129, 471, 86, 473, 92, 93, 94, 95, 22, 22, - 585, 586, 587, 129, 484, 519, 591, 78, 79, 80, - 129, 92, 93, 94, 95, 130, 129, 22, 603, 562, - 560, 561, 129, 566, 130, 610, 611, 129, 129, 129, - 573, 130, 546, 547, 45, 17, 576, 577, 129, 129, - 78, 85, 582, 114, 115, 116, 129, 129, 129, 634, - 121, 13, 116, 124, 125, 126, 127, 128, 538, 602, - 600, 646, 92, 93, 94, 95, 403, 583, 659, 583, - 584, 290, 657, 501, 425, 615, 616, 617, 116, 281, - 424, 514, 667, 121, 578, 431, 124, 125, 126, 127, - 128, 631, 632, 593, 401, 609, 590, 138, 246, 129, - -1, 21, 642, 23, -1, 639, 26, -1, 28, 29, - 650, 654, -1, 593, -1, 629, -1, -1, 658, 659, - -1, 41, 662, -1, 44, -1, -1, -1, 48, -1, - 0, 1, -1, -1, 54, 55, 56, 57, 58, -1, - 10, 11, -1, 13, -1, -1, 16, -1, -1, 19, - 20, 21, 22, -1, 24, 25, 26, 27, 28, 29, - 30, 31, 32, -1, -1, 35, 36, 37, 38, -1, - 40, 41, 42, 43, -1, -1, 46, 47, 48, 49, - 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, - 60, -1, 62, 63, 64, 65, 66, 67, 68, 69, - 70, -1, 72, 73, 74, 75, 76, 77, -1, -1, - -1, 81, 82, 83, 92, 93, 94, 95, 138, 89, - -1, 10, -1, -1, -1, -1, 96, 16, -1, -1, - -1, 20, -1, -1, -1, 24, 124, 125, 126, 127, - 128, 30, 92, 93, 94, 95, -1, 117, 118, -1, - 120, 129, 122, 123, -1, -1, -1, -1, -1, -1, - 130, -1, -1, -1, -1, -1, -1, 187, -1, -1, - -1, -1, -1, 193, -1, -1, 196, 197, 198, 199, - 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, - 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, - 220, 221, 0, 1, -1, 225, -1, -1, -1, -1, - -1, -1, 10, 11, -1, 13, -1, -1, 16, -1, - -1, 19, 20, 21, 22, -1, 24, 25, 26, 27, - 28, 29, 30, 31, 32, -1, -1, 35, 36, 37, - 38, -1, 40, 41, 42, 43, -1, -1, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - 58, 59, 60, -1, 62, 63, 64, 65, 66, 67, - 68, 69, 70, -1, 72, 73, 74, 75, 76, 77, - -1, -1, -1, 81, 82, 83, -1, -1, -1, -1, - -1, 89, -1, -1, -1, -1, -1, -1, 96, 3, - 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 1, 117, - 118, -1, 120, -1, 122, 123, -1, 10, 11, 12, - 13, -1, 130, 16, -1, -1, 19, 20, 21, 22, - -1, 24, 25, 26, 27, 28, 29, 30, 31, 32, - -1, -1, 35, 36, 37, 38, -1, 40, 41, 42, - 43, -1, -1, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, 58, 59, 60, -1, 62, - 63, 64, 65, 66, 67, 68, 69, 70, -1, 72, - 73, 74, 75, 76, 77, -1, -1, -1, 81, 82, - 83, -1, -1, -1, -1, -1, 89, -1, -1, -1, - -1, -1, -1, 96, -1, -1, -1, -1, -1, -1, + 234, 92, 93, 94, 95, 11, 130, 13, 22, 263, + 307, 14, 226, 268, 269, 660, 271, 272, 130, 563, + 130, 11, 492, 92, 93, 94, 95, 92, 93, 94, + 95, 22, 246, 267, 268, 269, 270, 271, 272, 22, + 300, 306, 39, 243, 244, 245, 306, 247, 248, 22, + 250, 251, 252, 253, 288, 32, 22, 22, 35, 36, + 37, 38, 14, 439, 41, 84, 92, 93, 94, 95, + 59, 84, 306, 130, 129, 87, 546, 547, 92, 93, + 94, 95, 316, 129, 22, 13, 320, 56, 56, 92, + 93, 94, 95, 92, 93, 94, 95, 92, 93, 94, + 95, 92, 93, 94, 95, 56, 84, 130, 362, 120, + 506, 582, 44, 61, 584, 92, 93, 94, 95, 92, + 93, 94, 95, 15, 88, 385, 360, 361, 59, 59, + 129, 129, 401, 22, 368, 12, 130, 401, 13, 609, + 400, 407, 439, 78, 615, 616, 617, 25, 362, 25, + 18, 25, 129, 25, 25, 389, 390, 59, 97, 629, + 631, 632, 56, 423, 424, 561, 400, 130, 22, 403, + 404, 405, 406, 433, 97, 130, 129, 437, 392, 439, + 651, 116, 12, 12, 560, 12, 121, 401, 659, 124, + 125, 126, 127, 128, 16, 12, 461, 92, 93, 94, + 95, 461, 402, 92, 93, 94, 95, 12, 408, 129, + 129, 411, 446, 130, 32, 10, 129, 35, 36, 37, + 38, 16, 22, 41, 129, 20, 129, 461, 129, 24, + 129, 431, 130, 56, 129, 30, 541, 542, 11, 499, + 11, 501, 88, 548, 78, 12, 506, 129, 22, 554, + 555, 92, 93, 94, 95, 15, 129, 22, 492, 22, + 130, 86, 129, 560, 129, 22, 130, 481, 129, 129, + 129, 471, 130, 473, 92, 93, 94, 95, 129, 45, + 585, 586, 587, 17, 484, 519, 591, 121, 129, 129, + 124, 125, 126, 127, 128, 85, 562, 129, 603, 13, + 560, 561, 116, 129, 583, 610, 611, 573, 92, 93, + 94, 95, 546, 547, 403, 660, 576, 577, 501, 290, + 281, 425, 582, 92, 93, 94, 95, 424, 514, 634, + 593, 78, 79, 599, 138, 431, 602, 401, 538, 246, + 600, -1, 647, -1, -1, 129, -1, -1, -1, 583, + 584, -1, -1, 658, -1, 615, 616, 617, -1, -1, + 129, -1, -1, 668, 578, -1, -1, -1, 115, 116, + -1, 631, 632, -1, 121, 609, 590, 124, 125, 126, + 127, 128, -1, 643, -1, 639, -1, -1, -1, 655, + -1, 651, -1, 593, -1, 629, -1, -1, -1, 659, + 660, -1, 21, 663, 23, -1, -1, 26, -1, 28, + 29, 92, 93, 94, 95, -1, -1, 92, 93, 94, + 95, -1, 41, -1, -1, 44, -1, -1, -1, 48, + -1, 0, 1, -1, -1, 54, 55, 56, 57, 58, + -1, 10, 11, -1, 13, -1, -1, 16, 129, -1, + 19, 20, 21, 22, 129, 24, 25, 26, 27, 28, + 29, 30, 31, 32, -1, -1, 35, 36, 37, 38, + -1, 40, 41, 42, 43, -1, -1, 46, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, + 59, 60, -1, 62, 63, 64, 65, 66, 67, 68, + 69, 70, -1, 72, 73, 74, 75, 76, 77, -1, + -1, -1, 81, 82, 83, 92, 93, 94, 95, 138, + 89, 124, 125, 126, 127, 128, -1, 96, 3, 4, + 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 117, 118, + -1, 120, 129, 122, 123, -1, -1, -1, -1, -1, + -1, 130, -1, -1, -1, -1, -1, -1, 187, -1, + -1, -1, -1, -1, 193, -1, -1, 196, 197, 198, + 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, + 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, + 219, 220, 221, 0, 1, -1, 225, -1, -1, -1, + -1, -1, -1, 10, 11, -1, 13, -1, -1, 16, + -1, -1, 19, 20, 21, 22, -1, 24, 25, 26, + 27, 28, 29, 30, 31, 32, -1, -1, 35, 36, + 37, 38, -1, 40, 41, 42, 43, -1, -1, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + 57, 58, 59, 60, -1, 62, 63, 64, 65, 66, + 67, 68, 69, 70, -1, 72, 73, 74, 75, 76, + 77, -1, -1, -1, 81, 82, 83, -1, -1, -1, + -1, -1, 89, -1, -1, -1, -1, -1, -1, 96, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 450, -1, -1, -1, 117, 118, -1, 120, -1, 122, - 123, -1, -1, 1, -1, -1, -1, 130, -1, -1, - -1, -1, 10, 11, 12, 13, -1, -1, 16, -1, - -1, 19, 20, 21, 22, -1, 24, 25, 26, 27, - 28, 29, 30, 31, 32, -1, -1, 35, 36, 37, - 38, -1, 40, 41, 42, 43, -1, 507, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - 58, 59, 60, -1, 62, 63, 64, 65, 66, 67, - 68, 69, 70, -1, 72, 73, 74, 75, 76, 77, - 540, -1, -1, 81, 82, 83, -1, -1, -1, -1, - -1, 89, -1, -1, -1, -1, -1, -1, 96, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, + 117, 118, -1, 120, -1, 122, 123, -1, 10, 11, + 12, 13, -1, 130, 16, -1, -1, 19, 20, 21, + 22, -1, 24, 25, 26, 27, 28, 29, 30, 31, + 32, -1, -1, 35, 36, 37, 38, -1, 40, 41, + 42, 43, -1, -1, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, -1, + 62, 63, 64, 65, 66, 67, 68, 69, 70, -1, + 72, 73, 74, 75, 76, 77, -1, -1, -1, 81, + 82, 83, -1, -1, -1, -1, -1, 89, -1, -1, + -1, -1, -1, -1, 96, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 1, 117, - 118, -1, 120, -1, 122, 123, -1, 10, 11, 12, - 13, -1, 130, 16, -1, -1, 19, 20, 21, 22, - -1, 24, 25, 26, 27, 28, 29, 30, 31, 32, - -1, -1, 35, 36, 37, 38, -1, 40, 41, 42, - 43, -1, -1, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, 58, 59, 60, -1, 62, - 63, 64, 65, 66, 67, 68, 69, 70, -1, 72, - 73, 74, 75, 76, 77, -1, -1, -1, 81, 82, - 83, -1, -1, -1, -1, -1, 89, -1, -1, -1, - -1, -1, -1, 96, -1, -1, -1, -1, -1, -1, + -1, 450, -1, -1, -1, 117, 118, -1, 120, -1, + 122, 123, -1, -1, 1, -1, -1, -1, 130, -1, + -1, -1, -1, 10, 11, 12, 13, -1, -1, 16, + -1, -1, 19, 20, 21, 22, -1, 24, 25, 26, + 27, 28, 29, 30, 31, 32, -1, -1, 35, 36, + 37, 38, -1, 40, 41, 42, 43, -1, 507, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + 57, 58, 59, 60, -1, 62, 63, 64, 65, 66, + 67, 68, 69, 70, -1, 72, 73, 74, 75, 76, + 77, 540, -1, -1, 81, 82, 83, -1, -1, -1, + -1, -1, 89, -1, -1, -1, -1, -1, -1, 96, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 1, 117, 118, -1, 120, -1, 122, - 123, -1, 10, 11, 12, 13, -1, 130, 16, -1, - -1, 19, 20, 21, 22, -1, 24, 25, 26, 27, - 28, 29, 30, 31, 32, -1, -1, 35, 36, 37, - 38, -1, 40, 41, 42, 43, -1, -1, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - 58, 59, 60, -1, 62, 63, 64, 65, 66, 67, - 68, 69, 70, -1, 72, 73, 74, 75, 76, 77, - -1, -1, -1, 81, 82, 83, -1, -1, -1, -1, - -1, 89, -1, -1, -1, -1, -1, -1, 96, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, + 117, 118, -1, 120, -1, 122, 123, -1, 10, 11, + 12, 13, -1, 130, 16, -1, -1, 19, 20, 21, + 22, -1, 24, 25, 26, 27, 28, 29, 30, 31, + 32, -1, -1, 35, 36, 37, 38, -1, 40, 41, + 42, 43, -1, -1, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, -1, + 62, 63, 64, 65, 66, 67, 68, 69, 70, -1, + 72, 73, 74, 75, 76, 77, -1, -1, -1, 81, + 82, 83, -1, -1, -1, -1, -1, 89, -1, -1, + -1, -1, -1, -1, 96, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 1, 117, - 118, -1, 120, -1, 122, 123, -1, 10, 11, 12, - 13, -1, 130, 16, -1, -1, 19, 20, 21, 22, - -1, 24, 25, 26, 27, 28, 29, 30, 31, 32, - -1, -1, 35, 36, 37, 38, -1, 40, 41, 42, - 43, -1, -1, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, 58, 59, 60, -1, 62, - 63, 64, 65, 66, 67, 68, 69, 70, -1, 72, - 73, 74, 75, 76, 77, -1, -1, -1, 81, 82, - 83, -1, -1, -1, -1, -1, 89, -1, -1, -1, - -1, -1, -1, 96, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 1, 117, 118, -1, 120, -1, + 122, 123, -1, 10, 11, 12, 13, -1, 130, 16, + -1, -1, 19, 20, 21, 22, -1, 24, 25, 26, + 27, 28, 29, 30, 31, 32, -1, -1, 35, 36, + 37, 38, -1, 40, 41, 42, 43, -1, -1, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + 57, 58, 59, 60, -1, 62, 63, 64, 65, 66, + 67, 68, 69, 70, -1, 72, 73, 74, 75, 76, + 77, -1, -1, -1, 81, 82, 83, -1, -1, -1, + -1, -1, 89, -1, -1, -1, -1, -1, -1, 96, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 1, 117, 118, -1, 120, -1, 122, - 123, -1, 10, 11, 12, 13, -1, 130, 16, -1, - -1, 19, 20, 21, 22, -1, 24, 25, 26, 27, - 28, 29, 30, 31, 32, -1, -1, 35, 36, 37, - 38, -1, 40, 41, 42, 43, -1, -1, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - 58, 59, 60, -1, 62, 63, 64, 65, 66, 67, - 68, 69, 70, -1, 72, 73, 74, 75, 76, 77, - -1, -1, -1, 81, 82, 83, -1, -1, -1, -1, - -1, 89, -1, -1, -1, -1, -1, -1, 96, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, + 117, 118, -1, 120, -1, 122, 123, -1, 10, 11, + 12, 13, -1, 130, 16, -1, -1, 19, 20, 21, + 22, -1, 24, 25, 26, 27, 28, 29, 30, 31, + 32, -1, -1, 35, 36, 37, 38, -1, 40, 41, + 42, 43, -1, -1, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, -1, + 62, 63, 64, 65, 66, 67, 68, 69, 70, -1, + 72, 73, 74, 75, 76, 77, -1, -1, -1, 81, + 82, 83, -1, -1, -1, -1, -1, 89, -1, -1, + -1, -1, -1, -1, 96, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 1, 117, - 118, -1, 120, -1, 122, 123, -1, 10, 11, -1, - 13, -1, 130, 16, -1, -1, 19, 20, 21, 22, - -1, 24, 25, 26, 27, 28, 29, 30, 31, 32, - -1, -1, 35, 36, 37, 38, -1, 40, 41, 42, - 43, -1, -1, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, 58, 59, 60, -1, 62, - 63, 64, 65, 66, 67, 68, 69, 70, -1, 72, - 73, 74, 75, 76, 77, -1, -1, -1, 81, 82, - 83, -1, -1, 86, -1, -1, 89, -1, -1, -1, - -1, -1, -1, 96, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 1, 117, 118, -1, 120, -1, + 122, 123, -1, 10, 11, 12, 13, -1, 130, 16, + -1, -1, 19, 20, 21, 22, -1, 24, 25, 26, + 27, 28, 29, 30, 31, 32, -1, -1, 35, 36, + 37, 38, -1, 40, 41, 42, 43, -1, -1, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + 57, 58, 59, 60, -1, 62, 63, 64, 65, 66, + 67, 68, 69, 70, -1, 72, 73, 74, 75, 76, + 77, -1, -1, -1, 81, 82, 83, -1, -1, -1, + -1, -1, 89, -1, -1, -1, -1, -1, -1, 96, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 1, 117, 118, -1, 120, -1, 122, - 123, -1, 10, 11, -1, 13, -1, 130, 16, -1, - -1, 19, 20, 21, 22, -1, 24, 25, 26, 27, - 28, 29, 30, 31, 32, -1, -1, 35, 36, 37, - 38, -1, 40, 41, 42, 43, -1, -1, 46, 47, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - 58, 59, 60, -1, 62, 63, 64, 65, 66, 67, - 68, 69, 70, -1, 72, 73, 74, 75, 76, 77, - -1, -1, -1, 81, 82, 83, -1, -1, -1, -1, - -1, 89, -1, -1, -1, -1, -1, -1, 96, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, + 117, 118, -1, 120, -1, 122, 123, -1, 10, 11, + -1, 13, -1, 130, 16, -1, -1, 19, 20, 21, + 22, -1, 24, 25, 26, 27, 28, 29, 30, 31, + 32, -1, -1, 35, 36, 37, 38, -1, 40, 41, + 42, 43, -1, -1, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, -1, + 62, 63, 64, 65, 66, 67, 68, 69, 70, -1, + 72, 73, 74, 75, 76, 77, -1, -1, -1, 81, + 82, 83, -1, -1, 86, -1, -1, 89, -1, -1, + -1, -1, -1, -1, 96, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 1, 117, - 118, -1, 120, -1, 122, 123, -1, 10, 11, -1, - 13, -1, 130, 16, -1, -1, 19, 20, 21, 22, - -1, 24, 25, 26, 27, 28, 29, 30, 31, 32, - -1, -1, 35, 36, 37, 38, -1, 40, 41, 42, - 43, -1, -1, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 55, 56, 57, 58, 59, 60, -1, 62, - 63, 64, 65, 66, 67, 68, -1, 70, -1, 72, - 73, 74, 75, 76, 77, -1, -1, -1, 81, 82, - 83, -1, 1, -1, -1, -1, 89, -1, -1, -1, - -1, 10, -1, 96, 13, -1, -1, 16, -1, -1, - 19, 20, 21, 22, -1, 24, 25, -1, -1, -1, - 29, 30, -1, -1, 117, 118, -1, 120, -1, 122, - 123, -1, -1, -1, -1, -1, -1, 130, 47, 48, - -1, -1, -1, 52, 53, -1, 55, 56, 57, 58, + -1, -1, -1, -1, 1, 117, 118, -1, 120, -1, + 122, 123, -1, 10, 11, -1, 13, -1, 130, 16, + -1, -1, 19, 20, 21, 22, -1, 24, 25, 26, + 27, 28, 29, 30, 31, 32, -1, -1, 35, 36, + 37, 38, -1, 40, 41, 42, 43, -1, -1, 46, + 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + 57, 58, 59, 60, -1, 62, 63, 64, 65, 66, + 67, 68, 69, 70, -1, 72, 73, 74, 75, 76, + 77, -1, -1, -1, 81, 82, 83, -1, -1, -1, + -1, -1, 89, -1, -1, -1, -1, -1, -1, 96, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, + 117, 118, -1, 120, -1, 122, 123, -1, 10, 11, + -1, 13, -1, 130, 16, -1, -1, 19, 20, 21, + 22, -1, 24, 25, 26, 27, 28, 29, 30, 31, + 32, -1, -1, 35, 36, 37, 38, -1, 40, 41, + 42, 43, -1, -1, 46, 47, 48, 49, 50, 51, + 52, 53, 54, 55, 56, 57, 58, 59, 60, -1, + 62, 63, 64, 65, 66, 67, 68, -1, 70, -1, + 72, 73, 74, 75, 76, 77, -1, -1, -1, 81, + 82, 83, -1, 1, -1, -1, -1, 89, -1, -1, + -1, -1, 10, -1, 96, 13, -1, -1, 16, -1, + -1, 19, 20, 21, 22, -1, 24, 25, -1, -1, + -1, 29, 30, -1, -1, 117, 118, -1, 120, -1, + 122, 123, -1, -1, -1, -1, -1, -1, 130, 47, + 48, -1, -1, -1, 52, 53, -1, 55, 56, 57, + 58, 59, 60, -1, 62, 63, 64, 65, 66, 67, + -1, -1, 70, -1, -1, 73, 74, 75, 76, 77, + -1, -1, 1, 81, 82, 83, -1, -1, -1, -1, + -1, 10, -1, -1, 13, -1, -1, 16, 96, -1, + 19, 20, 21, -1, -1, 24, 25, -1, -1, -1, + 29, 30, -1, -1, -1, -1, -1, -1, -1, 117, + 118, -1, 120, -1, 122, 123, -1, -1, 47, 48, + -1, -1, 130, 52, 53, -1, 55, 56, 57, 58, 59, 60, -1, 62, 63, 64, 65, 66, 67, -1, -1, 70, -1, -1, 73, 74, 75, 76, 77, -1, - -1, 1, 81, 82, 83, -1, -1, -1, -1, -1, - 10, -1, -1, 13, -1, -1, 16, 96, -1, 19, + -1, -1, 81, 82, 83, -1, -1, -1, -1, -1, + 10, 11, -1, 13, -1, -1, 16, 96, -1, 19, 20, 21, -1, -1, 24, 25, -1, -1, -1, 29, 30, -1, -1, -1, -1, -1, -1, -1, 117, 118, -1, 120, -1, 122, 123, -1, -1, 47, 48, -1, - -1, 130, 52, 53, -1, 55, 56, 57, 58, 59, - 60, -1, 62, 63, 64, 65, 66, 67, -1, -1, + 129, 130, 52, 53, -1, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, -1, -1, 70, -1, -1, 73, 74, 75, 76, 77, -1, -1, -1, 81, 82, 83, -1, -1, -1, -1, -1, 10, 11, -1, 13, -1, -1, 16, 96, -1, 19, 20, 21, -1, -1, 24, 25, -1, -1, -1, 29, 30, -1, -1, -1, -1, -1, -1, -1, 117, 118, -1, - 120, -1, 122, 123, -1, -1, 47, 48, -1, 129, + 120, -1, 122, 123, -1, -1, 47, 48, -1, -1, 130, 52, 53, -1, 55, 56, 57, 58, 59, 60, - 61, 62, 63, 64, 65, 66, 67, -1, -1, 70, + -1, 62, 63, 64, 65, 66, 67, -1, -1, 70, -1, -1, 73, 74, 75, 76, 77, -1, -1, -1, - 81, 82, 83, -1, -1, -1, -1, -1, 10, 11, + 81, 82, 83, -1, -1, -1, -1, -1, 10, -1, -1, 13, -1, -1, 16, 96, -1, 19, 20, 21, -1, -1, 24, 25, -1, -1, -1, 29, 30, -1, -1, -1, -1, -1, -1, -1, 117, 118, -1, 120, @@ -985,7 +1270,7 @@ static const yytype_int16 yycheck[] = 13, -1, -1, 16, 96, -1, 19, 20, 21, -1, -1, 24, 25, -1, -1, -1, 29, 30, -1, -1, -1, -1, -1, -1, -1, 117, 118, -1, 120, -1, - 122, 123, -1, -1, 47, 48, -1, -1, 130, 52, + 122, 123, -1, -1, 47, 48, -1, 129, 130, 52, 53, -1, 55, 56, 57, 58, 59, 60, -1, 62, 63, 64, 65, 66, 67, -1, -1, 70, -1, -1, 73, 74, 75, 76, 77, -1, -1, -1, 81, 82, @@ -997,7 +1282,7 @@ static const yytype_int16 yycheck[] = -1, 55, 56, 57, 58, 59, 60, -1, 62, 63, 64, 65, 66, 67, -1, -1, 70, -1, -1, 73, 74, 75, 76, 77, -1, -1, -1, 81, 82, 83, - -1, -1, -1, -1, -1, 10, -1, -1, 13, -1, + -1, -1, -1, -1, -1, 10, 11, -1, 13, -1, -1, 16, 96, -1, 19, 20, 21, -1, -1, 24, 25, -1, -1, -1, 29, 30, -1, -1, -1, -1, -1, -1, -1, 117, 118, -1, 120, -1, 122, 123, @@ -1005,11 +1290,11 @@ static const yytype_int16 yycheck[] = 55, 56, 57, 58, 59, 60, -1, 62, 63, 64, 65, 66, 67, -1, -1, 70, -1, -1, 73, 74, 75, 76, 77, -1, -1, -1, 81, 82, 83, -1, - -1, -1, -1, -1, 10, 11, -1, 13, -1, -1, + -1, -1, -1, -1, 10, -1, -1, 13, -1, -1, 16, 96, -1, 19, 20, 21, -1, -1, 24, 25, -1, -1, -1, 29, 30, -1, -1, -1, -1, -1, -1, -1, 117, 118, -1, 120, -1, 122, 123, -1, - -1, 47, 48, -1, 129, 130, 52, 53, -1, 55, + -1, 47, 48, -1, -1, 130, 52, 53, -1, 55, 56, 57, 58, 59, 60, -1, 62, 63, 64, 65, 66, 67, -1, -1, 70, -1, -1, 73, 74, 75, 76, 77, -1, -1, -1, 81, 82, 83, -1, -1, @@ -1017,7 +1302,7 @@ static const yytype_int16 yycheck[] = 96, -1, 19, 20, 21, -1, -1, 24, 25, -1, -1, -1, 29, 30, -1, -1, -1, -1, -1, -1, -1, 117, 118, -1, 120, -1, 122, 123, -1, -1, - 47, 48, -1, -1, 130, 52, 53, -1, 55, 56, + 47, 48, -1, 129, 130, 52, 53, -1, 55, 56, 57, 58, 59, 60, -1, 62, 63, 64, 65, 66, 67, -1, -1, 70, -1, -1, 73, 74, 75, 76, 77, -1, -1, -1, 81, 82, 83, -1, -1, -1, @@ -1048,7 +1333,7 @@ static const yytype_int16 yycheck[] = -1, -1, 13, -1, -1, 16, 96, -1, 19, 20, 21, -1, -1, 24, 25, -1, -1, -1, 29, 30, -1, -1, -1, -1, -1, -1, -1, 117, 118, -1, - 120, -1, 122, 123, -1, -1, 47, 48, -1, 129, + 120, -1, 122, 123, -1, -1, 47, 48, -1, -1, 130, 52, 53, -1, 55, 56, 57, 58, 59, 60, -1, 62, 63, 64, 65, 66, 67, -1, -1, 70, -1, -1, 73, 74, 75, 76, 77, -1, -1, -1, @@ -1060,66 +1345,60 @@ static const yytype_int16 yycheck[] = 52, 53, -1, 55, 56, 57, 58, 59, 60, -1, 62, 63, 64, 65, 66, 67, -1, -1, 70, -1, -1, 73, 74, 75, 76, 77, -1, -1, -1, 81, - 82, 83, -1, -1, -1, -1, -1, 10, -1, -1, - 13, -1, -1, 16, 96, -1, 19, 20, 21, -1, - -1, 24, 25, -1, -1, -1, 29, 30, -1, -1, - -1, -1, -1, -1, -1, 117, 118, -1, 120, -1, - 122, 123, -1, -1, 47, 48, -1, -1, 130, 52, - 53, -1, 55, 56, 57, 58, 59, 60, -1, 62, - 63, 64, 65, 66, 67, -1, -1, 70, -1, -1, - 73, 74, 75, 76, 77, -1, -1, -1, 81, 82, - 83, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 96, -1, -1, -1, -1, -1, -1, - -1, -1, 71, -1, -1, -1, -1, -1, -1, 78, - 79, 80, -1, -1, 117, 118, -1, 120, -1, 122, - 123, -1, 91, -1, -1, -1, -1, 130, 97, 98, - 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, - 109, 110, 111, 112, 113, 114, 115, 116, -1, -1, - -1, -1, 121, 71, -1, 124, 125, 126, 127, 128, - 78, 79, 80, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 91, -1, -1, -1, -1, -1, 97, - 98, 99, -1, 101, 102, 103, 104, 105, 106, 107, + 82, 83, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 96, -1, -1, -1, -1, -1, + -1, -1, -1, 71, -1, -1, -1, -1, -1, -1, + 78, 79, 80, -1, -1, 117, 118, -1, 120, -1, + 122, 123, -1, 91, -1, -1, -1, -1, 130, 97, + 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, -1, -1, -1, 121, 71, -1, 124, 125, 126, 127, 128, 78, 79, 80, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 91, -1, -1, -1, 78, 79, + -1, -1, -1, -1, 91, -1, -1, -1, -1, -1, 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, -1, -1, -1, 121, 71, -1, 124, 125, 126, - 127, 128, 78, 79, 80, 115, 116, -1, -1, -1, - -1, 121, -1, -1, 124, 125, 126, 127, 128, -1, + 127, 128, 78, 79, 80, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 91, -1, -1, -1, -1, -1, 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, -1, -1, -1, 121, 71, -1, 124, 125, 126, 127, 128, 78, 79, 80, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, 99, -1, 101, 102, 103, 104, + -1, -1, 97, 98, 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, -1, -1, -1, -1, 121, 71, -1, 124, 125, 126, 127, 128, 78, 79, 80, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 101, 102, 103, + -1, -1, 78, 79, 80, 99, -1, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, - 114, 115, 116, 78, 79, 80, -1, 121, -1, -1, - 124, 125, 126, 127, 128, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 78, 79, 80, 104, - 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, - 115, 116, -1, -1, -1, -1, 121, -1, -1, 124, - 125, 126, 127, 128, 106, 107, 108, 109, 110, 111, + 114, 115, 116, -1, -1, -1, -1, 121, 71, -1, + 124, 125, 126, 127, 128, 78, 79, 80, 114, 115, + 116, -1, -1, -1, -1, 121, -1, -1, 124, 125, + 126, 127, 128, -1, -1, -1, -1, -1, 101, 102, + 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 78, 79, 80, -1, 121, -1, + -1, 124, 125, 126, 127, 128, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 78, 79, 80, + 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, + 114, 115, 116, -1, -1, -1, -1, 121, -1, -1, + 124, 125, 126, 127, 128, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 78, 79, 80, -1, + 121, -1, -1, 124, 125, 126, 127, 128, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 78, 79, 80, + -1, -1, -1, -1, -1, 107, 108, 109, 110, 111, + 112, 113, 114, 115, 116, -1, 78, 79, 80, 121, + -1, -1, 124, 125, 126, 127, 128, 108, 109, 110, + 111, 112, 113, 114, 115, 116, 78, 79, 80, -1, + 121, -1, -1, 124, 125, 126, 127, 128, 110, 111, 112, 113, 114, 115, 116, 78, 79, 80, -1, 121, -1, -1, 124, 125, 126, 127, 128, -1, -1, -1, - -1, -1, -1, -1, -1, -1, 78, 79, 80, -1, - -1, -1, -1, -1, 107, 108, 109, 110, 111, 112, - 113, 114, 115, 116, -1, 78, 79, 80, 121, -1, - -1, 124, 125, 126, 127, 128, 108, 109, 110, 111, 112, 113, 114, 115, 116, 78, 79, 80, -1, 121, - -1, -1, 124, 125, 126, 127, 128, 110, 111, 112, - 113, 114, 115, 116, 78, 79, 80, -1, 121, -1, - -1, 124, 125, 126, 127, 128, -1, -1, -1, 112, + -1, -1, 124, 125, 126, 127, 128, -1, -1, 112, 113, 114, 115, 116, -1, -1, -1, -1, 121, -1, - -1, 124, 125, 126, 127, 128, -1, -1, 112, 113, - 114, 115, 116, -1, -1, -1, -1, 121, -1, -1, - 124, 125, 126, 127, 128 + -1, 124, 125, 126, 127, 128, -1, -1, -1, -1, + 113, 114, 115, 116, -1, -1, -1, -1, 121, -1, + -1, 124, 125, 126, 127, 128 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing @@ -1132,67 +1411,67 @@ static const yytype_uint8 yystos[] = 52, 53, 55, 56, 57, 58, 59, 60, 62, 63, 64, 65, 66, 67, 70, 73, 74, 75, 76, 77, 81, 82, 83, 96, 117, 118, 120, 122, 123, 130, - 142, 203, 204, 205, 208, 209, 210, 211, 212, 213, - 214, 215, 216, 217, 219, 226, 234, 235, 236, 237, - 238, 239, 240, 241, 242, 11, 141, 1, 22, 26, + 142, 204, 205, 206, 209, 210, 211, 212, 213, 214, + 215, 216, 217, 218, 220, 227, 235, 236, 237, 238, + 239, 240, 241, 242, 243, 11, 141, 1, 22, 26, 27, 28, 31, 32, 35, 36, 37, 38, 40, 41, 42, 43, 46, 49, 50, 51, 54, 68, 72, 89, - 140, 141, 154, 168, 203, 223, 69, 152, 153, 154, - 142, 150, 197, 198, 150, 56, 61, 141, 235, 243, - 226, 243, 217, 243, 217, 243, 243, 217, 120, 130, - 220, 235, 236, 237, 217, 141, 217, 180, 180, 181, - 243, 243, 218, 13, 130, 217, 180, 217, 130, 130, - 87, 130, 141, 217, 56, 142, 204, 225, 235, 243, - 243, 226, 56, 61, 183, 204, 217, 217, 217, 217, - 217, 129, 203, 92, 93, 94, 95, 15, 11, 13, + 140, 141, 154, 168, 204, 224, 69, 152, 153, 154, + 142, 150, 197, 198, 150, 56, 61, 141, 236, 244, + 227, 244, 218, 244, 218, 244, 244, 218, 120, 130, + 221, 236, 237, 238, 218, 141, 218, 180, 180, 181, + 244, 244, 219, 13, 130, 218, 180, 218, 130, 130, + 87, 130, 141, 218, 56, 142, 205, 226, 236, 244, + 244, 227, 56, 61, 183, 205, 218, 218, 218, 218, + 218, 129, 204, 92, 93, 94, 95, 15, 11, 13, 130, 110, 111, 110, 108, 109, 108, 71, 78, 79, 80, 91, 97, 98, 99, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 121, 124, 125, 126, 127, 128, 130, 11, 13, - 11, 13, 11, 13, 11, 144, 182, 56, 56, 221, - 235, 236, 237, 130, 130, 30, 120, 130, 233, 235, + 11, 13, 11, 13, 11, 144, 182, 56, 56, 222, + 236, 237, 238, 130, 130, 30, 120, 130, 234, 236, 130, 130, 130, 130, 141, 11, 145, 145, 179, 183, 22, 179, 183, 39, 142, 170, 22, 32, 35, 36, 37, 38, 41, 22, 153, 154, 152, 16, 20, 24, - 142, 188, 189, 191, 192, 193, 194, 14, 130, 217, - 220, 235, 236, 237, 129, 203, 84, 186, 59, 142, - 184, 84, 142, 185, 185, 225, 130, 87, 203, 129, - 141, 129, 129, 203, 226, 226, 243, 204, 22, 225, - 13, 129, 203, 203, 203, 203, 217, 203, 203, 129, - 203, 217, 217, 217, 217, 217, 217, 217, 217, 217, - 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, - 217, 217, 217, 217, 217, 217, 217, 217, 217, 10, - 11, 13, 16, 20, 24, 25, 57, 81, 130, 207, - 235, 129, 203, 203, 203, 203, 203, 203, 203, 203, - 150, 56, 142, 178, 56, 56, 84, 142, 222, 144, - 144, 120, 144, 30, 231, 232, 234, 235, 236, 237, + 142, 188, 189, 191, 192, 193, 194, 14, 130, 218, + 221, 236, 237, 238, 129, 204, 84, 186, 59, 142, + 184, 84, 142, 185, 185, 226, 130, 87, 204, 129, + 141, 129, 129, 204, 227, 227, 244, 205, 22, 226, + 13, 129, 204, 204, 204, 204, 218, 204, 204, 129, + 204, 218, 218, 218, 218, 218, 218, 218, 218, 218, + 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, + 218, 218, 218, 218, 218, 218, 218, 218, 218, 10, + 11, 13, 16, 20, 24, 25, 57, 81, 130, 208, + 236, 129, 204, 204, 204, 204, 204, 204, 204, 204, + 150, 56, 142, 178, 56, 56, 84, 142, 223, 144, + 144, 120, 144, 30, 232, 233, 235, 236, 237, 238, 144, 144, 130, 144, 144, 144, 144, 146, 44, 158, - 179, 157, 179, 141, 167, 203, 167, 167, 175, 203, - 167, 167, 61, 187, 187, 15, 129, 203, 186, 129, - 59, 185, 59, 144, 202, 202, 226, 204, 14, 206, - 129, 88, 129, 203, 12, 203, 13, 22, 14, 129, - 100, 25, 203, 203, 25, 25, 25, 25, 25, 129, - 203, 130, 129, 22, 14, 22, 14, 22, 14, 22, - 12, 18, 143, 11, 22, 185, 59, 97, 176, 203, - 176, 130, 228, 235, 130, 142, 168, 173, 176, 177, - 203, 231, 144, 175, 174, 203, 176, 176, 150, 144, + 179, 157, 179, 141, 167, 204, 167, 167, 175, 204, + 167, 167, 61, 187, 187, 15, 129, 204, 186, 129, + 59, 185, 59, 144, 202, 202, 227, 205, 14, 207, + 129, 88, 129, 204, 12, 204, 13, 22, 14, 129, + 100, 25, 204, 204, 25, 25, 25, 25, 25, 129, + 204, 130, 129, 22, 14, 22, 14, 22, 14, 22, + 12, 18, 143, 11, 22, 185, 59, 97, 176, 204, + 176, 130, 229, 236, 130, 142, 168, 173, 176, 177, + 204, 232, 144, 175, 174, 204, 176, 176, 150, 144, 56, 155, 22, 144, 199, 200, 156, 97, 142, 190, 190, 192, 129, 200, 130, 142, 195, 196, 129, 23, - 142, 227, 225, 129, 14, 203, 12, 217, 22, 14, - 129, 226, 12, 12, 12, 12, 144, 144, 11, 22, - 224, 129, 129, 229, 230, 235, 130, 144, 129, 22, + 142, 228, 226, 129, 14, 204, 12, 218, 22, 14, + 129, 227, 12, 12, 12, 12, 144, 144, 11, 22, + 225, 129, 129, 230, 231, 236, 130, 144, 129, 22, 161, 176, 129, 129, 129, 129, 12, 130, 142, 147, - 56, 184, 11, 185, 217, 197, 11, 203, 88, 14, - 12, 129, 22, 163, 144, 217, 145, 145, 15, 129, + 56, 184, 11, 185, 218, 197, 11, 204, 88, 14, + 12, 129, 22, 163, 144, 218, 145, 145, 15, 129, 176, 176, 145, 159, 130, 129, 172, 172, 145, 145, - 148, 162, 225, 185, 150, 22, 201, 202, 129, 150, - 86, 150, 164, 33, 34, 142, 169, 169, 235, 130, - 129, 129, 170, 174, 176, 145, 145, 145, 235, 145, - 22, 199, 12, 12, 142, 151, 12, 150, 145, 130, + 148, 162, 226, 185, 150, 22, 201, 202, 129, 203, + 86, 150, 164, 33, 34, 142, 169, 169, 236, 130, + 129, 129, 170, 174, 176, 145, 145, 145, 236, 145, + 22, 199, 12, 150, 142, 151, 12, 150, 145, 130, 176, 145, 145, 22, 129, 170, 170, 170, 149, 45, - 171, 22, 59, 165, 12, 176, 129, 170, 170, 160, - 145, 129, 141, 17, 85, 142, 166, 129, 145, 172, - 170, 150, 145, 170, 177, 86, 169, 129, 145 + 171, 12, 22, 59, 165, 12, 176, 129, 170, 170, + 160, 145, 129, 141, 17, 85, 142, 166, 129, 145, + 172, 170, 150, 145, 170, 177, 86, 169, 129, 145 }; /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ @@ -1212,30 +1491,30 @@ static const yytype_uint8 yyr1[] = 183, 183, 184, 184, 185, 185, 185, 186, 186, 187, 187, 188, 188, 189, 190, 190, 190, 191, 192, 192, 193, 193, 193, 194, 194, 195, 195, 196, 198, 197, - 199, 199, 200, 201, 201, 202, 203, 203, 203, 203, - 203, 204, 204, 204, 205, 205, 205, 205, 205, 205, - 205, 205, 205, 206, 205, 207, 207, 208, 208, 208, - 208, 208, 208, 208, 208, 208, 208, 208, 208, 208, - 208, 209, 209, 209, 209, 209, 209, 209, 209, 209, + 199, 199, 200, 201, 201, 203, 202, 204, 204, 204, + 204, 204, 205, 205, 205, 206, 206, 206, 206, 206, + 206, 206, 206, 206, 207, 206, 208, 208, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, - 209, 209, 209, 210, 210, 210, 210, 210, 211, 211, - 212, 212, 212, 212, 213, 213, 214, 214, 214, 214, - 214, 214, 214, 214, 214, 215, 215, 215, 215, 215, - 216, 216, 217, 217, 217, 217, 217, 217, 217, 217, - 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, - 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, - 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, - 217, 217, 217, 217, 217, 217, 217, 217, 217, 217, - 218, 217, 217, 217, 217, 219, 219, 219, 219, 220, - 220, 220, 220, 220, 221, 221, 221, 222, 222, 222, - 223, 224, 223, 225, 225, 226, 226, 227, 227, 228, - 229, 229, 229, 230, 231, 231, 231, 232, 232, 233, - 233, 234, 235, 236, 237, 238, 238, 239, 240, 240, - 241, 241, 242, 242, 243, 243, 243, 243 + 209, 209, 210, 210, 210, 210, 210, 210, 210, 210, + 210, 210, 210, 210, 210, 210, 210, 210, 210, 210, + 210, 210, 210, 210, 211, 211, 211, 211, 211, 212, + 212, 213, 213, 213, 213, 214, 214, 215, 215, 215, + 215, 215, 215, 215, 215, 215, 216, 216, 216, 216, + 216, 217, 217, 218, 218, 218, 218, 218, 218, 218, + 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, + 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, + 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, + 218, 218, 218, 218, 218, 218, 218, 218, 218, 218, + 218, 219, 218, 218, 218, 218, 220, 220, 220, 220, + 221, 221, 221, 221, 221, 222, 222, 222, 223, 223, + 223, 224, 225, 224, 226, 226, 227, 227, 228, 228, + 229, 230, 230, 230, 231, 232, 232, 232, 233, 233, + 234, 234, 235, 236, 237, 238, 239, 239, 240, 241, + 241, 242, 242, 243, 243, 244, 244, 244, 244 }; /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = +static const yytype_int8 yyr2[] = { 0, 2, 0, 4, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 0, 3, 1, 1, 4, 0, @@ -1251,26 +1530,26 @@ static const yytype_uint8 yyr2[] = 1, 1, 1, 1, 1, 2, 1, 2, 1, 0, 1, 1, 1, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 1, 1, 1, 3, 0, 2, - 1, 1, 4, 1, 1, 5, 3, 3, 3, 3, - 1, 2, 3, 1, 3, 5, 6, 3, 3, 5, - 2, 4, 4, 0, 5, 1, 1, 5, 4, 5, - 4, 5, 6, 5, 4, 5, 4, 3, 6, 4, - 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 1, 1, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 1, 3, 2, 2, 3, 3, 3, - 1, 3, 2, 2, 3, 3, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 3, 4, 5, 4, 4, - 2, 2, 1, 1, 1, 1, 5, 2, 1, 2, - 3, 1, 2, 1, 1, 1, 1, 1, 1, 4, - 4, 5, 5, 1, 1, 3, 4, 3, 4, 4, - 4, 4, 4, 1, 2, 2, 1, 2, 2, 1, - 2, 1, 2, 1, 3, 1, 3, 1, 3, 4, - 0, 6, 1, 1, 1, 3, 2, 4, 3, 3, - 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, - 3, 0, 6, 1, 1, 1, 1, 1, 2, 1, - 2, 3, 1, 1, 1, 1, 1, 1, 1, 2, - 2, 2, 2, 2, 2, 2, 4, 2, 1, 3, - 1, 3, 1, 3, 1, 1, 1, 1 + 1, 1, 4, 1, 1, 0, 6, 3, 3, 3, + 3, 1, 2, 3, 1, 3, 5, 6, 3, 3, + 5, 2, 4, 4, 0, 5, 1, 1, 5, 4, + 5, 4, 5, 6, 5, 4, 5, 4, 3, 6, + 4, 5, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 1, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 1, 3, 2, 2, 3, 3, + 3, 1, 3, 2, 2, 3, 3, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 4, 5, 4, + 4, 2, 2, 1, 1, 1, 1, 5, 2, 1, + 2, 3, 1, 2, 1, 1, 1, 1, 1, 1, + 4, 4, 5, 5, 1, 1, 3, 4, 3, 4, + 4, 4, 4, 4, 1, 2, 2, 1, 2, 2, + 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, + 4, 0, 6, 1, 1, 1, 3, 2, 4, 3, + 3, 2, 1, 1, 1, 1, 1, 1, 2, 1, + 1, 3, 0, 6, 1, 1, 1, 1, 1, 2, + 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 4, 2, 1, + 3, 1, 3, 1, 3, 1, 1, 1, 1 }; typedef enum { @@ -1280,7 +1559,7 @@ typedef enum { /* type of each token/terminal */ static const toketypes yy_type_tab[] = { - toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, + toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, @@ -1290,7 +1569,7 @@ static const toketypes yy_type_tab[] = toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, - toketype_ival, toketype_ival, toketype_ival, toketype_ival, + toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_ival, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, @@ -1317,7 +1596,7 @@ static const toketypes yy_type_tab[] = toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_ival, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_ival, - toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, + toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_ival, toketype_opval, toketype_opval, toketype_opval, toketype_ival, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_opval, toketype_ival, toketype_opval, toketype_opval, toketype_pval, @@ -1328,6 +1607,6 @@ static const toketypes yy_type_tab[] = }; /* Generated from: - * 0a5fcd15cf0b7afb57ade6ceaf68037a38dd194acd9d60d3e4ad99c15233af75 perly.y + * 823630846fc59cc2a19502726ec723b568eabded55fdc5e9722c600e1098779e perly.y * acf1cbfd2545faeaaa58b1cf0cf9d7f98b5be0752eb7a54528ef904a9e2e1ca7 regen_perly.pl * ex: set ro ft=c: */ Index: gnu/usr.bin/perl/perly.y =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/perly.y,v diff -u -p -a -u -p -r1.22 perly.y --- gnu/usr.bin/perl/perly.y 14 May 2024 19:38:54 -0000 1.22 +++ gnu/usr.bin/perl/perly.y 22 Jan 2025 00:37:44 -0000 @@ -1056,7 +1056,9 @@ optsigsubbody ; /* Subroutine body with optional signature */ -sigsubbody: remember optsubsignature PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE +sigsubbody: remember optsubsignature PERLY_BRACE_OPEN + { PL_parser->sig_seen = FALSE; } + stmtseq PERLY_BRACE_CLOSE { if (parser->copline > (line_t)$PERLY_BRACE_OPEN) parser->copline = (line_t)$PERLY_BRACE_OPEN; @@ -1129,7 +1131,10 @@ listop : LSTOP indirob listexpr /* map { { $$ = op_convert_list($FUNC, 0, $optexpr); } | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */ { SvREFCNT_inc_simple_void(PL_compcv); - $$ = newANONATTRSUB($startanonsub, 0, NULL, $block); }[anonattrsub] + $$ = newANONATTRSUB($startanonsub, 0, NULL, $block); + /* prevent double op_free() if the following fails to parse */ + $block = NULL; + }[anonattrsub] optlistexpr %prec LSTOP /* ... @bar */ { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, op_append_elem(OP_LIST, @@ -1245,7 +1250,7 @@ termbinop: term[lhs] PLUGIN_HIGH_OP[op] | term[lhs] PLUGIN_LOGICAL_AND_OP[op] term[rhs] { $$ = build_infix_plugin($lhs, $rhs, $op); } | term[lhs] OROR term[rhs] /* $x || $y */ - { $$ = newLOGOP(OP_OR, 0, $lhs, $rhs); } + { $$ = newLOGOP($OROR, 0, $lhs, $rhs); } | term[lhs] PLUGIN_LOGICAL_OR_OP[op] term[rhs] { $$ = build_infix_plugin($lhs, $rhs, $op); } | term[lhs] DORDOR term[rhs] /* $x // $y */ Index: gnu/usr.bin/perl/pp.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/pp.c,v diff -u -p -a -u -p -r1.39 pp.c --- gnu/usr.bin/perl/pp.c 14 May 2024 19:39:39 -0000 1.39 +++ gnu/usr.bin/perl/pp.c 22 Jan 2025 00:37:45 -0000 @@ -36,10 +36,9 @@ PP(pp_stub) { - dSP; if (GIMME_V == G_SCALAR) - XPUSHs(&PL_sv_undef); - RETURN; + rpp_xpush_IMM(&PL_sv_undef); + return NORMAL; } /* Pushy stuff. */ @@ -48,10 +47,10 @@ PP(pp_stub) PP(pp_padcv) { - dSP; dTARGET; + dTARGET; assert(SvTYPE(TARG) == SVt_PVCV); - XPUSHs(TARG); - RETURN; + rpp_xpush_1(TARG); + return NORMAL; } PP(pp_introcv) @@ -187,9 +186,10 @@ S_rv2gv(pTHX_ SV *sv, const bool vivify_ return sv; } + PP(pp_rv2gv) { - dSP; dTOPss; + SV *sv = *PL_stack_sp; sv = S_rv2gv(aTHX_ sv, PL_op->op_private & OPpDEREF, @@ -199,14 +199,23 @@ PP(pp_rv2gv) ); if (PL_op->op_private & OPpLVAL_INTRO) save_gp(MUTABLE_GV(sv), !(PL_op->op_flags & OPf_SPECIAL)); - SETs(sv); - RETURN; + rpp_replace_1_1_NN(sv); + return NORMAL; } -/* Helper function for pp_rv2sv and pp_rv2av */ + +/* Helper function for pp_rv2sv and pp_rv2av/hv. + * + * Return a GV based on the value of sv, using symbolic references etc. + * On success: leaves argument on stack and returns gv. + * On failure: pops one item off stack; + * then unless (list context and not rv2sv), also pushes undef; + * then returns NULL. + */ + GV * Perl_softref2xv(pTHX_ SV *const sv, const char *const what, - const svtype type, SV ***spp) + const svtype type) { GV *gv; @@ -227,10 +236,10 @@ Perl_softref2xv(pTHX_ SV *const sv, cons if (ckWARN(WARN_UNINITIALIZED)) report_uninit(sv); if (type != SVt_PV && GIMME_V == G_LIST) { - (*spp)--; + rpp_popfree_1_NN(); return NULL; } - **spp = &PL_sv_undef; + rpp_replace_1_IMM_NN(&PL_sv_undef); return NULL; } if ((PL_op->op_flags & OPf_SPECIAL) && @@ -238,7 +247,7 @@ Perl_softref2xv(pTHX_ SV *const sv, cons { if (!(gv = gv_fetchsv_nomg(sv, GV_ADDMG, type))) { - **spp = &PL_sv_undef; + rpp_replace_1_IMM_NN(&PL_sv_undef); return NULL; } } @@ -250,7 +259,7 @@ Perl_softref2xv(pTHX_ SV *const sv, cons PP(pp_rv2sv) { - dSP; dTOPss; + SV *sv = *PL_stack_sp; GV *gv = NULL; SvGETMAGIC(sv); @@ -267,16 +276,16 @@ PP(pp_rv2sv) gv = MUTABLE_GV(sv); if (!isGV_with_GP(gv)) { - gv = Perl_softref2xv(aTHX_ sv, "a SCALAR", SVt_PV, &sp); + gv = Perl_softref2xv(aTHX_ sv, "a SCALAR", SVt_PV); if (!gv) - RETURN; + return NORMAL; } sv = GvSVn(gv); } if (PL_op->op_flags & OPf_MOD) { if (PL_op->op_private & OPpLVAL_INTRO) { if (cUNOP->op_first->op_type == OP_NULL) - sv = save_scalar(MUTABLE_GV(TOPs)); + sv = save_scalar(MUTABLE_GV(*PL_stack_sp)); else if (gv) sv = save_scalar(gv); else @@ -285,15 +294,13 @@ PP(pp_rv2sv) else if (PL_op->op_private & OPpDEREF) sv = vivify_ref(sv, PL_op->op_private & OPpDEREF); } - SPAGAIN; /* in case chasing soft refs reallocated the stack */ - SETs(sv); - RETURN; + rpp_replace_1_1_NN(sv); + return NORMAL; } PP(pp_av2arylen) { - dSP; - AV * const av = MUTABLE_AV(TOPs); + AV * const av = MUTABLE_AV(*PL_stack_sp); const I32 lvalue = PL_op->op_flags & OPf_MOD || LVRET; if (lvalue) { SV ** const svp = Perl_av_arylen_p(aTHX_ MUTABLE_AV(av)); @@ -301,46 +308,74 @@ PP(pp_av2arylen) *svp = newSV_type(SVt_PVMG); sv_magic(*svp, MUTABLE_SV(av), PERL_MAGIC_arylen, NULL, 0); } - SETs(*svp); + SV *sv_al = *svp; /* the temporary SV with arylen magic */ +#ifdef PERL_RC_STACK + if (SvREFCNT(av) == 1) { + /* At this point there are two SVs pointing at each other, + * av and sv_al. av -> sv_al is strong (MGf_REFCOUNTED), + * while sv_al -> av is weak, to avoid a leaking loop. + * + * The only thing keeping av alive right now is the ref from + * the stack. We want to swap av and sv_al on the stack, but + * that would trigger freeing av. So keep the ref counts and + * just swap the strong/weak pointer settings. + * + * XXX perhaps this should be done even for SvREFCNT(av)>1 ? + */ + MAGIC *mg_av = mg_find((const SV *)av, PERL_MAGIC_arylen_p); + MAGIC *mg_al = mg_find(sv_al, PERL_MAGIC_arylen); + assert(mg_av); + assert(mg_al); + assert( mg_av->mg_flags & MGf_REFCOUNTED); + assert(!(mg_al->mg_flags & MGf_REFCOUNTED)); + mg_av->mg_flags &= ~MGf_REFCOUNTED; + mg_al->mg_flags |= MGf_REFCOUNTED; + *PL_stack_sp = sv_al; + } + else +#endif + rpp_replace_1_1_NN(sv_al); } else { - SETs(sv_2mortal(newSViv(AvFILL(MUTABLE_AV(av))))); + SV *sv = newSViv(AvFILL(MUTABLE_AV(av))); + rpp_popfree_1(); + rpp_push_1_norc(sv); } - RETURN; + return NORMAL; } PP(pp_pos) { - dSP; dTOPss; + SV *sv = *PL_stack_sp; if (PL_op->op_flags & OPf_MOD || LVRET) { SV * const ret = newSV_type_mortal(SVt_PVLV);/* Not TARG RT#67838 */ sv_magic(ret, NULL, PERL_MAGIC_pos, NULL, 0); LvTYPE(ret) = '.'; LvTARG(ret) = SvREFCNT_inc_simple(sv); - SETs(ret); /* no SvSETMAGIC */ + rpp_replace_1_1_NN(ret); /* no SvSETMAGIC */ } else { const MAGIC * const mg = mg_find_mglob(sv); if (mg && mg->mg_len != -1) { STRLEN i = mg->mg_len; if (PL_op->op_private & OPpTRUEBOOL) - SETs(i ? &PL_sv_yes : &PL_sv_zero); + rpp_replace_1_IMM_NN(i ? &PL_sv_yes : &PL_sv_zero); else { dTARGET; if (mg->mg_flags & MGf_BYTES && DO_UTF8(sv)) i = sv_pos_b2u_flags(sv, i, SV_GMAGIC|SV_CONST_RETURN); - SETu(i); + TARGu(i,1); + rpp_replace_1_1_NN(targ); } return NORMAL; } - SETs(&PL_sv_undef); + rpp_replace_1_IMM_NN(&PL_sv_undef); } return NORMAL; } PP(pp_rv2cv) { - dSP; GV *gv; HV *stash_unused; const I32 flags = (PL_op->op_flags & OPf_SPECIAL) @@ -352,7 +387,7 @@ PP(pp_rv2cv) /* We usually try to add a non-existent subroutine in case of AUTOLOAD. */ /* (But not in defined().) */ - CV *cv = sv_2cv(TOPs, &stash_unused, &gv, flags); + CV *cv = sv_2cv(*PL_stack_sp, &stash_unused, &gv, flags); if (cv) NOOP; else if ((flags == (GV_ADD|GV_NOEXPAND)) && gv && SvROK(gv)) { cv = SvTYPE(SvRV(gv)) == SVt_PVCV @@ -361,26 +396,28 @@ PP(pp_rv2cv) } else cv = MUTABLE_CV(&PL_sv_undef); - SETs(MUTABLE_SV(cv)); + rpp_replace_1_1_NN(MUTABLE_SV(cv)); return NORMAL; } PP(pp_prototype) { - dSP; CV *cv; HV *stash; GV *gv; SV *ret = &PL_sv_undef; + SV *fn = *PL_stack_sp; + + if (SvGMAGICAL(fn)) + fn = sv_mortalcopy(fn); - if (SvGMAGICAL(TOPs)) SETs(sv_mortalcopy(TOPs)); - if (SvPOK(TOPs) && SvCUR(TOPs) >= 7) { - const char * s = SvPVX_const(TOPs); - if (memBEGINs(s, SvCUR(TOPs), "CORE::")) { - const int code = keyword(s + 6, SvCUR(TOPs) - 6, 1); + if (SvPOK(fn) && SvCUR(fn) >= 7) { + const char * s = SvPVX_const(fn); + if (memBEGINs(s, SvCUR(fn), "CORE::")) { + const int code = keyword(s + 6, SvCUR(fn) - 6, 1); if (!code) DIE(aTHX_ "Can't find an opnumber for \"%" UTF8f "\"", - UTF8fARG(SvFLAGS(TOPs) & SVf_UTF8, SvCUR(TOPs)-6, s+6)); + UTF8fARG(SvFLAGS(fn) & SVf_UTF8, SvCUR(fn)-6, s+6)); { SV * const sv = core_prototype(NULL, s + 6, code, NULL); if (sv) ret = sv; @@ -388,23 +425,21 @@ PP(pp_prototype) goto set; } } - cv = sv_2cv(TOPs, &stash, &gv, 0); + cv = sv_2cv(fn, &stash, &gv, 0); if (cv && SvPOK(cv)) ret = newSVpvn_flags( CvPROTO(cv), CvPROTOLEN(cv), SVs_TEMP | SvUTF8(cv) ); set: - SETs(ret); - RETURN; + rpp_replace_1_1_NN(ret); + return NORMAL; } PP(pp_anoncode) { - dSP; CV *cv = MUTABLE_CV(PAD_SV(PL_op->op_targ)); if (CvCLONE(cv)) cv = MUTABLE_CV(sv_2mortal(MUTABLE_SV(cv_clone(cv)))); - EXTEND(SP,1); SV* sv = MUTABLE_SV(cv); @@ -412,39 +447,58 @@ PP(pp_anoncode) sv = refto(sv); } - PUSHs(sv); - - RETURN; + rpp_xpush_1(sv); + return NORMAL; } PP(pp_srefgen) { - dSP; - *SP = refto(*SP); + rpp_replace_1_1_NN(refto(*PL_stack_sp)); return NORMAL; } + +/* \( ... list ... ) */ + PP(pp_refgen) { - dSP; dMARK; - if (GIMME_V != G_LIST) { - if (++MARK <= SP) - *MARK = *SP; - else - { - MEXTEND(SP, 1); - *MARK = &PL_sv_undef; + const U8 gimme = GIMME_V; + dMARK; + + if (gimme == G_VOID) + rpp_popfree_to_NN(mark); + else if (gimme == G_SCALAR) { + if (++mark < PL_stack_sp) { + /* 2+ args on stack: free all except top one */ + SV *topsv = *PL_stack_sp; + *PL_stack_sp = *mark; + *mark = topsv; + rpp_popfree_to_NN(mark); + } + else if (mark > PL_stack_sp) { + /* 0 args on stack */ + rpp_xpush_IMM(&PL_sv_undef); } - *MARK = refto(*MARK); - SP = MARK; - RETURN; + + rpp_replace_1_1_NN(refto(*PL_stack_sp)); } - EXTEND_MORTAL(SP - MARK); - while (++MARK <= SP) - *MARK = refto(*MARK); - RETURN; + else { + /* G_LIST */ + EXTEND_MORTAL(PL_stack_sp - MARK); /* refto() creates mortals */ + while (++MARK <= PL_stack_sp) { + SV *sv = *MARK; + SV *rv = refto(sv); +#ifdef PERL_RC_STACK + SvREFCNT_dec(sv); + SvREFCNT_inc(rv); +#endif + *MARK = rv; + } + } + return NORMAL; } + STATIC SV* S_refto(pTHX_ SV *sv) { @@ -482,12 +536,11 @@ S_refto(pTHX_ SV *sv) PP(pp_ref) { - dSP; - SV * const sv = TOPs; + SV * const sv = *PL_stack_sp; SvGETMAGIC(sv); if (!SvROK(sv)) { - SETs(&PL_sv_no); + rpp_replace_1_IMM_NN(&PL_sv_no); return NORMAL; } @@ -514,15 +567,15 @@ PP(pp_ref) goto do_sv_ref; } } - SETs(&PL_sv_yes); + rpp_replace_1_IMM_NN(&PL_sv_yes); return NORMAL; } do_sv_ref: { dTARGET; - SETs(TARG); sv_ref(TARG, SvRV(sv), TRUE); + rpp_replace_1_1_NN(TARG); SvSETMAGIC(TARG); return NORMAL; } @@ -532,8 +585,8 @@ PP(pp_ref) PP(pp_bless) { - dSP; HV *stash; + SV **sp = PL_stack_sp; if (MAXARG == 1) { @@ -543,11 +596,13 @@ PP(pp_bless) Perl_croak(aTHX_ "Attempt to bless into a freed package"); } else { - SV * const ssv = POPs; + SV * const ssv = *sp--; STRLEN len; const char *ptr; - if (!ssv) goto curstash; + if (!ssv) + goto curstash; + SvGETMAGIC(ssv); if (SvROK(ssv)) { if (!SvAMAGIC(ssv)) { @@ -567,18 +622,19 @@ PP(pp_bless) stash = gv_stashpvn(ptr, len, GV_ADD|SvUTF8(ssv)); } - (void)sv_bless(TOPs, stash); - RETURN; + (void)sv_bless(*sp, stash); + if (PL_stack_sp > sp) + rpp_popfree_1(); + return NORMAL; } + PP(pp_gelem) { - dSP; - - SV *sv = POPs; + SV *sv = PL_stack_sp[0]; STRLEN len; const char * const elem = SvPV_const(sv, len); - GV * const gv = MUTABLE_GV(TOPs); + GV * const gv = MUTABLE_GV(PL_stack_sp[-1]); SV * tmpRef = NULL; sv = NULL; @@ -641,34 +697,34 @@ PP(pp_gelem) sv_2mortal(sv); else sv = &PL_sv_undef; - SETs(sv); - RETURN; + rpp_replace_2_1_NN(sv); + return NORMAL; } /* Pattern matching */ PP(pp_study) { - dSP; dTOPss; + SV *sv = *PL_stack_sp; STRLEN len; (void)SvPV(sv, len); if (len == 0 || len > I32_MAX || !SvPOK(sv) || SvUTF8(sv) || SvVALID(sv)) { /* Historically, study was skipped in these cases. */ - SETs(&PL_sv_no); + rpp_replace_1_IMM_NN(&PL_sv_no); return NORMAL; } /* Make study a no-op. It's no longer useful and its existence complicates matters elsewhere. */ - SETs(&PL_sv_yes); + rpp_replace_1_IMM_NN(&PL_sv_yes); return NORMAL; } /* also used for: pp_transr() */ -PP(pp_trans) +PP_wrapped(pp_trans, ((PL_op->op_flags & OPf_STACKED) ? 1 : 0), 0) { dSP; SV *sv; @@ -711,9 +767,9 @@ S_do_chomp(pTHX_ SV *retval, SV *sv, boo if (chomping && (RsSNARF(PL_rs) || RsRECORD(PL_rs))) return 0; if (SvTYPE(sv) == SVt_PVAV) { - I32 i; + SSize_t i; AV *const av = MUTABLE_AV(sv); - const I32 max = AvFILL(av); + const SSize_t max = AvFILL(av); for (i = 0; i <= max; i++) { sv = MUTABLE_SV(av_fetch(av, i, FALSE)); @@ -812,9 +868,7 @@ S_do_chomp(pTHX_ SV *retval, SV *sv, boo if (s && len) { char * const send = s + len; char * const start = s; - s = send - 1; - while (s > start && UTF8_IS_CONTINUATION(*s)) - s--; + s = (char *) utf8_hop_back((U8 *) send, -1, (U8 *) start); if (is_utf8_string((U8*)s, send - s)) { sv_setpvn(retval, s, send - s); *s = '\0'; @@ -846,20 +900,21 @@ S_do_chomp(pTHX_ SV *retval, SV *sv, boo PP(pp_schop) { - dSP; dTARGET; + dTARGET; const bool chomping = PL_op->op_type == OP_SCHOMP; - const size_t count = do_chomp(TARG, TOPs, chomping); + const size_t count = do_chomp(TARG, *PL_stack_sp, chomping); if (chomping) sv_setiv(TARG, count); - SETTARG; + SvSETMAGIC(TARG); + rpp_replace_1_1_NN(TARG); return NORMAL; } /* also used for: pp_chomp() */ -PP(pp_chop) +PP_wrapped(pp_chop, 0, 1) { dSP; dMARK; dTARGET; dORIGMARK; const bool chomping = PL_op->op_type == OP_CHOMP; @@ -874,29 +929,35 @@ PP(pp_chop) RETURN; } + PP(pp_undef) { - dSP; SV *sv; if (!PL_op->op_private) { - EXTEND(SP, 1); - RETPUSHUNDEF; + rpp_xpush_IMM(&PL_sv_undef); + return NORMAL; } if (PL_op->op_private & OPpTARGET_MY) { + /* $lex = undef, or undef $lex */ SV** const padentry = &PAD_SVl(PL_op->op_targ); sv = *padentry; - EXTEND(SP,1);sp++;PUTBACK; - if ((PL_op->op_private & (OPpLVAL_INTRO|OPpPAD_STATE)) == OPpLVAL_INTRO) { + if (UNLIKELY((PL_op->op_flags & OPf_WANT) != OPf_WANT_VOID)) + rpp_xpush_1(sv); + if ((PL_op->op_private & (OPpLVAL_INTRO|OPpPAD_STATE)) + == OPpLVAL_INTRO) + { save_clearsv(padentry); } } else { - sv = TOPs; + sv = *PL_stack_sp; - if (!sv) - { - SETs(&PL_sv_undef); + if (!sv) { + /* sv is NULL when pp_undef is invoked like this: + * *myundef = \&CORE::undef; &myundef(); + */ + *PL_stack_sp = &PL_sv_undef; return NORMAL; } } @@ -987,10 +1048,13 @@ PP(pp_undef) } - if (PL_op->op_private & OPpTARGET_MY) - SETs(sv); - else - SETs(&PL_sv_undef); + if (!(PL_op->op_private & OPpTARGET_MY)) { + if (LIKELY((PL_op->op_flags & OPf_WANT) == OPf_WANT_VOID)) + rpp_popfree_1_NN(); + else + rpp_replace_1_1_NN(&PL_sv_undef); + } + return NORMAL; } @@ -1000,7 +1064,6 @@ PP(pp_undef) static OP * S_postincdec_common(pTHX_ SV *sv, SV *targ) { - dSP; const bool inc = PL_op->op_type == OP_POSTINC || PL_op->op_type == OP_I_POSTINC; @@ -1015,7 +1078,8 @@ S_postincdec_common(pTHX_ SV *sv, SV *ta /* special case for undef: see thread at 2003-03/msg00536.html in archive */ if (inc && !SvOK(TARG)) sv_setiv(TARG, 0); - SETTARG; + SvSETMAGIC(TARG); + rpp_replace_1_1_NN(TARG); return NORMAL; } @@ -1024,8 +1088,8 @@ S_postincdec_common(pTHX_ SV *sv, SV *ta PP(pp_postinc) { - dSP; dTARGET; - SV *sv = TOPs; + dTARGET; + SV *sv = *PL_stack_sp; /* special-case sv being a simple integer */ if (LIKELY(((sv->sv_flags & @@ -1037,7 +1101,7 @@ PP(pp_postinc) IV iv = SvIVX(sv); SvIV_set(sv, iv + 1); TARGi(iv, 0); /* arg not GMG, so can't be tainted */ - SETs(TARG); + rpp_replace_1_1_NN(TARG); return NORMAL; } @@ -1049,8 +1113,8 @@ PP(pp_postinc) PP(pp_postdec) { - dSP; dTARGET; - SV *sv = TOPs; + dTARGET; + SV *sv = *PL_stack_sp; /* special-case sv being a simple integer */ if (LIKELY(((sv->sv_flags & @@ -1062,7 +1126,7 @@ PP(pp_postdec) IV iv = SvIVX(sv); SvIV_set(sv, iv - 1); TARGi(iv, 0); /* arg not GMG, so can't be tainted */ - SETs(TARG); + rpp_replace_1_1_NN(TARG); return NORMAL; } @@ -1074,14 +1138,18 @@ PP(pp_postdec) PP(pp_pow) { - dSP; dATARGET; SV *svl, *svr; + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + if (rpp_try_AMAGIC_2(pow_amg, AMGf_assign|AMGf_numeric)) + return NORMAL; + + SV *svr = PL_stack_sp[0]; + SV *svl = PL_stack_sp[-1]; + #ifdef PERL_PRESERVE_IVUV bool is_int = 0; -#endif - tryAMAGICbin_MG(pow_amg, AMGf_assign|AMGf_numeric); - svr = TOPs; - svl = TOPm1s; -#ifdef PERL_PRESERVE_IVUV /* For integer to integer power, we do the calculation by hand wherever we're sure it is safe; otherwise we call pow() and try to convert to integer afterwards. */ @@ -1138,10 +1206,9 @@ PP(pp_pow) result *= base; } } - SP--; - SETn( result ); + TARGn(result, 1); SvIV_please_nomg(svr); - RETURN; + goto ret; } else { unsigned int highbit = 8 * sizeof(UV); unsigned int diff = 8 * sizeof(UV); @@ -1167,20 +1234,19 @@ PP(pp_pow) result *= base; } } - SP--; if (baseuok || !odd_power) /* answer is positive */ - SETu( result ); + TARGu(result, 1); else if (result <= (UV)IV_MAX) /* answer negative, fits in IV */ - SETi( -(IV)result ); + TARGi(-(IV)result, 1); else if (result == (UV)IV_MIN) /* 2's complement assumption: special case IV_MIN */ - SETi( IV_MIN ); + TARGi(IV_MIN, 1); else /* answer negative, doesn't fit */ - SETn( -(NV)result ); - RETURN; + TARGn(-(NV)result, 1); + goto ret; } } } @@ -1189,7 +1255,6 @@ PP(pp_pow) { NV right = SvNV_nomg(svr); NV left = SvNV_nomg(svl); - (void)POPs; #if defined(USE_LONG_DOUBLE) && defined(HAS_AIX_POWL_NEG_BASE_BUG) /* @@ -1218,14 +1283,14 @@ PP(pp_pow) if (left < 0.0) { NV mod2 = Perl_fmod( right, 2.0 ); if (mod2 == 1.0 || mod2 == -1.0) { /* odd integer */ - SETn( -Perl_pow( -left, right) ); + TARGn(-Perl_pow(-left, right), 1); } else if (mod2 == 0.0) { /* even integer */ - SETn( Perl_pow( -left, right) ); + TARGn(Perl_pow(-left, right), 1); } else { /* fractional power */ - SETn( NV_NAN ); + TARGn(NV_NAN, 1); } } else { - SETn( Perl_pow( left, right) ); + TARGn(Perl_pow(left, right), 1); } #elif IVSIZE == 4 && defined(LONGDOUBLE_DOUBLEDOUBLE) && defined(USE_LONG_DOUBLE) /* @@ -1237,28 +1302,38 @@ PP(pp_pow) */ if (is_int) { - SETn( roundl( Perl_pow( left, right) ) ); + TARGn(roundl(Perl_pow(left, right)), 1); } - else SETn( Perl_pow( left, right) ); + else + TARGn(Perl_pow(left, right), 1 ); #else - SETn( Perl_pow( left, right) ); + TARGn(Perl_pow(left, right), 1); #endif /* HAS_AIX_POWL_NEG_BASE_BUG */ #ifdef PERL_PRESERVE_IVUV if (is_int) SvIV_please_nomg(svr); #endif - RETURN; } + + ret: + rpp_replace_2_1_NN(targ); + return NORMAL; } + PP(pp_multiply) { - dSP; dATARGET; SV *svl, *svr; - tryAMAGICbin_MG(mult_amg, AMGf_assign|AMGf_numeric); - svr = TOPs; - svl = TOPm1s; + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + if (rpp_try_AMAGIC_2(mult_amg, AMGf_assign|AMGf_numeric)) + return NORMAL; + + SV *svr = PL_stack_sp[0]; + SV *svl = PL_stack_sp[-1]; #ifdef PERL_PRESERVE_IVUV @@ -1284,10 +1359,8 @@ PP(pp_multiply) ((topl+1) | (topr+1)) & ( (((UV)1) << (UVSIZE * 4 + 1)) - 2) /* 11..110 */ )) { - SP--; TARGi(il * ir, 0); /* args not GMG, so can't be tainted */ - SETs(TARG); - RETURN; + goto ret; } goto generic; } @@ -1301,7 +1374,6 @@ PP(pp_multiply) /* nothing was lost by converting to IVs */ goto do_iv; } - SP--; result = nl * nr; # if defined(__sgi) && defined(USE_LONG_DOUBLE) && LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE && NVSIZE == 16 if (Perl_isinf(result)) { @@ -1309,8 +1381,7 @@ PP(pp_multiply) } # endif TARGn(result, 0); /* args not GMG, so can't be tainted */ - SETs(TARG); - RETURN; + goto ret; } } @@ -1372,19 +1443,17 @@ PP(pp_multiply) const UV product = alow * blow; if (auvok == buvok) { /* -ve * -ve or +ve * +ve gives a +ve result. */ - SP--; - SETu( product ); - RETURN; + TARGu(product, 1); + goto ret; } else if (product <= (UV)IV_MIN) { /* 2s complement assumption that (UV)-IV_MIN is correct. */ /* -ve result, which could overflow an IV */ - SP--; /* can't negate IV_MIN, but there are aren't two * integers such that !ahigh && !bhigh, where the * product equals 0x800....000 */ assert(product != (UV)IV_MIN); - SETi( -(IV)product ); - RETURN; + TARGi(-(IV)product, 1); + goto ret; } /* else drop to NVs below. */ } else { /* One operand is large, 1 small */ @@ -1413,16 +1482,15 @@ PP(pp_multiply) /* didn't overflow */ if (auvok == buvok) { /* -ve * -ve or +ve * +ve gives a +ve result. */ - SP--; - SETu( product_low ); - RETURN; + TARGu(product_low, 1); + goto ret; } else if (product_low <= (UV)IV_MIN) { /* 2s complement assumption again */ /* -ve result, which could overflow an IV */ - SP--; - SETi(product_low == (UV)IV_MIN - ? IV_MIN : -(IV)product_low); - RETURN; + TARGi(product_low == (UV)IV_MIN + ? IV_MIN : -(IV)product_low, + 1); + goto ret; } /* else drop to NVs below. */ } } /* product_middle too large */ @@ -1435,23 +1503,33 @@ PP(pp_multiply) NV left = SvNV_nomg(svl); NV result = left * right; - (void)POPs; #if defined(__sgi) && defined(USE_LONG_DOUBLE) && LONG_DOUBLEKIND == LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE && NVSIZE == 16 if (Perl_isinf(result)) { Zero((U8*)&result + 8, 8, U8); } #endif - SETn(result); - RETURN; + TARGn(result, 1); + goto ret; } + + ret: + rpp_replace_2_1_NN(targ); + return NORMAL; } + PP(pp_divide) { - dSP; dATARGET; SV *svl, *svr; - tryAMAGICbin_MG(div_amg, AMGf_assign|AMGf_numeric); - svr = TOPs; - svl = TOPm1s; + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + if (rpp_try_AMAGIC_2(div_amg, AMGf_assign|AMGf_numeric)) + return NORMAL; + + SV *svr = PL_stack_sp[0]; + SV *svl = PL_stack_sp[-1]; + /* Only try to do UV divide first if ((SLOPPYDIVIDE is true) or (PERL_PRESERVE_IVUV is true and one or both SV is a UV too large @@ -1530,20 +1608,21 @@ PP(pp_divide) * modulo into a single div instruction */ const UV result = left / right; if (left % right == 0) { - SP--; /* result is valid */ + /* result is valid */ if (left_non_neg == right_non_neg) { /* signs identical, result is positive. */ - SETu( result ); - RETURN; + TARGu(result, 1); + goto ret; } /* 2s complement assumption */ if (result <= (UV)IV_MIN) - SETi(result == (UV)IV_MIN ? IV_MIN : -(IV)result); + TARGi(result == (UV)IV_MIN ? IV_MIN : -(IV)result, + 1); else { /* It's exact but too negative for IV. */ - SETn( -(NV)result ); + TARGn(-(NV)result, 1); } - RETURN; + goto ret; } /* tried integer divide but it was not an integer result */ } /* else (PERL_ABS(result) < 1.0) or (both UVs in range for NV) */ } /* one operand wasn't SvIOK */ @@ -1551,22 +1630,31 @@ PP(pp_divide) { NV right = SvNV_nomg(svr); NV left = SvNV_nomg(svl); - (void)POPs;(void)POPs; #if defined(NAN_COMPARE_BROKEN) && defined(Perl_isnan) if (! Perl_isnan(right) && right == 0.0) #else if (right == 0.0) #endif DIE(aTHX_ "Illegal division by zero"); - PUSHn( left / right ); - RETURN; + TARGn(left / right, 1); + goto ret; /* redundant, but silence -Wunused-label */ } + + ret: + rpp_replace_2_1_NN(targ); + return NORMAL; } + PP(pp_modulo) { - dSP; dATARGET; - tryAMAGICbin_MG(modulo_amg, AMGf_assign|AMGf_numeric); + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + if (rpp_try_AMAGIC_2(modulo_amg, AMGf_assign|AMGf_numeric)) + return NORMAL; + { UV left = 0; UV right = 0; @@ -1576,8 +1664,8 @@ PP(pp_modulo) bool dright_valid = FALSE; NV dright = 0.0; NV dleft = 0.0; - SV * const svr = TOPs; - SV * const svl = TOPm1s; + SV * const svr = PL_stack_sp[0]; + SV * const svl = PL_stack_sp[-1]; if (SvIV_please_nomg(svr)) { right_neg = !SvUOK(svr); if (!right_neg) { @@ -1588,7 +1676,7 @@ PP(pp_modulo) right = biv; right_neg = FALSE; /* effectively it's a UV now */ } else { - right = (UV) (0 - (UV) biv); + right = NEGATE_2UV(biv); } } } @@ -1618,7 +1706,7 @@ PP(pp_modulo) left = aiv; left_neg = FALSE; /* effectively it's a UV now */ } else { - left = (UV) (0 - (UV) aiv); + left = NEGATE_2UV(aiv); } } } @@ -1651,7 +1739,7 @@ PP(pp_modulo) } } } - sp -= 2; + if (use_double) { NV dans; @@ -1675,22 +1763,26 @@ PP(pp_modulo) if ((left_neg != right_neg) && ans) ans = right - ans; if (right_neg) { - /* XXX may warn: unary minus operator applied to unsigned type */ - /* could change -foo to be (~foo)+1 instead */ - if (ans <= ~((UV)IV_MAX)+1) - sv_setiv(TARG, ~ans+1); + if (ans <= ABS_IV_MIN) + sv_setiv(TARG, NEGATE_2IV(ans)); else sv_setnv(TARG, -(NV)ans); } else sv_setuv(TARG, ans); } - PUSHTARG; - RETURN; + + SvSETMAGIC(TARG); + rpp_replace_2_1_NN(targ); + return NORMAL; } } -PP(pp_repeat) + +PP_wrapped(pp_repeat, + /* two scalar args or one list */ + ((PL_op->op_private & OPpREPEAT_DOLIST) ? 0 : 2), + ((PL_op->op_private & OPpREPEAT_DOLIST) ? 1 : 0)) { dSP; dATARGET; IV count; @@ -1771,10 +1863,7 @@ PP(pp_repeat) if (count > 1) { SSize_t max; - if ( items > SSize_t_MAX / count /* max would overflow */ - /* repeatcpy would overflow */ - || items > I32_MAX / (I32)sizeof(SV *) - ) + if ( items > SSize_t_MAX / (SSize_t)sizeof(SV *) / count ) Perl_croak(aTHX_ "%s","Out of memory during list extend"); max = items * count; MEXTEND(MARK, max); @@ -1812,7 +1901,6 @@ PP(pp_repeat) STRLEN max; if ( len > (MEM_SIZE_MAX-1) / (UV)count /* max would overflow */ - || len > (U32)I32_MAX /* repeatcpy would overflow */ ) Perl_croak(aTHX_ "%s", "Out of memory during string extend"); @@ -1834,12 +1922,20 @@ PP(pp_repeat) RETURN; } + PP(pp_subtract) { - dSP; dATARGET; bool useleft; SV *svl, *svr; - tryAMAGICbin_MG(subtr_amg, AMGf_assign|AMGf_numeric); - svr = TOPs; - svl = TOPm1s; + bool useleft; + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + if (rpp_try_AMAGIC_2(subtr_amg, AMGf_assign|AMGf_numeric)) + return NORMAL; + + SV *svr = PL_stack_sp[0]; + SV *svl = PL_stack_sp[-1]; + #ifdef PERL_PRESERVE_IVUV @@ -1860,10 +1956,8 @@ PP(pp_subtract) * simple integer subtract: if the top of both numbers * are 00 or 11, then it's safe */ if (!( ((topl+1) | (topr+1)) & 2)) { - SP--; TARGi(il - ir, 0); /* args not GMG, so can't be tainted */ - SETs(TARG); - RETURN; + goto ret; } goto generic; } @@ -1876,10 +1970,8 @@ PP(pp_subtract) /* nothing was lost by converting to IVs */ goto do_iv; } - SP--; TARGn(nl - nr, 0); /* args not GMG, so can't be tainted */ - SETs(TARG); - RETURN; + goto ret; } } @@ -1966,20 +2058,20 @@ PP(pp_subtract) } } if (result_good) { - SP--; if (auvok) - SETu( result ); + TARGu(result, 1); else { /* Negate result */ if (result <= (UV)IV_MIN) - SETi(result == (UV)IV_MIN - ? IV_MIN : -(IV)result); + TARGi(result == (UV)IV_MIN + ? IV_MIN : -(IV)result, + 1); else { /* result valid, but out of range for IV. */ - SETn( -(NV)result ); + TARGn(-(NV)result, 1); } } - RETURN; + goto ret; } /* Overflow, drop through to NVs. */ } } @@ -1988,18 +2080,23 @@ PP(pp_subtract) #endif { NV value = SvNV_nomg(svr); - (void)POPs; if (!useleft) { /* left operand is undef, treat as zero - value */ - SETn(-value); - RETURN; + TARGn(-value, 1); + goto ret; } - SETn( SvNV_nomg(svl) - value ); - RETURN; + TARGn(SvNV_nomg(svl) - value, 1); + goto ret; } + + ret: + rpp_replace_2_1_NN(targ); + return NORMAL; + } + #define IV_BITS (IVSIZE * 8) /* Taking the right operand of bitwise shift operators, returns an int @@ -2066,150 +2163,166 @@ static IV S_iv_shift(IV iv, int shift, b PP(pp_left_shift) { - dSP; dATARGET; SV *svl, *svr; - tryAMAGICbin_MG(lshift_amg, AMGf_assign|AMGf_numeric); - svr = POPs; - svl = TOPs; + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + if (rpp_try_AMAGIC_2(lshift_amg, AMGf_assign|AMGf_numeric)) + return NORMAL; + + SV *svr = PL_stack_sp[0]; + SV *svl = PL_stack_sp[-1]; + { const int shift = S_shift_amount(aTHX_ svr); if (PL_op->op_private & OPpUSEINT) { - SETi(IV_LEFT_SHIFT(SvIV_nomg(svl), shift)); + TARGi(IV_LEFT_SHIFT(SvIV_nomg(svl), shift), 1); } else { - SETu(UV_LEFT_SHIFT(SvUV_nomg(svl), shift)); + TARGu(UV_LEFT_SHIFT(SvUV_nomg(svl), shift), 1); } - RETURN; + rpp_replace_2_1_NN(targ); + return NORMAL; } } + PP(pp_right_shift) { - dSP; dATARGET; SV *svl, *svr; - tryAMAGICbin_MG(rshift_amg, AMGf_assign|AMGf_numeric); - svr = POPs; - svl = TOPs; + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + if (rpp_try_AMAGIC_2(rshift_amg, AMGf_assign|AMGf_numeric)) + return NORMAL; + + SV *svr = PL_stack_sp[0]; + SV *svl = PL_stack_sp[-1]; + { const int shift = S_shift_amount(aTHX_ svr); if (PL_op->op_private & OPpUSEINT) { - SETi(IV_RIGHT_SHIFT(SvIV_nomg(svl), shift)); + TARGi(IV_RIGHT_SHIFT(SvIV_nomg(svl), shift), 1); } else { - SETu(UV_RIGHT_SHIFT(SvUV_nomg(svl), shift)); + TARGu(UV_RIGHT_SHIFT(SvUV_nomg(svl), shift), 1); } - RETURN; + rpp_replace_2_1_NN(targ); + return NORMAL; } } + PP(pp_lt) { - dSP; - SV *left, *right; - U32 flags_and, flags_or; + if (rpp_try_AMAGIC_2(lt_amg, AMGf_numeric)) + return NORMAL; - tryAMAGICbin_MG(lt_amg, AMGf_numeric); - right = POPs; - left = TOPs; - flags_and = SvFLAGS(left) & SvFLAGS(right); - flags_or = SvFLAGS(left) | SvFLAGS(right); + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; - SETs(boolSV( + U32 flags_and = SvFLAGS(left) & SvFLAGS(right); + U32 flags_or = SvFLAGS(left) | SvFLAGS(right); + + rpp_replace_2_IMM_NN(boolSV( ( (flags_and & SVf_IOK) && ((flags_or & SVf_IVisUV) ==0 ) ) ? (SvIVX(left) < SvIVX(right)) : (flags_and & SVf_NOK) ? (SvNVX(left) < SvNVX(right)) : (do_ncmp(left, right) == -1) )); - RETURN; + return NORMAL; } + PP(pp_gt) { - dSP; - SV *left, *right; - U32 flags_and, flags_or; + if (rpp_try_AMAGIC_2(gt_amg, AMGf_numeric)) + return NORMAL; - tryAMAGICbin_MG(gt_amg, AMGf_numeric); - right = POPs; - left = TOPs; - flags_and = SvFLAGS(left) & SvFLAGS(right); - flags_or = SvFLAGS(left) | SvFLAGS(right); + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + + U32 flags_and = SvFLAGS(left) & SvFLAGS(right); + U32 flags_or = SvFLAGS(left) | SvFLAGS(right); - SETs(boolSV( + rpp_replace_2_IMM_NN(boolSV( ( (flags_and & SVf_IOK) && ((flags_or & SVf_IVisUV) ==0 ) ) ? (SvIVX(left) > SvIVX(right)) : (flags_and & SVf_NOK) ? (SvNVX(left) > SvNVX(right)) : (do_ncmp(left, right) == 1) )); - RETURN; + return NORMAL; } + PP(pp_le) { - dSP; - SV *left, *right; - U32 flags_and, flags_or; + if (rpp_try_AMAGIC_2(le_amg, AMGf_numeric)) + return NORMAL; - tryAMAGICbin_MG(le_amg, AMGf_numeric); - right = POPs; - left = TOPs; - flags_and = SvFLAGS(left) & SvFLAGS(right); - flags_or = SvFLAGS(left) | SvFLAGS(right); + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + + U32 flags_and = SvFLAGS(left) & SvFLAGS(right); + U32 flags_or = SvFLAGS(left) | SvFLAGS(right); - SETs(boolSV( + rpp_replace_2_IMM_NN(boolSV( ( (flags_and & SVf_IOK) && ((flags_or & SVf_IVisUV) ==0 ) ) ? (SvIVX(left) <= SvIVX(right)) : (flags_and & SVf_NOK) ? (SvNVX(left) <= SvNVX(right)) : (do_ncmp(left, right) <= 0) )); - RETURN; + return NORMAL; } + PP(pp_ge) { - dSP; - SV *left, *right; - U32 flags_and, flags_or; + if (rpp_try_AMAGIC_2(ge_amg, AMGf_numeric)) + return NORMAL; - tryAMAGICbin_MG(ge_amg, AMGf_numeric); - right = POPs; - left = TOPs; - flags_and = SvFLAGS(left) & SvFLAGS(right); - flags_or = SvFLAGS(left) | SvFLAGS(right); + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; - SETs(boolSV( + U32 flags_and = SvFLAGS(left) & SvFLAGS(right); + U32 flags_or = SvFLAGS(left) | SvFLAGS(right); + + rpp_replace_2_IMM_NN(boolSV( ( (flags_and & SVf_IOK) && ((flags_or & SVf_IVisUV) ==0 ) ) ? (SvIVX(left) >= SvIVX(right)) : (flags_and & SVf_NOK) ? (SvNVX(left) >= SvNVX(right)) : ( (do_ncmp(left, right) & 2) == 0) )); - RETURN; + return NORMAL; } + PP(pp_ne) { - dSP; - SV *left, *right; - U32 flags_and, flags_or; + if (rpp_try_AMAGIC_2(ne_amg, AMGf_numeric)) + return NORMAL; - tryAMAGICbin_MG(ne_amg, AMGf_numeric); - right = POPs; - left = TOPs; - flags_and = SvFLAGS(left) & SvFLAGS(right); - flags_or = SvFLAGS(left) | SvFLAGS(right); + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + + U32 flags_and = SvFLAGS(left) & SvFLAGS(right); + U32 flags_or = SvFLAGS(left) | SvFLAGS(right); - SETs(boolSV( + rpp_replace_2_IMM_NN(boolSV( ( (flags_and & SVf_IOK) && ((flags_or & SVf_IVisUV) ==0 ) ) ? (SvIVX(left) != SvIVX(right)) : (flags_and & SVf_NOK) ? (SvNVX(left) != SvNVX(right)) : (do_ncmp(left, right) != 0) )); - RETURN; + return NORMAL; } + /* compare left and right SVs. Returns: * -1: < * 0: == @@ -2284,21 +2397,23 @@ Perl_do_ncmp(pTHX_ SV* const left, SV * PP(pp_ncmp) { - dSP; - SV *left, *right; - I32 value; - tryAMAGICbin_MG(ncmp_amg, AMGf_numeric); - right = POPs; - left = TOPs; - value = do_ncmp(left, right); + if (rpp_try_AMAGIC_2(ncmp_amg, AMGf_numeric)) + return NORMAL; + + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + + SV *targ; + I32 value = do_ncmp(left, right); if (value == 2) { - SETs(&PL_sv_undef); + targ = &PL_sv_undef; } else { - dTARGET; - SETi(value); + GETTARGET; + TARGi(value, 1); } - RETURN; + rpp_replace_2_1_NN(targ); + return NORMAL; } @@ -2306,8 +2421,6 @@ PP(pp_ncmp) PP(pp_sle) { - dSP; - int amg_type = sle_amg; int multiplier = 1; int rhs = 1; @@ -2331,128 +2444,175 @@ PP(pp_sle) break; } - tryAMAGICbin_MG(amg_type, 0); - { - dPOPTOPssrl; - const int cmp = + if (rpp_try_AMAGIC_2(amg_type, 0)) + return NORMAL; + + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + + const int cmp = #ifdef USE_LOCALE_COLLATE (IN_LC_RUNTIME(LC_COLLATE)) ? sv_cmp_locale_flags(left, right, 0) : #endif sv_cmp_flags(left, right, 0); - SETs(boolSV(cmp * multiplier < rhs)); - RETURN; - } + rpp_replace_2_IMM_NN(boolSV(cmp * multiplier < rhs)); + return NORMAL; } + PP(pp_seq) { - dSP; - tryAMAGICbin_MG(seq_amg, 0); - { - dPOPTOPssrl; - SETs(boolSV(sv_eq_flags(left, right, 0))); - RETURN; - } + if (rpp_try_AMAGIC_2(seq_amg, 0)) + return NORMAL; + + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + + rpp_replace_2_IMM_NN(boolSV(sv_eq_flags(left, right, 0)));; + return NORMAL; } + PP(pp_sne) { - dSP; - tryAMAGICbin_MG(sne_amg, 0); - { - dPOPTOPssrl; - SETs(boolSV(!sv_eq_flags(left, right, 0))); - RETURN; - } + if (rpp_try_AMAGIC_2(sne_amg, 0)) + return NORMAL; + + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + + rpp_replace_2_IMM_NN(boolSV(!sv_eq_flags(left, right, 0))); + return NORMAL; } + PP(pp_scmp) { - dSP; dTARGET; - tryAMAGICbin_MG(scmp_amg, 0); - { - dPOPTOPssrl; - const int cmp = + dTARGET; + + if (rpp_try_AMAGIC_2(scmp_amg, 0)) + return NORMAL; + + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + + const int cmp = #ifdef USE_LOCALE_COLLATE (IN_LC_RUNTIME(LC_COLLATE)) ? sv_cmp_locale_flags(left, right, 0) : #endif sv_cmp_flags(left, right, 0); - SETi( cmp ); - RETURN; - } + TARGi(cmp, 1); + rpp_replace_2_1_NN(targ); + return NORMAL; } + PP(pp_bit_and) { - dSP; dATARGET; - tryAMAGICbin_MG(band_amg, AMGf_assign); + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + if (rpp_try_AMAGIC_2(band_amg, AMGf_assign)) + return NORMAL; + + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + { - dPOPTOPssrl; if (SvNIOKp(left) || SvNIOKp(right)) { const bool left_ro_nonnum = !SvNIOKp(left) && SvREADONLY(left); const bool right_ro_nonnum = !SvNIOKp(right) && SvREADONLY(right); if (PL_op->op_private & OPpUSEINT) { const IV i = SvIV_nomg(left) & SvIV_nomg(right); - SETi(i); + TARGi(i, 1); } else { const UV u = SvUV_nomg(left) & SvUV_nomg(right); - SETu(u); + TARGu(u, 1); } if (left_ro_nonnum && left != TARG) SvNIOK_off(left); if (right_ro_nonnum) SvNIOK_off(right); } else { do_vop(PL_op->op_type, TARG, left, right); - SETTARG; + SvSETMAGIC(targ); + } - RETURN; } + rpp_replace_2_1_NN(targ); + return NORMAL; } + PP(pp_nbit_and) { - dSP; - tryAMAGICbin_MG(band_amg, AMGf_assign|AMGf_numarg); + if (rpp_try_AMAGIC_2(band_amg, AMGf_assign|AMGf_numarg)) + return NORMAL; + + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + { - dATARGET; dPOPTOPssrl; if (PL_op->op_private & OPpUSEINT) { const IV i = SvIV_nomg(left) & SvIV_nomg(right); - SETi(i); + TARGi(i, 1); } else { const UV u = SvUV_nomg(left) & SvUV_nomg(right); - SETu(u); + TARGu(u, 1); } } - RETURN; + rpp_replace_2_1_NN(targ); + return NORMAL; } + PP(pp_sbit_and) { - dSP; - tryAMAGICbin_MG(sband_amg, AMGf_assign); - { - dATARGET; dPOPTOPssrl; - do_vop(OP_BIT_AND, TARG, left, right); - RETSETTARG; - } + if (rpp_try_AMAGIC_2(sband_amg, AMGf_assign)) + return NORMAL; + + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + + do_vop(OP_BIT_AND, targ, left, right); + SvSETMAGIC(targ); + rpp_replace_2_1_NN(targ); + return NORMAL; } + /* also used for: pp_bit_xor() */ PP(pp_bit_or) { - dSP; dATARGET; + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + const int op_type = PL_op->op_type; - tryAMAGICbin_MG((op_type == OP_BIT_OR ? bor_amg : bxor_amg), AMGf_assign); + if (rpp_try_AMAGIC_2((op_type == OP_BIT_OR ? bor_amg : bxor_amg), + AMGf_assign)) + return NORMAL; + + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + { - dPOPTOPssrl; if (SvNIOKp(left) || SvNIOKp(right)) { const bool left_ro_nonnum = !SvNIOKp(left) && SvREADONLY(left); const bool right_ro_nonnum = !SvNIOKp(right) && SvREADONLY(right); @@ -2460,99 +2620,134 @@ PP(pp_bit_or) const IV l = (USE_LEFT(left) ? SvIV_nomg(left) : 0); const IV r = SvIV_nomg(right); const IV result = op_type == OP_BIT_OR ? (l | r) : (l ^ r); - SETi(result); + TARGi(result, 1); } else { const UV l = (USE_LEFT(left) ? SvUV_nomg(left) : 0); const UV r = SvUV_nomg(right); const UV result = op_type == OP_BIT_OR ? (l | r) : (l ^ r); - SETu(result); + TARGu(result, 1); } if (left_ro_nonnum && left != TARG) SvNIOK_off(left); if (right_ro_nonnum) SvNIOK_off(right); } else { do_vop(op_type, TARG, left, right); - SETTARG; + SvSETMAGIC(targ); } - RETURN; + rpp_replace_2_1_NN(targ); + return NORMAL; } } + /* also used for: pp_nbit_xor() */ PP(pp_nbit_or) { - dSP; const int op_type = PL_op->op_type; - tryAMAGICbin_MG((op_type == OP_NBIT_OR ? bor_amg : bxor_amg), - AMGf_assign|AMGf_numarg); + if (rpp_try_AMAGIC_2((op_type == OP_NBIT_OR ? bor_amg : bxor_amg), + AMGf_assign|AMGf_numarg)) + return NORMAL; + + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + { - dATARGET; dPOPTOPssrl; if (PL_op->op_private & OPpUSEINT) { const IV l = (USE_LEFT(left) ? SvIV_nomg(left) : 0); const IV r = SvIV_nomg(right); const IV result = op_type == OP_NBIT_OR ? (l | r) : (l ^ r); - SETi(result); + TARGi(result, 1); } else { const UV l = (USE_LEFT(left) ? SvUV_nomg(left) : 0); const UV r = SvUV_nomg(right); const UV result = op_type == OP_NBIT_OR ? (l | r) : (l ^ r); - SETu(result); + TARGu(result, 1); } } - RETURN; + rpp_replace_2_1_NN(targ); + return NORMAL; } + /* also used for: pp_sbit_xor() */ PP(pp_sbit_or) { - dSP; const int op_type = PL_op->op_type; - tryAMAGICbin_MG((op_type == OP_SBIT_OR ? sbor_amg : sbxor_amg), - AMGf_assign); - { - dATARGET; dPOPTOPssrl; - do_vop(op_type == OP_SBIT_OR ? OP_BIT_OR : OP_BIT_XOR, TARG, left, - right); - RETSETTARG; - } + if (rpp_try_AMAGIC_2((op_type == OP_SBIT_OR ? sbor_amg : sbxor_amg), + AMGf_assign)) + return NORMAL; + + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + + do_vop(op_type == OP_SBIT_OR ? OP_BIT_OR : OP_BIT_XOR, targ, + left, right); + + SvSETMAGIC(TARG); + rpp_replace_2_1_NN(targ); + return NORMAL; } + PERL_STATIC_INLINE bool S_negate_string(pTHX) { - dTARGET; dSP; + dTARGET; STRLEN len; const char *s; - SV * const sv = TOPs; - if (!SvPOKp(sv) || SvNIOK(sv) || (!SvPOK(sv) && SvNIOKp(sv))) + SV * const sv = *PL_stack_sp; + + assert(SvPOKp(sv)); + if (SvNIOK(sv) || (!SvPOK(sv) && SvNIOKp(sv))) return FALSE; + s = SvPV_nomg_const(sv, len); if (isIDFIRST(*s)) { - sv_setpvs(TARG, "-"); - sv_catsv(TARG, sv); + if (LIKELY(TARG!=sv)) { + sv_setpvs(TARG, "-"); + sv_catsv(TARG, sv); + } else { + sv_insert_flags(TARG, 0, 0, "-", 1, 0); + } } else if (*s == '+' || (*s == '-' && !looks_like_number(sv))) { sv_setsv_nomg(TARG, sv); *SvPV_force_nomg(TARG, len) = *s == '-' ? '+' : '-'; } else return FALSE; - SETTARG; + SvSETMAGIC(TARG); + if (LIKELY(targ != sv)) + rpp_replace_1_1_NN(TARG); return TRUE; } PP(pp_negate) { - dSP; dTARGET; - tryAMAGICun_MG(neg_amg, AMGf_numeric); - if (S_negate_string(aTHX)) return NORMAL; + dTARGET; + + if (rpp_try_AMAGIC_1(neg_amg, AMGf_numeric)) + return NORMAL; + + SV * const sv = *PL_stack_sp; + + if (SvPOKp(sv) && S_negate_string(aTHX)) + return NORMAL; + { - SV * const sv = TOPs; if (SvIOK(sv)) { /* It's publicly an integer */ @@ -2560,44 +2755,46 @@ PP(pp_negate) if (SvIsUV(sv)) { if (SvIVX(sv) == IV_MIN) { /* 2s complement assumption. */ - SETi(SvIVX(sv)); /* special case: -((UV)IV_MAX+1) == + TARGi(SvIVX(sv), 1);/* special case: -((UV)IV_MAX+1) == IV_MIN */ - return NORMAL; + goto ret; } else if (SvUVX(sv) <= IV_MAX) { - SETi(-SvIVX(sv)); - return NORMAL; + TARGi(-SvIVX(sv), 1); + goto ret; } } else if (SvIVX(sv) != IV_MIN) { - SETi(-SvIVX(sv)); - return NORMAL; + TARGi(-SvIVX(sv), 1); + goto ret; } #ifdef PERL_PRESERVE_IVUV else { - SETu((UV)IV_MIN); - return NORMAL; + TARGu((UV)IV_MIN, 1); + goto ret; } #endif } if (SvNIOKp(sv) && (SvNIOK(sv) || !SvPOK(sv))) - SETn(-SvNV_nomg(sv)); + TARGn(-SvNV_nomg(sv), 1); else if (SvPOKp(sv) && SvIV_please_nomg(sv)) goto oops_its_an_int; else - SETn(-SvNV_nomg(sv)); + TARGn(-SvNV_nomg(sv), 1); } + + ret: + if (LIKELY(targ != sv)) + rpp_replace_1_1_NN(TARG); return NORMAL; } + PP(pp_not) { - dSP; - SV *sv; - - tryAMAGICun_MG(not_amg, 0); - sv = *PL_stack_sp; - *PL_stack_sp = boolSV(!SvTRUE_nomg_NN(sv)); + if (rpp_try_AMAGIC_1(not_amg, 0)) + return NORMAL; + rpp_replace_1_IMM_NN(boolSV(!SvTRUE_nomg_NN(*PL_stack_sp))); return NORMAL; } @@ -2605,7 +2802,7 @@ static void S_scomplement(pTHX_ SV *targ, SV *sv) { U8 *tmps; - I32 anum; + SSize_t anum; STRLEN len; sv_copypv_nomg(TARG, sv); @@ -2626,7 +2823,7 @@ S_scomplement(pTHX_ SV *targ, SV *sv) for ( ; anum && PTR2nat(tmps) % sizeof(long); anum--, tmps++) *tmps = ~*tmps; tmpl = (long*)tmps; - for ( ; anum >= (I32)sizeof(long); anum -= (I32)sizeof(long), tmpl++) + for ( ; anum >= (SSize_t)sizeof(long); anum -= (SSize_t)sizeof(long), tmpl++) *tmpl = ~*tmpl; tmps = (U8*)tmpl; } @@ -2637,204 +2834,271 @@ S_scomplement(pTHX_ SV *targ, SV *sv) PP(pp_complement) { - dSP; dTARGET; - tryAMAGICun_MG(compl_amg, AMGf_numeric); + dTARGET; + if (rpp_try_AMAGIC_1(compl_amg, AMGf_numeric)) + return NORMAL; + { - dTOPss; + SV *sv = *PL_stack_sp; if (SvNIOKp(sv)) { if (PL_op->op_private & OPpUSEINT) { const IV i = ~SvIV_nomg(sv); - SETi(i); + TARGi(i, 1); } else { const UV u = ~SvUV_nomg(sv); - SETu(u); + TARGu(u, 1); } } else { S_scomplement(aTHX_ TARG, sv); - SETTARG; + SvSETMAGIC(TARG); } + + rpp_replace_1_1_NN(TARG); return NORMAL; } } PP(pp_ncomplement) { - dSP; - tryAMAGICun_MG(compl_amg, AMGf_numeric|AMGf_numarg); + if (rpp_try_AMAGIC_1(compl_amg, AMGf_numeric|AMGf_numarg)) + return NORMAL; + + dTARGET; { - dTARGET; dTOPss; + SV *sv = *PL_stack_sp; if (PL_op->op_private & OPpUSEINT) { const IV i = ~SvIV_nomg(sv); - SETi(i); + TARGi(i, 1); } else { const UV u = ~SvUV_nomg(sv); - SETu(u); + TARGu(u, 1); } } + + rpp_replace_1_1_NN(TARG); return NORMAL; } PP(pp_scomplement) { - dSP; - tryAMAGICun_MG(scompl_amg, AMGf_numeric); - { - dTARGET; dTOPss; - S_scomplement(aTHX_ TARG, sv); - SETTARG; + if (rpp_try_AMAGIC_1(scompl_amg, AMGf_numeric)) return NORMAL; - } + + dTARGET; + SV *sv = *PL_stack_sp; + S_scomplement(aTHX_ TARG, sv); + SvSETMAGIC(TARG); + rpp_replace_1_1_NN(TARG); + return NORMAL; } + /* integer versions of some of the above */ PP(pp_i_multiply) { - dSP; dATARGET; - tryAMAGICbin_MG(mult_amg, AMGf_assign); - { - dPOPTOPiirl_nomg; - SETi( (IV)((UV)left * (UV)right) ); - RETURN; - } + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + if (rpp_try_AMAGIC_2(mult_amg, AMGf_assign)) + return NORMAL; + + IV right = SvIV_nomg(PL_stack_sp[0]); + IV left = SvIV_nomg(PL_stack_sp[-1]); + + TARGi((IV)((UV)left * (UV)right), 1); + rpp_replace_2_1_NN(targ); + return NORMAL; } + PP(pp_i_divide) { - IV num; - dSP; dATARGET; - tryAMAGICbin_MG(div_amg, AMGf_assign); + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + if (rpp_try_AMAGIC_2(div_amg, AMGf_assign)) + return NORMAL; + + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + { - dPOPTOPssrl; IV value = SvIV_nomg(right); if (value == 0) DIE(aTHX_ "Illegal division by zero"); - num = SvIV_nomg(left); + IV num = SvIV_nomg(left); /* avoid FPE_INTOVF on some platforms when num is IV_MIN */ if (value == -1) value = (IV)-(UV)num; else value = num / value; - SETi(value); - RETURN; + TARGi(value, 1); + rpp_replace_2_1_NN(targ); + return NORMAL; } } + PP(pp_i_modulo) { - dSP; dATARGET; - tryAMAGICbin_MG(modulo_amg, AMGf_assign); + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + if (rpp_try_AMAGIC_2(modulo_amg, AMGf_assign)) + return NORMAL; + + IV right = SvIV_nomg(PL_stack_sp[0]); + IV left = SvIV_nomg(PL_stack_sp[-1]); + { - dPOPTOPiirl_nomg; if (!right) DIE(aTHX_ "Illegal modulus zero"); /* avoid FPE_INTOVF on some platforms when left is IV_MIN */ if (right == -1) - SETi( 0 ); + TARGi(0, 1); else - SETi( left % right ); - RETURN; + TARGi(left % right, 1); } + rpp_replace_2_1_NN(targ); + return NORMAL; } + PP(pp_i_add) { - dSP; dATARGET; - tryAMAGICbin_MG(add_amg, AMGf_assign); - { - dPOPTOPiirl_ul_nomg; - SETi( (IV)((UV)left + (UV)right) ); - RETURN; - } + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + if (rpp_try_AMAGIC_2(add_amg, AMGf_assign)) + return NORMAL; + + IV right = SvIV_nomg(PL_stack_sp[0]); + SV *leftsv = PL_stack_sp[-1]; + IV left = USE_LEFT(leftsv) ? SvIV_nomg(leftsv) : 0; + + TARGi((IV)((UV)left + (UV)right), 1); + rpp_replace_2_1_NN(targ); + return NORMAL; } + PP(pp_i_subtract) { - dSP; dATARGET; - tryAMAGICbin_MG(subtr_amg, AMGf_assign); - { - dPOPTOPiirl_ul_nomg; - SETi( (IV)((UV)left - (UV)right) ); - RETURN; - } + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + if (rpp_try_AMAGIC_2(subtr_amg, AMGf_assign)) + return NORMAL; + + IV right = SvIV_nomg(PL_stack_sp[0]); + SV *leftsv = PL_stack_sp[-1]; + IV left = USE_LEFT(leftsv) ? SvIV_nomg(leftsv) : 0; + + TARGi((IV)((UV)left - (UV)right), 1); + rpp_replace_2_1_NN(targ); + return NORMAL; } + PP(pp_i_lt) { - dSP; - tryAMAGICbin_MG(lt_amg, 0); - { - dPOPTOPiirl_nomg; - SETs(boolSV(left < right)); - RETURN; - } + if (rpp_try_AMAGIC_2(lt_amg, 0)) + return NORMAL; + + IV right = SvIV_nomg(PL_stack_sp[0]); + IV left = SvIV_nomg(PL_stack_sp[-1]); + + rpp_replace_2_IMM_NN(boolSV(left < right)); + return NORMAL; } + PP(pp_i_gt) { - dSP; - tryAMAGICbin_MG(gt_amg, 0); - { - dPOPTOPiirl_nomg; - SETs(boolSV(left > right)); - RETURN; - } + if (rpp_try_AMAGIC_2(gt_amg, 0)) + return NORMAL; + + IV right = SvIV_nomg(PL_stack_sp[0]); + IV left = SvIV_nomg(PL_stack_sp[-1]); + + rpp_replace_2_IMM_NN(boolSV(left > right)); + return NORMAL; } + PP(pp_i_le) { - dSP; - tryAMAGICbin_MG(le_amg, 0); - { - dPOPTOPiirl_nomg; - SETs(boolSV(left <= right)); - RETURN; - } + if (rpp_try_AMAGIC_2(le_amg, 0)) + return NORMAL; + + IV right = SvIV_nomg(PL_stack_sp[0]); + IV left = SvIV_nomg(PL_stack_sp[-1]); + + rpp_replace_2_IMM_NN(boolSV(left <= right)); + return NORMAL; } + PP(pp_i_ge) { - dSP; - tryAMAGICbin_MG(ge_amg, 0); - { - dPOPTOPiirl_nomg; - SETs(boolSV(left >= right)); - RETURN; - } + if (rpp_try_AMAGIC_2(ge_amg, 0)) + return NORMAL; + + IV right = SvIV_nomg(PL_stack_sp[0]); + IV left = SvIV_nomg(PL_stack_sp[-1]); + + rpp_replace_2_IMM_NN(boolSV(left >= right)); + return NORMAL; } + PP(pp_i_eq) { - dSP; - tryAMAGICbin_MG(eq_amg, 0); - { - dPOPTOPiirl_nomg; - SETs(boolSV(left == right)); - RETURN; - } + if (rpp_try_AMAGIC_2(eq_amg, 0)) + return NORMAL; + + IV right = SvIV_nomg(PL_stack_sp[0]); + IV left = SvIV_nomg(PL_stack_sp[-1]); + + rpp_replace_2_IMM_NN(boolSV(left == right)); + return NORMAL; } + PP(pp_i_ne) { - dSP; - tryAMAGICbin_MG(ne_amg, 0); - { - dPOPTOPiirl_nomg; - SETs(boolSV(left != right)); - RETURN; - } + if (rpp_try_AMAGIC_2(ne_amg, 0)) + return NORMAL; + + IV right = SvIV_nomg(PL_stack_sp[0]); + IV left = SvIV_nomg(PL_stack_sp[-1]); + + rpp_replace_2_IMM_NN(boolSV(left != right)); + return NORMAL; } + PP(pp_i_ncmp) { - dSP; dTARGET; - tryAMAGICbin_MG(ncmp_amg, 0); + dTARGET; + if (rpp_try_AMAGIC_2(ncmp_amg, 0)) + return NORMAL; + + IV right = SvIV_nomg(PL_stack_sp[0]); + IV left = SvIV_nomg(PL_stack_sp[-1]); + + { - dPOPTOPiirl_nomg; I32 value; if (left > right) @@ -2843,35 +3107,46 @@ PP(pp_i_ncmp) value = -1; else value = 0; - SETi(value); - RETURN; + TARGi(value, 1); } + rpp_replace_2_1_NN(targ); + return NORMAL; } PP(pp_i_negate) { - dSP; dTARGET; - tryAMAGICun_MG(neg_amg, 0); - if (S_negate_string(aTHX)) return NORMAL; + dTARGET; + if (rpp_try_AMAGIC_1(neg_amg, 0)) + return NORMAL; + + SV * const sv = *PL_stack_sp; + + if (SvPOKp(sv) && S_negate_string(aTHX)) + return NORMAL; { - SV * const sv = TOPs; IV const i = SvIV_nomg(sv); - SETi((IV)-(UV)i); + TARGi((IV)-(UV)i, 1); + if (LIKELY(targ != sv)) + rpp_replace_1_1_NN(TARG); return NORMAL; } } + /* High falutin' math. */ PP(pp_atan2) { - dSP; dTARGET; - tryAMAGICbin_MG(atan2_amg, 0); - { - dPOPTOPnnrl_nomg; - SETn(Perl_atan2(left, right)); - RETURN; - } + dTARGET; + if (rpp_try_AMAGIC_2(atan2_amg, 0)) + return NORMAL; + + NV right = SvNV_nomg(PL_stack_sp[0]); + NV left = SvNV_nomg(PL_stack_sp[-1]); + + TARGn(Perl_atan2(left, right), 1); + rpp_replace_2_1_NN(targ); + return NORMAL; } @@ -2879,7 +3154,7 @@ PP(pp_atan2) PP(pp_sin) { - dSP; dTARGET; + dTARGET; int amg_type = fallback_amg; const char *neg_report = NULL; const int op_type = PL_op->op_type; @@ -2894,9 +3169,11 @@ PP(pp_sin) assert(amg_type != fallback_amg); - tryAMAGICun_MG(amg_type, 0); + if (rpp_try_AMAGIC_1(amg_type, 0)) + return NORMAL; + { - SV * const arg = TOPs; + SV * const arg = *PL_stack_sp; const NV value = SvNV_nomg(arg); #ifdef NV_NAN NV result = NV_NAN; @@ -2928,7 +3205,8 @@ PP(pp_sin) case OP_LOG: result = Perl_log(value); break; case OP_SQRT: result = Perl_sqrt(value); break; } - SETn(result); + TARGn(result, 1); + rpp_replace_1_1_NN(TARG); return NORMAL; } } @@ -2944,7 +3222,7 @@ PP(pp_sin) --Jarkko Hietaniemi 27 September 1998 */ -PP(pp_rand) +PP_wrapped(pp_rand, MAXARG, 0) { if (!PL_srand_called) { Rand_seed_t s; @@ -2995,7 +3273,7 @@ PP(pp_rand) return NORMAL; } -PP(pp_srand) +PP_wrapped(pp_srand, MAXARG, 0) { dSP; dTARGET; UV anum; @@ -3043,10 +3321,11 @@ PP(pp_srand) PP(pp_int) { - dSP; dTARGET; - tryAMAGICun_MG(int_amg, AMGf_numeric); + dTARGET; + if (rpp_try_AMAGIC_1(int_amg, AMGf_numeric)) + return NORMAL; { - SV * const sv = TOPs; + SV * const sv = *PL_stack_sp; const IV iv = SvIV_nomg(sv); /* XXX it's arguable that compiler casting to IV might be subtly different from modf (for numbers inside (IV_MIN,UV_MAX)) in which @@ -3054,43 +3333,46 @@ PP(pp_int) relying on floating point to be accurate is a bug. */ if (!SvOK(sv)) { - SETu(0); + TARGu(0, 1); } else if (SvIOK(sv)) { if (SvIsUV(sv)) - SETu(SvUV_nomg(sv)); + TARGu(SvUV_nomg(sv), 1); else - SETi(iv); + TARGi(iv, 1); } else { const NV value = SvNV_nomg(sv); if (UNLIKELY(Perl_isinfnan(value))) - SETn(value); + TARGn(value, 1); else if (value >= 0.0) { if (value < (NV)UV_MAX + 0.5) { - SETu(U_V(value)); + TARGu(U_V(value), 1); } else { - SETn(Perl_floor(value)); + TARGn(Perl_floor(value), 1); } } else { if (value > (NV)IV_MIN - 0.5) { - SETi(I_V(value)); + TARGi(I_V(value), 1); } else { - SETn(Perl_ceil(value)); + TARGn(Perl_ceil(value), 1); } } } } + rpp_replace_1_1_NN(TARG); return NORMAL; } PP(pp_abs) { - dSP; dTARGET; - tryAMAGICun_MG(abs_amg, AMGf_numeric); + dTARGET; + if (rpp_try_AMAGIC_1(abs_amg, AMGf_numeric)) + return NORMAL; + { - SV * const sv = TOPs; + SV * const sv = *PL_stack_sp; /* This will cache the NV value if string isn't actually integer */ const IV iv = SvIV_nomg(sv); UV uv; @@ -3116,12 +3398,14 @@ PP(pp_abs) } } set_uv: - SETu(uv); + TARGu(uv, 1); } else{ const NV value = SvNV_nomg(sv); - SETn(Perl_fabs(value)); + TARGn(Perl_fabs(value), 1); } } + + rpp_replace_1_1_NN(TARG); return NORMAL; } @@ -3130,13 +3414,13 @@ PP(pp_abs) PP(pp_oct) { - dSP; dTARGET; + dTARGET; const char *tmps; I32 flags = PERL_SCAN_ALLOW_UNDERSCORES; STRLEN len; NV result_nv; UV result_uv; - SV* const sv = TOPs; + SV* const sv = *PL_stack_sp; tmps = (SvPV_const(sv, len)); if (DO_UTF8(sv)) { @@ -3174,11 +3458,13 @@ PP(pp_oct) } if (flags & PERL_SCAN_GREATER_THAN_UV_MAX) { - SETn(result_nv); + TARGn(result_nv, 1); } else { - SETu(result_uv); + TARGu(result_uv, 1); } + + rpp_replace_1_1_NN(TARG); return NORMAL; } @@ -3187,8 +3473,8 @@ PP(pp_oct) PP(pp_length) { - dSP; dTARGET; - SV * const sv = TOPs; + dTARGET; + SV * const sv = *PL_stack_sp; U32 in_bytes = IN_BYTES; /* Simplest case shortcut: @@ -3199,7 +3485,6 @@ PP(pp_length) U32 svflags = (SvFLAGS(sv) ^ (in_bytes << 26)) & (SVf_POK|SVs_GMG|SVf_UTF8); STATIC_ASSERT_STMT(SVf_UTF8 == (HINT_BYTES << 26)); - SETs(TARG); if (LIKELY(svflags == SVf_POK)) goto simple_pv; @@ -3226,7 +3511,7 @@ PP(pp_length) len = SvCUR(sv); if (PL_op->op_private & OPpTRUEBOOL) { return_bool: - SETs(len ? &PL_sv_yes : &PL_sv_zero); + rpp_replace_1_IMM_NN(len ? &PL_sv_yes : &PL_sv_zero); return NORMAL; } } @@ -3243,12 +3528,11 @@ PP(pp_length) SvSETMAGIC(TARG); } else - /* TARG is on stack at this point and is overwritten by SETs. - * This branch is the odd one out, so put TARG by default on - * stack earlier to let local SP go out of liveness sooner */ - SETs(&PL_sv_undef); + targ = &PL_sv_undef; } - return NORMAL; /* no putback, SP didn't move in this opcode */ + + rpp_replace_1_1_NN(TARG); + return NORMAL; } @@ -3319,7 +3603,10 @@ Perl_translate_substr_offsets( STRLEN cu return TRUE; } -PP(pp_substr) +PP_wrapped(pp_substr, + (PL_op->op_private & 7) + + ((PL_op->op_private & OPpSUBSTR_REPL_FIRST) ? 1 : 0), + 0) { dSP; dTARGET; SV *sv; @@ -3459,7 +3746,7 @@ PP(pp_substr) RETPUSHUNDEF; } -PP(pp_vec) +PP_wrapped(pp_vec, 3, 0) { dSP; const IV size = POPi; @@ -3518,7 +3805,9 @@ PP(pp_vec) PP(pp_index) { - dSP; dTARGET; + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); SV *big; SV *little; SV *temp = NULL; @@ -3531,12 +3820,24 @@ PP(pp_index) bool big_utf8; bool little_utf8; const bool is_index = PL_op->op_type == OP_INDEX; - const bool threeargs = MAXARG >= 3 && (TOPs || ((void)POPs,0)); - if (threeargs) - offset = POPi; - little = POPs; - big = POPs; + assert(MAXARG == 2 || MAXARG == 3); + + bool threeargs = (MAXARG == 3); + if (MAXARG == 3 && !PL_stack_sp[0]) { + /* pp_coreargs pushes a NULL in order to flag that &CORE::index() + * was called with two args */ + PL_stack_sp--; + threeargs = FALSE; + } + + if (threeargs) { + offset = SvIV(*PL_stack_sp); + rpp_popfree_1_NN(); + } + + little = PL_stack_sp[0]; + big = PL_stack_sp[-1]; big_p = SvPV_const(big, biglen); little_p = SvPV_const(little, llen); @@ -3623,52 +3924,56 @@ PP(pp_index) if (PL_op->op_private & OPpTRUEBOOL) { SV *result = ((retval != -1) ^ cBOOL(PL_op->op_private & OPpINDEX_BOOLNEG)) ? &PL_sv_yes : &PL_sv_no; - if (PL_op->op_private & OPpTARGET_MY) { + if (PL_op->op_private & OPpTARGET_MY) /* $lex = (index() == -1) */ - sv_setsv_mg(TARG, result); - PUSHs(TARG); - } - else { - PUSHs(result); - } + sv_setsv_mg(targ, result); + else + targ = result; } else - PUSHi(retval); - RETURN; + TARGi(retval, 1); + + rpp_replace_2_1_NN(targ); + return NORMAL; } + PP(pp_sprintf) { - dSP; dMARK; dORIGMARK; dTARGET; + dMARK; dORIGMARK; dTARGET; SvTAINTED_off(TARG); - do_sprintf(TARG, SP-MARK, MARK+1); + do_sprintf(TARG, PL_stack_sp - MARK, MARK + 1); TAINT_IF(SvTAINTED(TARG)); - SP = ORIGMARK; - PUSHTARG; - RETURN; + rpp_popfree_to_NN(ORIGMARK); + SvSETMAGIC(TARG); + rpp_push_1(TARG); + return NORMAL; } + PP(pp_ord) { - dSP; dTARGET; + dTARGET; - SV *argsv = TOPs; + SV *argsv = *PL_stack_sp; STRLEN len; const U8 *s = (U8*)SvPV_const(argsv, len); - SETu(DO_UTF8(argsv) + TARGu(DO_UTF8(argsv) ? (len ? utf8n_to_uvchr(s, len, 0, UTF8_ALLOW_ANYUV) : 0) - : (UV)(*s)); + : (UV)(*s), + 1); + rpp_replace_1_1_NN(TARG); return NORMAL; } PP(pp_chr) { - dSP; dTARGET; + dTARGET; char *tmps; UV value; - SV *top = TOPs; + SV *top = *PL_stack_sp; SvGETMAGIC(top); if (UNLIKELY(SvAMAGIC(top))) @@ -3706,8 +4011,7 @@ PP(pp_chr) *tmps = '\0'; (void)SvPOK_only(TARG); SvUTF8_on(TARG); - SETTARG; - return NORMAL; + goto ret; } SvGROW(TARG,2); @@ -3717,15 +4021,19 @@ PP(pp_chr) *tmps = '\0'; (void)SvPOK_only(TARG); - SETTARG; + ret: + SvSETMAGIC(TARG); + rpp_replace_1_1_NN(TARG); return NORMAL; } + PP(pp_crypt) { #ifdef HAS_CRYPT - dSP; dTARGET; - dPOPTOPssrl; + dTARGET; + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; STRLEN len; const char *tmps = SvPV_const(left, len); @@ -3758,21 +4066,23 @@ PP(pp_crypt) sv_setpv(TARG, PerlProc_crypt(tmps, SvPV_nolen_const(right))); SvUTF8_off(TARG); - SETTARG; - RETURN; + SvSETMAGIC(TARG); + rpp_replace_2_1_NN(targ); + return NORMAL; #else DIE(aTHX_ "The crypt() function is unimplemented due to excessive paranoia."); #endif } + /* Generally UTF-8 and UTF-EBCDIC are indistinguishable at this level. So * most comments below say UTF-8, when in fact they mean UTF-EBCDIC as well */ /* also used for: pp_lcfirst() */ -PP(pp_ucfirst) +PP_wrapped(pp_ucfirst, 1, 0) { /* Actually is both lcfirst() and ucfirst(). Only the first character * changes. This means that possibly we can change in-place, ie., just @@ -4120,7 +4430,8 @@ PP(pp_ucfirst) return NORMAL; } -PP(pp_uc) + +PP_wrapped(pp_uc, 1, 0) { dSP; SV *source = TOPs; @@ -4444,7 +4755,7 @@ PP(pp_uc) return NORMAL; } -PP(pp_lc) +PP_wrapped(pp_lc, 1, 0) { dSP; SV *source = TOPs; @@ -4663,8 +4974,8 @@ PP(pp_lc) PP(pp_quotemeta) { - dSP; dTARGET; - SV * const sv = TOPs; + dTARGET; + SV * const sv = *PL_stack_sp; STRLEN len; const char *s = SvPV_const(sv,len); @@ -4735,11 +5046,13 @@ PP(pp_quotemeta) } else sv_setpvn(TARG, s, len); - SETTARG; + + SvSETMAGIC(TARG); + rpp_replace_1_1_NN(TARG); return NORMAL; } -PP(pp_fc) +PP_wrapped(pp_fc, 1, 0) { dTARGET; dSP; @@ -4949,10 +5262,11 @@ PP(pp_fc) /* Arrays. */ + PP(pp_aslice) { - dSP; dMARK; dORIGMARK; - AV *const av = MUTABLE_AV(POPs); + dMARK; dORIGMARK; + AV *const av = MUTABLE_AV(*PL_stack_sp); const I32 lval = (PL_op->op_flags & OPf_MOD || LVRET); if (SvTYPE(av) == SVt_PVAV) { @@ -4969,7 +5283,7 @@ PP(pp_aslice) if (lval && localizing) { SV **svp; SSize_t max = -1; - for (svp = MARK + 1; svp <= SP; svp++) { + for (svp = MARK + 1; svp < PL_stack_sp; svp++) { const SSize_t elem = SvIV(*svp); if (elem > max) max = elem; @@ -4978,7 +5292,7 @@ PP(pp_aslice) av_extend(av, max); } - while (++MARK <= SP) { + while (++MARK < PL_stack_sp) { SV **svp; SSize_t elem = SvIV(*MARK); bool preeminent = TRUE; @@ -5002,23 +5316,25 @@ PP(pp_aslice) SAVEADELETE(av, elem); } } - *MARK = svp ? *svp : &PL_sv_undef; + + rpp_replace_at_NN(MARK, svp ? *svp : &PL_sv_undef); } } - if (GIMME_V != G_LIST) { - MARK = ORIGMARK; - *++MARK = SP > ORIGMARK ? *SP : &PL_sv_undef; - SP = MARK; - } - RETURN; + + rpp_context(ORIGMARK, GIMME_V, 1); + return NORMAL; } + +/* %ary[1,3,5] */ + PP(pp_kvaslice) { - dSP; dMARK; - AV *const av = MUTABLE_AV(POPs); + dMARK; dORIGMARK; + /* leave av on stack for now to avoid leak on croak */ + AV *const av = MUTABLE_AV(*PL_stack_sp); I32 lval = (PL_op->op_flags & OPf_MOD); - SSize_t items = SP - MARK; + SSize_t items = PL_stack_sp - MARK - 1; if (PL_op->op_private & OPpMAYBE_LVSUB) { const I32 flags = is_lvalue_sub(); @@ -5030,15 +5346,24 @@ PP(pp_kvaslice) } } - MEXTEND(SP,items); - while (items > 1) { - *(MARK+items*2-1) = *(MARK+items); - items--; + rpp_extend(items); + MARK = ORIGMARK; + + /* move av from old top-of-stack to new top-of-stack */ + PL_stack_sp[items] = PL_stack_sp[0]; + PL_stack_sp[0] = NULL; + + /* spread the index SVs out to every second location */ + SSize_t i = items; + while (i > 1) { + *(MARK+i*2-1) = *(MARK+i); + *(MARK+i*2) = NULL; + *(MARK+i) = NULL; + i--; } - items = SP-MARK; - SP += items; + PL_stack_sp += items; - while (++MARK <= SP) { + while (++MARK < PL_stack_sp) { SV **svp; svp = av_fetch(av, SvIV(*MARK), lval); @@ -5046,20 +5371,29 @@ PP(pp_kvaslice) if (!svp || !*svp || *svp == &PL_sv_undef) { DIE(aTHX_ PL_no_aelem, SvIV(*MARK)); } - *MARK = sv_mortalcopy(*MARK); + /* replace key SV with a copy */ + SV *oldsv = *MARK; + SV *newsv = newSVsv(oldsv); +#ifdef PERL_RC_STACK + *MARK = newsv; + SvREFCNT_dec(oldsv); +#else + *MARK = sv_2mortal(newsv); +#endif } - *++MARK = svp ? *svp : &PL_sv_undef; - } - if (GIMME_V != G_LIST) { - MARK = SP - items*2; - *++MARK = items > 0 ? *SP : &PL_sv_undef; - SP = MARK; + + MARK++; + rpp_replace_at(MARK, svp ? *svp : &PL_sv_undef); } - RETURN; + + /* pop AV, then apply void/scalar/list context to stack above mark */ + rpp_context(ORIGMARK, GIMME_V, 1); + return NORMAL; } -PP(pp_aeach) + +PP_wrapped(pp_aeach, 1, 0) { dSP; AV *array = MUTABLE_AV(POPs); @@ -5085,7 +5419,7 @@ PP(pp_aeach) } /* also used for: pp_avalues()*/ -PP(pp_akeys) +PP_wrapped(pp_akeys, 1, 0) { dSP; AV *array = MUTABLE_AV(POPs); @@ -5132,7 +5466,7 @@ PP(pp_akeys) /* Associative arrays. */ -PP(pp_each) +PP_wrapped(pp_each, 1, 0) { dSP; HV * hash = MUTABLE_HV(POPs); @@ -5268,7 +5602,9 @@ S_do_delete_local(pTHX) RETURN; } -PP(pp_delete) +PP_wrapped(pp_delete, + ((PL_op->op_private & (OPpSLICE|OPpKVSLICE)) ? 0 : 2), + ((PL_op->op_private & (OPpSLICE|OPpKVSLICE)) ? 1 : 0)) { dSP; U8 gimme; @@ -5346,7 +5682,7 @@ PP(pp_delete) RETURN; } -PP(pp_exists) +PP_wrapped(pp_exists, ((PL_op->op_private & OPpEXISTS_SUB) ? 1 : 2), 0) { dSP; SV *tmpsv; @@ -5410,9 +5746,8 @@ PP(pp_exists) PP(pp_helemexistsor) { - dSP; - SV *keysv = POPs; - HV *hv = MUTABLE_HV(POPs); + SV *keysv = PL_stack_sp[0]; + HV *hv = MUTABLE_HV(PL_stack_sp[-1]); bool is_delete = PL_op->op_private & OPpHELEMEXISTSOR_DELETE; assert(SvTYPE(hv) == SVt_PVHV); @@ -5444,18 +5779,21 @@ PP(pp_helemexistsor) if(!val) { other: - PUTBACK; + rpp_popfree_2_NN(); return cLOGOP->op_other; } - PUSHs(val); - RETURN; + rpp_replace_2_1_NN(val); + return NORMAL; } + +/* @hash{'foo', 'bar'} */ + PP(pp_hslice) { - dSP; dMARK; dORIGMARK; - HV * const hv = MUTABLE_HV(POPs); + dMARK; dORIGMARK; + HV * const hv = MUTABLE_HV(*PL_stack_sp); const I32 lval = (PL_op->op_flags & OPf_MOD || LVRET); const bool localizing = PL_op->op_private & OPpLVAL_INTRO; bool can_preserve = FALSE; @@ -5468,7 +5806,7 @@ PP(pp_hslice) can_preserve = TRUE; } - while (++MARK <= SP) { + while (++MARK < PL_stack_sp) { SV * const keysv = *MARK; SV **svp; HE *he; @@ -5499,22 +5837,24 @@ PP(pp_hslice) SAVEHDELETE(hv, keysv); } } - *MARK = svp && *svp ? *svp : &PL_sv_undef; - } - if (GIMME_V != G_LIST) { - MARK = ORIGMARK; - *++MARK = SP > ORIGMARK ? *SP : &PL_sv_undef; - SP = MARK; + + rpp_replace_at_NN(MARK, svp && *svp ? *svp : &PL_sv_undef); } - RETURN; + + rpp_context(ORIGMARK, GIMME_V, 1); + return NORMAL; } + +/* %hash{'foo', 'bar'} */ + PP(pp_kvhslice) { - dSP; dMARK; - HV * const hv = MUTABLE_HV(POPs); + dMARK; dORIGMARK; + /* leave hv on stack for now to avoid leak on croak */ + HV * const hv = MUTABLE_HV(*PL_stack_sp); I32 lval = (PL_op->op_flags & OPf_MOD); - SSize_t items = SP - MARK; + SSize_t items = PL_stack_sp - MARK - 1; if (PL_op->op_private & OPpMAYBE_LVSUB) { const I32 flags = is_lvalue_sub(); @@ -5527,15 +5867,24 @@ PP(pp_kvhslice) } } - MEXTEND(SP,items); - while (items > 1) { - *(MARK+items*2-1) = *(MARK+items); - items--; + rpp_extend(items); + MARK = ORIGMARK; + + /* move hv from old top-of-stack to new top-of-stack */ + PL_stack_sp[items] = PL_stack_sp[0]; + PL_stack_sp[0] = NULL; + + /* spread the key SVs out to every second location */ + SSize_t i = items; + while (i > 1) { + *(MARK+i*2-1) = *(MARK+i); + *(MARK+i*2) = NULL; + *(MARK+i) = NULL; + i--; } - items = SP-MARK; - SP += items; + PL_stack_sp += items; - while (++MARK <= SP) { + while (++MARK < PL_stack_sp) { SV * const keysv = *MARK; SV **svp; HE *he; @@ -5547,40 +5896,39 @@ PP(pp_kvhslice) if (!svp || !*svp || *svp == &PL_sv_undef) { DIE(aTHX_ PL_no_helem_sv, SVfARG(keysv)); } - *MARK = sv_mortalcopy(*MARK); + /* replace key SV with a copy */ + SV *oldsv = *MARK; + SV *newsv = newSVsv(oldsv); +#ifdef PERL_RC_STACK + *MARK = newsv; + SvREFCNT_dec(oldsv); +#else + *MARK = sv_2mortal(newsv); +#endif } - *++MARK = svp && *svp ? *svp : &PL_sv_undef; - } - if (GIMME_V != G_LIST) { - MARK = SP - items*2; - *++MARK = items > 0 ? *SP : &PL_sv_undef; - SP = MARK; + + MARK++; + rpp_replace_at(MARK, (svp && *svp) ? *svp : &PL_sv_undef); } - RETURN; + + /* pop HV, then apply void/scalar/list context to stack above mark */ + rpp_context(ORIGMARK, GIMME_V, 1); + return NORMAL; } + /* List operators. */ + PP(pp_list) { - I32 markidx = POPMARK; - if (GIMME_V != G_LIST) { - /* don't initialize mark here, EXTEND() may move the stack */ - SV **mark; - dSP; - EXTEND(SP, 1); /* in case no arguments, as in @empty */ - mark = PL_stack_base + markidx; - if (++MARK <= SP) - *MARK = *SP; /* unwanted list, return last item */ - else - *MARK = &PL_sv_undef; - SP = MARK; - PUTBACK; - } + dMARK; + rpp_context(mark, GIMME_V, 0); return NORMAL; } -PP(pp_lslice) + +PP_wrapped(pp_lslice, 0, 2) { dSP; SV ** const lastrelem = PL_stack_sp; @@ -5589,7 +5937,7 @@ PP(pp_lslice) SV ** const firstrelem = lastlelem + 1; const U8 mod = PL_op->op_flags & OPf_MOD; - const I32 max = lastrelem - lastlelem; + const SSize_t max = lastrelem - lastlelem; SV **lelem; if (GIMME_V != G_LIST) { @@ -5598,7 +5946,7 @@ PP(pp_lslice) *firstlelem = &PL_sv_undef; } else { - I32 ix = SvIV(*lastlelem); + SSize_t ix = SvIV(*lastlelem); if (ix < 0) ix += max; if (ix < 0 || ix >= max) @@ -5616,7 +5964,7 @@ PP(pp_lslice) } for (lelem = firstlelem; lelem <= lastlelem; lelem++) { - I32 ix = SvIV(*lelem); + SSize_t ix = SvIV(*lelem); if (ix < 0) ix += max; if (ix < 0 || ix >= max) @@ -5633,23 +5981,29 @@ PP(pp_lslice) RETURN; } + PP(pp_anonlist) { - dSP; dMARK; - const I32 items = SP - MARK; + dMARK; + const SSize_t items = PL_stack_sp - MARK; SV * const av = MUTABLE_SV(av_make(items, MARK+1)); - SP = MARK; - mXPUSHs((PL_op->op_flags & OPf_SPECIAL) - ? newRV_noinc(av) : av); - RETURN; + /* attach new SV to stack before freeing everything else, + * so no leak on croak */ + rpp_extend(1); + SV *sv = (PL_op->op_flags & OPf_SPECIAL) ? newRV_noinc(av) : (SV*)av; + rpp_push_1_norc(sv); /* this handles ref count and/or mortalising */ + PL_stack_sp[0] = PL_stack_sp[-items]; + PL_stack_sp[-items] = sv; + rpp_popfree_to_NN(PL_stack_sp - items); + return NORMAL; } + /* When an anonlist or anonhash will (1) be empty and (2) return an RV * pointing to the new AV/HV, the peephole optimizer can swap in this * simpler function and op_null the originally associated PUSHMARK. */ PP(pp_emptyavhv) { - dSP; OP * const op = PL_op; SV * rv; SV * const sv = MUTABLE_SV( newSV_type( @@ -5674,42 +6028,55 @@ PP(pp_emptyavhv) save_clearsv(padentry); } if (GIMME_V == G_VOID) { - RETURN; /* skip extending and pushing */ + return NORMAL; /* skip extending and pushing */ } + rpp_xpush_1(rv); } else { /* Inlined newRV_noinc */ - SV * refsv = newSV_type_mortal(SVt_IV); + SV * refsv = newSV_type(SVt_IV); SvRV_set(refsv, sv); SvROK_on(refsv); - - rv = refsv; + rpp_extend(1); + rpp_push_1_norc(refsv); } - - XPUSHs(rv); - RETURN; + return NORMAL; /* skip extending and pushing */ } + +/* return { list }; + * without OPf_SPECIAL, return hash rather than hash ref */ + PP(pp_anonhash) { - dSP; dMARK; dORIGMARK; + dMARK; dORIGMARK; HV* const hv = newHV(); - SV* const retval = sv_2mortal( PL_op->op_flags & OPf_SPECIAL + SV* const retval = (PL_op->op_flags & OPf_SPECIAL) ? newRV_noinc(MUTABLE_SV(hv)) - : MUTABLE_SV(hv) ); - /* This isn't quite true for an odd sized list (it's one too few) but it's - not worth the runtime +1 just to optimise for the warning case. */ - SSize_t pairs = (SP - MARK) >> 1; + : MUTABLE_SV(hv); + /* + 1 because a lone scalar {FOO} counts as a {FOO => undef} pair */ + const SSize_t pairs = (PL_stack_sp - MARK + 1) >> 1; + + /* temporarily save the hv/hvref at the top of the stack to + * avoid possible premature free */ + rpp_extend(1); + rpp_push_1_norc(retval); + MARK = ORIGMARK; /* in case stack was reallocated */ + + if (pairs == 0) + return NORMAL; + if (pairs > PERL_HASH_DEFAULT_HvMAX) { hv_ksplit(hv, pairs); } - while (MARK < SP) { - SV * const key = - (MARK++, SvGMAGICAL(*MARK) ? sv_mortalcopy(*MARK) : *MARK); + while (++MARK < PL_stack_sp) { + SV *key = *MARK; + if (SvGMAGICAL(key)) + key = sv_mortalcopy(key); + SV *val; - if (MARK < SP) + if (++MARK < PL_stack_sp) { - MARK++; SvGETMAGIC(*MARK); val = newSV_type(SVt_NULL); sv_setsv_nomg(val, *MARK); @@ -5721,12 +6088,18 @@ PP(pp_anonhash) } (void)hv_store_ent(hv,key,val,0); } - SP = ORIGMARK; - XPUSHs(retval); - RETURN; + + /* swap the HV (which is at the top of stack) with the first key + * (which is at the bottom of the stack frame), then free everything + * above it */ + *PL_stack_sp = ORIGMARK[1]; + ORIGMARK[1] = retval; + rpp_popfree_to_NN(ORIGMARK+1); + return NORMAL; } -PP(pp_splice) + +PP_wrapped(pp_splice, 0, 1) { dSP; dMARK; dORIGMARK; int num_args = (SP - MARK); @@ -5943,29 +6316,35 @@ PP(pp_splice) RETURN; } + PP(pp_push) { - dSP; dMARK; dORIGMARK; dTARGET; + dMARK; dORIGMARK; dTARGET; AV * const ary = MUTABLE_AV(*++MARK); const MAGIC * const mg = SvTIED_mg((const SV *)ary, PERL_MAGIC_tied); if (mg) { - *MARK-- = SvTIED_obj(MUTABLE_SV(ary), mg); - PUSHMARK(MARK); - PUTBACK; ENTER_with_name("call_PUSH"); + SV *obj = SvTIED_obj(MUTABLE_SV(ary), mg); +#ifdef PERL_RC_STACK + /* keep ary alive as it's replaced on the stack with obj */ + SAVEFREESV(MUTABLE_SV(ary)); + SvREFCNT_inc_simple_void(obj); +#endif + *MARK-- = obj; + PUSHMARK(MARK); call_sv(SV_CONST(PUSH),G_SCALAR|G_DISCARD|G_METHOD_NAMED); LEAVE_with_name("call_PUSH"); - /* SPAGAIN; not needed: SP is assigned to immediately below */ } else { /* PL_delaymagic is restored by JMPENV_POP on dieing, so we * only need to save locally, not on the save stack */ U16 old_delaymagic = PL_delaymagic; - if (SvREADONLY(ary) && MARK < SP) Perl_croak_no_modify(); + if (SvREADONLY(ary) && MARK < PL_stack_sp) + Perl_croak_no_modify(); PL_delaymagic = DM_DELAY; - for (++MARK; MARK <= SP; MARK++) { + for (++MARK; MARK <= PL_stack_sp; MARK++) { SV *sv; if (*MARK) SvGETMAGIC(*MARK); sv = newSV_type(SVt_NULL); @@ -5977,15 +6356,20 @@ PP(pp_push) mg_set(MUTABLE_SV(ary)); PL_delaymagic = old_delaymagic; } - SP = ORIGMARK; - if (OP_GIMME(PL_op, 0) != G_VOID) { - PUSHi( AvFILL(ary) + 1 ); + rpp_popfree_to_NN(ORIGMARK); + if ( (PL_op->op_flags & OPf_WANT) != G_VOID + || (PL_op->op_private & OPpTARGET_MY)) + { + TARGi(AvFILL(ary) + 1, 1); + if ((PL_op->op_flags & OPf_WANT) != G_VOID) + rpp_push_1(targ); } - RETURN; + return NORMAL; } + /* also used for: pp_pop()*/ -PP(pp_shift) +PP_wrapped(pp_shift, (PL_op->op_flags & OPf_SPECIAL ? 0 : 1), 0) { dSP; AV * const av = PL_op->op_flags & OPf_SPECIAL @@ -5999,20 +6383,25 @@ PP(pp_shift) RETURN; } + PP(pp_unshift) { - dSP; dMARK; dORIGMARK; dTARGET; + dMARK; dORIGMARK; dTARGET; AV *ary = MUTABLE_AV(*++MARK); const MAGIC * const mg = SvTIED_mg((const SV *)ary, PERL_MAGIC_tied); if (mg) { - *MARK-- = SvTIED_obj(MUTABLE_SV(ary), mg); - PUSHMARK(MARK); - PUTBACK; ENTER_with_name("call_UNSHIFT"); + SV *obj = SvTIED_obj(MUTABLE_SV(ary), mg); +#ifdef PERL_RC_STACK + /* keep ary alive as it's replaced on the stack with obj */ + SAVEFREESV(MUTABLE_SV(ary)); + SvREFCNT_inc_simple_void(obj); +#endif + *MARK-- = obj; + PUSHMARK(MARK); call_sv(SV_CONST(UNSHIFT),G_SCALAR|G_DISCARD|G_METHOD_NAMED); LEAVE_with_name("call_UNSHIFT"); - /* SPAGAIN; not needed: SP is assigned to immediately below */ } else { /* PL_delaymagic is restored by JMPENV_POP on dieing, so we @@ -6020,14 +6409,15 @@ PP(pp_unshift) U16 old_delaymagic = PL_delaymagic; SSize_t i = 0; - av_unshift(ary, SP - MARK); + /* unshift N undefs into the array */ + av_unshift(ary, PL_stack_sp - MARK); PL_delaymagic = DM_DELAY; if (!SvMAGICAL(ary)) { /* The av_unshift above means that many of the checks inside * av_store are unnecessary. If ary does not have magic attached * then a simple direct assignment is possible here. */ - while (MARK < SP) { + while (MARK < PL_stack_sp) { SV * const sv = newSVsv(*++MARK); assert( !SvTIED_mg((const SV *)ary, PERL_MAGIC_tied) ); assert( i >= 0 ); @@ -6041,7 +6431,7 @@ PP(pp_unshift) i++; } } else { - while (MARK < SP) { + while (MARK < PL_stack_sp) { SV * const sv = newSVsv(*++MARK); (void)av_store(ary, i++, sv); } @@ -6051,14 +6441,19 @@ PP(pp_unshift) mg_set(MUTABLE_SV(ary)); PL_delaymagic = old_delaymagic; } - SP = ORIGMARK; - if (OP_GIMME(PL_op, 0) != G_VOID) { - PUSHi( AvFILL(ary) + 1 ); + rpp_popfree_to_NN(ORIGMARK); + if ( (PL_op->op_flags & OPf_WANT) != G_VOID + || (PL_op->op_private & OPpTARGET_MY)) + { + TARGi(AvFILL(ary) + 1, 1); + if ((PL_op->op_flags & OPf_WANT) != G_VOID) + rpp_push_1(targ); } - RETURN; + return NORMAL; } -PP(pp_reverse) + +PP_wrapped(pp_reverse, 0, 1) { dSP; dMARK; @@ -6193,7 +6588,11 @@ PP(pp_reverse) RETURN; } -PP(pp_split) +PP_wrapped(pp_split, + ( (PL_op->op_private & OPpSPLIT_ASSIGN) + && (PL_op->op_flags & OPf_STACKED)) + ? 3 : 2, + 0) { dSP; dTARG; AV *ary = ( (PL_op->op_private & OPpSPLIT_ASSIGN) /* @a = split */ @@ -6219,7 +6618,7 @@ PP(pp_split) const char *orig; const IV origlimit = limit; bool realarray = 0; - I32 base; + SSize_t base; const U8 gimme = GIMME_V; bool gimme_scalar; I32 oldsave = PL_savestack_ix; @@ -6646,29 +7045,27 @@ PP(pp_split) PP(pp_once) { - dSP; SV *const sv = PAD_SVl(PL_op->op_targ); if (SvPADSTALE(sv)) { /* First time. */ SvPADSTALE_off(sv); - RETURNOP(cLOGOP->op_other); + return cLOGOP->op_other; } - RETURNOP(cLOGOP->op_next); + return cLOGOP->op_next; } PP(pp_lock) { - dSP; - dTOPss; + SV *sv = *PL_stack_sp; SV *retsv = sv; SvLOCK(sv); if (SvTYPE(retsv) == SVt_PVAV || SvTYPE(retsv) == SVt_PVHV || SvTYPE(retsv) == SVt_PVCV) { retsv = refto(retsv); } - SETs(retsv); - RETURN; + rpp_replace_1_1_NN(retsv); + return NORMAL; } @@ -6706,7 +7103,7 @@ S_maybe_unwind_defav(pTHX) } /* For sorting out arguments passed to a &CORE:: subroutine */ -PP(pp_coreargs) +PP_wrapped(pp_coreargs, 0, 0) { dSP; int opnum = SvIOK(cSVOP_sv) ? (int)SvUV(cSVOP_sv) : 0; @@ -6882,23 +7279,27 @@ PP(pp_coreargs) PP(pp_avhvswitch) { - dSP; return PL_ppaddr[ - (SvTYPE(TOPs) == SVt_PVAV ? OP_AEACH : OP_EACH) + (SvTYPE(*PL_stack_sp) == SVt_PVAV ? OP_AEACH : OP_EACH) + (PL_op->op_private & OPpAVHVSWITCH_MASK) ](aTHX); } PP(pp_runcv) { - dSP; CV *cv; if (PL_op->op_private & OPpOFFBYONE) { cv = find_runcv_where(FIND_RUNCV_level_eq, 1, NULL); } else cv = find_runcv(NULL); - XPUSHs(CvEVAL(cv) ? &PL_sv_undef : sv_2mortal(newRV((SV *)cv))); - RETURN; + + rpp_extend(1); + if (CvEVAL(cv)) + rpp_push_IMM(&PL_sv_undef); + else + rpp_push_1_norc(newRV((SV *)cv)); + + return NORMAL; } static void @@ -6952,10 +7353,24 @@ S_localise_gv_slot(pTHX_ GV *gv, U8 type PP(pp_refassign) { - dSP; - SV * const key = PL_op->op_private & OPpLVREF_ELEM ? POPs : NULL; - SV * const left = PL_op->op_flags & OPf_STACKED ? POPs : NULL; - dTOPss; + SV *key = NULL; + SV *left = NULL; + SSize_t extra = 0; + + /* \$a[key] = ...; or \$h{key} = ...; */ + if (PL_op->op_private & OPpLVREF_ELEM) { + key = PL_stack_sp[0]; + extra++; + } + + /* \X = ...; rather than \my X = ...; so X on stack */ + if (PL_op->op_flags & OPf_STACKED) { + left = PL_stack_sp[-extra]; + extra++; + } + + SV *sv = PL_stack_sp[-extra]; + const char *bad = NULL; const U8 type = PL_op->op_private & OPpLVREF_TYPE; if (!SvROK(sv)) DIE(aTHX_ "Assigned value is not a reference"); @@ -6979,9 +7394,7 @@ PP(pp_refassign) if (bad) /* diag_listed_as: Assigned value is not %s reference */ DIE(aTHX_ "Assigned value is not a%s reference", bad); - { - MAGIC *mg; - HV *stash; + switch (left ? SvTYPE(left) : 0) { case 0: { @@ -7003,6 +7416,8 @@ PP(pp_refassign) case SVt_PVAV: assert(key); if (UNLIKELY(PL_op->op_private & OPpLVAL_INTRO)) { + MAGIC *mg; + HV *stash; S_localise_aelem_lval(aTHX_ (AV *)left, key, SvCANEXISTDELETE(left)); } @@ -7011,20 +7426,31 @@ PP(pp_refassign) case SVt_PVHV: if (UNLIKELY(PL_op->op_private & OPpLVAL_INTRO)) { assert(key); + MAGIC *mg; + HV *stash; S_localise_helem_lval(aTHX_ (HV *)left, key, SvCANEXISTDELETE(left)); } (void)hv_store_ent((HV *)left, key, SvREFCNT_inc_simple_NN(SvRV(sv)), 0); } - if (PL_op->op_flags & OPf_MOD) - SETs(sv_2mortal(newSVsv(sv))); - /* XXX else can weak references go stale before they are read, e.g., - in leavesub? */ - RETURN; + + if (UNLIKELY(PL_op->op_flags & OPf_MOD)) { + /* e.g. f(\$x = \1); */ + rpp_popfree_to_NN(PL_stack_sp - extra); + rpp_replace_at_norc(PL_stack_sp, newSVsv(sv)); + /* XXX else can weak references go stale before they are read, e.g., + in leavesub? */ } + else + rpp_popfree_to_NN(PL_stack_sp - (extra + 1)); + + return NORMAL; } -PP(pp_lvref) + +PP_wrapped(pp_lvref, + !!(PL_op->op_private & OPpLVREF_ELEM) + !!(PL_op->op_flags & OPf_STACKED), + 0) { dSP; SV * const ret = newSV_type_mortal(SVt_PVMG); @@ -7060,7 +7486,7 @@ PP(pp_lvref) RETURN; } -PP(pp_lvrefslice) +PP_wrapped(pp_lvrefslice, 0, 1) { dSP; dMARK; AV * const av = (AV *)POPs; @@ -7108,18 +7534,19 @@ PP(pp_lvavref) else Perl_pp_padav(aTHX); { - dSP; - dTOPss; - SETs(0); /* special alias marker that aassign recognises */ - XPUSHs(sv); - RETURN; + /* shift the return value up one and insert below it a special + * alias marker that aassign recognises */ + rpp_extend(1); + PL_stack_sp[1] = PL_stack_sp[0]; + PL_stack_sp[0] = NULL; + PL_stack_sp++; + return NORMAL; } } PP(pp_anonconst) { - dSP; - dTOPss; + SV *sv = *PL_stack_sp; CV* constsub = newCONSTSUB( SvTYPE(CopSTASH(PL_curcop))==SVt_PVHV ? CopSTASH(PL_curcop) : NULL, @@ -7138,8 +7565,8 @@ PP(pp_anonconst) ret_sv = refto(ret_sv); } - SETs(ret_sv); - RETURN; + rpp_replace_1_1_NN(ret_sv); + return NORMAL; } @@ -7157,7 +7584,10 @@ PP(pp_anonconst) * etc */ -PP(pp_argelem) +PP_wrapped(pp_argelem, + !!( (PL_op->op_private & OPpARGELEM_MASK) == OPpARGELEM_SV + && (PL_op->op_flags & OPf_STACKED)), + 0) { dTARG; SV *val; @@ -7326,9 +7756,8 @@ PP(pp_argdefelem) if ((PL_op->op_private & OPpARG_IF_FALSE) && !SvTRUE(val)) return cLOGOPo->op_other; - dSP; - XPUSHs(val); - RETURN; + rpp_xpush_1(val); + return NORMAL; } @@ -7394,7 +7823,7 @@ PP(pp_argcheck) return NORMAL; } -PP(pp_isa) +PP_wrapped(pp_isa, 2, 0) { dSP; SV *left, *right; @@ -7406,37 +7835,38 @@ PP(pp_isa) RETURN; } + PP(pp_cmpchain_and) { - dSP; - SV *result = POPs; - PUTBACK; + SV *result = PL_stack_sp[0]; if (SvTRUE_NN(result)) { + rpp_popfree_1_NN(); return cLOGOP->op_other; } else { - TOPs = result; + rpp_replace_2_1_NN(result); return NORMAL; } } + PP(pp_cmpchain_dup) { - dSP; - SV *right = TOPs; - SV *left = TOPm1s; - TOPm1s = right; - TOPs = left; - XPUSHs(right); - RETURN; + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; + PL_stack_sp[-1] = right; + PL_stack_sp[0] = left; + rpp_xpush_1(right); + return NORMAL; } + PP(pp_is_bool) { SV *arg = *PL_stack_sp; SvGETMAGIC(arg); - *PL_stack_sp = boolSV(SvIsBOOL(arg)); + rpp_replace_1_IMM_NN(boolSV(SvIsBOOL(arg))); return NORMAL; } @@ -7446,39 +7876,34 @@ PP(pp_is_weak) SvGETMAGIC(arg); - *PL_stack_sp = boolSV(SvWEAKREF(arg)); + rpp_replace_1_IMM_NN(boolSV(SvWEAKREF(arg))); return NORMAL; } PP(pp_weaken) { - dSP; - SV *arg = POPs; - - sv_rvweaken(arg); - RETURN; + sv_rvweaken(*PL_stack_sp); + rpp_popfree_1_NN(); + return NORMAL; } PP(pp_unweaken) { - dSP; - SV *arg = POPs; - - sv_rvunweaken(arg); - RETURN; + sv_rvunweaken(*PL_stack_sp); + rpp_popfree_1_NN(); + return NORMAL; } PP(pp_blessed) { - dSP; - SV *arg = TOPs; - SV *rv; + SV *arg = *PL_stack_sp; + SV *rv, *ret; SvGETMAGIC(arg); if(!SvROK(arg) || !SvOBJECT((rv = SvRV(arg)))) { - SETs(&PL_sv_undef); - RETURN; + ret = &PL_sv_undef; + goto ret; } if((PL_op->op_private & OPpTRUEBOOL) || @@ -7494,64 +7919,17 @@ PP(pp_blessed) if(UNLIKELY(len == HEf_SVKEY || (len == 1 && HEK_KEY(hek)[0] == '0'))) goto fallback; - SETs(&PL_sv_yes); + ret = &PL_sv_yes; + goto ret; } else { fallback: - SETs(sv_ref(NULL, rv, TRUE)); + ret = (sv_ref(NULL, rv, TRUE)); } - RETURN; -} - -PP(pp_refaddr) -{ - dSP; - dTARGET; - SV *arg = POPs; - - SvGETMAGIC(arg); - - if(SvROK(arg)) - sv_setuv_mg(TARG, PTR2UV(SvRV(arg))); - else - sv_setsv(TARG, &PL_sv_undef); - - PUSHs(TARG); - RETURN; -} - -PP(pp_reftype) -{ - dSP; - dTARGET; - SV *arg = POPs; - - SvGETMAGIC(arg); - - if(SvROK(arg)) - sv_setpv_mg(TARG, sv_reftype(SvRV(arg), FALSE)); - else - sv_setsv(TARG, &PL_sv_undef); - - PUSHs(TARG); - RETURN; -} - -PP(pp_ceil) -{ - dSP; - dTARGET; - PUSHn(Perl_ceil(POPn)); - RETURN; -} - -PP(pp_floor) -{ - dSP; - dTARGET; - PUSHn(Perl_floor(POPn)); - RETURN; + ret: + rpp_replace_1_1_NN(ret); + return NORMAL; } PP(pp_is_tainted) @@ -7560,7 +7938,7 @@ PP(pp_is_tainted) SvGETMAGIC(arg); - *PL_stack_sp = boolSV(SvTAINTED(arg)); + rpp_replace_1_IMM_NN(boolSV(SvTAINTED(arg))); return NORMAL; } Index: gnu/usr.bin/perl/pp.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/pp.h,v diff -u -p -a -u -p -r1.21 pp.h --- gnu/usr.bin/perl/pp.h 14 May 2024 19:38:54 -0000 1.21 +++ gnu/usr.bin/perl/pp.h 22 Jan 2025 00:37:45 -0000 @@ -8,6 +8,57 @@ * */ +/* +=for apidoc_section $rpp + +=for apidoc Amux||XSPP_wrapped|xsppw_name|I32 xsppw_nargs|I32 xsppw_nlists +Declare and wrap a non-reference-counted PP-style function. +On traditional perl builds where the stack isn't reference-counted, this +just produces a function declaration like + + OP * xsppw_name(pTHX) + +Conversely, in ref-counted builds it creates xsppw_name() as a small +wrapper function which calls the real function via a wrapper which +processes the args and return values to ensure that reference counts are +properly handled for code which uses old-style dSP, PUSHs(), POPs() etc, +which don't adjust the reference counts of the items they manipulate. + +xsppw_nargs indicates how many arguments the function consumes off the +stack. It can be a constant value or an expression, such as + + ((PL_op->op_flags & OPf_STACKED) ? 2 : 1) + +Alternatively if xsppw_nlists is 1, it indicates that the PP function +consumes a list (or - rarely - if 2, consumes two lists, like +pp_aassign()), as indicated by the top markstack position. + +This is intended as a temporary fix when converting XS code to run under +PERL_RC_STACK builds. In the longer term, the PP function should be +rewritten to replace PUSHs() etc with rpp_push_1() etc. + +=cut +*/ + +#ifdef PERL_RC_STACK +# define XSPP_wrapped(xsppw_name, xsppw_nargs, xsppw_nlists) \ + \ +STATIC OP* S_##xsppw_name##_norc(pTHX); \ +OP* xsppw_name(pTHX) \ +{ \ + return Perl_pp_wrap(aTHX_ S_##xsppw_name##_norc, \ + (xsppw_nargs), (xsppw_nlists)); \ +} \ +STATIC OP* S_##xsppw_name##_norc(pTHX) + +#else +# define XSPP_wrapped(xsppw_name, xsppw_nargs, xsppw_nlists) \ + OP * xsppw_name(pTHX) +#endif + +#define PP_wrapped(ppw_name, ppw_nargs, ppw_nlists) \ + XSPP_wrapped(Perl_##ppw_name, ppw_nargs, ppw_nlists) + #define PP(s) OP * Perl_##s(pTHX) /* @@ -67,11 +118,11 @@ value for the OP, but some use it for ot #define PUSHMARK(p) \ STMT_START { \ - I32 * mark_stack_entry; \ + Stack_off_t * mark_stack_entry; \ if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr) \ == PL_markstack_max)) \ mark_stack_entry = markstack_grow(); \ - *mark_stack_entry = (I32)((p) - PL_stack_base); \ + *mark_stack_entry = (Stack_off_t)((p) - PL_stack_base); \ DEBUG_s(DEBUG_v(PerlIO_printf(Perl_debug_log, \ "MARK push %p %" IVdf "\n", \ PL_markstack_ptr, (IV)*mark_stack_entry))); \ @@ -91,7 +142,7 @@ value for the OP, but some use it for ot #define dSP SV **sp = PL_stack_sp #define djSP dSP #define dMARK SV **mark = PL_stack_base + POPMARK -#define dORIGMARK const I32 origmark = (I32)(mark - PL_stack_base) +#define dORIGMARK const SSize_t origmark = (SSize_t)(mark - PL_stack_base) #define ORIGMARK (PL_stack_base + origmark) #define SPAGAIN sp = PL_stack_sp @@ -159,7 +210,12 @@ Pops an unsigned long off the stack. #define RETURNOP(o) return (PUTBACK, o) #define RETURNX(x) return (x, PUTBACK, NORMAL) -#define POPs (*sp--) +#ifdef PERL_RC_STACK +# define POPs (assert(!rpp_stack_is_rc()), *sp--) +#else +# define POPs (*sp--) +#endif + #define POPp POPpx #define POPpx (SvPVx_nolen(POPs)) #define POPpconstx (SvPVx_nolen_const(POPs)) @@ -331,7 +387,7 @@ Does not use C. See also C. See also C. See also C. See also Cop_private & OPpARG4_MASK) +/* for backcompat - use switch_argstack() instead */ + #define SWITCHSTACK(f,t) \ - STMT_START { \ - AvFILLp(f) = sp - PL_stack_base; \ - PL_stack_base = AvARRAY(t); \ - PL_stack_max = PL_stack_base + AvMAX(t); \ - sp = PL_stack_sp = PL_stack_base + AvFILLp(t); \ - PL_curstack = t; \ + STMT_START { \ + PL_curstack = f; \ + PL_stack_sp = sp; \ + switch_argstack(t); \ + sp = PL_stack_sp; \ } STMT_END #define EXTEND_MORTAL(n) \ @@ -618,51 +680,6 @@ Does not use C. See also Cop_flags & OPf_STACKED) \ - sp--; \ - SETTARG; \ - } \ - PUTBACK; \ - if (jump) { \ - OP *jump_o = NORMAL->op_next; \ - while (jump_o->op_type == OP_NULL) \ - jump_o = jump_o->op_next; \ - assert(jump_o->op_type == OP_ENTERSUB); \ - (void)POPMARK; \ - return jump_o->op_next; \ - } \ - return NORMAL; \ - } \ - } STMT_END /* This is no longer used anywhere in the core. You might wish to consider calling amagic_deref_call() directly, as it has a cleaner interface. */ Index: gnu/usr.bin/perl/pp_ctl.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/pp_ctl.c,v diff -u -p -a -u -p -r1.26 pp_ctl.c --- gnu/usr.bin/perl/pp_ctl.c 14 May 2024 19:38:54 -0000 1.26 +++ gnu/usr.bin/perl/pp_ctl.c 22 Jan 2025 00:37:45 -0000 @@ -44,29 +44,40 @@ PP(pp_wantarray) { - dSP; I32 cxix; const PERL_CONTEXT *cx; - EXTEND(SP, 1); + SV *sv; if (PL_op->op_private & OPpOFFBYONE) { - if (!(cx = caller_cx(1,NULL))) RETPUSHUNDEF; + if (!(cx = caller_cx(1,NULL))) { + sv = &PL_sv_undef; + goto ret; + } } else { cxix = dopopto_cursub(); - if (cxix < 0) - RETPUSHUNDEF; + if (cxix < 0) { + sv = &PL_sv_undef; + goto ret; + } cx = &cxstack[cxix]; } switch (cx->blk_gimme) { case G_LIST: - RETPUSHYES; + sv = &PL_sv_yes; + break; case G_SCALAR: - RETPUSHNO; + sv = &PL_sv_no; + break; default: - RETPUSHUNDEF; + sv = &PL_sv_undef; + break; } + + ret: + rpp_xpush_IMM(sv); + return NORMAL; } PP(pp_regcreset) @@ -77,7 +88,6 @@ PP(pp_regcreset) PP(pp_regcomp) { - dSP; PMOP *pm = cPMOPx(cLOGOP->op_other); SV **args; int nargs; @@ -88,20 +98,18 @@ PP(pp_regcomp) if (PL_op->op_flags & OPf_STACKED) { dMARK; - nargs = SP - MARK; + nargs = PL_stack_sp - MARK; args = ++MARK; } else { nargs = 1; - args = SP; + args = PL_stack_sp; } /* prevent recompiling under /o and ithreads. */ #if defined(USE_ITHREADS) - if (pm->op_pmflags & PMf_KEEP && PM_GETRE(pm)) { - SP = args-1; - RETURN; - } + if (pm->op_pmflags & PMf_KEEP && PM_GETRE(pm)) + goto finish; #endif re = PM_GETRE(pm); @@ -127,7 +135,7 @@ PP(pp_regcomp) (e.g. $' =~ /$re/ while foo; see bug 70764). So we must call get-magic now before we replace the regexp. Hopefully this hack can be replaced with the approach described at - http://www.nntp.perl.org/group/perl.perl5.porters/2007/03/msg122415.html + https://www.nntp.perl.org/group/perl.perl5.porters/2007/03/msg122415.html some day. */ if (pm->op_type == OP_MATCH) { SV *lhs; @@ -180,14 +188,31 @@ PP(pp_regcomp) } #endif - SP = args-1; - RETURN; +#if defined(USE_ITHREADS) + finish: +#endif + rpp_popfree_to_NN(args - 1); + return NORMAL; } +/* s/.../expr/e is executed in order as if written as + * + * pp_subst(); + * while (pp_substcont()) { + * expr; + * } + * + * Only on the second and later calls to pp_substcont() is there a scalar + * on the stack holding the value of expr. + * + * Note that pp_subst() leaves its original 0-2 args on the stack to + * avoid them being prematurely freed. It is pp_substcont()'s + * responsibility to pop them after the last iteration. + */ + PP(pp_substcont) { - dSP; PERL_CONTEXT *cx = CX_CUR(); PMOP * const pm = cPMOPx(cLOGOP->op_other); SV * const dstr = cx->sb_dstr; @@ -209,14 +234,16 @@ PP(pp_substcont) rxres_restore(&cx->sb_rxres, rx); if (cx->sb_iters++) { + /* second+ time round. Result is on stack */ const SSize_t saviters = cx->sb_iters; if (cx->sb_iters > cx->sb_maxiters) DIE(aTHX_ "Substitution loop"); - SvGETMAGIC(TOPs); /* possibly clear taint on $1 etc: #67962 */ + SvGETMAGIC(*PL_stack_sp); /* possibly clear taint on $1 etc: #67962 */ /* See "how taint works": pp_subst() in pp_hot.c */ - sv_catsv_nomg(dstr, POPs); + sv_catsv_nomg(dstr, *PL_stack_sp); + rpp_popfree_1_NN(); if (UNLIKELY(TAINT_get)) cx->sb_rxtainted |= SUBST_TAINT_REPL; if (CxONCE(cx) || s < orig || @@ -224,7 +251,9 @@ PP(pp_substcont) (s == m), cx->sb_targ, NULL, (REXEC_IGNOREPOS|REXEC_NOT_FIRST|REXEC_FAIL_ON_UNDERFLOW))) { + /* no more iterations. Push return value etc */ SV *targ = cx->sb_targ; + SV *retval; assert(cx->sb_strend >= s); if(cx->sb_strend > s) { @@ -237,7 +266,7 @@ PP(pp_substcont) cx->sb_rxtainted |= SUBST_TAINT_PAT; if (pm->op_pmflags & PMf_NONDESTRUCT) { - PUSHs(dstr); + retval = dstr; /* From here on down we're using the copy, and leaving the original untouched. */ targ = dstr; @@ -254,11 +283,21 @@ PP(pp_substcont) SvPV_set(dstr, NULL); PL_tainted = 0; - mPUSHi(saviters - 1); + retval = sv_newmortal(); + sv_setiv(retval, saviters - 1); (void)SvPOK_only_UTF8(targ); } + /* pop the original args (if any) to pp_subst(), + * then push the result */ + if (pm->op_pmflags & PMf_CONST) + rpp_popfree_1_NN(); /* pop replacement string */ + if (pm->op_flags & OPf_STACKED) + rpp_replace_1_1_NN(retval); /* pop LHS of =~ */ + else + rpp_push_1(retval); + /* update the taint state of various variables in * preparation for final exit. * See "how taint works": pp_subst() in pp_hot.c */ @@ -272,7 +311,7 @@ PP(pp_substcont) if (!(cx->sb_rxtainted & SUBST_TAINT_BOOLRET) && (cx->sb_rxtainted & (SUBST_TAINT_STR|SUBST_TAINT_PAT)) ) - SvTAINTED_on(TOPs); /* taint return value */ + SvTAINTED_on(retval); /* taint return value */ /* needed for mg_set below */ TAINT_set( cBOOL(cx->sb_rxtainted & @@ -307,11 +346,15 @@ PP(pp_substcont) CX_POP(cx); PERL_ASYNC_CHECK(); - RETURNOP(pm->op_next); + return pm->op_next; NOT_REACHED; /* NOTREACHED */ } cx->sb_iters = saviters; } + + /* First iteration. The substitution expression hasn;'t been executed + * this time */ + if (RX_MATCH_COPIED(rx) && RX_SUBBEG(rx) != orig) { m = s; s = orig; @@ -367,9 +410,10 @@ PP(pp_substcont) } rxres_save(&cx->sb_rxres, rx); PL_curpm = pm; - RETURNOP(pm->op_pmstashstartu.op_pmreplstart); + return pm->op_pmstashstartu.op_pmreplstart; } + void Perl_rxres_save(pTHX_ void **rsp, REGEXP *rx) { @@ -435,12 +479,12 @@ S_rxres_restore(pTHX_ void **rsp, REGEXP #endif RX_SUBBEG(rx) = INT2PTR(char*,*p++); - RX_SUBLEN(rx) = (I32)(*p++); - RX_SUBOFFSET(rx) = (I32)*p++; - RX_SUBCOFFSET(rx) = (I32)*p++; + RX_SUBLEN(rx) = (SSize_t)(*p++); + RX_SUBOFFSET(rx) = (Size_t)*p++; + RX_SUBCOFFSET(rx) = (SSize_t)*p++; for (i = 0; i <= RX_NPARENS(rx); ++i) { - RX_OFFSp(rx)[i].start = (I32)(*p++); - RX_OFFSp(rx)[i].end = (I32)(*p++); + RX_OFFSp(rx)[i].start = (SSize_t)(*p++); + RX_OFFSp(rx)[i].end = (SSize_t)(*p++); } } @@ -478,7 +522,7 @@ S_rxres_free(pTHX_ void **rsp) #define FORM_NUM_BLANK (1<<30) #define FORM_NUM_POINT (1<<29) -PP(pp_formline) +PP_wrapped(pp_formline, 0, 1) { dSP; dMARK; dORIGMARK; SV * const tmpForm = *++MARK; @@ -973,19 +1017,20 @@ PP(pp_grepstart) * pp_mapwhile() for an explanation of how the stack is used * during a grep or map. */ - - dSP; SV *src; + SV **svp; - if (PL_stack_base + TOPMARK == SP) { + if (PL_stack_base + TOPMARK == PL_stack_sp) { (void)POPMARK; - if (GIMME_V == G_SCALAR) - XPUSHs(&PL_sv_zero); - RETURNOP(PL_op->op_next->op_next); - } - PL_stack_sp = PL_stack_base + TOPMARK + 1; - PUSHMARK(PL_stack_sp); /* push dst */ - PUSHMARK(PL_stack_sp); /* push src */ + if (GIMME_V == G_SCALAR) { + rpp_extend(1); + *++PL_stack_sp = &PL_sv_zero; + } + return PL_op->op_next->op_next; + } + svp = PL_stack_base + TOPMARK + 1; + PUSHMARK(svp); /* push dst */ + PUSHMARK(svp); /* push src */ ENTER_with_name("grep"); /* enter outer scope */ SAVETMPS; @@ -995,13 +1040,18 @@ PP(pp_grepstart) src = PL_stack_base[TOPMARK]; if (SvPADTMP(src)) { - src = PL_stack_base[TOPMARK] = sv_mortalcopy(src); + SV *newsrc = sv_mortalcopy(src); PL_tmps_floor++; + PL_stack_base[TOPMARK] = newsrc; +#ifdef PERL_RC_STACK + SvREFCNT_inc_simple_void_NN(newsrc); + SvREFCNT_dec(src); +#endif + src = newsrc; } SvTEMP_off(src); DEFSV_set(src); - PUTBACK; if (PL_op->op_type == OP_MAPSTART) PUSHMARK(PL_stack_sp); /* push top */ return cLOGOPx(PL_op->op_next)->op_other; @@ -1067,14 +1117,25 @@ PP(pp_mapwhile) * */ - dSP; const U8 gimme = GIMME_V; - I32 items = (SP - PL_stack_base) - TOPMARK; /* how many new items */ - I32 count; - I32 shift; + SSize_t items = (PL_stack_sp - PL_stack_base) - TOPMARK; /* how many new items */ + SSize_t count; + SSize_t shift; SV** src; SV** dst; +#ifdef PERL_RC_STACK + /* for ref-counted stack, we need to account for the currently-aliased + * stack element, as it might (or might not) get over-written when + * copying values from the expr to the end of the accumulated results + * section of the list. By RC--ing and zeroing out the stack entry, we + * ensure consistent handling. + */ + dst = PL_stack_base + PL_markstack_ptr[-1]; + SvREFCNT_dec_NN(*dst); + *dst = NULL; +#endif + /* first, move source pointer to the next item in the source list */ ++PL_markstack_ptr[-1]; @@ -1093,7 +1154,7 @@ PP(pp_mapwhile) shift = items - (PL_markstack_ptr[-1] - PL_markstack_ptr[-2]); /* items to shift up (accounting for the moved source pointer) */ - count = (SP - PL_stack_base) - (PL_markstack_ptr[-1] - 1); + count = (PL_stack_sp - PL_stack_base) - (PL_markstack_ptr[-1] - 1); /* This optimization is by Ben Tilly and it does * things differently from what Sarathy (gsar) @@ -1106,16 +1167,25 @@ PP(pp_mapwhile) if (shift < count) shift = count; /* Avoid shifting too often --Ben Tilly */ - EXTEND(SP,shift); - src = SP; - dst = (SP += shift); + rpp_extend(shift); + src = PL_stack_sp; + PL_stack_sp += shift; + dst = PL_stack_sp; PL_markstack_ptr[-1] += shift; *PL_markstack_ptr += shift; while (count--) *dst-- = *src--; +#ifdef PERL_RC_STACK + /* zero out the hole just created, so that on a + * reference-counted stack, so that the just-shifted SVs + * aren't counted twice. + */ + Zero(src+1, (dst-src), SV*); +#endif } /* copy the new items down to the destination list */ - dst = PL_stack_base + (PL_markstack_ptr[-2] += items) - 1; + PL_markstack_ptr[-2] += items; + dst = PL_stack_base + PL_markstack_ptr[-2] - 1; if (gimme == G_LIST) { /* add returned items to the collection (making mortal copies * if necessary), then clear the current temps stack frame @@ -1127,8 +1197,8 @@ PP(pp_mapwhile) * We have to do to this way so that everything gets correctly * freed if we die during the map. */ - I32 tmpsbase; - I32 i = items; + SSize_t tmpsbase; + SSize_t i = items; /* make space for the slice */ EXTEND_MORTAL(items); tmpsbase = PL_tmps_floor + 1; @@ -1139,10 +1209,28 @@ PP(pp_mapwhile) PL_tmps_ix += items; while (i-- > 0) { - SV *sv = POPs; +#ifdef PERL_RC_STACK + SV *sv = *PL_stack_sp; + assert(!*dst); /* not overwriting ptrs to refcnted SVs */ + if (!SvTEMP(sv)) { + sv = sv_mortalcopy(sv); + /* NB - don't really need the mortalising above. + * A simple copy would suffice */ + *dst-- = sv; + SvREFCNT_inc_simple_void_NN(sv); + rpp_popfree_1_NN(); + } + else { + *dst-- = sv; + PL_stack_sp--; + } + +#else + SV *sv = *PL_stack_sp--; if (!SvTEMP(sv)) sv = sv_mortalcopy(sv); *dst-- = sv; +#endif PL_tmps_stack[tmpsbase++] = SvREFCNT_inc_simple(sv); } /* clear the stack frame except for the items */ @@ -1157,14 +1245,16 @@ PP(pp_mapwhile) /* scalar context: we don't care about which values map returns * (we use undef here). And so we certainly don't want to do mortal * copies of meaningless values. */ - while (items-- > 0) { - (void)POPs; - *dst-- = &PL_sv_undef; - } + *(dst - items + 1) = &PL_sv_undef; + rpp_popfree_to(PL_stack_sp - items); FREETMPS; } } else { + if (items) { + assert(gimme == G_VOID); + rpp_popfree_to(PL_stack_sp - items); + } FREETMPS; } LEAVE_with_name("grep_item"); /* exit inner scope */ @@ -1177,14 +1267,17 @@ PP(pp_mapwhile) (void)POPMARK; /* pop src */ items = --*PL_markstack_ptr - PL_markstack_ptr[-1]; (void)POPMARK; /* pop dst */ - SP = PL_stack_base + POPMARK; /* pop original mark */ + SV **svp = PL_stack_base + POPMARK; /* pop original mark */ + if (gimme == G_LIST) + svp += items; + rpp_popfree_to(svp); if (gimme == G_SCALAR) { - dTARGET; - XPUSHi(items); + dTARGET; + TARGi(items, 1); + /* XXX is the extend necessary? */ + rpp_xpush_1(targ); } - else if (gimme == G_LIST) - SP += items; - RETURN; + return NORMAL; } else { SV *src; @@ -1195,12 +1288,21 @@ PP(pp_mapwhile) /* set $_ to the new source item */ src = PL_stack_base[PL_markstack_ptr[-1]]; if (SvPADTMP(src)) { + SV *newsrc = sv_mortalcopy(src); + PL_stack_base[PL_markstack_ptr[-1]] = newsrc; +#ifdef PERL_RC_STACK + SvREFCNT_inc_simple_void_NN(newsrc); + SvREFCNT_dec(src); +#endif + src = newsrc; + } + if (SvPADTMP(src)) { src = sv_mortalcopy(src); } SvTEMP_off(src); DEFSV_set(src); - RETURNOP(cLOGOP->op_other); + return cLOGOP->op_other; } } @@ -1218,7 +1320,8 @@ PP(pp_range) return NORMAL; } -PP(pp_flip) + +PP_wrapped(pp_flip,((GIMME_V == G_LIST) ? 0 : 1), 0) { dSP; @@ -1261,6 +1364,7 @@ PP(pp_flip) } } + /* This code tries to decide if "$left .. $right" should use the magical string increment, or if the range is numeric. Initially, an exception was made for *any* string beginning with "0" (see @@ -1276,7 +1380,8 @@ PP(pp_flip) && !(*SvPVX_const(left) == '0' && SvCUR(left)>1 ) )) \ && (!SvOK(right) || looks_like_number(right)))) -PP(pp_flop) + +PP_wrapped(pp_flop, (GIMME_V == G_LIST) ? 2 : 1, 0) { dSP; @@ -1370,6 +1475,7 @@ PP(pp_flop) RETURN; } + /* Control. */ static const char * const context_name[] = { @@ -1714,6 +1820,39 @@ Perl_dounwind(pTHX_ I32 cxix) } + +/* Like rpp_popfree_to(), but takes an offset rather than a pointer, + * and frees everything above ix appropriately, *regardless* of the + * refcountedness of the stack. If necessary it removes any split stack. + * Intended for use during exit() and die() and similar. +*/ +void +Perl_rpp_obliterate_stack_to(pTHX_ I32 ix) +{ +#ifdef PERL_RC_STACK + I32 nonrc_base = PL_curstackinfo->si_stack_nonrc_base; + assert(ix >= 0); + assert(ix <= PL_stack_sp - PL_stack_base); + assert(nonrc_base <= PL_stack_sp - PL_stack_base + 1); + + if (nonrc_base && nonrc_base > ix) { + /* abandon any non-refcounted stuff */ + PL_stack_sp = PL_stack_base + nonrc_base - 1; + /* and mark the stack as fully refcounted again */ + PL_curstackinfo->si_stack_nonrc_base = 0; + } + + if (rpp_stack_is_rc()) + rpp_popfree_to(PL_stack_base + ix); + else + PL_stack_sp = PL_stack_base + ix; +#else + PL_stack_sp = PL_stack_base + ix; +#endif + +} + + void Perl_qerror(pTHX_ SV *err) { @@ -1887,12 +2026,12 @@ Perl_die_unwind(pTHX_ SV *msv) && PL_curstackinfo->si_prev) { dounwind(-1); + rpp_obliterate_stack_to(0); POPSTACK; } if (cxix >= 0) { PERL_CONTEXT *cx; - SV **oldsp; U8 gimme; JMPENV *restartjmpenv; OP *restartop; @@ -1903,12 +2042,12 @@ Perl_die_unwind(pTHX_ SV *msv) cx = CX_CUR(); assert(CxTYPE(cx) == CXt_EVAL); + rpp_obliterate_stack_to(cx->blk_oldsp); + /* return false to the caller of eval */ - oldsp = PL_stack_base + cx->blk_oldsp; gimme = cx->blk_gimme; if (gimme == G_SCALAR) - *++oldsp = &PL_sv_undef; - PL_stack_sp = oldsp; + rpp_xpush_IMM(&PL_sv_undef); restartjmpenv = cx->blk_eval.cur_top_env; restartop = cx->blk_eval.retop; @@ -1954,15 +2093,18 @@ Perl_die_unwind(pTHX_ SV *msv) NOT_REACHED; /* NOTREACHED */ } + PP(pp_xor) { - dSP; dPOPTOPssrl; - if (SvTRUE_NN(left) != SvTRUE_NN(right)) - RETSETYES; - else - RETSETNO; + SV *left = PL_stack_sp[0]; + SV *right = PL_stack_sp[-1]; + rpp_replace_2_IMM_NN(SvTRUE_NN(left) != SvTRUE_NN(right) + ? &PL_sv_yes + : &PL_sv_no); + return NORMAL; } + /* =for apidoc_section $CV @@ -2026,7 +2168,7 @@ Perl_caller_cx(pTHX_ I32 count, const PE return cx; } -PP(pp_caller) +PP_wrapped(pp_caller, MAXARG, 0) { dSP; const PERL_CONTEXT *cx; @@ -2052,6 +2194,42 @@ PP(pp_caller) RETURN; } + /* populate @DB::args ? */ + if (CxTYPE(cx) == CXt_SUB && CxHASARGS(cx) + && CopSTASH_eq(PL_curcop, PL_debstash)) + { + /* slot 0 of the pad contains the original @_ */ + AV * const ary = MUTABLE_AV(AvARRAY(MUTABLE_AV( + PadlistARRAY(CvPADLIST(cx->blk_sub.cv))[ + cx->blk_sub.olddepth+1]))[0]); + const SSize_t off = AvARRAY(ary) - AvALLOC(ary); + + Perl_init_dbargs(aTHX); + + if (AvMAX(PL_dbargs) < AvFILLp(ary) + off) + av_extend(PL_dbargs, AvFILLp(ary) + off); + + /* Alias elements of @_ to @DB::args */ + for (SSize_t i = AvFILLp(ary) + off; i >= 0; i--) { + SV* sv = AvALLOC(ary)[i]; + /* for a shifted @_, the elements between AvALLOC and AvARRAY + * point to old SVs which may have been freed or even + * reallocated in the meantime. In the interests of + * reconstructing the original @_ before any shifting, use + * those old values, even at the risk of them being wrong. + * But if the ref count is 0, then don't use it because + * further assigning that value anywhere will panic. + * Of course there's nothing to stop a RC != 0 SV being + * subsequently freed, but hopefully people quickly copy the + * contents of @DB::args before doing anything else. + */ + if (sv && (SvREFCNT(sv) == 0 || SvIS_FREED(sv))) + sv = NULL; + AvARRAY(PL_dbargs)[i] = sv; + } + AvFILLp(PL_dbargs) = AvFILLp(ary) + off; + } + CX_DEBUG(cx, "CALLER"); assert(CopSTASH(cx->blk_oldcop)); stash_hek = SvTYPE(CopSTASH(cx->blk_oldcop)) == SVt_PVHV @@ -2136,23 +2314,7 @@ PP(pp_caller) PUSHs(&PL_sv_undef); PUSHs(&PL_sv_undef); } - if (CxTYPE(cx) == CXt_SUB && CxHASARGS(cx) - && CopSTASH_eq(PL_curcop, PL_debstash)) - { - /* slot 0 of the pad contains the original @_ */ - AV * const ary = MUTABLE_AV(AvARRAY(MUTABLE_AV( - PadlistARRAY(CvPADLIST(cx->blk_sub.cv))[ - cx->blk_sub.olddepth+1]))[0]); - const SSize_t off = AvARRAY(ary) - AvALLOC(ary); - Perl_init_dbargs(aTHX); - - if (AvMAX(PL_dbargs) < AvFILLp(ary) + off) - av_extend(PL_dbargs, AvFILLp(ary) + off); - if (AvFILLp(ary) + 1 + off) - Copy(AvALLOC(ary), AvARRAY(PL_dbargs), AvFILLp(ary) + 1 + off, SV*); - AvFILLp(PL_dbargs) = AvFILLp(ary) + off; - } mPUSHi(CopHINTS_get(cx->blk_oldcop)); { SV * mask ; @@ -2177,7 +2339,8 @@ PP(pp_caller) RETURN; } -PP(pp_reset) + +PP_wrapped(pp_reset, MAXARG, 0) { dSP; const char * tmps; @@ -2199,7 +2362,7 @@ PP(pp_dbstate) { PL_curcop = (COP*)PL_op; TAINT_NOT; /* Each statement is presumed innocent */ - PL_stack_sp = PL_stack_base + CX_CUR()->blk_oldsp; + rpp_popfree_to_NN(PL_stack_base + CX_CUR()->blk_oldsp); FREETMPS; PERL_ASYNC_CHECK(); @@ -2207,7 +2370,6 @@ PP(pp_dbstate) if (PL_op->op_flags & OPf_SPECIAL /* breakpoint */ || PL_DBsingle_iv || PL_DBsignal_iv || PL_DBtrace_iv) { - dSP; PERL_CONTEXT *cx; const U8 gimme = G_LIST; GV * const gv = PL_DBgv; @@ -2227,16 +2389,37 @@ PP(pp_dbstate) ENTER; SAVEI32(PL_debug); PL_debug = 0; + /* I suspect that saving the stack position is no longer + * required. It was added in 5.001 by: + * + * NETaa13155: &DB::DB left trash on the stack. + * From: Thomas Koenig + * Files patched: lib/perl5db.pl pp_ctl.c + * The call by pp_dbstate() to &DB::DB left trash on the + * stack. It now calls DB in list context, and DB returns + * (). + * + * but the details of what bug it fixed are long lost to + * history. SAVESTACK_POS() doesn't work well with stacks + * which may be split into partly reference-counted and partly + * not halves, so skip it and hope it doesn't cause any + * problems. + */ +#ifndef PERL_RC_STACK SAVESTACK_POS(); +#endif SAVETMPS; - PUSHMARK(SP); - (void)(*CvXSUB(cv))(aTHX_ cv); + PUSHMARK(PL_stack_sp); + rpp_invoke_xs(cv); FREETMPS; LEAVE; return NORMAL; } else { - cx = cx_pushblock(CXt_SUB, gimme, SP, PL_savestack_ix); +#ifdef PERL_RC_STACK + assert(!PL_curstackinfo->si_stack_nonrc_base); +#endif + cx = cx_pushblock(CXt_SUB, gimme, PL_stack_sp, PL_savestack_ix); cx_pushsub(cx, cv, PL_op->op_next, 0); /* OP_DBSTATE's op_private holds hint bits rather than * the lvalue-ish flags seen in OP_ENTERSUB. So cancel @@ -2245,12 +2428,15 @@ PP(pp_dbstate) SAVEI32(PL_debug); PL_debug = 0; + /* see comment above about SAVESTACK_POS */ +#ifndef PERL_RC_STACK SAVESTACK_POS(); +#endif CvDEPTH(cv)++; if (CvDEPTH(cv) >= 2) pad_push(CvPADLIST(cv), CvDEPTH(cv)); PAD_SET_CUR_NOSAVE(CvPADLIST(cv), CvDEPTH(cv)); - RETURNOP(CvSTART(cv)); + return CvSTART(cv); } } else @@ -2284,7 +2470,7 @@ PP(pp_leave) gimme = cx->blk_gimme; if (gimme == G_VOID) - PL_stack_sp = oldsp; + rpp_popfree_to_NN(oldsp); else leave_adjust_stacks(oldsp, oldsp, gimme, PL_op->op_private & OPpLVALUE ? 3 : 1); @@ -2320,7 +2506,7 @@ S_outside_integer(pTHX_ SV *sv) PP(pp_enteriter) { - dSP; dMARK; + dMARK; PERL_CONTEXT *cx; const U8 gimme = GIMME_V; void *itervarp; /* GV or pad slot of the iteration variable */ @@ -2341,10 +2527,9 @@ PP(pp_enteriter) cxflags = CXp_FOR_PAD; } else { - SV * const sv = POPs; + SV * const sv = *PL_stack_sp; itervarp = (void *)sv; if (LIKELY(isGV(sv))) { /* symbol table variable */ - SvREFCNT_inc_simple_void(sv); itersave = GvSV(sv); SvREFCNT_inc_simple_void(itersave); cxflags = CXp_FOR_GV; @@ -2357,8 +2542,10 @@ PP(pp_enteriter) assert(SvMAGIC(sv)->mg_type == PERL_MAGIC_lvref); itersave = NULL; cxflags = CXp_FOR_LVREF; - SvREFCNT_inc_simple_void(sv); } + /* we transfer ownership of 1 ref count of itervarp from the stack + * to the CX entry, so no SvREFCNT_dec() needed */ + (void)rpp_pop_1_norc(); } /* OPpITER_DEF (implicit $_) should only occur with a GV iter var */ assert((cxflags & CXp_FOR_GV) || !(PL_op->op_private & OPpITER_DEF)); @@ -2375,10 +2562,10 @@ PP(pp_enteriter) /* OPf_STACKED implies either a single array: for(@), with a * single AV on the stack, or a range: for (1..5), with 1 and 5 on * the stack */ - SV *maybe_ary = POPs; + SV *maybe_ary = *PL_stack_sp; if (SvTYPE(maybe_ary) != SVt_PVAV) { /* range */ - dPOPss; + SV* sv = PL_stack_sp[-1]; SV * const right = maybe_ary; if (UNLIKELY(cxflags & CXp_FOR_LVREF)) DIE(aTHX_ "Assigned value is not a reference"); @@ -2391,12 +2578,18 @@ PP(pp_enteriter) DIE(aTHX_ "Range iterator outside integer range"); cx->blk_loop.state_u.lazyiv.cur = SvIV_nomg(sv); cx->blk_loop.state_u.lazyiv.end = SvIV_nomg(right); + rpp_popfree_2_NN(); } else { cx->cx_type |= CXt_LOOP_LAZYSV; cx->blk_loop.state_u.lazysv.cur = newSVsv(sv); cx->blk_loop.state_u.lazysv.end = right; - SvREFCNT_inc_simple_void_NN(right); + + /* we transfer ownership of 1 ref count of right from the + * stack to the CX .end entry, so no SvREFCNT_dec() needed */ + (void)rpp_pop_1_norc(); + + rpp_popfree_1_NN(); /* free the (now copied) start SV */ (void) SvPV_force_nolen(cx->blk_loop.state_u.lazysv.cur); /* This will do the upgrade to SVt_PV, and warn if the value is uninitialised. */ @@ -2413,17 +2606,20 @@ PP(pp_enteriter) /* for (@array) {} */ cx->cx_type |= CXt_LOOP_ARY; cx->blk_loop.state_u.ary.ary = MUTABLE_AV(maybe_ary); - SvREFCNT_inc_simple_void_NN(maybe_ary); + /* we transfer ownership of 1 ref count of the av from the + * stack to the CX .ary entry, so no SvREFCNT_dec() needed */ + (void)rpp_pop_1_norc(); cx->blk_loop.state_u.ary.ix = (PL_op->op_private & OPpITER_REVERSED) ? AvFILL(cx->blk_loop.state_u.ary.ary) + 1 : -1; } - /* EXTEND(SP, 1) not needed in this branch because we just did POPs */ + /* rpp_extend(1) not needed in this branch + * because we just popped 1 item */ } else { /* iterating over items on the stack */ cx->cx_type |= CXt_LOOP_LIST; - cx->blk_oldsp = SP - PL_stack_base; + cx->blk_oldsp = PL_stack_sp - PL_stack_base; cx->blk_loop.state_u.stack.basesp = MARK - PL_stack_base; cx->blk_loop.state_u.stack.ix = (PL_op->op_private & OPpITER_REVERSED) @@ -2431,10 +2627,10 @@ PP(pp_enteriter) : cx->blk_loop.state_u.stack.basesp; /* pre-extend stack so pp_iter doesn't have to check every time * it pushes yes/no */ - EXTEND(SP, 1); + rpp_extend(1); } - RETURN; + return NORMAL; } PP(pp_enterloop) @@ -2464,7 +2660,7 @@ PP(pp_leaveloop) gimme = cx->blk_gimme; if (gimme == G_VOID) - PL_stack_sp = base; + rpp_popfree_to_NN(base); else leave_adjust_stacks(oldsp, base, gimme, PL_op->op_private & OPpLVALUE ? 3 : 1); @@ -2509,7 +2705,7 @@ PP(pp_leavesublv) oldsp = PL_stack_base + cx->blk_oldsp; /* last arg of previous frame */ if (gimme == G_VOID) - PL_stack_sp = oldsp; + rpp_popfree_to_NN(oldsp); else { U8 lval = CxLVAL(cx); bool is_lval = (lval && !(lval & OPpENTERSUB_INARGS)); @@ -2541,12 +2737,11 @@ PP(pp_leavesublv) if (lval & OPpDEREF) { /* lval_sub()->{...} and similar */ - dSP; - SvGETMAGIC(TOPs); - if (!SvOK(TOPs)) { - TOPs = vivify_ref(TOPs, CxLVAL(cx) & OPpDEREF); + SvGETMAGIC(*PL_stack_sp); + if (!SvOK(*PL_stack_sp)) { + SV *sv = vivify_ref(*PL_stack_sp, CxLVAL(cx) & OPpDEREF); + rpp_replace_1_1_NN(sv); } - PUTBACK; } } else { @@ -2595,7 +2790,7 @@ static const char *S_defer_blockname(PER PP(pp_return) { - dSP; dMARK; + dMARK; PERL_CONTEXT *cx; I32 cxix = dopopto_cursub(); @@ -2628,12 +2823,16 @@ PP(pp_return) /* See comment below about context popping. Since we know * we're scalar and not lvalue, we can preserve the return * value in a simpler fashion than there. */ - SV *sv = *SP; + SV *sv = *PL_stack_sp; assert(cxstack[0].blk_gimme == G_SCALAR); - if ( (sp != PL_stack_base) + if ( (PL_stack_sp != PL_stack_base) && !(SvFLAGS(sv) & (SVs_TEMP|SVs_PADTMP)) ) - *SP = sv_mortalcopy(sv); +#ifdef PERL_RC_STACK + rpp_replace_at_norc(PL_stack_sp, newSVsv(sv)); +#else + *PL_stack_sp = sv_mortalcopy(sv); +#endif dounwind(0); } /* caller responsible for popping cxstack[0] */ @@ -2655,13 +2854,11 @@ PP(pp_return) * isn't as inefficient as it sounds. */ cx = &cxstack[cxix]; - PUTBACK; if (cx->blk_gimme != G_VOID) leave_adjust_stacks(MARK, PL_stack_base + cx->blk_oldsp, cx->blk_gimme, CxTYPE(cx) == CXt_SUB && CvLVALUE(cx->blk_sub.cv) ? 3 : 0); - SPAGAIN; dounwind(cxix); cx = &cxstack[cxix]; /* CX stack may have been realloced */ } @@ -2675,23 +2872,33 @@ PP(pp_return) * context we can leave as-is (pp_leavesub will later return the * top stack element). But for an empty arg list, e.g. * for (1,2) { return } - * we need to set sp = oldsp so that pp_leavesub knows to push - * &PL_sv_undef onto the stack. + * we need to set PL_stack_sp = oldsp so that pp_leavesub knows to + * push &PL_sv_undef onto the stack. */ SV **oldsp; cx = &cxstack[cxix]; oldsp = PL_stack_base + cx->blk_oldsp; if (oldsp != MARK) { - SSize_t nargs = SP - MARK; + SSize_t nargs = PL_stack_sp - MARK; if (nargs) { if (cx->blk_gimme == G_LIST) { /* shift return args to base of call stack frame */ +#ifdef PERL_RC_STACK + /* free the items on the stack that will get + * overwritten */ + SV **p; + for (p = MARK; p > oldsp; p--) { + SV *sv = *p; + *p = NULL; + SvREFCNT_dec(sv); + } +#endif Move(MARK + 1, oldsp + 1, nargs, SV*); PL_stack_sp = oldsp + nargs; } } else - PL_stack_sp = oldsp; + rpp_popfree_to_NN(oldsp); } } @@ -2732,9 +2939,7 @@ S_unwind_loop(pTHX) SV *sv; if (PL_op->op_flags & OPf_STACKED) { - dSP; - sv = POPs; - PUTBACK; + sv = *PL_stack_sp; label = SvPV(sv, label_len); label_flags = SvUTF8(sv); } @@ -2756,7 +2961,10 @@ S_unwind_loop(pTHX) : newSVpvn_flags(label, label_len, label_flags | SVs_TEMP))); + if (PL_op->op_flags & OPf_STACKED) + rpp_popfree_1_NN(); } + if (cxix < cxstack_ix) { I32 i; /* Check for defer { last ... } etc */ @@ -2781,11 +2989,11 @@ PP(pp_last) cx = S_unwind_loop(aTHX); assert(CxTYPE_is_LOOP(cx)); - PL_stack_sp = PL_stack_base + rpp_popfree_to_NN(PL_stack_base + (CxTYPE(cx) == CXt_LOOP_LIST ? cx->blk_loop.state_u.stack.basesp : cx->blk_oldsp - ); + )); TAINT_NOT; @@ -2954,7 +3162,6 @@ S_check_op_type(pTHX_ OP * const o) PP(pp_goto) { - dSP; OP *retop = NULL; I32 ix; PERL_CONTEXT *cx; @@ -2968,7 +3175,7 @@ PP(pp_goto) if (PL_op->op_flags & OPf_STACKED) { /* goto EXPR or goto &foo */ - SV * const sv = POPs; + SV * const sv = *PL_stack_sp; SvGETMAGIC(sv); if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVCV) { @@ -3027,13 +3234,14 @@ PP(pp_goto) /* First do some returnish stuff. */ SvREFCNT_inc_simple_void(cv); /* avoid premature free during unwind */ + rpp_popfree_1_NN(); /* safe to free original sv now */ + FREETMPS; if (cxix < cxstack_ix) { dounwind(cxix); } cx = CX_CUR(); cx_topblock(cx); - SPAGAIN; /* protect @_ during save stack unwind. */ if (arg) @@ -3055,9 +3263,15 @@ PP(pp_goto) * unless pad[0] and @_ differ (e.g. if the old sub did * local *_ = []); in which case clear the old pad[0] * array in the usual way */ - if (av == arg || AvREAL(av)) + + if (av != arg && !SvMAGICAL(av) && SvREFCNT(av) == 1 +#ifndef PERL_RC_STACK + && !AvREAL(av) +#endif + ) + clear_defarray_simple(av); + else clear_defarray(av, av == arg); - else CLEAR_ARGARRAY(av); } /* don't restore PL_comppad here. It won't be needed if the @@ -3104,13 +3318,16 @@ PP(pp_goto) SAVEFREESV(old_cv); /* ditto, deferred freeing of old CV */ /* put GvAV(defgv) back onto stack */ - if (items) { - EXTEND(SP, items+1); /* @_ could have been extended. */ - } - mark = SP; + if (items) + rpp_extend(items + 1); /* @_ could have been extended. */ + mark = PL_stack_sp; if (items) { SSize_t index; +#ifdef PERL_RC_STACK + assert(AvREAL(arg)); +#else bool r = cBOOL(AvREAL(arg)); +#endif for (index=0; indexblk_oldcop; PAD_SET_CUR_NOSAVE(padlist, CvDEPTH(cv)); + if (CxHASARGS(cx)) { /* second half of donating @_ from the old sub to the @@ -3216,11 +3444,15 @@ PP(pp_goto) } } retop = CvSTART(cv); - goto putback_return; + goto finish; } } else { /* goto EXPR */ + /* avoid premature free of label before popping it off stack */ + SvREFCNT_inc_NN(sv); + sv_2mortal(sv); + rpp_popfree_1_NN(); label = SvPV_nomg_const(sv, label_len); label_flags = SvUTF8(sv); } @@ -3336,7 +3568,9 @@ PP(pp_goto) ? 2 : 1; if (enterops[i]) - deprecate(WARN_DEPRECATED__GOTO_CONSTRUCT, "Use of \"goto\" to jump into a construct"); + deprecate_fatal_in(WARN_DEPRECATED__GOTO_CONSTRUCT, + "5.42", + "Use of \"goto\" to jump into a construct"); } /* pop unwanted frames */ @@ -3381,14 +3615,12 @@ PP(pp_goto) PL_do_undump = FALSE; } - putback_return: - PL_stack_sp = sp; - _return: + finish: PERL_ASYNC_CHECK(); return retop; } -PP(pp_exit) +PP_wrapped(pp_exit, 1, 0) { dSP; I32 anum; @@ -3754,7 +3986,6 @@ S_try_run_unitcheck(pTHX_ OP* caller_op) STATIC bool S_doeval_compile(pTHX_ U8 gimme, CV* outside, U32 seq, HV *hh) { - dSP; OP * const saveop = PL_op; bool clear_hints = saveop->op_type != OP_ENTEREVAL; COP * const oldcurcop = PL_curcop; @@ -3768,7 +3999,7 @@ S_doeval_compile(pTHX_ U8 gimme, CV* out ((PL_op->op_private & OPpEVAL_RE_REPARSING) ? EVAL_RE_REPARSING : 0))); - PUSHMARK(SP); + PUSHMARK(PL_stack_sp); evalcv = MUTABLE_CV(newSV_type(SVt_PVCV)); CvEVAL_on(evalcv); @@ -3831,6 +4062,7 @@ S_doeval_compile(pTHX_ U8 gimme, CV* out else { PL_hints = saveop->op_private & OPpEVAL_COPHH ? oldcurcop->cop_hints : (U32)saveop->op_targ; + PL_prevailing_version = 0; /* we might change this below */ /* making 'use re eval' not be in scope when compiling the * qr/mabye_has_runtime_code_block/ ensures that we don't get @@ -3845,6 +4077,18 @@ S_doeval_compile(pTHX_ U8 gimme, CV* out SvREFCNT_dec(GvHV(PL_hintgv)); GvHV(PL_hintgv) = hh; FETCHFEATUREBITSHH(hh); + /* temporarily turn magical flags off so we can delete without it getting in the way */ + const U32 wasflags = SvFLAGS(hh); + SvMAGICAL_off(hh); + + SV *versv; + /* hh is a new copy for us to use; we are permitted to delete keys */ + if((versv = hv_deletes(hh, "CORE/prevailing_version", 0)) && SvOK(versv)) { + SAVEI16(PL_prevailing_version); + PL_prevailing_version = SvUV(versv); + } + + SvFLAGS(hh) = wasflags; } } SAVECOMPILEWARNINGS(); @@ -3899,11 +4143,11 @@ S_doeval_compile(pTHX_ U8 gimme, CV* out if (!in_require) invoke_exception_hook(ERRSV,FALSE); - if (PL_eval_root) { - op_free(PL_eval_root); - PL_eval_root = NULL; - } - SP = PL_stack_base + POPMARK; /* pop original mark */ + + op_free(PL_eval_root); + PL_eval_root = NULL; + + rpp_popfree_to(PL_stack_base + POPMARK); /* pop original mark */ cx = CX_CUR(); assert(CxTYPE(cx) == CXt_EVAL); /* If we are in an eval we need to make sure that $SIG{__DIE__} @@ -3912,6 +4156,7 @@ S_doeval_compile(pTHX_ U8 gimme, CV* out * so it will happen there. */ /* pop the CXt_EVAL, and if was a require, croak */ S_pop_eval_context_maybe_croak(aTHX_ cx, ERRSV, 2); + } /* die_unwind() re-croaks when in require, having popped the @@ -3923,9 +4168,15 @@ S_doeval_compile(pTHX_ U8 gimme, CV* out if (!*(SvPV_nolen_const(errsv))) sv_setpvs(errsv, "Compilation error"); - - if (gimme != G_LIST) PUSHs(&PL_sv_undef); - PUTBACK; + if (gimme == G_SCALAR) { + if (yystatus == 3) { + /* die_unwind already pushed undef in scalar context */ + assert(*PL_stack_sp == &PL_sv_undef); + } + else { + rpp_xpush_1(&PL_sv_undef); + } + } return FALSE; } @@ -3943,10 +4194,8 @@ S_doeval_compile(pTHX_ U8 gimme, CV* out if (PERLDB_INTER && saveop->op_type == OP_REQUIRE) { CV * const cv = get_cvs("DB::postponed", 0); if (cv) { - dSP; - PUSHMARK(SP); - XPUSHs(MUTABLE_SV(CopFILEGV(&PL_compiling))); - PUTBACK; + PUSHMARK(PL_stack_sp); + rpp_xpush_1(MUTABLE_SV(CopFILEGV(&PL_compiling))); call_sv(MUTABLE_SV(cv), G_DISCARD); } } @@ -3972,22 +4221,22 @@ S_doeval_compile(pTHX_ U8 gimme, CV* out sv_setpvs(errsv, "Unit check error"); } - if (gimme != G_LIST) PUSHs(&PL_sv_undef); - PUTBACK; + if (gimme != G_LIST) + rpp_xpush_1(&PL_sv_undef); return FALSE; } PL_eval_start = es; } CvDEPTH(evalcv) = 1; - SP = PL_stack_base + POPMARK; /* pop original mark */ + rpp_popfree_to_NN(PL_stack_base + POPMARK); /* pop original mark */ PL_op = saveop; /* The caller may need it. */ PL_parser->lex_state = LEX_NOTPARSING; /* $^S needs this. */ - PUTBACK; return TRUE; } + /* Return NULL if the file doesn't exist or isn't a file; * else return PerlIO_openn(). */ @@ -4130,9 +4379,9 @@ S_path_is_searchable(const char *name) static OP * S_require_version(pTHX_ SV *sv) { - dSP; - sv = sv_2mortal(new_version(sv)); + rpp_popfree_1_NN(); + if (!Perl_sv_derived_from_pvn(aTHX_ PL_patchlevel, STR_WITH_LEN("version"), 0)) upg_version(PL_patchlevel, TRUE); if (cUNOP->op_first->op_type == OP_CONST && cUNOP->op_first->op_private & OPpCONST_NOVER) { @@ -4186,18 +4435,19 @@ S_require_version(pTHX_ SV *sv) } } - RETPUSHYES; + rpp_push_IMM(&PL_sv_yes); + return NORMAL; } + /* Handle C, C and C. * The first form will have already been converted at compile time to - * the second form */ + * the second form. + * sv is still on the stack at this point. */ static OP * S_require_file(pTHX_ SV *sv) { - dSP; - PERL_CONTEXT *cx; const char *name; STRLEN len; @@ -4244,26 +4494,31 @@ S_require_file(pTHX_ SV *sv) ENTER_with_name("call_PRE_REQUIRE"); SAVETMPS; - EXTEND(SP, 1); - PUSHMARK(SP); - PUSHs(name_sv); /* always use the object for method calls */ - PUTBACK; - int count = call_sv(PL_hook__require__before, G_SCALAR); - SPAGAIN; - if (count && SvOK(*SP) && SvROK(*SP) && SvTYPE(SvRV(*SP)) == SVt_PVCV) - post_hook__require__before_sv = SvREFCNT_inc_simple_NN(*SP); + PUSHMARK(PL_stack_sp); + rpp_xpush_1(name_sv); /* always use the object for method calls */ + call_sv(PL_hook__require__before, G_SCALAR); + SV *rsv = *PL_stack_sp; + if (SvOK(rsv) && SvROK(rsv) && SvTYPE(SvRV(rsv)) == SVt_PVCV) { + /* the RC++ preserves it across the popping and/or FREETMPS + * below */ + post_hook__require__before_sv = SvREFCNT_inc_simple_NN(rsv); + rpp_popfree_1_NN(); + } if (!sv_streq(name_sv,sv)) { /* they modified the name argument, so do some sleight of hand */ name = SvPV_nomg_const(name_sv, len); if (!(name && len > 0 && *name)) DIE(aTHX_ "Missing or undefined argument to %s via %%{^HOOK}{require__before}", op_name); - sv = SvREFCNT_inc_simple_NN(name_sv); + sv = name_sv; } FREETMPS; LEAVE_with_name("call_PRE_REQUIRE"); if (post_hook__require__before_sv) { - MORTALDESTRUCTOR_SV(post_hook__require__before_sv, newSVsv(sv)); + SV *nsv = newSVsv(sv); + MORTALDESTRUCTOR_SV(post_hook__require__before_sv, nsv); + SvREFCNT_dec_NN(nsv); + SvREFCNT_dec_NN(post_hook__require__before_sv); } } if ( @@ -4271,7 +4526,9 @@ S_require_file(pTHX_ SV *sv) && SvROK(PL_hook__require__after) && SvTYPE(SvRV(PL_hook__require__after)) == SVt_PVCV ) { - MORTALDESTRUCTOR_SV(PL_hook__require__after, newSVsv(sv)); + SV *nsv = newSVsv(sv); + MORTALDESTRUCTOR_SV(PL_hook__require__after, nsv); + SvREFCNT_dec_NN(nsv); } #ifndef VMS @@ -4279,14 +4536,20 @@ S_require_file(pTHX_ SV *sv) if (op_is_require) { /* can optimize to only perform one single lookup */ svp_cached = hv_fetch(GvHVn(PL_incgv), (char*) name, len, 0); - if ( svp_cached && (SvGETMAGIC(*svp_cached), SvOK(*svp_cached)) ) RETPUSHYES; + if (svp_cached && + (SvGETMAGIC(*svp_cached), SvOK(*svp_cached))) + { + rpp_replace_1_IMM_NN(&PL_sv_yes); + return NORMAL; + } } #endif if (!IS_SAFE_PATHNAME(name, len, op_name)) { if (!op_is_require) { CLEAR_ERRSV(); - RETPUSHUNDEF; + rpp_replace_1_IMM_NN(&PL_sv_undef); + return NORMAL; } DIE(aTHX_ "Can't locate %s: %s", pv_escape(newSVpvs_flags("",SVs_TEMP),name,len,len*2, @@ -4327,8 +4590,10 @@ S_require_file(pTHX_ SV *sv) /* we already did a get magic if this was cached */ if (!svp_cached) SvGETMAGIC(*svp); - if (SvOK(*svp)) - RETPUSHYES; + if (SvOK(*svp)) { + rpp_replace_1_IMM_NN(&PL_sv_yes); + return NORMAL; + } else DIE(aTHX_ "Attempt to reload %s aborted.\n" "Compilation failed in require", unixname); @@ -4526,25 +4791,27 @@ S_require_file(pTHX_ SV *sv) ENTER_with_name("call_INC_hook"); SAVETMPS; - EXTEND(SP, 2 + ((method && (loader != dirsv)) ? 1 : 0)); - PUSHMARK(SP); - PUSHs(method ? loader : dirsv); /* always use the object for method calls */ - PUSHs(nsv); - if (method && (loader != dirsv)) /* add the args array for method calls */ - PUSHs(dirsv); - PUTBACK; + PUSHMARK(PL_stack_sp); + /* add the args array for method calls */ + bool add_dirsv = (method && (loader != dirsv)); + rpp_extend(2 + add_dirsv); + rpp_push_2( + /* always use the object for method calls */ + method ? loader : dirsv, + nsv + ); + if (add_dirsv) + rpp_push_1(dirsv); if (method) { count = call_method(method, G_LIST|G_EVAL); } else { count = call_sv(loader, G_LIST|G_EVAL); } - SPAGAIN; if (count > 0) { int i = 0; SV *arg; - - SP -= count - 1; + SV **base = PL_stack_sp - count + 1; if (is_incdir) { /* push the stringified returned items into the @@ -4555,7 +4822,7 @@ S_require_file(pTHX_ SV *sv) * stable. We speficially do *not* support returning * coderefs from an INCDIR call. */ while (count-->0) { - arg = SP[i++]; + arg = base[i++]; SvGETMAGIC(arg); if (!SvOK(arg)) continue; @@ -4587,14 +4854,14 @@ S_require_file(pTHX_ SV *sv) goto done_hook; } - arg = SP[i++]; + arg = base[i++]; if (SvROK(arg) && (SvTYPE(SvRV(arg)) <= SVt_PVLV) && !isGV_with_GP(SvRV(arg))) { filter_cache = SvRV(arg); if (i < count) { - arg = SP[i++]; + arg = base[i++]; } } @@ -4617,7 +4884,7 @@ S_require_file(pTHX_ SV *sv) } if (i < count) { - arg = SP[i++]; + arg = base[i++]; } } @@ -4626,7 +4893,7 @@ S_require_file(pTHX_ SV *sv) SvREFCNT_inc_simple_void_NN(filter_sub); if (i < count) { - filter_state = SP[i]; + filter_state = base[i]; SvREFCNT_inc_simple_void(filter_state); } } @@ -4635,8 +4902,8 @@ S_require_file(pTHX_ SV *sv) tryrsfp = PerlIO_open(BIT_BUCKET, PERL_SCRIPT_MODE); } - done_hook: - SP--; + done_hook: + rpp_popfree_to_NN(base - 1); } else { SV *errsv= ERRSV; if (SvTRUE(errsv) && !SvROK(errsv)) { @@ -4681,7 +4948,6 @@ S_require_file(pTHX_ SV *sv) inc_idx_sv = GvSVn(PL_incgv); inc_idx = SvOK(inc_idx_sv) ? SvIV(inc_idx_sv) : -1; - PUTBACK; FREETMPS; LEAVE_with_name("call_INC_hook"); @@ -4910,12 +5176,15 @@ S_require_file(pTHX_ SV *sv) } #endif CLEAR_ERRSV(); - RETPUSHUNDEF; + rpp_replace_1_IMM_NN(&PL_sv_undef); + return NORMAL; } } else SETERRNO(0, SS_NORMAL); + rpp_popfree_1_NN(); /* finished with sv now */ + /* Update %INC. Assume success here to prevent recursive requirement. */ /* name is never assigned to again, so len is still strlen(name) */ /* Check whether a hook in @INC has already filled %INC */ @@ -4955,14 +5224,12 @@ S_require_file(pTHX_ SV *sv) /* switch to eval mode */ assert(!CATCH_GET); - cx = cx_pushblock(CXt_EVAL, gimme, SP, old_savestack_ix); + cx = cx_pushblock(CXt_EVAL, gimme, PL_stack_sp, old_savestack_ix); cx_pusheval(cx, PL_op->op_next, newSVpv(name, 0)); SAVECOPLINE(&PL_compiling); CopLINE_set(&PL_compiling, 0); - PUTBACK; - if (doeval_compile(gimme, NULL, PL_curcop->cop_seq, NULL)) op = PL_eval_start; else @@ -4989,10 +5256,10 @@ PP(pp_require) return docatch(Perl_pp_require); { - dSP; - SV *sv = POPs; + SV *sv = *PL_stack_sp; SvGETMAGIC(sv); - PUTBACK; + /* these tail-called subs are responsible for popping sv off the + * stack */ return ((SvNIOKp(sv) || SvVOK(sv)) && PL_op->op_type != OP_DOFILE) ? S_require_version(aTHX_ sv) : S_require_file(aTHX_ sv); @@ -5006,15 +5273,14 @@ PP(pp_require) PP(pp_hintseval) { - dSP; - mXPUSHs(MUTABLE_SV(hv_copy_hints_hv(MUTABLE_HV(cSVOP_sv)))); - RETURN; + rpp_extend(1); + rpp_push_1_norc(MUTABLE_SV(hv_copy_hints_hv(MUTABLE_HV(cSVOP_sv)))); + return NORMAL; } PP(pp_entereval) { - dSP; PERL_CONTEXT *cx; SV *sv; U8 gimme; @@ -5050,7 +5316,7 @@ PP(pp_entereval) bytes = PL_op->op_private & OPpEVAL_BYTES; if (PL_op->op_private & OPpEVAL_HAS_HH) { - saved_hh = MUTABLE_HV(SvREFCNT_inc(POPs)); + saved_hh = MUTABLE_HV(rpp_pop_1_norc()); } else if (PL_hints & HINT_LOCALIZE_HH || ( PL_op->op_private & OPpEVAL_COPHH @@ -5059,7 +5325,7 @@ PP(pp_entereval) saved_hh = cop_hints_2hv(PL_curcop, 0); hv_magic(saved_hh, NULL, PERL_MAGIC_hints); } - sv = POPs; + sv = *PL_stack_sp; if (!SvPOK(sv)) { /* make sure we've got a plain PV (no overload etc) before testing * for taint. Making a copy here is probably overkill, but better @@ -5093,6 +5359,8 @@ PP(pp_entereval) ) ); + rpp_popfree_1_NN(); /* can free sv now */ + /* switch to eval mode */ if (PERLDB_NAMEEVAL && CopLINE(PL_curcop)) { @@ -5117,7 +5385,8 @@ PP(pp_entereval) runcv = find_runcv(&seq); assert(!CATCH_GET); - cx = cx_pushblock((CXt_EVAL|CXp_REAL), gimme, SP, old_savestack_ix); + cx = cx_pushblock((CXt_EVAL|CXp_REAL), + gimme, PL_stack_sp, old_savestack_ix); cx_pusheval(cx, PL_op->op_next, NULL); /* prepare to compile string */ @@ -5135,8 +5404,6 @@ PP(pp_entereval) saved_delete = TRUE; } - PUTBACK; - if (doeval_compile(gimme, runcv, seq, saved_hh)) { if (was != PL_breakable_sub_gen /* Some subs defined here. */ ? PERLDB_LINE_OR_SAVESRC @@ -5242,7 +5509,7 @@ PP(pp_leaveeval) : PL_stack_sp > oldsp); if (gimme == G_VOID) { - PL_stack_sp = oldsp; + rpp_popfree_to(oldsp); /* free now to avoid late-called destructors clobbering $@ */ FREETMPS; } @@ -5270,11 +5537,8 @@ PP(pp_leaveeval) /* make sure that we use a standard return when feature 'module_load' * is enabled. Returns from require are problematic (consider what happens * when it is called twice) */ - if (gimme == G_SCALAR) { - /* this following is an optimization of POPs()/PUSHs(). - * and does the same thing with less bookkeeping */ - *PL_stack_sp = &PL_sv_yes; - } + if (gimme == G_SCALAR) + rpp_replace_1_IMM_NN(&PL_sv_yes); assert(gimme == G_VOID || gimme == G_SCALAR); failed = 0; } @@ -5366,13 +5630,15 @@ Perl_delete_eval_scope(pTHX) /* Common-ish code salvaged from Perl_call_sv and pp_entertry, because it was also needed by Perl_fold_constants. */ void -Perl_create_eval_scope(pTHX_ OP *retop, U32 flags) +Perl_create_eval_scope(pTHX_ OP *retop, SV **sp, U32 flags) { PERL_CONTEXT *cx; const U8 gimme = GIMME_V; + + PERL_ARGS_ASSERT_CREATE_EVAL_SCOPE; cx = cx_pushblock((CXt_EVAL|CXp_EVALBLOCK), gimme, - PL_stack_sp, PL_savestack_ix); + sp, PL_savestack_ix); cx_pusheval(cx, retop, NULL); PL_in_eval = EVAL_INEVAL; @@ -5401,7 +5667,7 @@ PP(pp_entertry) assert(!CATCH_GET); - create_eval_scope(retop, 0); + create_eval_scope(retop, PL_stack_sp, 0); return PL_op->op_next; } @@ -5424,7 +5690,7 @@ PP(pp_leavetry) gimme = cx->blk_gimme; if (gimme == G_VOID) { - PL_stack_sp = oldsp; + rpp_popfree_to_NN(oldsp); /* free now to avoid late-called destructors clobbering $@ */ FREETMPS; } @@ -5442,19 +5708,17 @@ PP(pp_leavetry) PP(pp_entergiven) { - dSP; PERL_CONTEXT *cx; const U8 gimme = GIMME_V; SV *origsv = DEFSV; - SV *newsv = POPs; assert(!PL_op->op_targ); /* used to be set for lexical $_ */ - GvSV(PL_defgv) = SvREFCNT_inc(newsv); + GvSV(PL_defgv) = rpp_pop_1_norc(); - cx = cx_pushblock(CXt_GIVEN, gimme, SP, PL_savestack_ix); + cx = cx_pushblock(CXt_GIVEN, gimme, PL_stack_sp, PL_savestack_ix); cx_pushgiven(cx, origsv); - RETURN; + return NORMAL; } PP(pp_leavegiven) @@ -5470,7 +5734,7 @@ PP(pp_leavegiven) gimme = cx->blk_gimme; if (gimme == G_VOID) - PL_stack_sp = oldsp; + rpp_popfree_to_NN(oldsp); else leave_adjust_stacks(oldsp, oldsp, gimme, 1); @@ -5501,19 +5765,15 @@ S_make_matcher(pTHX_ REGEXP *re) STATIC bool S_matcher_matches_sv(pTHX_ PMOP *matcher, SV *sv) { - dSP; bool result; PERL_ARGS_ASSERT_MATCHER_MATCHES_SV; PL_op = (OP *) matcher; - XPUSHs(sv); - PUTBACK; + rpp_xpush_1(sv); (void) Perl_pp_match(aTHX); - SPAGAIN; - result = SvTRUEx(POPs); - PUTBACK; - + result = SvTRUEx(*PL_stack_sp); + rpp_popfree_1_NN(); return result; } @@ -5527,6 +5787,7 @@ S_destroy_matcher(pTHX_ PMOP *matcher) LEAVE_with_name("matcher"); } + /* Do a smart match */ PP(pp_smartmatch) { @@ -5534,17 +5795,16 @@ PP(pp_smartmatch) return do_smartmatch(NULL, NULL, 0); } + /* This version of do_smartmatch() implements the * table of smart matches that is found in perlsyn. */ STATIC OP * S_do_smartmatch(pTHX_ HV *seen_this, HV *seen_other, const bool copied) { - dSP; - bool object_on_left = FALSE; - SV *e = TOPs; /* e is for 'expression' */ - SV *d = TOPm1s; /* d is for 'default', as in PL_defgv */ + SV *e = PL_stack_sp[0]; /* e is for 'expression' */ + SV *d = PL_stack_sp[-1]; /* d is for 'default', as in PL_defgv */ /* Take care only to invoke mg_get() once for each argument. * Currently we do this by copying the SV if it's magical. */ @@ -5567,24 +5827,19 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV tmpsv = amagic_call(d, e, smart_amg, AMGf_noleft); if (tmpsv) { - SPAGAIN; - (void)POPs; - SETs(tmpsv); - RETURN; + rpp_replace_2_1_NN(tmpsv); + return NORMAL; } DEBUG_M(Perl_deb(aTHX_ " failed to run overload method; continuing...\n")); } - SP -= 2; /* Pop the values */ - PUTBACK; - /* ~~ undef */ if (!SvOK(e)) { DEBUG_M(Perl_deb(aTHX_ " applying rule Any-undef\n")); if (SvOK(d)) - RETPUSHNO; + goto ret_no; else - RETPUSHYES; + goto ret_yes; } if (SvROK(e) && SvOBJECT(SvRV(e)) && (SvTYPE(SvRV(e)) != SVt_REGEXP)) { @@ -5596,7 +5851,6 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV /* ~~ sub */ if (SvROK(e) && SvTYPE(SvRV(e)) == SVt_PVCV) { - I32 c; if (object_on_left) { goto sm_any_sub; /* Treat objects like scalars */ } @@ -5608,27 +5862,23 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV I32 numkeys = hv_iterinit(hv); DEBUG_M(Perl_deb(aTHX_ " applying rule Hash-CodeRef\n")); if (numkeys == 0) - RETPUSHYES; + goto ret_yes; while ( (he = hv_iternext(hv)) ) { DEBUG_M(Perl_deb(aTHX_ " testing hash key...\n")); ENTER_with_name("smartmatch_hash_key_test"); SAVETMPS; - PUSHMARK(SP); - PUSHs(hv_iterkeysv(he)); - PUTBACK; - c = call_sv(e, G_SCALAR); - SPAGAIN; - if (c == 0) - andedresults = FALSE; - else - andedresults = SvTRUEx(POPs) && andedresults; + PUSHMARK(PL_stack_sp); + rpp_xpush_1(hv_iterkeysv(he)); + (void)call_sv(e, G_SCALAR); + andedresults = SvTRUEx(PL_stack_sp[0]) && andedresults; + rpp_popfree_1_NN(); FREETMPS; LEAVE_with_name("smartmatch_hash_key_test"); } if (andedresults) - RETPUSHYES; + goto ret_yes; else - RETPUSHNO; + goto ret_no; } else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVAV) { /* Test sub truth for each element */ @@ -5638,47 +5888,40 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV const Size_t len = av_count(av); DEBUG_M(Perl_deb(aTHX_ " applying rule Array-CodeRef\n")); if (len == 0) - RETPUSHYES; + goto ret_yes; for (i = 0; i < len; ++i) { SV * const * const svp = av_fetch(av, i, FALSE); DEBUG_M(Perl_deb(aTHX_ " testing array element...\n")); ENTER_with_name("smartmatch_array_elem_test"); SAVETMPS; - PUSHMARK(SP); + PUSHMARK(PL_stack_sp); if (svp) - PUSHs(*svp); - PUTBACK; - c = call_sv(e, G_SCALAR); - SPAGAIN; - if (c == 0) - andedresults = FALSE; - else - andedresults = SvTRUEx(POPs) && andedresults; + rpp_xpush_1(*svp); + (void)call_sv(e, G_SCALAR); + andedresults = SvTRUEx(PL_stack_sp[0]) && andedresults; + rpp_popfree_1_NN(); FREETMPS; LEAVE_with_name("smartmatch_array_elem_test"); } if (andedresults) - RETPUSHYES; + goto ret_yes; else - RETPUSHNO; + goto ret_no; } else { sm_any_sub: DEBUG_M(Perl_deb(aTHX_ " applying rule Any-CodeRef\n")); ENTER_with_name("smartmatch_coderef"); - SAVETMPS; - PUSHMARK(SP); - PUSHs(d); - PUTBACK; - c = call_sv(e, G_SCALAR); - SPAGAIN; - if (c == 0) - PUSHs(&PL_sv_no); - else if (SvTEMP(TOPs)) - SvREFCNT_inc_void(TOPs); - FREETMPS; + PUSHMARK(PL_stack_sp); + rpp_xpush_1(d); + (void)call_sv(e, G_SCALAR); LEAVE_with_name("smartmatch_coderef"); - RETURN; + SV *retsv = *PL_stack_sp--; + rpp_replace_2_1(retsv); +#ifdef PERL_RC_STACK + SvREFCNT_dec(retsv); +#endif + return NORMAL; } } /* ~~ %hash */ @@ -5688,7 +5931,7 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV } else if (!SvOK(d)) { DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Hash ($a undef)\n")); - RETPUSHNO; + goto ret_no; } else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVHV) { /* Check that the key-sets are identical */ @@ -5714,7 +5957,7 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV other_tied = FALSE; } else if(HvUSEDKEYS((const HV *) hv) != HvUSEDKEYS(other_hv)) - RETPUSHNO; + goto ret_no; } /* The hashes have the same number of keys, so it suffices @@ -5728,7 +5971,7 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV if(!hv_exists_ent(other_hv, key, 0)) { (void) hv_iterinit(hv); /* reset iterator */ - RETPUSHNO; + goto ret_no; } } @@ -5741,9 +5984,9 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV other_key_count = HvUSEDKEYS(other_hv); if (this_key_count != other_key_count) - RETPUSHNO; + goto ret_no; else - RETPUSHYES; + goto ret_yes; } else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVAV) { AV * const other_av = MUTABLE_AV(SvRV(d)); @@ -5757,10 +6000,10 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV DEBUG_M(Perl_deb(aTHX_ " checking for key existence...\n")); if (svp) { /* ??? When can this not happen? */ if (hv_exists_ent(hv, *svp, 0)) - RETPUSHYES; + goto ret_yes; } } - RETPUSHNO; + goto ret_no; } else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_REGEXP) { DEBUG_M(Perl_deb(aTHX_ " applying rule Regex-Hash\n")); @@ -5773,26 +6016,23 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV (void) hv_iterinit(hv); while ( (he = hv_iternext(hv)) ) { DEBUG_M(Perl_deb(aTHX_ " testing key against pattern...\n")); - PUTBACK; if (matcher_matches_sv(matcher, hv_iterkeysv(he))) { - SPAGAIN; (void) hv_iterinit(hv); destroy_matcher(matcher); - RETPUSHYES; + goto ret_yes; } - SPAGAIN; } destroy_matcher(matcher); - RETPUSHNO; + goto ret_no; } } else { sm_any_hash: DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Hash\n")); if (hv_exists_ent(MUTABLE_HV(SvRV(e)), d, 0)) - RETPUSHYES; + goto ret_yes; else - RETPUSHNO; + goto ret_no; } } /* ~~ @array */ @@ -5812,16 +6052,16 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV DEBUG_M(Perl_deb(aTHX_ " testing for key existence...\n")); if (svp) { /* ??? When can this not happen? */ if (hv_exists_ent(MUTABLE_HV(SvRV(d)), *svp, 0)) - RETPUSHYES; + goto ret_yes; } } - RETPUSHNO; + goto ret_no; } if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_PVAV) { AV *other_av = MUTABLE_AV(SvRV(d)); DEBUG_M(Perl_deb(aTHX_ " applying rule Array-Array\n")); if (av_count(MUTABLE_AV(SvRV(e))) != av_count(other_av)) - RETPUSHNO; + goto ret_no; else { Size_t i; const Size_t other_len = av_count(other_av); @@ -5839,7 +6079,7 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV if (!this_elem || !other_elem) { if ((this_elem && SvOK(*this_elem)) || (other_elem && SvOK(*other_elem))) - RETPUSHNO; + goto ret_no; } else if (hv_exists_ent(seen_this, sv_2mortal(newSViv(PTR2IV(*this_elem))), 0) || @@ -5847,7 +6087,7 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV sv_2mortal(newSViv(PTR2IV(*other_elem))), 0)) { if (*this_elem != *other_elem) - RETPUSHNO; + goto ret_no; } else { (void)hv_store_ent(seen_this, @@ -5856,20 +6096,18 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV (void)hv_store_ent(seen_other, sv_2mortal(newSViv(PTR2IV(*other_elem))), &PL_sv_undef, 0); - PUSHs(*other_elem); - PUSHs(*this_elem); - - PUTBACK; + rpp_xpush_2(*other_elem, *this_elem); DEBUG_M(Perl_deb(aTHX_ " recursively comparing array element...\n")); (void) do_smartmatch(seen_this, seen_other, 0); - SPAGAIN; DEBUG_M(Perl_deb(aTHX_ " recursion finished\n")); - if (!SvTRUEx(POPs)) - RETPUSHNO; + bool ok = SvTRUEx(PL_stack_sp[0]); + rpp_popfree_1_NN(); + if (!ok) + goto ret_no; } } - RETPUSHYES; + goto ret_yes; } } else if (SvROK(d) && SvTYPE(SvRV(d)) == SVt_REGEXP) { @@ -5883,16 +6121,13 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV for(i = 0; i < this_len; ++i) { SV * const * const svp = av_fetch(MUTABLE_AV(SvRV(e)), i, FALSE); DEBUG_M(Perl_deb(aTHX_ " testing element against pattern...\n")); - PUTBACK; if (svp && matcher_matches_sv(matcher, *svp)) { - SPAGAIN; destroy_matcher(matcher); - RETPUSHYES; + goto ret_yes; } - SPAGAIN; } destroy_matcher(matcher); - RETPUSHNO; + goto ret_no; } } else if (!SvOK(d)) { @@ -5905,9 +6140,9 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV SV * const * const svp = av_fetch(MUTABLE_AV(SvRV(e)), i, FALSE); DEBUG_M(Perl_deb(aTHX_ " testing for undef element...\n")); if (!svp || !SvOK(*svp)) - RETPUSHYES; + goto ret_yes; } - RETPUSHNO; + goto ret_no; } else { sm_any_array: @@ -5921,18 +6156,17 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV if (!svp) continue; - PUSHs(d); - PUSHs(*svp); - PUTBACK; + rpp_xpush_2(d, *svp); /* infinite recursion isn't supposed to happen here */ DEBUG_M(Perl_deb(aTHX_ " recursively testing array element...\n")); (void) do_smartmatch(NULL, NULL, 1); - SPAGAIN; DEBUG_M(Perl_deb(aTHX_ " recursion finished\n")); - if (SvTRUEx(POPs)) - RETPUSHYES; + bool ok = SvTRUEx(PL_stack_sp[0]); + rpp_popfree_1_NN(); + if (ok) + goto ret_yes; } - RETPUSHNO; + goto ret_no; } } } @@ -5953,12 +6187,12 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV bool result; DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Regex\n")); - PUTBACK; result = matcher_matches_sv(matcher, d); - SPAGAIN; - PUSHs(result ? &PL_sv_yes : &PL_sv_no); destroy_matcher(matcher); - RETURN; + if (result) + goto ret_yes; + else + goto ret_no; } } /* ~~ scalar */ @@ -5967,23 +6201,19 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV SV *tmpsv; DEBUG_M(Perl_deb(aTHX_ " applying rule Object-Any\n")); DEBUG_M(Perl_deb(aTHX_ " attempting overload\n")); - PUSHs(d); PUSHs(e); - PUTBACK; tmpsv = amagic_call(d, e, smart_amg, AMGf_noright); if (tmpsv) { - SPAGAIN; - (void)POPs; - SETs(tmpsv); - RETURN; + rpp_replace_2_1_NN(tmpsv); + return NORMAL; } - SP -= 2; + DEBUG_M(Perl_deb(aTHX_ " failed to run overload method; falling back...\n")); goto sm_any_scalar; } else if (!SvOK(d)) { /* undef ~~ scalar ; we already know that the scalar is SvOK */ DEBUG_M(Perl_deb(aTHX_ " applying rule undef-Any\n")); - RETPUSHNO; + goto ret_no; } else sm_any_scalar: @@ -5994,29 +6224,44 @@ S_do_smartmatch(pTHX_ HV *seen_this, HV Perl_deb(aTHX_ " applying rule Num-numish\n"); ); /* numeric comparison */ - PUSHs(d); PUSHs(e); - PUTBACK; + rpp_xpush_2(d, e); if (CopHINTS_get(PL_curcop) & HINT_INTEGER) (void) Perl_pp_i_eq(aTHX); else (void) Perl_pp_eq(aTHX); - SPAGAIN; - if (SvTRUEx(POPs)) - RETPUSHYES; + bool ok = SvTRUEx(PL_stack_sp[0]); + rpp_popfree_1_NN(); + if (ok) + goto ret_yes; else - RETPUSHNO; + goto ret_no; } /* As a last resort, use string comparison */ DEBUG_M(Perl_deb(aTHX_ " applying rule Any-Any\n")); - PUSHs(d); PUSHs(e); - PUTBACK; - return Perl_pp_seq(aTHX); + rpp_xpush_2(d, e); + Perl_pp_seq(aTHX); + { + bool ok = SvTRUEx(PL_stack_sp[0]); + rpp_popfree_1_NN(); + if (ok) + goto ret_yes; + else + goto ret_no; + } + + ret_no: + rpp_replace_2_IMM_NN(&PL_sv_no); + return NORMAL; + + ret_yes: + rpp_replace_2_IMM_NN(&PL_sv_yes); + return NORMAL; } + PP(pp_enterwhen) { - dSP; PERL_CONTEXT *cx; const U8 gimme = GIMME_V; @@ -6024,18 +6269,21 @@ PP(pp_enterwhen) fails, we don't want to push a context and then pop it again right away, so we skip straight to the op that follows the leavewhen. - RETURNOP calls PUTBACK which restores the stack pointer after the POPs. */ - if (!(PL_op->op_flags & OPf_SPECIAL) && !SvTRUEx(POPs)) { - if (gimme == G_SCALAR) - PUSHs(&PL_sv_undef); - RETURNOP(cLOGOP->op_other->op_next); + if (!(PL_op->op_flags & OPf_SPECIAL)) { /* SPECIAL implies no condition */ + bool tr = SvTRUEx(*PL_stack_sp); + rpp_popfree_1_NN(); + if (!tr) { + if (gimme == G_SCALAR) + rpp_push_IMM(&PL_sv_undef); + return cLOGOP->op_other->op_next; + } } - cx = cx_pushblock(CXt_WHEN, gimme, SP, PL_savestack_ix); + cx = cx_pushblock(CXt_WHEN, gimme, PL_stack_sp, PL_savestack_ix); cx_pushwhen(cx); - RETURN; + return NORMAL; } PP(pp_leavewhen) @@ -6057,7 +6305,7 @@ PP(pp_leavewhen) oldsp = PL_stack_base + cx->blk_oldsp; if (gimme == G_VOID) - PL_stack_sp = oldsp; + rpp_popfree_to_NN(oldsp); else leave_adjust_stacks(oldsp, oldsp, gimme, 1); @@ -6097,7 +6345,7 @@ PP(pp_continue) cx = CX_CUR(); assert(CxTYPE(cx) == CXt_WHEN); - PL_stack_sp = PL_stack_base + cx->blk_oldsp; + rpp_popfree_to_NN(PL_stack_base + cx->blk_oldsp); CX_LEAVE_SCOPE(cx); cx_popwhen(cx); cx_popblock(cx); @@ -6125,7 +6373,7 @@ PP(pp_break) /* Restore the sp at the time we entered the given block */ cx = CX_CUR(); - PL_stack_sp = PL_stack_base + cx->blk_oldsp; + rpp_popfree_to_NN(PL_stack_base + cx->blk_oldsp); return cx->blk_givwhen.leave_op; } @@ -6156,7 +6404,16 @@ _invoke_defer_block(pTHX_ U8 type, void cx = CX_CUR(); assert(CxTYPE(cx) == CXt_DEFER); - PL_stack_sp = PL_stack_base + cx->blk_oldsp; + /* since we're called during a scope cleanup (including after + * a croak), theere's no guarantee thr stack is currently + * ref-counted */ +#ifdef PERL_RC_STACK + if (rpp_stack_is_rc()) + rpp_popfree_to_NN(PL_stack_base + cx->blk_oldsp); + else +#endif + PL_stack_sp = PL_stack_base + cx->blk_oldsp; + CX_LEAVE_SCOPE(cx); cx_popblock(cx); Index: gnu/usr.bin/perl/pp_hot.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/pp_hot.c,v diff -u -p -a -u -p -r1.26 pp_hot.c --- gnu/usr.bin/perl/pp_hot.c 14 May 2024 19:38:54 -0000 1.26 +++ gnu/usr.bin/perl/pp_hot.c 22 Jan 2025 00:37:45 -0000 @@ -35,21 +35,204 @@ #define PERL_IN_PP_HOT_C #include "perl.h" #include "regcomp.h" +#include "feature.h" /* Hot code. */ + +#ifdef PERL_RC_STACK + +/* common code for pp_wrap() and xs_wrap(): + * free any original arguments, and bump and shift down any return + * args + */ + +STATIC void +S_pp_xs_wrap_return(pTHX_ I32 nargs, I32 old_sp) +{ + I32 nret = (I32)(PL_stack_sp - PL_stack_base) - old_sp; + assert(nret >= 0); + + /* bump any returned values */ + if (nret) { + SV **svp = PL_stack_sp - nret + 1; + while (svp <= PL_stack_sp) { + SvREFCNT_inc(*svp); + svp++; + } + } + + PL_curstackinfo->si_stack_nonrc_base = 0; + + /* free the original args and shift the returned valued down */ + if (nargs) { + SV **svp = PL_stack_sp - nret; + I32 i = nargs; + while (i--) { + SvREFCNT_dec(*svp); + *svp = NULL; + svp--; + } + + if (nret) { + Move(PL_stack_sp - nret + 1, + PL_stack_sp - nret - nargs + 1, + nret, SV*); + } + PL_stack_sp -= nargs; + } +} + +/* pp_wrap(): + * wrapper function for pp() functions to turn them into functions + * that can operate on a reference-counted stack, by taking a non- + * reference-counted copy of the current stack frame, calling the real + * pp() function, then incrementing the reference count of any returned + * args. + * + * nargs or nlists indicate the number of stack arguments or the + * number of stack lists (delimited by MARKs) which the function expects. + */ +OP* +Perl_pp_wrap(pTHX_ Perl_ppaddr_t real_pp_fn, I32 nargs, int nlists) +{ + PERL_ARGS_ASSERT_PP_WRAP; + + if (!rpp_stack_is_rc()) + /* stack-already non-RC; nothing needing wrapping */ + return real_pp_fn(aTHX); + + OP *next_op; + I32 old_sp = (I32)(PL_stack_sp - PL_stack_base); + + assert(nargs >= 0); + assert(nlists >= 0); + assert(AvREAL(PL_curstack)); + + PL_curstackinfo->si_stack_nonrc_base = PL_stack_sp - PL_stack_base + 1; + + if (nlists) { + assert(nargs == 0); + I32 mark = PL_markstack_ptr[-nlists+1]; + nargs = (PL_stack_sp - PL_stack_base) - mark; + assert(nlists <= 2); /* if ever more, make below a loop */ + PL_markstack_ptr[0] += nargs; + if (nlists == 2) + PL_markstack_ptr[-1] += nargs; + } + + if (nargs) { + /* duplicate all the arg pointers further up the stack */ + rpp_extend(nargs); + Copy(PL_stack_sp - nargs + 1, PL_stack_sp + 1, nargs, SV*); + PL_stack_sp += nargs; + } + + next_op = real_pp_fn(aTHX); + + /* we should still be a split stack */ + assert(AvREAL(PL_curstack)); + assert(PL_curstackinfo->si_stack_nonrc_base); + + S_pp_xs_wrap_return(aTHX_ nargs, old_sp); + + return next_op; +} + + +/* xs_wrap(): + * similar in concept to pp_wrap: make a non-referenced-counted copy of + * a (not refcount aware) XS sub's args, call the XS subs, then bump any + * return values and free the original args */ + +void +Perl_xs_wrap(pTHX_ XSUBADDR_t xsub, CV *cv) +{ + PERL_ARGS_ASSERT_XS_WRAP; + + I32 old_sp = (I32)(PL_stack_sp - PL_stack_base); + I32 mark = PL_markstack_ptr[0]; + I32 nargs = (PL_stack_sp - PL_stack_base) - mark; + + /* we should be a fully refcounted stack */ + assert(AvREAL(PL_curstack)); + assert(!PL_curstackinfo->si_stack_nonrc_base); + + PL_curstackinfo->si_stack_nonrc_base = PL_stack_sp - PL_stack_base + 1; + + + if (nargs) { + /* duplicate all the arg pointers further up the stack */ + rpp_extend(nargs); + Copy(PL_stack_sp - nargs + 1, PL_stack_sp + 1, nargs, SV*); + PL_stack_sp += nargs; + PL_markstack_ptr[0] += nargs; + } + + xsub(aTHX_ cv); + + S_pp_xs_wrap_return(aTHX_ nargs, old_sp); +} + +#endif + + + +/* Private helper function for Perl_rpp_replace_2_1_COMMON() + * and rpp_popfree_2_NN(). + * Free the two passed SVs, whose original ref counts are rc1 and rc2. + * Assumes the stack initially looked like + * .... sv1 sv2 + * and is now: + * .... X + * but where sv2 is still on the slot above the current PL_stack_sp. + */ + +void +Perl_rpp_free_2_(pTHX_ SV *const sv1, SV *const sv2, + const U32 rc1, const U32 rc2) +{ + + PERL_ARGS_ASSERT_RPP_FREE_2_; + +#ifdef PERL_RC_STACK + if (rc1 > 1) + SvREFCNT(sv1) = rc1 - 1; + else { + /* temporarily reclaim sv2 on stack in case we die while freeing sv1 */ + assert(PL_stack_sp[1] == sv2); + PL_stack_sp++; + Perl_sv_free2(aTHX_ sv1, rc1); + PL_stack_sp--; + } + if (rc2 > 1) + SvREFCNT(sv2) = rc2 - 1; + else + Perl_sv_free2(aTHX_ sv2, rc2); +#else + PERL_UNUSED_VAR(sv1); + PERL_UNUSED_VAR(sv2); + PERL_UNUSED_VAR(rc1); + PERL_UNUSED_VAR(rc2); +#endif +} + + + +/* ----------------------------------------------------------- */ + + PP(pp_const) { - dSP; - XPUSHs(cSVOP_sv); - RETURN; + rpp_xpush_1(cSVOP_sv); + return NORMAL; } PP(pp_nextstate) { PL_curcop = (COP*)PL_op; TAINT_NOT; /* Each statement is presumed innocent */ - PL_stack_sp = PL_stack_base + CX_CUR()->blk_oldsp; + rpp_popfree_to_NN(PL_stack_base + CX_CUR()->blk_oldsp); FREETMPS; PERL_ASYNC_CHECK(); return NORMAL; @@ -57,14 +240,12 @@ PP(pp_nextstate) PP(pp_gvsv) { - dSP; assert(SvTYPE(cGVOP_gv) == SVt_PVGV); - EXTEND(SP,1); - if (UNLIKELY(PL_op->op_private & OPpLVAL_INTRO)) - PUSHs(save_scalar(cGVOP_gv)); - else - PUSHs(GvSVn(cGVOP_gv)); - RETURN; + rpp_xpush_1( + UNLIKELY(PL_op->op_private & OPpLVAL_INTRO) + ? save_scalar(cGVOP_gv) + : GvSVn(cGVOP_gv)); + return NORMAL; } @@ -85,23 +266,20 @@ PP(pp_pushmark) PP(pp_stringify) { - dSP; dTARGET; - SV * const sv = TOPs; - SETs(TARG); - sv_copypv(TARG, sv); + dTARGET; + sv_copypv(TARG, *PL_stack_sp); SvSETMAGIC(TARG); - /* no PUTBACK, SETs doesn't inc/dec SP */ + rpp_replace_1_1_NN(TARG); return NORMAL; } PP(pp_gv) { - dSP; /* cGVOP_gv might be a real GV or might be an RV to a CV */ assert(SvTYPE(cGVOP_gv) == SVt_PVGV || (SvTYPE(cGVOP_gv) <= SVt_PVMG && SvROK(cGVOP_gv) && SvTYPE(SvRV(cGVOP_gv)) == SVt_PVCV)); - XPUSHs(MUTABLE_SV(cGVOP_gv)); - RETURN; + rpp_xpush_1(MUTABLE_SV(cGVOP_gv)); + return NORMAL; } @@ -111,17 +289,12 @@ PP(pp_and) { PERL_ASYNC_CHECK(); { - /* SP is not used to remove a variable that is saved across the - sv_2bool_flags call in SvTRUE_NN, if a RISC/CISC or low/high machine - register or load/store vs direct mem ops macro is introduced, this - should be a define block between direct PL_stack_sp and dSP operations, - presently, using PL_stack_sp is bias towards CISC cpus */ SV * const sv = *PL_stack_sp; if (!SvTRUE_NN(sv)) return NORMAL; else { if (PL_op->op_type == OP_AND) - --PL_stack_sp; + rpp_popfree_1_NN(); return cLOGOP->op_other; } } @@ -137,11 +310,10 @@ PP(pp_and) PP(pp_padsv_store) { - dSP; OP * const op = PL_op; SV** const padentry = &PAD_SVl(op->op_targ); SV* targ = *padentry; /* lvalue to assign into */ - SV* const val = TOPs; /* RHS value to assign */ + SV* const val = *PL_stack_sp; /* RHS value to assign */ /* !OPf_STACKED is not handled by this OP */ assert(op->op_flags & OPf_STACKED); @@ -165,17 +337,17 @@ PP(pp_padsv_store) ); SvSetMagicSV(targ, val); - SETs(targ); - RETURN; + rpp_replace_1_1_NN(targ); + return NORMAL; } + /* A mashup of simplified AELEMFAST_LEX + SASSIGN OPs */ PP(pp_aelemfastlex_store) { - dSP; OP * const op = PL_op; - SV* const val = TOPs; /* RHS value to assign */ + SV* const val = *PL_stack_sp; /* RHS value to assign */ AV * const av = MUTABLE_AV(PAD_SV(op->op_targ)); const I8 key = (I8)PL_op->op_private; SV * targ = NULL; @@ -215,25 +387,29 @@ PP(pp_aelemfastlex_store) SvSetMagicSV(targ, val); - SETs(targ); - RETURN; + assert(GIMME_V == G_VOID); + rpp_popfree_1_NN(); + return NORMAL; } PP(pp_sassign) { - dSP; /* sassign keeps its args in the optree traditionally backwards. So we pop them differently. */ - SV *left = POPs; SV *right = TOPs; + SV *left = PL_stack_sp[0]; + SV *right = PL_stack_sp[-1]; if (PL_op->op_private & OPpASSIGN_BACKWARDS) { /* {or,and,dor}assign */ SV * const temp = left; left = right; right = temp; + PL_stack_sp[0] = left; + PL_stack_sp[-1] = right; } assert(TAINTING_get || !TAINT_get); if (UNLIKELY(TAINT_get) && !SvTAINTED(right)) TAINT_NOT; + if (UNLIKELY(PL_op->op_private & OPpASSIGN_CV_TO_GV)) { /* *foo =\&bar */ SV * const cv = SvRV(right); @@ -260,15 +436,17 @@ PP(pp_sassign) SvPCS_IMPORTED_on(gv); SvRV_set(gv, value); SvREFCNT_inc_simple_void(value); - SETs(left); - RETURN; + rpp_replace_2_1_NN(left); + return NORMAL; } } /* Need to fix things up. */ if (!is_gv) { /* Need to fix GV. */ - left = MUTABLE_SV(gv_fetchsv_nomg(left,GV_ADD, SVt_PVGV)); + SV *sv = MUTABLE_SV(gv_fetchsv_nomg(left,GV_ADD, SVt_PVGV)); + rpp_replace_1_1_NN(sv); + left = sv; } if (!got_coderef) { @@ -314,25 +492,34 @@ PP(pp_sassign) } if ( - UNLIKELY(SvTEMP(left)) && !SvSMAGICAL(left) && SvREFCNT(left) == 1 && + rpp_is_lone(left) && !SvSMAGICAL(left) && (!isGV_with_GP(left) || SvFAKE(left)) && ckWARN(WARN_MISC) ) Perl_warner(aTHX_ packWARN(WARN_MISC), "Useless assignment to a temporary" ); SvSetMagicSV(left, right); - SETs(left); - RETURN; + if (LIKELY(GIMME_V == G_VOID)) + rpp_popfree_2_NN(); /* pop left and right */ + else { + /* pop right, leave left on the stack */ + assert(PL_stack_sp[-1] == right); + assert(PL_stack_sp[0] == left); + *--PL_stack_sp = left; +#ifdef PERL_RC_STACK + SvREFCNT_dec_NN(right); +#endif + } + + return NORMAL; } PP(pp_cond_expr) { - dSP; - SV *sv; - PERL_ASYNC_CHECK(); - sv = POPs; - RETURNOP(SvTRUE_NN(sv) ? cLOGOP->op_other : cLOGOP->op_next); + bool ok = SvTRUE_NN(*PL_stack_sp); + rpp_popfree_1_NN(); + return (ok ? cLOGOP->op_other : cLOGOP->op_next); } PP(pp_unstack) @@ -341,7 +528,7 @@ PP(pp_unstack) PERL_ASYNC_CHECK(); TAINT_NOT; /* Each statement is presumed innocent */ cx = CX_CUR(); - PL_stack_sp = PL_stack_base + cx->blk_oldsp; + rpp_popfree_to_NN(PL_stack_base + CX_CUR()->blk_oldsp); FREETMPS; if (!(PL_op->op_flags & OPf_SPECIAL)) { assert(CxTYPE(cx) == CXt_BLOCK || CxTYPE_is_LOOP(cx)); @@ -423,13 +610,18 @@ S_do_concat(pTHX_ SV *left, SV *right, S PP(pp_concat) { - dSP; dATARGET; tryAMAGICbin_MG(concat_amg, AMGf_assign); - { - dPOPTOPssrl; + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + + if (rpp_try_AMAGIC_2(concat_amg, AMGf_assign)) + return NORMAL; + + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; S_do_concat(aTHX_ left, right, targ, PL_op->op_private & OPpTARGET_MY); - SETs(TARG); - RETURN; - } + rpp_replace_2_1_NN(targ); + return NORMAL; } @@ -494,7 +686,6 @@ have differing overloading behaviour. PP(pp_multiconcat) { - dSP; SV *targ; /* The SV to be assigned or appended to */ char *targ_pv; /* where within SvPVX(targ) we're writing to */ STRLEN targ_len; /* SvCUR(targ) */ @@ -503,7 +694,7 @@ PP(pp_multiconcat) UNOP_AUX_item *const_lens; /* the segment length array part of aux */ const char *const_pv; /* the current segment of the const string buf */ SSize_t nargs; /* how many args were expected */ - SSize_t stack_adj; /* how much to adjust SP on return */ + SSize_t stack_adj; /* how much to adjust PL_stack_sp on return */ STRLEN grow; /* final size of destination string (targ) */ UV targ_count; /* how many times targ has appeared on the RHS */ bool is_append; /* OPpMULTICONCAT_APPEND flag is set */ @@ -528,15 +719,18 @@ PP(pp_multiconcat) /* get targ from the stack or pad */ + toparg = PL_stack_sp; if (PL_op->op_flags & OPf_STACKED) { + stack_adj++; if (is_append) { /* for 'expr .= ...', expr is the bottom item on the stack */ - targ = SP[-nargs]; - stack_adj++; + targ = PL_stack_sp[-nargs]; } - else + else { /* for 'expr = ...', expr is the top item on the stack */ - targ = POPs; + targ = *PL_stack_sp; + toparg--; + } } else { SV **svp = &(PAD_SVl(PL_op->op_targ)); @@ -547,11 +741,9 @@ PP(pp_multiconcat) } if (!nargs) /* $lex .= "const" doesn't cause anything to be pushed */ - EXTEND(SP,1); + rpp_extend(1); } - toparg = SP; - SP -= (nargs - 1); grow = 1; /* allow for '\0' at minimum */ targ_count = 0; targ_chain = NULL; @@ -578,14 +770,14 @@ PP(pp_multiconcat) * pp_cpncat() on each arg in turn' is done. */ - for (; SP <= toparg; SP++, svpv_end++) { + for (SV **svp = toparg - (nargs - 1); svp <= toparg; svp++, svpv_end++) { U32 utf8; STRLEN len; SV *sv; assert(svpv_end - svpv_buf < PERL_MULTICONCAT_MAXARG); - sv = *SP; + sv = *svp; /* this if/else chain is arranged so that common/simple cases * take few conditionals */ @@ -1012,10 +1204,11 @@ PP(pp_multiconcat) * return result */ - SP -= stack_adj; + rpp_popfree_to_NN(PL_stack_sp - stack_adj); SvTAINT(targ); - SETTARG; - RETURN; + SvSETMAGIC(targ); + rpp_push_1(targ); + return NORMAL; /* -------------------------------------------------------------- * Phase 7: @@ -1045,6 +1238,7 @@ PP(pp_multiconcat) U32 utf8 = 0; SV **svp; const char *cpv = aux[PERL_MULTICONCAT_IX_PLAIN_PV].pv; + SV *csv = NULL; /* SV which will hold cpv */ UNOP_AUX_item *lens = aux + PERL_MULTICONCAT_IX_LENGTHS; Size_t arg_count = 0; /* how many args have been processed */ @@ -1088,7 +1282,8 @@ PP(pp_multiconcat) ) ) { - SV *tmp = newSV_type_mortal(SVt_PV); + assert(aux[PERL_MULTICONCAT_IX_PADTMP2].pad_offset); + SV *tmp = PAD_SV(aux[PERL_MULTICONCAT_IX_PADTMP2].pad_offset); sv_copypv(tmp, left); SvSETMAGIC(tmp); left = tmp; @@ -1110,7 +1305,36 @@ PP(pp_multiconcat) else if (len < 0) continue; /* no const in this position */ else { - right = newSVpvn_flags(cpv, len, (utf8 | SVs_TEMP)); + /* Use one of our PADTMPs to fake up the SV which would + * have been returned by an OP_CONST. Try to reuse it if + * possible. If the refcount has gone up, something like + * overload code has taken a reference to it, so abandon + * it */ + if (!csv || SvREFCNT(csv) > 1 || SvLEN(csv) != 0) { + if (csv) + csv = newSV_type_mortal(SVt_PV); + else { + assert(aux[PERL_MULTICONCAT_IX_PADTMP1].pad_offset); + csv = PAD_SV( + aux[PERL_MULTICONCAT_IX_PADTMP1].pad_offset); + SvUPGRADE(csv, SVt_PV); + } + + if (utf8) + SvUTF8_on(csv); + SvREADONLY_on(csv); + SvPOK_on(csv); + } + /* use the const string buffer directly with the + * SvLEN==0 trick */ + + /* cast away constness because we think we know it's safe + * (SvREADONLY) */ + SvPV_set(csv, (char *)cpv); + SvLEN_set(csv, 0); + SvCUR_set(csv, len); + + right = csv; cpv += len; } @@ -1122,10 +1346,10 @@ PP(pp_multiconcat) } if (arg_count == 2 && i < n) { - /* for the first concat, create a mortal acting like the - * padtmp from OP_CONST. In later iterations this will + /* for the first concat, use one of the PADTMPs to emulate + * the PADTMP from OP_CONST. In later iterations this will * be appended to */ - nexttarg = sv_newmortal(); + nexttarg = PAD_SV(aux[PERL_MULTICONCAT_IX_PADTMP0].pad_offset); nextappend = FALSE; } else { @@ -1138,7 +1362,8 @@ PP(pp_multiconcat) * tryAMAGICbin_MG(concat_amg, AMGf_assign); * and * Perl_try_amagic_bin() - * call, but using left and right rather than SP[-1], SP[0], + * call, but using left and right rather than + * PL_stack_sp[-1], PL_stack_sp[0], * and not relying on OPf_STACKED implying .= */ @@ -1192,8 +1417,6 @@ PP(pp_multiconcat) left = nexttarg; } - SP = toparg - stack_adj + 1; - /* Return the result of all RHS concats, unless this op includes * an assign ($lex = x.y.z or expr = x.y.z), in which case copy * to target (which will be $lex or expr). @@ -1208,8 +1431,10 @@ PP(pp_multiconcat) } else targ = left; - SETs(targ); - RETURN; + + rpp_popfree_to_NN(PL_stack_sp - stack_adj); + rpp_push_1(targ); + return NORMAL; } } @@ -1220,33 +1445,32 @@ PP(pp_multiconcat) STATIC OP* S_pushav(pTHX_ AV* const av) { - dSP; const SSize_t maxarg = AvFILL(av) + 1; - EXTEND(SP, maxarg); + rpp_extend(maxarg); if (UNLIKELY(SvRMAGICAL(av))) { PADOFFSET i; for (i=0; i < (PADOFFSET)maxarg; i++) { SV ** const svp = av_fetch(av, i, FALSE); - SP[i+1] = LIKELY(svp) + rpp_push_1(LIKELY(svp) ? *svp : UNLIKELY(PL_op->op_flags & OPf_MOD) ? av_nonelem(av,i) - : &PL_sv_undef; + : &PL_sv_undef + ); } } else { PADOFFSET i; for (i=0; i < (PADOFFSET)maxarg; i++) { SV *sv = AvARRAY(av)[i]; - SP[i+1] = LIKELY(sv) + rpp_push_1(LIKELY(sv) ? sv : UNLIKELY(PL_op->op_flags & OPf_MOD) ? av_nonelem(av,i) - : &PL_sv_undef; + : &PL_sv_undef + ); } } - SP += maxarg; - PUTBACK; return NORMAL; } @@ -1255,25 +1479,24 @@ S_pushav(pTHX_ AV* const av) PP(pp_padrange) { - dSP; PADOFFSET base = PL_op->op_targ; int count = (int)(PL_op->op_private) & OPpPADRANGE_COUNTMASK; if (PL_op->op_flags & OPf_SPECIAL) { /* fake the RHS of my ($x,$y,..) = @_ */ - PUSHMARK(SP); + PUSHMARK(PL_stack_sp); (void)S_pushav(aTHX_ GvAVn(PL_defgv)); - SPAGAIN; } /* note, this is only skipped for compile-time-known void cxt */ if ((PL_op->op_flags & OPf_WANT) != OPf_WANT_VOID) { int i; - EXTEND(SP, count); - PUSHMARK(SP); + rpp_extend(count); + PUSHMARK(PL_stack_sp); for (i = 0; i op_private & OPpLVAL_INTRO) { SV **svp = &(PAD_SVl(base)); const UV payload = (UV)( @@ -1294,14 +1517,12 @@ PP(pp_padrange) for (i = 0; i op_flags & OPf_MOD) { if (op->op_private & OPpLVAL_INTRO) if (!(op->op_private & OPpPAD_STATE)) save_clearsv(padentry); if (op->op_private & OPpDEREF) { - /* TOPs is equivalent to TARG here. Using TOPs (SP) rather + /* *sp is equivalent to TARG here. Using *sp rather than TARG reduces the scope of TARG, so it does not span the call to save_clearsv, resulting in smaller machine code. */ - TOPs = vivify_ref(TOPs, op->op_private & OPpDEREF); + rpp_replace_1_1_NN( + vivify_ref(*PL_stack_sp, op->op_private & OPpDEREF)); } } return op->op_next; } } + +/* Implement readline(), and also and <> in the cases where X is + * seen by the parser as file-handle-ish rather than glob-ish. + * + * It expects at least one arg: the typeglob or scalar filehandle to read + * from. An empty <> isn't handled specially by this op; instead the parser + * will have planted a preceding gv(*ARGV) op. + * + * Scalar assignment is optimised away by making the assignment target be + * passed as a second argument, with OPf_STACKED set. For example, + * + * $x[$i] = readline($fh); + * + * is implemented as if written as + * + * readline($x[$i], $fh); + * + * (that is, if the perl-level readline function took two args, which it + * doesn't). The 'while (<>) {...}' construct is handled specially by the + * parser, but not specially by this op. The parser treats the condition + * as + * + * defined($_ = <>) + * + * which is then optimised into the equivalent of + * + * defined(readline($_, *ARGV)) + * + * When called as a real function, e.g. (\&CORE::readline)->(*STDIN), + * pp_coreargs() will have pushed a NULL if no argument was supplied. + * + * The parser decides whether '' in the perl src code causes an + * OP_GLOB or an OP_READLINE op to be planted. + */ + PP(pp_readline) { - dSP; + SV *arg = *PL_stack_sp; + /* pp_coreargs pushes a NULL to indicate no args passed to * CORE::readline() */ - if (TOPs) { - SvGETMAGIC(TOPs); - tryAMAGICunTARGETlist(iter_amg, 0); - PL_last_in_gv = MUTABLE_GV(*PL_stack_sp--); + if (arg) { + SvGETMAGIC(arg); + + /* unrolled tryAMAGICunTARGETlist(iter_amg, 0) */ + SV *tmpsv; + U8 gimme = GIMME_V; + if (UNLIKELY(SvAMAGIC(arg) && + (tmpsv = amagic_call(arg, &PL_sv_undef, iter_amg, + AMGf_want_list | AMGf_noright + |AMGf_unary)))) + { + if (gimme == G_VOID) { + NOOP; + } + else if (gimme == G_LIST) { + SSize_t i; + SSize_t len; + assert(SvTYPE(tmpsv) == SVt_PVAV); + len = av_count((AV *)tmpsv); + assert(*PL_stack_sp == arg); + rpp_popfree_1_NN(); /* pop the original filehhandle arg */ + /* no assignment target to pop */ + assert(!(PL_op->op_flags & OPf_STACKED)); + rpp_extend(len); + for (i = 0; i < len; ++i) + /* amagic_call() naughtily doesn't increment the ref counts + * of the items it pushes onto the temporary array. So we + * don't need to decrement them when shifting off. */ + rpp_push_1(av_shift((AV *)tmpsv)); + } + else { /* AMGf_want_scalar */ + /* OPf_STACKED: assignment optimised away and target + * on stack */ + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); + sv_setsv(targ, tmpsv); + SvSETMAGIC(targ); + if (PL_op->op_flags & OPf_STACKED) { + rpp_popfree_1_NN(); + assert(*PL_stack_sp == targ); + } + else + rpp_replace_1_1_NN(targ); + } + return NORMAL; + } + /* end of unrolled tryAMAGICunTARGETlist */ + + PL_last_in_gv = MUTABLE_GV(*PL_stack_sp); +#ifdef PERL_RC_STACK + /* PL_last_in_gv appears to be non-refcounted, so won't keep + * GV alive */ + if (SvREFCNT(PL_last_in_gv) < 2) + sv_2mortal((SV*)PL_last_in_gv); +#endif + rpp_popfree_1_NN(); } - else PL_last_in_gv = PL_argvgv, PL_stack_sp--; + else { + PL_last_in_gv = PL_argvgv; + PL_stack_sp--; + } + + + /* is it *FOO, $fh, or 'FOO' ? */ if (!isGV_with_GP(PL_last_in_gv)) { if (SvROK(PL_last_in_gv) && isGV_with_GP(SvRV(PL_last_in_gv))) PL_last_in_gv = MUTABLE_GV(SvRV(PL_last_in_gv)); else { - dSP; - XPUSHs(MUTABLE_SV(PL_last_in_gv)); - PUTBACK; + rpp_xpush_1(MUTABLE_SV(PL_last_in_gv)); Perl_pp_rv2gv(aTHX); - PL_last_in_gv = MUTABLE_GV(*PL_stack_sp--); - assert((SV*)PL_last_in_gv == &PL_sv_undef || isGV_with_GP(PL_last_in_gv)); + PL_last_in_gv = MUTABLE_GV(*PL_stack_sp); + rpp_popfree_1_NN(); + assert( (SV*)PL_last_in_gv == &PL_sv_undef + || isGV_with_GP(PL_last_in_gv)); } } + return do_readline(); } + PP(pp_eq) { - dSP; - SV *left, *right; - U32 flags_and, flags_or; - - tryAMAGICbin_MG(eq_amg, AMGf_numeric); - right = POPs; - left = TOPs; - flags_and = SvFLAGS(left) & SvFLAGS(right); - flags_or = SvFLAGS(left) | SvFLAGS(right); + if (rpp_try_AMAGIC_2(eq_amg, AMGf_numeric)) + return NORMAL; + + SV *right = PL_stack_sp[0]; + SV *left = PL_stack_sp[-1]; - SETs(boolSV( + U32 flags_and = SvFLAGS(left) & SvFLAGS(right); + U32 flags_or = SvFLAGS(left) | SvFLAGS(right); + + rpp_replace_2_IMM_NN(boolSV( ( (flags_and & SVf_IOK) && ((flags_or & SVf_IVisUV) ==0 ) ) ? (SvIVX(left) == SvIVX(right)) : (flags_and & SVf_NOK) ? (SvNVX(left) == SvNVX(right)) : ( do_ncmp(left, right) == 0) )); - RETURN; + return NORMAL; } @@ -1423,16 +1740,15 @@ PP(pp_predec) PP(pp_or) { - dSP; SV *sv; PERL_ASYNC_CHECK(); - sv = TOPs; + sv = *PL_stack_sp; if (SvTRUE_NN(sv)) - RETURN; + return NORMAL; else { if (PL_op->op_type == OP_OR) - --SP; - RETURNOP(cLOGOP->op_other); + rpp_popfree_1_NN(); + return cLOGOP->op_other; } } @@ -1441,8 +1757,7 @@ PP(pp_or) PP(pp_defined) { - dSP; - SV* sv = TOPs; + SV* sv = *PL_stack_sp; bool defined = FALSE; const int op_type = PL_op->op_type; const bool is_dor = (op_type == OP_DOR || op_type == OP_DORASSIGN); @@ -1451,14 +1766,16 @@ PP(pp_defined) PERL_ASYNC_CHECK(); if (UNLIKELY(!sv || !SvANY(sv))) { if (op_type == OP_DOR) - --SP; - RETURNOP(cLOGOP->op_other); + rpp_popfree_1(); + return cLOGOP->op_other; } } else { /* OP_DEFINED */ - if (UNLIKELY(!sv || !SvANY(sv))) - RETSETNO; + if (UNLIKELY(!sv || !SvANY(sv))) { + rpp_replace_1_1(&PL_sv_no); + return NORMAL; + } } /* Historically what followed was a switch on SvTYPE(sv), handling SVt_PVAV, @@ -1482,26 +1799,30 @@ PP(pp_defined) if (is_dor) { if(defined) - RETURN; + return NORMAL; if(op_type == OP_DOR) - --SP; - RETURNOP(cLOGOP->op_other); + rpp_popfree_1_NN(); + return cLOGOP->op_other; } /* assuming OP_DEFINED */ - if(defined) - RETSETYES; - RETSETNO; + rpp_replace_1_IMM_NN(defined ? &PL_sv_yes : &PL_sv_no); + return NORMAL; } PP(pp_add) { - dSP; dATARGET; bool useleft; SV *svl, *svr; + bool useleft; SV *svl, *svr; + SV *targ = (PL_op->op_flags & OPf_STACKED) + ? PL_stack_sp[-1] + : PAD_SV(PL_op->op_targ); - tryAMAGICbin_MG(add_amg, AMGf_assign|AMGf_numeric); - svr = TOPs; - svl = TOPm1s; + if (rpp_try_AMAGIC_2(add_amg, AMGf_assign|AMGf_numeric)) + return NORMAL; + + svr = PL_stack_sp[0]; + svl = PL_stack_sp[-1]; #ifdef PERL_PRESERVE_IVUV @@ -1522,10 +1843,8 @@ PP(pp_add) * simple integer add: if the top of both numbers * are 00 or 11, then it's safe */ if (!( ((topl+1) | (topr+1)) & 2)) { - SP--; TARGi(il + ir, 0); /* args not GMG, so can't be tainted */ - SETs(TARG); - RETURN; + goto ret; } goto generic; } @@ -1538,10 +1857,8 @@ PP(pp_add) /* nothing was lost by converting to IVs */ goto do_iv; } - SP--; TARGn(nl + nr, 0); /* args not GMG, so can't be tainted */ - SETs(TARG); - RETURN; + goto ret; } } @@ -1606,8 +1923,9 @@ PP(pp_add) auv = 0; a_valid = auvok = 1; /* left operand is undef, treat as zero. + 0 is identity, - Could SETi or SETu right now, but space optimise by not adding - lots of code to speed up what is probably a rarish case. */ + Could TARGi or TARGu right now, but space optimise by not + adding lots of code to speed up what is probably a rare-ish + case. */ } else { /* Left operand is defined, so is it IV? */ if (SvIV_please_nomg(svl)) { @@ -1676,20 +1994,19 @@ PP(pp_add) result_good = 1; } if (result_good) { - SP--; if (auvok) - SETu( result ); + TARGu(result,1); else { /* Negate result */ if (result <= (UV)IV_MIN) - SETi(result == (UV)IV_MIN - ? IV_MIN : -(IV)result); + TARGi(result == (UV)IV_MIN + ? IV_MIN : -(IV)result, 1); else { /* result valid, but out of range for IV. */ - SETn( -(NV)result ); + TARGn(-(NV)result, 1); } } - RETURN; + goto ret; } /* Overflow, drop through to NVs. */ } } @@ -1700,15 +2017,18 @@ PP(pp_add) { NV value = SvNV_nomg(svr); - (void)POPs; if (!useleft) { /* left operand is undef, treat as zero. + 0.0 is identity. */ - SETn(value); - RETURN; + TARGn(value, 1); + } + else { + TARGn(value + SvNV_nomg(svl), 1); } - SETn( value + SvNV_nomg(svl) ); - RETURN; } + + ret: + rpp_replace_2_1_NN(targ); + return NORMAL; } @@ -1716,7 +2036,6 @@ PP(pp_add) PP(pp_aelemfast) { - dSP; AV * const av = PL_op->op_type == OP_AELEMFAST_LEX ? MUTABLE_AV(PAD_SV(PL_op->op_targ)) : GvAVn(cGVOP_gv); const U32 lval = PL_op->op_flags & OPf_MOD; @@ -1726,17 +2045,14 @@ PP(pp_aelemfast) assert(SvTYPE(av) == SVt_PVAV); - EXTEND(SP, 1); - /* inlined av_fetch() for simple cases ... */ if (!SvRMAGICAL(av) && key >= 0 && key <= AvFILLp(av)) { sv = AvARRAY(av)[key]; - if (sv) { - PUSHs(sv); - RETURN; - } else if (!lval) { - PUSHs(&PL_sv_undef); - RETURN; + if (sv) + goto ret; + if (!lval) { + sv = &PL_sv_undef; + goto ret; } } @@ -1749,32 +2065,36 @@ PP(pp_aelemfast) if (!lval && SvRMAGICAL(av) && SvGMAGICAL(sv)) /* see note in pp_helem() */ mg_get(sv); - PUSHs(sv); - RETURN; + + ret: + rpp_xpush_1(sv); + return NORMAL; } PP(pp_join) { - dSP; dMARK; dTARGET; + dMARK; dTARGET; MARK++; - do_join(TARG, *MARK, MARK, SP); - SP = MARK; - SETs(TARG); - RETURN; + do_join(TARG, *MARK, MARK, PL_stack_sp); + rpp_popfree_to_NN(MARK - 1); + rpp_push_1(TARG); + return NORMAL; } + /* Oversized hot code. */ /* also used for: pp_say() */ PP(pp_print) { - dSP; dMARK; dORIGMARK; + dMARK; dORIGMARK; PerlIO *fp; MAGIC *mg; GV * const gv = (PL_op->op_flags & OPf_STACKED) ? MUTABLE_GV(*++MARK) : PL_defoutgv; IO *io = GvIO(gv); + SV *retval = &PL_sv_undef; if (io && (mg = SvTIED_mg((const SV *)io, PERL_MAGIC_tiedscalar))) @@ -1784,17 +2104,21 @@ PP(pp_print) /* If using default handle then we need to make space to * pass object as 1st arg, so move other args up ... */ - MEXTEND(SP, 1); + rpp_extend(1); + MARK = ORIGMARK; /* stack may have been realloced */ ++MARK; - Move(MARK, MARK + 1, (SP - MARK) + 1, SV*); - ++SP; + Move(MARK, MARK + 1, (PL_stack_sp - MARK) + 1, SV*); + *MARK = NULL; + ++PL_stack_sp; } return Perl_tied_method(aTHX_ SV_CONST(PRINT), mark - 1, MUTABLE_SV(io), mg, (G_SCALAR | TIED_METHOD_ARGUMENTS_ON_STACK | (PL_op->op_type == OP_SAY - ? TIED_METHOD_SAY : 0)), sp - mark); + ? TIED_METHOD_SAY : 0)), + PL_stack_sp - mark); } + if (!io) { if ( gv && GvEGVx(gv) && (io = GvIO(GvEGV(gv))) && (mg = SvTIED_mg((const SV *)io, PERL_MAGIC_tiedscalar))) @@ -1815,11 +2139,11 @@ PP(pp_print) SV * const ofs = GvSV(PL_ofsgv); /* $, */ MARK++; if (ofs && (SvGMAGICAL(ofs) || SvOK(ofs))) { - while (MARK <= SP) { + while (MARK <= PL_stack_sp) { if (!do_print(*MARK, fp)) break; MARK++; - if (MARK <= SP) { + if (MARK <= PL_stack_sp) { /* don't use 'ofs' here - it may be invalidated by magic callbacks */ if (!do_print(GvSV(PL_ofsgv), fp)) { MARK--; @@ -1829,13 +2153,13 @@ PP(pp_print) } } else { - while (MARK <= SP) { + while (MARK <= PL_stack_sp) { if (!do_print(*MARK, fp)) break; MARK++; } } - if (MARK <= SP) + if (MARK <= PL_stack_sp) goto just_say_no; else { if (PL_op->op_type == OP_SAY) { @@ -1851,34 +2175,52 @@ PP(pp_print) goto just_say_no; } } - SP = ORIGMARK; - XPUSHs(&PL_sv_yes); - RETURN; + retval = &PL_sv_yes; just_say_no: - SP = ORIGMARK; - XPUSHs(&PL_sv_undef); - RETURN; + rpp_popfree_to_NN(ORIGMARK); + if ((PL_op->op_flags & OPf_WANT) != OPf_WANT_VOID) + rpp_xpush_IMM(retval); + return NORMAL; } /* do the common parts of pp_padhv() and pp_rv2hv() - * It assumes the caller has done EXTEND(SP, 1) or equivalent. + * It assumes the caller has done rpp_extend(1) or equivalent. * 'is_keys' indicates the OPpPADHV_ISKEYS/OPpRV2HV_ISKEYS flag is set. * 'has_targ' indicates that the op has a target - this should * be a compile-time constant so that the code can constant-folded as - * appropriate + * appropriate. has_targ also implies that the caller has left an + * arg on the stack which needs freeing. * */ PERL_STATIC_INLINE OP* S_padhv_rv2hv_common(pTHX_ HV *hv, U8 gimme, bool is_keys, bool has_targ) { - dSP; - assert(PL_op->op_type == OP_PADHV || PL_op->op_type == OP_RV2HV); if (gimme == G_LIST) { - hv_pushkv(hv, 3); + /* push all (key,value) pairs onto stack */ + if (has_targ) { /* i.e. if has arg still on stack */ +#ifdef PERL_RC_STACK + SSize_t sp_base = PL_stack_sp - PL_stack_base; + hv_pushkv(hv, 3); + /* Now safe to free the original arg on the stack and shuffle + * down one place anything pushed on top of it */ + SSize_t nitems = PL_stack_sp - (PL_stack_base + sp_base); + SV *old_sv = PL_stack_sp[-nitems]; + if (nitems) + Move(PL_stack_sp - nitems + 1, + PL_stack_sp - nitems, nitems, SV*); + PL_stack_sp--; + SvREFCNT_dec_NN(old_sv); +#else + rpp_popfree_1_NN(); + hv_pushkv(hv, 3); +#endif + } + else + hv_pushkv(hv, 3); return NORMAL; } @@ -1886,8 +2228,11 @@ S_padhv_rv2hv_common(pTHX_ HV *hv, U8 gi /* 'keys %h' masquerading as '%h': reset iterator */ (void)hv_iterinit(hv); - if (gimme == G_VOID) + if (gimme == G_VOID) { + if (has_targ) + rpp_popfree_1_NN(); return NORMAL; + } bool is_bool = ( PL_op->op_private & OPpTRUEBOOL || ( PL_op->op_private & OPpMAYBE_TRUEBOOL @@ -1904,11 +2249,17 @@ S_padhv_rv2hv_common(pTHX_ HV *hv, U8 gi i = 0; while (hv_iternext(hv)) i++; + /* hv finished with. Safe to free arg now */ + if (has_targ) + rpp_popfree_1_NN(); goto push_i; } else { sv = magic_scalarpack(hv, is_tied_mg); - goto push_sv; + /* hv finished with. Safe to free arg now */ + if (has_targ) + rpp_popfree_1_NN(); + rpp_push_1(sv); } } else { @@ -1926,16 +2277,20 @@ S_padhv_rv2hv_common(pTHX_ HV *hv, U8 gi } #endif i = HvUSEDKEYS(hv); + + /* hv finished with. Safe to free arg now */ + if (has_targ) + rpp_popfree_1_NN(); + if (is_bool) { - sv = i ? &PL_sv_yes : &PL_sv_zero; - push_sv: - PUSHs(sv); + rpp_push_IMM(i ? &PL_sv_yes : &PL_sv_zero); } else { push_i: if (has_targ) { dTARGET; - PUSHi(i); + TARGi(i,1); + rpp_push_1(targ); } else if (is_keys) { @@ -1948,14 +2303,14 @@ S_padhv_rv2hv_common(pTHX_ HV *hv, U8 gi k = PL_op->op_sibparent; assert(k->op_type == OP_KEYS); TARG = PAD_SV(k->op_targ); - PUSHi(i); + TARGi(i,1); + rpp_push_1(targ); } else - mPUSHi(i); + rpp_push_1_norc(newSViv(i)); } } - PUTBACK; return NORMAL; } @@ -1963,26 +2318,25 @@ S_padhv_rv2hv_common(pTHX_ HV *hv, U8 gi /* This is also called directly by pp_lvavref. */ PP(pp_padav) { - dSP; dTARGET; + dTARGET; U8 gimme; + assert(SvTYPE(TARG) == SVt_PVAV); if (UNLIKELY( PL_op->op_private & OPpLVAL_INTRO )) if (LIKELY( !(PL_op->op_private & OPpPAD_STATE) )) SAVECLEARSV(PAD_SVl(PL_op->op_targ)); - EXTEND(SP, 1); - if (PL_op->op_flags & OPf_REF) { - PUSHs(TARG); - RETURN; - } - else if (PL_op->op_private & OPpMAYBE_LVSUB) { + + if (PL_op->op_flags & OPf_REF) + goto ret; + + if (PL_op->op_private & OPpMAYBE_LVSUB) { const I32 flags = is_lvalue_sub(); if (flags && !(flags & OPpENTERSUB_INARGS)) { if (GIMME_V == G_SCALAR) /* diag_listed_as: Can't return %s to lvalue scalar context */ Perl_croak(aTHX_ "Can't return array to lvalue scalar context"); - PUSHs(TARG); - RETURN; + goto ret; } } @@ -1990,22 +2344,33 @@ PP(pp_padav) if (gimme == G_LIST) return S_pushav(aTHX_ (AV*)TARG); - if (gimme == G_SCALAR) { + if (gimme == G_VOID) + return NORMAL; + + { const SSize_t maxarg = AvFILL(MUTABLE_AV(TARG)) + 1; + rpp_extend(1); if (!maxarg) - PUSHs(&PL_sv_zero); + targ = &PL_sv_zero; else if (PL_op->op_private & OPpTRUEBOOL) - PUSHs(&PL_sv_yes); - else - mPUSHi(maxarg); + targ = &PL_sv_yes; + else { + rpp_push_1_norc(newSViv(maxarg)); + return NORMAL; + } + rpp_push_IMM(targ); + return NORMAL; } - RETURN; + + ret: + rpp_xpush_1(targ); + return NORMAL; } PP(pp_padhv) { - dSP; dTARGET; + dTARGET; U8 gimme; assert(SvTYPE(TARG) == SVt_PVHV); @@ -2013,11 +2378,11 @@ PP(pp_padhv) if (LIKELY( !(PL_op->op_private & OPpPAD_STATE) )) SAVECLEARSV(PAD_SVl(PL_op->op_targ)); - EXTEND(SP, 1); + rpp_extend(1); if (PL_op->op_flags & OPf_REF) { - PUSHs(TARG); - RETURN; + rpp_push_1(TARG); + return NORMAL; } else if (PL_op->op_private & OPpMAYBE_LVSUB) { const I32 flags = is_lvalue_sub(); @@ -2025,8 +2390,8 @@ PP(pp_padhv) if (GIMME_V == G_SCALAR) /* diag_listed_as: Can't return %s to lvalue scalar context */ Perl_croak(aTHX_ "Can't return hash to lvalue scalar context"); - PUSHs(TARG); - RETURN; + rpp_push_1(TARG); + return NORMAL; } } @@ -2043,7 +2408,7 @@ PP(pp_padhv) PP(pp_rv2av) { - dSP; dTOPss; + SV *sv = *PL_stack_sp; const U8 gimme = GIMME_V; static const char an_array[] = "an ARRAY"; static const char a_hash[] = "a HASH"; @@ -2069,9 +2434,9 @@ PP(pp_rv2av) if (!isGV_with_GP(sv)) { gv = Perl_softref2xv(aTHX_ sv, is_pp_rv2av ? an_array : a_hash, - type, &sp); + type); if (!gv) - RETURN; + return NORMAL; } else { gv = MUTABLE_GV(sv); @@ -2081,16 +2446,16 @@ PP(pp_rv2av) sv = is_pp_rv2av ? MUTABLE_SV(save_ary(gv)) : MUTABLE_SV(save_hash(gv)); } if (PL_op->op_flags & OPf_REF) { - SETs(sv); - RETURN; + rpp_replace_1_1_NN(sv); + return NORMAL; } else if (UNLIKELY(PL_op->op_private & OPpMAYBE_LVSUB)) { const I32 flags = is_lvalue_sub(); if (flags && !(flags & OPpENTERSUB_INARGS)) { if (gimme != G_LIST) goto croak_cant_return; - SETs(sv); - RETURN; + rpp_replace_1_1_NN(sv); + return NORMAL; } } @@ -2098,35 +2463,50 @@ PP(pp_rv2av) AV *const av = MUTABLE_AV(sv); if (gimme == G_LIST) { - SP--; - PUTBACK; +#ifdef PERL_RC_STACK + SSize_t sp_base = PL_stack_sp - PL_stack_base; + (void)S_pushav(aTHX_ av); + /* Now safe to free the original arg on the stack and shuffle + * down one place anything pushed on top of it */ + SSize_t nitems = PL_stack_sp - (PL_stack_base + sp_base); + SV *old_sv = PL_stack_sp[-nitems]; + if (nitems) + Move(PL_stack_sp - nitems + 1, + PL_stack_sp - nitems, nitems, SV*); + PL_stack_sp--; + SvREFCNT_dec_NN(old_sv); + return NORMAL; +#else + rpp_popfree_1_NN(); return S_pushav(aTHX_ av); +#endif } if (gimme == G_SCALAR) { const SSize_t maxarg = AvFILL(av) + 1; if (PL_op->op_private & OPpTRUEBOOL) - SETs(maxarg ? &PL_sv_yes : &PL_sv_zero); + rpp_replace_1_IMM_NN(maxarg ? &PL_sv_yes : &PL_sv_zero); else { dTARGET; - SETi(maxarg); + TARGi(maxarg, 1); + rpp_replace_1_1_NN(targ); } } } else { - SP--; PUTBACK; + /* this static function is responsible for popping sv off stack */ return S_padhv_rv2hv_common(aTHX_ (HV*)sv, gimme, cBOOL(PL_op->op_private & OPpRV2HV_ISKEYS), 1 /* has_targ*/); } - RETURN; + return NORMAL; croak_cant_return: Perl_croak(aTHX_ "Can't return %s to lvalue scalar context", is_pp_rv2av ? "array" : "hash"); - RETURN; } + STATIC void S_do_oddball(pTHX_ SV **oddkey, SV **firstkey) { @@ -2159,8 +2539,8 @@ S_do_oddball(pTHX_ SV **oddkey, SV **fir * For example in ($a,$b) = ($b,$a), assigning the value of the first RHS * element ($b) to the first LH element ($a), modifies $a; when the * second assignment is done, the second RH element now has the wrong - * value. So we initially replace the RHS with ($b, mortalcopy($a)). - * Note that we don't need to make a mortal copy of $b. + * value. So we initially replace the RHS with ($b, copy($a)). + * Note that we don't need to make a copy of $b. * * The algorithm below works by, for every RHS element, mark the * corresponding LHS target element with SVf_BREAK. Then if the RHS @@ -2235,7 +2615,14 @@ S_aassign_copy_common(pTHX_ SV **firstle lcount = -1; lelem--; /* no need to unmark this element */ } - else if (!(do_rc1 && SvREFCNT(svl) == 1) && !SvIMMORTAL(svl)) { + else if (!(do_rc1 && +#ifdef PERL_RC_STACK + SvREFCNT(svl) <= 2 +#else + SvREFCNT(svl) == 1 +#endif + ) && !SvIMMORTAL(svl)) + { SvFLAGS(svl) |= SVf_BREAK; marked = TRUE; } @@ -2267,6 +2654,11 @@ S_aassign_copy_common(pTHX_ SV **firstle TAINT_NOT; /* Each item is independent */ +#ifndef PERL_RC_STACK + /* The TODO test was eventually commented out. It's now been + * revived, but only on PERL_RC_STACK builds. Continue + * this hacky workaround otherwise - DAPM Sept 2023 */ + /* Dear TODO test in t/op/sort.t, I love you. (It's relying on a panic, not a "semi-panic" from newSVsv() and then an assertion failure below.) */ @@ -2274,6 +2666,8 @@ S_aassign_copy_common(pTHX_ SV **firstle Perl_croak(aTHX_ "panic: attempt to copy freed scalar %p", (void*)svr); } +#endif + /* avoid break flag while copying; otherwise COW etc * disabled... */ SvFLAGS(svr) &= ~SVf_BREAK; @@ -2285,8 +2679,14 @@ S_aassign_copy_common(pTHX_ SV **firstle count bump. (Although I suspect that the SV won't be stealable here anyway - DAPM). */ +#ifdef PERL_RC_STACK + *relem = newSVsv_flags(svr, + SV_GMAGIC|SV_DO_COW_SVSETSV|SV_NOSTEAL); + SvREFCNT_dec_NN(svr); +#else *relem = sv_mortalcopy_flags(svr, SV_GMAGIC|SV_DO_COW_SVSETSV|SV_NOSTEAL); +#endif /* ... but restore afterwards in case it's needed again, * e.g. ($a,$b,$c) = (1,$a,$a) */ @@ -2310,10 +2710,104 @@ S_aassign_copy_common(pTHX_ SV **firstle } +/* Helper function for pp_aassign(): after performing something like + * + * ($<,$>) = ($>,$<); # swap real and effective uids + * + * the assignment to the magic variables just sets various flags in + * PL_delaymagic; now we tell the OS to update the uids/gids atomically. + */ + +STATIC void +S_aassign_uid(pTHX) +{ + /* Will be used to set PL_tainting below */ + Uid_t tmp_uid = PerlProc_getuid(); + Uid_t tmp_euid = PerlProc_geteuid(); + Gid_t tmp_gid = PerlProc_getgid(); + Gid_t tmp_egid = PerlProc_getegid(); + + /* XXX $> et al currently silently ignore failures */ + if (PL_delaymagic & DM_UID) { +#ifdef HAS_SETRESUID + PERL_UNUSED_RESULT( + setresuid((PL_delaymagic & DM_RUID) ? PL_delaymagic_uid : (Uid_t)-1, + (PL_delaymagic & DM_EUID) ? PL_delaymagic_euid : (Uid_t)-1, + (Uid_t)-1)); +#elif defined(HAS_SETREUID) + PERL_UNUSED_RESULT( + setreuid((PL_delaymagic & DM_RUID) ? PL_delaymagic_uid : (Uid_t)-1, + (PL_delaymagic & DM_EUID) ? PL_delaymagic_euid : (Uid_t)-1)); +#else +# ifdef HAS_SETRUID + if ((PL_delaymagic & DM_UID) == DM_RUID) { + PERL_UNUSED_RESULT(setruid(PL_delaymagic_uid)); + PL_delaymagic &= ~DM_RUID; + } +# endif /* HAS_SETRUID */ +# ifdef HAS_SETEUID + if ((PL_delaymagic & DM_UID) == DM_EUID) { + PERL_UNUSED_RESULT(seteuid(PL_delaymagic_euid)); + PL_delaymagic &= ~DM_EUID; + } +# endif /* HAS_SETEUID */ + if (PL_delaymagic & DM_UID) { + if (PL_delaymagic_uid != PL_delaymagic_euid) + Perl_die(aTHX_ "No setreuid available"); + PERL_UNUSED_RESULT(PerlProc_setuid(PL_delaymagic_uid)); + } +#endif /* HAS_SETRESUID */ + + tmp_uid = PerlProc_getuid(); + tmp_euid = PerlProc_geteuid(); + } + + /* XXX $> et al currently silently ignore failures */ + if (PL_delaymagic & DM_GID) { +#ifdef HAS_SETRESGID + PERL_UNUSED_RESULT( + setresgid((PL_delaymagic & DM_RGID) ? PL_delaymagic_gid : (Gid_t)-1, + (PL_delaymagic & DM_EGID) ? PL_delaymagic_egid : (Gid_t)-1, + (Gid_t)-1)); +#elif defined(HAS_SETREGID) + PERL_UNUSED_RESULT( + setregid((PL_delaymagic & DM_RGID) ? PL_delaymagic_gid : (Gid_t)-1, + (PL_delaymagic & DM_EGID) ? PL_delaymagic_egid : (Gid_t)-1)); +#else +# ifdef HAS_SETRGID + if ((PL_delaymagic & DM_GID) == DM_RGID) { + PERL_UNUSED_RESULT(setrgid(PL_delaymagic_gid)); + PL_delaymagic &= ~DM_RGID; + } +# endif /* HAS_SETRGID */ +# ifdef HAS_SETEGID + if ((PL_delaymagic & DM_GID) == DM_EGID) { + PERL_UNUSED_RESULT(setegid(PL_delaymagic_egid)); + PL_delaymagic &= ~DM_EGID; + } +# endif /* HAS_SETEGID */ + if (PL_delaymagic & DM_GID) { + if (PL_delaymagic_gid != PL_delaymagic_egid) + Perl_die(aTHX_ "No setregid available"); + PERL_UNUSED_RESULT(PerlProc_setgid(PL_delaymagic_gid)); + } +#endif /* HAS_SETRESGID */ + + tmp_gid = PerlProc_getgid(); + tmp_egid = PerlProc_getegid(); + } + TAINTING_set( TAINTING_get | (tmp_uid && (tmp_euid != tmp_uid || tmp_egid != tmp_gid)) ); +#ifdef NO_TAINT_SUPPORT + PERL_UNUSED_VAR(tmp_uid); + PERL_UNUSED_VAR(tmp_euid); + PERL_UNUSED_VAR(tmp_gid); + PERL_UNUSED_VAR(tmp_egid); +#endif +} + PP(pp_aassign) { - dSP; SV **lastlelem = PL_stack_sp; SV **lastrelem = PL_stack_base + POPMARK; SV **firstrelem = PL_stack_base + POPMARK + 1; @@ -2351,7 +2845,13 @@ PP(pp_aassign) /* skip the scan if all scalars have a ref count of 1 */ for (lelem = firstlelem; lelem <= lastlelem; lelem++) { SV *sv = *lelem; - if (!sv || SvREFCNT(sv) == 1) + if (!sv || +#ifdef PERL_RC_STACK + SvREFCNT(sv) <= 2 +#else + SvREFCNT(sv) == 1 +#endif + ) continue; if (SvTYPE(sv) != SVt_PVAV && SvTYPE(sv) != SVt_PVAV) goto do_scan; @@ -2382,8 +2882,17 @@ PP(pp_aassign) #endif gimme = GIMME_V; + bool is_list = (gimme == G_LIST); relem = firstrelem; lelem = firstlelem; +#ifdef PERL_RC_STACK + /* Where we can reset stack to at the end, without needing to free + * each element. This is normally all the lelem's, but it can vary for + * things like odd number of hash elements, which pushes a + * &PL_sv_undef into the 'lvalue' part of the stack. + */ + SV ** first_discard = firstlelem; +#endif if (relem > lastrelem) goto no_relems; @@ -2391,14 +2900,14 @@ PP(pp_aassign) /* first lelem loop while there are still relems */ while (LIKELY(lelem <= lastlelem)) { bool alias = FALSE; - SV *lsv = *lelem++; + SV *lsv = *lelem; TAINT_NOT; /* Each item stands on its own, taintwise. */ assert(relem <= lastrelem); if (UNLIKELY(!lsv)) { alias = TRUE; - lsv = *lelem++; + lsv = *++lelem; ASSUME(SvTYPE(lsv) == SVt_PVAV); } @@ -2406,7 +2915,6 @@ PP(pp_aassign) case SVt_PVAV: { SV **svp; SSize_t i; - SSize_t tmps_base; SSize_t nelems = lastrelem - relem + 1; AV *ary = MUTABLE_AV(lsv); @@ -2459,23 +2967,40 @@ PP(pp_aassign) * @a = ($a[0]) case, but the current implementation uses the * same algorithm regardless, so ignores that flag. (It *is* * used in the hash branch below, however). - */ + * + * + * The net effect of this next block of code (apart from + * optimisations and aliasing) is to make a copy of each + * *relem and store the new SV both in the array and back on + * the *relem slot of the stack, overwriting the original. + * This new list of SVs will later be either returned + * (G_LIST), or popped. + * + * Note that under PERL_RC_STACK builds most of this + * complexity can be thrown away: things can be kept alive on + * the argument stack without involving the temps stack. In + * particular, the args are kept on the argument stack and + * processed from there, rather than their pointers being + * copied to the temps stack and then processed from there. + */ +#ifndef PERL_RC_STACK /* Reserve slots for ary, plus the elems we're about to copy, * then protect ary and temporarily void the remaining slots * with &PL_sv_undef */ EXTEND_MORTAL(nelems + 1); PL_tmps_stack[++PL_tmps_ix] = SvREFCNT_inc_simple_NN(ary); - tmps_base = PL_tmps_ix + 1; + SSize_t tmps_base = PL_tmps_ix + 1; for (i = 0; i < nelems; i++) PL_tmps_stack[tmps_base + i] = &PL_sv_undef; PL_tmps_ix += nelems; +#endif /* Make a copy of each RHS elem and save on the tmps_stack * (or pass through where we can optimise away the copy) */ if (UNLIKELY(alias)) { - U32 lval = (gimme == G_LIST) + U32 lval = (is_list) ? (PL_op->op_flags & OPf_MOD || LVRET) : 0; for (svp = relem; svp <= lastrelem; svp++) { SV *rsv = *svp; @@ -2487,21 +3012,30 @@ PP(pp_aassign) /* diag_listed_as: Assigned value is not %s reference */ DIE(aTHX_ "Assigned value is not a SCALAR reference"); - if (lval) - *svp = rsv = sv_mortalcopy(rsv); + if (lval) { + /* XXX the 'mortal' part here is probably + * unnecessary under PERL_RC_STACK. + */ + rsv = sv_mortalcopy(rsv); + rpp_replace_at_NN(svp, rsv); + } /* XXX else check for weak refs? */ +#ifndef PERL_RC_STACK rsv = SvREFCNT_inc_NN(SvRV(rsv)); assert(tmps_base <= PL_tmps_max); PL_tmps_stack[tmps_base++] = rsv; +#endif } } else { for (svp = relem; svp <= lastrelem; svp++) { SV *rsv = *svp; - if (SvTEMP(rsv) && !SvGMAGICAL(rsv) && SvREFCNT(rsv) == 1) { + if (rpp_is_lone(rsv) && !SvGMAGICAL(rsv)) { /* can skip the copy */ +#ifndef PERL_RC_STACK SvREFCNT_inc_simple_void_NN(rsv); +#endif SvTEMP_off(rsv); } else { @@ -2510,45 +3044,91 @@ PP(pp_aassign) * SV_NOSTEAL */ nsv = newSVsv_flags(rsv, (SV_DO_COW_SVSETSV|SV_NOSTEAL|SV_GMAGIC)); - rsv = *svp = nsv; +#ifdef PERL_RC_STACK + rpp_replace_at_norc_NN(svp, nsv); +#else + /* using rpp_replace_at_norc() would mortalise, + * but we're manually adding nsv to the tmps stack + * below already */ + rpp_replace_at_NN(svp, nsv); +#endif + + rsv = nsv; } +#ifndef PERL_RC_STACK assert(tmps_base <= PL_tmps_max); PL_tmps_stack[tmps_base++] = rsv; +#endif } } if (SvRMAGICAL(ary) || AvFILLp(ary) >= 0) /* may be non-empty */ av_clear(ary); - /* store in the array, the SVs that are in the tmps stack */ + /* Store in the array, the argument copies that are in the + * tmps stack (or for PERL_RC_STACK, on the args stack) */ +#ifndef PERL_RC_STACK tmps_base -= nelems; - - if (SvMAGICAL(ary) || SvREADONLY(ary) || !AvREAL(ary)) { +#endif + if (alias || SvMAGICAL(ary) || SvREADONLY(ary) || !AvREAL(ary)) { /* for arrays we can't cheat with, use the official API */ av_extend(ary, nelems - 1); for (i = 0; i < nelems; i++) { - SV **svp = &(PL_tmps_stack[tmps_base + i]); + SV **svp = +#ifdef PERL_RC_STACK + &relem[i]; +#else + &(PL_tmps_stack[tmps_base + i]); +#endif + SV *rsv = *svp; +#ifdef PERL_RC_STACK + if (alias) { + assert(SvROK(rsv)); + rsv = SvRV(rsv); + } +#endif + /* A tied store won't take ownership of rsv, so keep * the 1 refcnt on the tmps stack; otherwise disarm * the tmps stack entry */ if (av_store(ary, i, rsv)) +#ifdef PERL_RC_STACK + SvREFCNT_inc_simple_NN(rsv); +#else *svp = &PL_sv_undef; +#endif /* av_store() may have added set magic to rsv */; SvSETMAGIC(rsv); } +#ifndef PERL_RC_STACK /* disarm ary refcount: see comments below about leak */ PL_tmps_stack[tmps_base - 1] = &PL_sv_undef; +#endif } else { - /* directly access/set the guts of the AV */ + /* Simple array: directly access/set the guts of the AV */ SSize_t fill = nelems - 1; if (fill > AvMAX(ary)) av_extend_guts(ary, fill, &AvMAX(ary), &AvALLOC(ary), &AvARRAY(ary)); AvFILLp(ary) = fill; +#ifdef PERL_RC_STACK + Copy(relem, AvARRAY(ary), nelems, SV*); + /* ownership of one ref count of each elem passed to + * array. Quietly remove old SVs from stack, or if need + * to keep the list on the stack too, bump the count */ + if (UNLIKELY(is_list)) + for (i = 0; i < nelems; i++) + SvREFCNT_inc_void_NN(relem[i]); + else { + assert(first_discard == relem + nelems); + Zero(relem, nelems, SV*); + first_discard = relem; + } +#else Copy(&(PL_tmps_stack[tmps_base]), AvARRAY(ary), nelems, SV*); /* Quietly remove all the SVs from the tmps stack slots, * since ary has now taken ownership of the refcnt. @@ -2560,13 +3140,19 @@ PP(pp_aassign) PL_tmps_ix - (tmps_base + nelems) + 1, SV*); PL_tmps_ix -= (nelems + 1); +#endif } if (UNLIKELY(PL_delaymagic & DM_ARRAY_ISA)) /* its assumed @ISA set magic can't die and leak ary */ SvSETMAGIC(MUTABLE_SV(ary)); + +#ifdef PERL_RC_STACK + assert(*lelem == (SV*)ary); + *lelem = NULL; +#endif + lelem++; SvREFCNT_dec_NN(ary); - relem = lastrelem + 1; goto no_relems; } @@ -2574,15 +3160,28 @@ PP(pp_aassign) case SVt_PVHV: { /* normal hash */ SV **svp; - bool dirty_tmps; SSize_t i; - SSize_t tmps_base; SSize_t nelems = lastrelem - relem + 1; HV *hash = MUTABLE_HV(lsv); if (UNLIKELY(nelems & 1)) { do_oddball(lastrelem, relem); /* we have firstlelem to reuse, it's not needed any more */ +#ifdef PERL_RC_STACK + if (lelem == lastrelem + 1) { + /* the lelem slot we want to use is the + * one keeping hash alive. Mortalise the hash + * so it doesn't leak */ + assert(lastrelem[1] == (SV*)hash); + sv_2mortal((SV*)hash); + } + else { + /* safe to repurpose old lelem slot */ + assert(!lastrelem[1] || SvIMMORTAL(lastrelem[1])); + } + first_discard++; + assert(first_discard = lastrelem + 2); +#endif *++lastrelem = &PL_sv_undef; nelems++; } @@ -2594,7 +3193,8 @@ PP(pp_aassign) * copied (except for the SvTEMP optimisation), since they * need to be stored in the hash; while keys are only * processed where they might get prematurely freed or - * whatever. */ + * whatever. The same comments about simplifying under + * PERL_RC_STACK apply here too */ /* tmps stack slots: * * reserve a slot for the hash keepalive; @@ -2603,16 +3203,19 @@ PP(pp_aassign) * later; * then protect hash and temporarily void the remaining * value slots with &PL_sv_undef */ +#ifndef PERL_RC_STACK EXTEND_MORTAL(nelems + 1); - +#endif /* convert to number of key/value pairs */ nelems >>= 1; +#ifndef PERL_RC_STACK PL_tmps_stack[++PL_tmps_ix] = SvREFCNT_inc_simple_NN(hash); - tmps_base = PL_tmps_ix + 1; + SSize_t tmps_base = PL_tmps_ix + 1; for (i = 0; i < nelems; i++) PL_tmps_stack[tmps_base + i] = &PL_sv_undef; PL_tmps_ix += nelems; +#endif /* Make a copy of each RHS hash value and save on the tmps_stack * (or pass through where we can optimise away the copy) */ @@ -2620,9 +3223,11 @@ PP(pp_aassign) for (svp = relem + 1; svp <= lastrelem; svp += 2) { SV *rsv = *svp; - if (SvTEMP(rsv) && !SvGMAGICAL(rsv) && SvREFCNT(rsv) == 1) { + if (rpp_is_lone(rsv) && !SvGMAGICAL(rsv)) { /* can skip the copy */ +#ifndef PERL_RC_STACK SvREFCNT_inc_simple_void_NN(rsv); +#endif SvTEMP_off(rsv); } else { @@ -2631,26 +3236,43 @@ PP(pp_aassign) * SV_NOSTEAL */ nsv = newSVsv_flags(rsv, (SV_DO_COW_SVSETSV|SV_NOSTEAL|SV_GMAGIC)); - rsv = *svp = nsv; +#ifdef PERL_RC_STACK + rpp_replace_at_norc_NN(svp, nsv); +#else + /* using rpp_replace_at_norc() would mortalise, + * but we're manually adding nsv to the tmps stack + * below already */ + rpp_replace_at_NN(svp, nsv); +#endif + rsv = nsv; } +#ifndef PERL_RC_STACK assert(tmps_base <= PL_tmps_max); PL_tmps_stack[tmps_base++] = rsv; +#endif } + +#ifndef PERL_RC_STACK tmps_base -= nelems; +#endif /* possibly protect keys */ - if (UNLIKELY(gimme == G_LIST)) { + if (UNLIKELY(is_list)) { /* handle e.g. * @a = ((%h = ($$r, 1)), $r = "x"); * $_++ for %h = (1,2,3,4); */ +#ifndef PERL_RC_STACK EXTEND_MORTAL(nelems); - for (svp = relem; svp <= lastrelem; svp += 2) - *svp = sv_mortalcopy_flags(*svp, - SV_GMAGIC|SV_DO_COW_SVSETSV|SV_NOSTEAL); +#endif + for (svp = relem; svp <= lastrelem; svp += 2) { + rpp_replace_at_norc_NN(svp, + newSVsv_flags(*svp, + SV_GMAGIC|SV_DO_COW_SVSETSV|SV_NOSTEAL)); + } } else if (PL_op->op_private & OPpASSIGN_COMMON_AGG) { /* for possible commonality, e.g. @@ -2664,14 +3286,29 @@ PP(pp_aassign) * cases, not just under OPpASSIGN_COMMON_AGG, but in * practice, !OPpASSIGN_COMMON_AGG implies only * constants or padtmps on the RHS. + * + * For PERL_RC_STACK, no danger of premature frees, so + * just handle the magic. */ +#ifdef PERL_RC_STACK + for (svp = relem; svp <= lastrelem; svp += 2) { + SV *rsv = *svp; + if (UNLIKELY(SvGMAGICAL(rsv))) + /* XXX does this actually need to be copied, or + * could we just call the get magic??? */ + rpp_replace_at_norc_NN(svp, + newSVsv_flags(rsv, + SV_GMAGIC|SV_DO_COW_SVSETSV|SV_NOSTEAL)); + } +#else EXTEND_MORTAL(nelems); for (svp = relem; svp <= lastrelem; svp += 2) { SV *rsv = *svp; if (UNLIKELY(SvGMAGICAL(rsv))) { SSize_t n; - *svp = sv_mortalcopy_flags(*svp, - SV_GMAGIC|SV_DO_COW_SVSETSV|SV_NOSTEAL); + rpp_replace_at_norc_NN(svp, + newSVsv_flags(rsv, + SV_GMAGIC|SV_DO_COW_SVSETSV|SV_NOSTEAL)); /* allow other branch to continue pushing * onto tmps stack without checking each time */ n = (lastrelem - relem) >> 1; @@ -2681,6 +3318,7 @@ PP(pp_aassign) PL_tmps_stack[++PL_tmps_ix] = SvREFCNT_inc_simple_NN(rsv); } +#endif } if (SvRMAGICAL(hash) || HvUSEDKEYS(hash)) @@ -2693,9 +3331,10 @@ PP(pp_aassign) /* now assign the keys and values to the hash */ - dirty_tmps = FALSE; - - if (UNLIKELY(gimme == G_LIST)) { +#ifndef PERL_RC_STACK + bool dirty_tmps = FALSE; +#endif + if (UNLIKELY(is_list)) { /* @a = (%h = (...)) etc */ SV **svp; SV **topelem = relem; @@ -2709,19 +3348,24 @@ PP(pp_aassign) * stack location if we encountered dups earlier, * The values will be updated later */ - *topelem = key; + rpp_replace_at_NN(topelem, key); topelem += 2; } /* A tied store won't take ownership of val, so keep * the 1 refcnt on the tmps stack; otherwise disarm * the tmps stack entry */ if (hv_store_ent(hash, key, val, 0)) +#ifdef PERL_RC_STACK + SvREFCNT_inc_simple_NN(val); +#else PL_tmps_stack[tmps_base + i] = &PL_sv_undef; else dirty_tmps = TRUE; +#endif /* hv_store_ent() may have added set magic to val */; SvSETMAGIC(val); } + if (topelem < svp) { /* at this point we have removed the duplicate key/value * pairs from the stack, but the remaining values may be @@ -2733,7 +3377,8 @@ PP(pp_aassign) while (relem < lastrelem) { HE *he; he = hv_fetch_ent(hash, *relem++, 0, 0); - *relem++ = (he ? HeVAL(he) : &PL_sv_undef); + rpp_replace_at_NN(relem++, + (he ? HeVAL(he) : &PL_sv_undef)); } } } @@ -2742,15 +3387,46 @@ PP(pp_aassign) for (i = 0, svp = relem; svp <= lastrelem; i++, svp++) { SV *key = *svp++; SV *val = *svp; +#ifdef PERL_RC_STACK + { + HE *stored = hv_store_ent(hash, key, val, 0); + /* hv_store_ent() may have added set magic to val */; + SvSETMAGIC(val); + /* remove key and val from stack */ + *svp = NULL; + if (!stored) + SvREFCNT_dec_NN(val); + svp[-1] = NULL; + SvREFCNT_dec_NN(key); + } +#else if (hv_store_ent(hash, key, val, 0)) PL_tmps_stack[tmps_base + i] = &PL_sv_undef; else dirty_tmps = TRUE; /* hv_store_ent() may have added set magic to val */; SvSETMAGIC(val); +#endif } +#ifdef PERL_RC_STACK + /* now that all the key and val slots on the stack have + * been discarded, we can skip freeing them on return */ + assert(first_discard == lastrelem + 1); + first_discard = relem; +#endif } +#ifdef PERL_RC_STACK + /* Disarm the ref-counted pointer on the stack. This will + * usually point to the hash, except for the case of an odd + * number of elems where the hash was mortalised and its slot + * on the stack was made part of the relems with the slot's + * value overwritten with &PL_sv_undef. */ + if (*lelem == (SV*)hash) { + *lelem = NULL; + SvREFCNT_dec_NN(hash); + } +#else if (dirty_tmps) { /* there are still some 'live' recounts on the tmps stack * - usually caused by storing into a tied hash. So let @@ -2773,17 +3449,16 @@ PP(pp_aassign) } SvREFCNT_dec_NN(hash); - +#endif + lelem++; relem = lastrelem + 1; goto no_relems; } default: if (!SvIMMORTAL(lsv)) { - SV *ref; - if (UNLIKELY( - SvTEMP(lsv) && !SvSMAGICAL(lsv) && SvREFCNT(lsv) == 1 && + rpp_is_lone(lsv) && !SvSMAGICAL(lsv) && (!isGV_with_GP(lsv) || SvFAKE(lsv)) && ckWARN(WARN_MISC) )) Perl_warner(aTHX_ @@ -2791,11 +3466,13 @@ PP(pp_aassign) "Useless assignment to a temporary" ); +#ifndef PERL_RC_STACK /* avoid freeing $$lsv if it might be needed for further * elements, e.g. ($ref, $foo) = (1, $$ref) */ + SV *ref; if ( SvROK(lsv) && ( ((ref = SvRV(lsv)), SvREFCNT(ref)) == 1) - && lelem <= lastlelem + && lelem < lastlelem ) { SSize_t ix; SvREFCNT_inc_simple_void_NN(ref); @@ -2804,14 +3481,21 @@ PP(pp_aassign) if (UNLIKELY(ix >= PL_tmps_max)) /* speculatively grow enough to cover other * possible refs */ - (void)tmps_grow_p(ix + (lastlelem - lelem)); + (void)tmps_grow_p(ix + (lastlelem - lelem + 1)); PL_tmps_stack[ix] = ref; } +#endif sv_setsv(lsv, *relem); - *relem = lsv; SvSETMAGIC(lsv); + if (UNLIKELY(is_list)) + rpp_replace_at_NN(relem, lsv); +#ifdef PERL_RC_STACK + *lelem = NULL; + SvREFCNT_dec_NN(lsv); +#endif } + lelem++; if (++relem > lastrelem) goto no_relems; break; @@ -2823,12 +3507,12 @@ PP(pp_aassign) /* simplified lelem loop for when there are no relems left */ while (LIKELY(lelem <= lastlelem)) { - SV *lsv = *lelem++; + SV *lsv = *lelem; TAINT_NOT; /* Each item stands on its own, taintwise. */ if (UNLIKELY(!lsv)) { - lsv = *lelem++; + lsv = *++lelem; ASSUME(SvTYPE(lsv) == SVt_PVAV); } @@ -2851,119 +3535,85 @@ PP(pp_aassign) sv_set_undef(lsv); SvSETMAGIC(lsv); } - *relem++ = lsv; + if (UNLIKELY(is_list)) { + /* this usually grows the list of relems to be returned + * into the stack space holding lelems (unless + * there was previously a hash with dup elements) */ +#ifdef PERL_RC_STACK + assert(relem <= first_discard); + assert(relem <= lelem); + if (relem == first_discard) + first_discard++; +#endif + rpp_replace_at(relem++, lsv); +#ifdef PERL_RC_STACK + if (relem == lelem + 1) { + lelem++; + /* skip the NULLing of the slot */ + continue; + } +#endif + } break; } /* switch */ +#ifdef PERL_RC_STACK + *lelem = NULL; + SvREFCNT_dec_NN(lsv); +#endif + lelem++; } /* while */ TAINT_NOT; /* result of list assign isn't tainted */ - if (UNLIKELY(PL_delaymagic & ~DM_DELAY)) { - /* Will be used to set PL_tainting below */ - Uid_t tmp_uid = PerlProc_getuid(); - Uid_t tmp_euid = PerlProc_geteuid(); - Gid_t tmp_gid = PerlProc_getgid(); - Gid_t tmp_egid = PerlProc_getegid(); + if (UNLIKELY(PL_delaymagic & ~DM_DELAY)) + /* update system UIDs and/or GIDs */ + S_aassign_uid(aTHX); + PL_delaymagic = old_delaymagic; - /* XXX $> et al currently silently ignore failures */ - if (PL_delaymagic & DM_UID) { -#ifdef HAS_SETRESUID - PERL_UNUSED_RESULT( - setresuid((PL_delaymagic & DM_RUID) ? PL_delaymagic_uid : (Uid_t)-1, - (PL_delaymagic & DM_EUID) ? PL_delaymagic_euid : (Uid_t)-1, - (Uid_t)-1)); -#elif defined(HAS_SETREUID) - PERL_UNUSED_RESULT( - setreuid((PL_delaymagic & DM_RUID) ? PL_delaymagic_uid : (Uid_t)-1, - (PL_delaymagic & DM_EUID) ? PL_delaymagic_euid : (Uid_t)-1)); -#else -# ifdef HAS_SETRUID - if ((PL_delaymagic & DM_UID) == DM_RUID) { - PERL_UNUSED_RESULT(setruid(PL_delaymagic_uid)); - PL_delaymagic &= ~DM_RUID; - } -# endif /* HAS_SETRUID */ -# ifdef HAS_SETEUID - if ((PL_delaymagic & DM_UID) == DM_EUID) { - PERL_UNUSED_RESULT(seteuid(PL_delaymagic_euid)); - PL_delaymagic &= ~DM_EUID; - } -# endif /* HAS_SETEUID */ - if (PL_delaymagic & DM_UID) { - if (PL_delaymagic_uid != PL_delaymagic_euid) - DIE(aTHX_ "No setreuid available"); - PERL_UNUSED_RESULT(PerlProc_setuid(PL_delaymagic_uid)); - } -#endif /* HAS_SETRESUID */ +#ifdef PERL_RC_STACK + /* On ref-counted builds, the code above should have stored + * NULL in each lelem field and already freed each lelem. Thus + * the popfree_to() can start at a lower point. + * Under some circumstances, &PL_sv_undef might be stored rather than + * NULL, but this also doesn't need its refcount decrementing. + * Assert that this is true. + * Note that duplicate hash keys in list context can cause + * lastrelem and relem to be lower than at the start; + * while an odd number of hash elements can cause lastrelem to + * have a value one higher than at the start */ +# ifdef DEBUGGING + for (SV **svp = first_discard; svp <= PL_stack_sp; svp++) + assert(!*svp || SvIMMORTAL(*svp)); +# endif + PL_stack_sp = first_discard - 1; - tmp_uid = PerlProc_getuid(); - tmp_euid = PerlProc_geteuid(); - } - /* XXX $> et al currently silently ignore failures */ - if (PL_delaymagic & DM_GID) { -#ifdef HAS_SETRESGID - PERL_UNUSED_RESULT( - setresgid((PL_delaymagic & DM_RGID) ? PL_delaymagic_gid : (Gid_t)-1, - (PL_delaymagic & DM_EGID) ? PL_delaymagic_egid : (Gid_t)-1, - (Gid_t)-1)); -#elif defined(HAS_SETREGID) - PERL_UNUSED_RESULT( - setregid((PL_delaymagic & DM_RGID) ? PL_delaymagic_gid : (Gid_t)-1, - (PL_delaymagic & DM_EGID) ? PL_delaymagic_egid : (Gid_t)-1)); -#else -# ifdef HAS_SETRGID - if ((PL_delaymagic & DM_GID) == DM_RGID) { - PERL_UNUSED_RESULT(setrgid(PL_delaymagic_gid)); - PL_delaymagic &= ~DM_RGID; - } -# endif /* HAS_SETRGID */ -# ifdef HAS_SETEGID - if ((PL_delaymagic & DM_GID) == DM_EGID) { - PERL_UNUSED_RESULT(setegid(PL_delaymagic_egid)); - PL_delaymagic &= ~DM_EGID; - } -# endif /* HAS_SETEGID */ - if (PL_delaymagic & DM_GID) { - if (PL_delaymagic_gid != PL_delaymagic_egid) - DIE(aTHX_ "No setregid available"); - PERL_UNUSED_RESULT(PerlProc_setgid(PL_delaymagic_gid)); - } -#endif /* HAS_SETRESGID */ + /* now pop all the R elements too */ + rpp_popfree_to_NN((is_list ? relem : firstrelem) - 1); - tmp_gid = PerlProc_getgid(); - tmp_egid = PerlProc_getegid(); - } - TAINTING_set( TAINTING_get | (tmp_uid && (tmp_euid != tmp_uid || tmp_egid != tmp_gid)) ); -#ifdef NO_TAINT_SUPPORT - PERL_UNUSED_VAR(tmp_uid); - PERL_UNUSED_VAR(tmp_euid); - PERL_UNUSED_VAR(tmp_gid); - PERL_UNUSED_VAR(tmp_egid); +#else + /* pop all L and R elements apart from any being returned */ + rpp_popfree_to_NN((is_list ? relem : firstrelem) - 1); #endif - } - PL_delaymagic = old_delaymagic; - if (gimme == G_VOID) - SP = firstrelem - 1; - else if (gimme == G_SCALAR) { - SP = firstrelem; - EXTEND(SP,1); + if (gimme == G_SCALAR) { + rpp_extend(1); + SV *sv; if (PL_op->op_private & OPpASSIGN_TRUEBOOL) - SETs((firstlelem - firstrelem) ? &PL_sv_yes : &PL_sv_zero); + rpp_push_IMM((firstlelem - firstrelem) ? &PL_sv_yes : &PL_sv_zero); else { dTARGET; - SETi(firstlelem - firstrelem); + TARGi(firstlelem - firstrelem, 1); + sv = targ; + rpp_push_1(sv); } } - else - SP = relem - 1; - RETURN; + return NORMAL; } + PP(pp_qr) { - dSP; PMOP * const pm = cPMOP; REGEXP * rx = PM_GETRE(pm); regexp *prog = ReANY(rx); @@ -2998,8 +3648,8 @@ PP(pp_qr) SvTAINTED_on(rv); SvTAINTED_on(SvRV(rv)); } - XPUSHs(rv); - RETURN; + rpp_xpush_1(rv); + return NORMAL; } STATIC bool @@ -3043,9 +3693,10 @@ S_should_we_output_Debug_r(pTHX_ regexp return S_are_we_in_Debug_EXECUTE_r(aTHX); } + PP(pp_match) { - dSP; dTARG; + SV *targ; PMOP *pm = cPMOP; PMOP *dynpm = pm; const char *s; @@ -3062,19 +3713,27 @@ PP(pp_match) const I32 oldsave = PL_savestack_ix; I32 had_zerolen = 0; MAGIC *mg = NULL; + SSize_t sp_base; - if (PL_op->op_flags & OPf_STACKED) - TARG = POPs; + if (PL_op->op_flags & OPf_STACKED) { + targ = PL_stack_sp[0]; + /* We have to keep targ alive on the stack. At the end we have to + * free it and shuffle down all the return values by one. + * Remember the position. + */ + sp_base = PL_stack_sp - PL_stack_base; + assert(sp_base > 0); + } else { - if (ARGTARG) - GETTARGET; + sp_base = 0; + if (PL_op->op_targ) + targ = PAD_SV(PL_op->op_targ); else { - TARG = DEFSV; + targ = DEFSV; } - EXTEND(SP,1); + rpp_extend(1); } - PUTBACK; /* EVAL blocks need stack_sp. */ /* Skip get-magic if this is a qr// clone, because regcomp has already done it. */ truebase = prog->mother_re @@ -3150,7 +3809,7 @@ PP(pp_match) #endif { r_flags |= (REXEC_COPY_STR|REXEC_COPY_SKIP_PRE); - /* in @a =~ /(.)/g, we iterate multiple times, but copy the buffer + /* In @a = /(.)/g, we iterate multiple times, but copy the buffer * only on the first iteration. Therefore we need to copy $' as well * as $&, to make the rest of the string available for captures in * subsequent iterations */ @@ -3199,7 +3858,10 @@ PP(pp_match) if ((!RXp_NPARENS(prog) && !global) || gimme != G_LIST) { LEAVE_SCOPE(oldsave); - RETPUSHYES; + if (sp_base) + rpp_popfree_1(); /* free arg */ + rpp_push_IMM(&PL_sv_yes); + return NORMAL; } /* push captures on stack */ @@ -3207,19 +3869,19 @@ PP(pp_match) { const I32 logical_nparens = RXp_LOGICAL_NPARENS(prog); /* This following statement is *devious* code. If we are in a global - match and the pattern has no parens in it we should return $& + match and the pattern has no parens in it, we should return $& (offset pair 0). So we set logical_paren to 1 when we should return $&, otherwise we set it to 0. This allows us to simply add logical_nparens to logical_paren to compute the number of elements we are going to return. - In the loop intit we "not" it with: logical_paren = !logical_paren + In the loop init we "not" it with: logical_paren = !logical_paren which results in it being 0 inside the loop when we want to return $&, and results in it being 1 when we want to return the parens. Thus we either loop over 1..logical_nparens, or just over 0. - This is an elegant way to do this code wise, but is super devious + This is an elegant way to do this code-wise, but is super devious and potentially confusing. When I first saw this logic I thought "WTF?". But it makes sense after you poke it a while. @@ -3227,15 +3889,14 @@ PP(pp_match) I am leaving it. - Yves */ I32 logical_paren = (global && !logical_nparens) ? 1 : 0; I32 *l2p = RXp_LOGICAL_TO_PARNO(prog); - /* this is used to step through the physical parens associated - * with a given logical paren. */ + /* This is used to step through the physical parens associated + with a given logical paren. */ I32 *p2l_next = RXp_PARNO_TO_LOGICAL_NEXT(prog); - SPAGAIN; /* EVAL blocks could move the stack. */ - EXTEND(SP, logical_nparens + logical_paren); /* devious code ... */ + rpp_extend(logical_nparens + logical_paren); /* devious code ... */ EXTEND_MORTAL(logical_nparens + logical_paren); /* ... see above */ - /* loop over the logical parens in the pattern. This may not + /* Loop over the logical parens in the pattern. This may not correspond to the actual paren checked, as branch reset may mean that there is more than one paren "behind" the logical parens. Eg, in /(?|(a)|(b))/ there are two parens, but one @@ -3244,10 +3905,10 @@ PP(pp_match) logical_paren <= logical_nparens; logical_paren++) { - /* now convert the logical_paren to the physical parens which - are "behind" it. If branch reset was not used then + /* Now convert the logical_paren to the physical parens which + are "behind" it. If branch reset was not used, then physical_paren and logical_paren are the same as each other - and we will only perform one iteration of the loop */ + and we will only perform one iteration of the loop. */ I32 phys_paren = l2p ? l2p[logical_paren] : logical_paren; SSize_t offs_start, offs_end; /* We check the loop invariants below and break out of the loop @@ -3256,7 +3917,7 @@ PP(pp_match) while (1) { /* Check end offset first, as the start might be >=0 even though the end is -1, so testing the end first helps - use avoid the start check. Really we should be able to + us avoid the start check. Really we should be able to get away with ONLY testing the end, but testing both doesn't hurt much and preserves sanity. */ if (((offs_end = RXp_OFFS_END(prog, phys_paren)) != -1) && @@ -3269,7 +3930,7 @@ PP(pp_match) "start=%zd, end=%zd, s=%p, strend=%p, len=%zd", phys_paren, offs_start, offs_end, s, strend, len); } - PUSHs(newSVpvn_flags(s, len, + rpp_push_1(newSVpvn_flags(s, len, (DO_UTF8(TARG)) ? SVf_UTF8|SVs_TEMP : SVs_TEMP) @@ -3282,7 +3943,7 @@ PP(pp_match) of physical parens associated with this logical paren. Either way we are done, and we can push undef and break out of the loop. */ - PUSHs(sv_newmortal()); + rpp_push_1(sv_newmortal()); break; } } @@ -3290,12 +3951,11 @@ PP(pp_match) if (global) { curpos = (UV)RXp_OFFS_END(prog,0); had_zerolen = RXp_ZERO_LEN(prog); - PUTBACK; /* EVAL blocks may use stack */ r_flags |= REXEC_IGNOREPOS | REXEC_NOT_FIRST; goto play_it_again; } LEAVE_SCOPE(oldsave); - RETURN; + goto ret_list; } NOT_REACHED; /* NOTREACHED */ @@ -3307,39 +3967,150 @@ PP(pp_match) mg->mg_len = -1; } LEAVE_SCOPE(oldsave); - if (gimme == G_LIST) - RETURN; - RETPUSHNO; + if (gimme != G_LIST) { + if (sp_base) + rpp_popfree_1(); /* free arg */ + rpp_push_IMM(&PL_sv_no); + return NORMAL; + } + + ret_list: + /* return when in list context (i.e. don't push YES/NO, but do return + * a (possibly empty) list of matches */ + if (sp_base) { + /* need to free the original argument and shift any results down + * by one */ + SSize_t nitems = PL_stack_sp - (PL_stack_base + sp_base); +#ifdef PERL_RC_STACK + SV *old_sv = PL_stack_sp[-nitems]; +#endif + if (nitems) + Move(PL_stack_sp - nitems + 1, + PL_stack_sp - nitems, nitems, SV*); + PL_stack_sp--; +#ifdef PERL_RC_STACK + SvREFCNT_dec_NN(old_sv); +#endif + } + + return NORMAL; } + +/* Perl_do_readline(): implement <$fh>, readline($fh) and glob('*.h') + * + * This function is tail-called by pp_readline(), pp_rcatline() and + * pp_glob(), and it may check PL_op's op_type and op_flags as + * appropriate. + * + * For file reading: + * It reads the line(s) from PL_last_in_gv. + * It returns a list of lines, or in scalar context, reads one line into + * targ (or if OPf_STACKED, into the top SV on the stack), and + * returns that. (If OP_RCATLINE, concats rather than sets). + * + * So it normally expects zero args, or one arg when the OPf_STACKED + * optimisation is present. + * + * For file globbing: + * Note that we don't normally reach here: we only get here if perl is + * built with PERL_EXTERNAL_GLOB, which is normally only when + * building miniperl. + * + * Expects one arg, which is the pattern string (e.g. '*.h'). + * The caller sets PL_last_in_gv to a plain GV that just has a new + * IO::File PVIO attached. That PVIO is used to attach a pipe file + * handle to when an external glob is being run in scalar context, + * so the pipe is available on subsequent iterations. + * + * Handles tied IO magic, but not overloading - that's the caller's + * responsibility. + * + * Handles the *ARGV filehandle specially, to do all the <> wizardry. + * + * In summary: on entry, the stack has zero or one items pushed, and + * looks like: + * + * - when OP_READLINE without OPf_STACKED + * target when OP_READLINE with OPf_STACKED, or when OP_RCATLINE + * '*.h' when OP_GLOB + */ + OP * Perl_do_readline(pTHX) { - dSP; dTARGETSTACKED; + + const I32 type = PL_op->op_type; + + /* only readline/rcatline can have the STACKED optimisation, + * and rcatline *always* has it */ + if (PL_op->op_flags & OPf_STACKED) { + assert(type != OP_GLOB); + assert(GIMME_V == G_SCALAR); + } + if (type == OP_RCATLINE) + assert(PL_op->op_flags & OPf_STACKED); + + const U8 gimme = GIMME_V; + SV *targ = (gimme == G_SCALAR) + ? (PL_op->op_flags & OPf_STACKED) + ? *PL_stack_sp + : PAD_SV(PL_op->op_targ) + : NULL; SV *sv; STRLEN tmplen = 0; STRLEN offset; PerlIO *fp; IO * const io = GvIO(PL_last_in_gv); - const I32 type = PL_op->op_type; - const U8 gimme = GIMME_V; + + /* process tied file handle if present */ if (io) { const MAGIC *const mg = SvTIED_mg((const SV *)io, PERL_MAGIC_tiedscalar); if (mg) { - Perl_tied_method(aTHX_ SV_CONST(READLINE), SP, MUTABLE_SV(io), mg, gimme, 0); + /* not possible for the faked-up IO passed by an OP_GLOB to be + * tied */ + assert(type != OP_GLOB); + /* OPf_STACKED only applies when in scalar context */ + assert(!(gimme != G_SCALAR && (PL_op->op_flags & OPf_STACKED))); + + /* tied_method() frees everything currently above the passed + * mark, and returns any values at mark[1] onwards */ + Perl_tied_method(aTHX_ SV_CONST(READLINE), + /* mark => */ PL_stack_sp, + MUTABLE_SV(io), mg, gimme, 0); + if (gimme == G_SCALAR) { - SPAGAIN; - SvSetSV_nosteal(TARG, TOPs); - SETTARG; + SvSetSV_nosteal(targ, *PL_stack_sp); + SvSETMAGIC(targ); + if (PL_op->op_flags & OPf_STACKED) { + /* free the tied method call's return value */ + rpp_popfree_1(); + assert(*PL_stack_sp == targ); + } + else + rpp_replace_1_1(targ); } + else + /* no targ to pop off the stack - any returned values + * are in the right place in the stack */ + assert(!(PL_op->op_flags & OPf_STACKED)); + return NORMAL; } } + fp = NULL; + + /* handle possible *ARGV, and check for read on write-only FH */ + if (io) { fp = IoIFP(io); - if (!fp) { + if (fp) { + if (IoTYPE(io) == IoTYPE_WRONLY) + report_wrongway_fh(PL_last_in_gv, '>'); + } + else { if (IoFLAGS(io) & IOf_ARGV) { if (IoFLAGS(io) & IOf_START) { IoLINES(io) = 0; @@ -3358,15 +4129,15 @@ Perl_do_readline(pTHX) (void)do_close(PL_last_in_gv, FALSE); /* now it does*/ } } - else if (type == OP_GLOB) - fp = Perl_start_glob(aTHX_ POPs, io); - } - else if (type == OP_GLOB) - SP--; - else if (IoTYPE(io) == IoTYPE_WRONLY) { - report_wrongway_fh(PL_last_in_gv, '>'); + else if (type == OP_GLOB) { + fp = Perl_start_glob(aTHX_ *PL_stack_sp, io); + rpp_popfree_1_NN(); + } } } + + /* handle bad file handle */ + if (!fp) { if ((!io || !(IoFLAGS(io) & IOf_START)) && ckWARN(WARN_CLOSED) @@ -3374,20 +4145,26 @@ Perl_do_readline(pTHX) { report_evil_fh(PL_last_in_gv); } + if (gimme == G_SCALAR) { - /* undef TARG, and push that undefined value */ - if (type != OP_RCATLINE) { - sv_set_undef(TARG); - } - PUSHTARG; + /* undef targ, and return that undefined value */ + if (type != OP_RCATLINE) + sv_set_undef(targ); + if (!(PL_op->op_flags & OPf_STACKED)) + rpp_push_1(targ); } - RETURN; + return NORMAL; } + have_fp: + + /* prepare targ to have a string assigned to it */ + if (gimme == G_SCALAR) { - sv = TARG; + sv = targ; if (type == OP_RCATLINE && SvGMAGICAL(sv)) mg_get(sv); + if (SvROK(sv)) { if (type == OP_RCATLINE) SvPV_force_nomg_nolen(sv); @@ -3397,6 +4174,7 @@ Perl_do_readline(pTHX) else if (isGV_with_GP(sv)) { SvPV_force_nomg_nolen(sv); } + SvUPGRADE(sv, SVt_PV); tmplen = SvLEN(sv); /* remember if already alloced */ if (!tmplen && !SvREADONLY(sv) && !SvIsCOW(sv)) { @@ -3405,6 +4183,7 @@ Perl_do_readline(pTHX) */ Sv_Grow(sv, 80); } + offset = 0; if (type == OP_RCATLINE && SvOK(sv)) { if (!SvPOK(sv)) { @@ -3414,6 +4193,7 @@ Perl_do_readline(pTHX) } } else { + /* XXX on RC builds, push on stack rather than mortalize ? */ sv = sv_2mortal(newSV(80)); offset = 0; } @@ -3430,8 +4210,9 @@ Perl_do_readline(pTHX) (gimme != G_SCALAR || SvCUR(sv) \ || (IoFLAGS(io) & IOf_NOLINE) || !RsSNARF(rs)) + /* create one or more lines, or (if OP_GLOB), pathnames */ + for (;;) { - PUTBACK; if (!sv_gets(sv, fp, offset) && (type == OP_GLOB || SNARF_EOF(gimme, PL_rs, io, sv) @@ -3457,27 +4238,44 @@ Perl_do_readline(pTHX) (STATUS_CURRENT & 0x80) ? ", core dumped" : ""); } } + if (gimme == G_SCALAR) { if (type != OP_RCATLINE) { - SV_CHECK_THINKFIRST_COW_DROP(TARG); - SvOK_off(TARG); + SV_CHECK_THINKFIRST_COW_DROP(targ); + SvOK_off(targ); } - SPAGAIN; - PUSHTARG; + /* targ not already there? */ + if (!(PL_op->op_flags & OPf_STACKED)) + rpp_push_1(targ); } + else if (PL_op->op_flags & OPf_STACKED) + rpp_popfree_1_NN(); + MAYBE_TAINT_LINE(io, sv); - RETURN; + return NORMAL; } + MAYBE_TAINT_LINE(io, sv); IoLINES(io)++; IoFLAGS(io) |= IOf_NOLINE; SvSETMAGIC(sv); - SPAGAIN; - XPUSHs(sv); + rpp_extend(1); + if (PL_op->op_flags & OPf_STACKED) { + /* push sv while keeping targ above it, so targ doesn't get + * freed */ + assert(*PL_stack_sp == targ); + PL_stack_sp[1] = targ; + *PL_stack_sp++ = NULL; + rpp_replace_at(PL_stack_sp - 1, sv); + } + else + rpp_push_1(sv); + if (type == OP_GLOB) { const char *t1; Stat_t statbuf; + /* chomp(sv) */ if (SvCUR(sv) > 0 && SvCUR(PL_rs) > 0) { char * const tmps = SvEND(sv) - 1; if (*tmps == *SvPVX_const(PL_rs)) { @@ -3485,18 +4283,26 @@ Perl_do_readline(pTHX) SvCUR_set(sv, SvCUR(sv) - 1); } } - for (t1 = SvPVX_const(sv); *t1; t1++) + + /* find longest substring of sv up to first metachar */ + for (t1 = SvPVX_const(sv); *t1; t1++) { #ifdef __VMS if (memCHRs("*%?", *t1)) #else if (memCHRs("$&*(){}[]'\";\\|?<>~`", *t1)) #endif break; + } + if (*t1 && PerlLIO_lstat(SvPVX_const(sv), &statbuf) < 0) { - (void)POPs; /* Unmatched wildcard? Chuck it... */ + /* Unmatched wildcard? Chuck it... */ + /* no need to worry about targ still on top of stack */ + assert(!(PL_op->op_flags & OPf_STACKED)); + rpp_popfree_1(); continue; } } else if (SvUTF8(sv)) { /* OP_READLINE, OP_RCATLINE */ + /* check line if valid Unicode */ if (ckWARN(WARN_UTF8)) { const U8 * const s = (const U8*)SvPVX_const(sv) + offset; const STRLEN len = SvCUR(sv) - offset; @@ -3509,38 +4315,49 @@ Perl_do_readline(pTHX) f < (U8*)SvEND(sv) ? *f : 0); } } + if (gimme == G_LIST) { if (SvLEN(sv) - SvCUR(sv) > 20) { SvPV_shrink_to_cur(sv); } + /* XXX on RC builds, push on stack rather than mortalize ? */ sv = sv_2mortal(newSV(80)); continue; } - else if (gimme == G_SCALAR && !tmplen && SvLEN(sv) - SvCUR(sv) > 80) { + + if (gimme == G_SCALAR && !tmplen && SvLEN(sv) - SvCUR(sv) > 80) { /* try to reclaim a bit of scalar space (only on 1st alloc) */ const STRLEN new_len = SvCUR(sv) < 60 ? 80 : SvCUR(sv)+40; /* allow some slop */ SvPV_renew(sv, new_len); } - RETURN; - } + + + if (PL_op->op_flags & OPf_STACKED) + rpp_popfree_1_NN(); /* finally remove targ */ + /* return sv, which was recently pushed onto the stack */ + return NORMAL; + } /* for (;;) */ } + PP(pp_helem) { - dSP; HE* he; SV **svp; - SV * const keysv = POPs; - HV * const hv = MUTABLE_HV(POPs); + SV * const keysv = PL_stack_sp[0]; + HV * const hv = MUTABLE_HV(PL_stack_sp[-1]); const U32 lval = PL_op->op_flags & OPf_MOD || LVRET; const U32 defer = PL_op->op_private & OPpLVAL_DEFER; SV *sv; const bool localizing = PL_op->op_private & OPpLVAL_INTRO; bool preeminent = TRUE; + SV *retsv; - if (SvTYPE(hv) != SVt_PVHV) - RETPUSHUNDEF; + if (SvTYPE(hv) != SVt_PVHV) { + retsv = &PL_sv_undef; + goto ret; + } if (localizing) { MAGIC *mg; @@ -3568,9 +4385,10 @@ PP(pp_helem) SvREFCNT_dec_NN(key2); /* sv_magic() increments refcount */ LvTARG(lv) = SvREFCNT_inc_simple_NN(hv); LvTARGLEN(lv) = 1; - PUSHs(lv); - RETURN; + retsv = lv; + goto ret; } + if (localizing) { if (HvNAME_get(hv) && isGV_or_RVCV(*svp)) save_gp(MUTABLE_GV(*svp), !(PL_op->op_flags & OPf_SPECIAL)); @@ -3581,8 +4399,8 @@ PP(pp_helem) SAVEHDELETE(hv, keysv); } else if (PL_op->op_private & OPpDEREF) { - PUSHs(vivify_ref(*svp, PL_op->op_private & OPpDEREF)); - RETURN; + retsv = vivify_ref(*svp, PL_op->op_private & OPpDEREF); + goto ret;; } } sv = (svp && *svp ? *svp : &PL_sv_undef); @@ -3600,8 +4418,11 @@ PP(pp_helem) * being called too many times). */ if (!lval && SvRMAGICAL(hv) && SvGMAGICAL(sv)) mg_get(sv); - PUSHs(sv); - RETURN; + retsv = sv; + + ret: + rpp_replace_2_1_NN(retsv); + return NORMAL; } @@ -3644,6 +4465,7 @@ PP(pp_multideref) assert(actions); /* this tells find_uninit_var() where we're up to */ PL_multideref_pc = items; + bool replace = FALSE; while (1) { /* there are three main classes of action; the first retrieves @@ -3669,9 +4491,8 @@ PP(pp_multideref) case MDEREF_AV_pop_rv2av_aelem: /* expr->[...] */ { - dSP; - sv = POPs; - PUTBACK; + sv = *PL_stack_sp; + replace = TRUE; goto do_AV_rv2av_aelem; } @@ -3841,9 +4662,11 @@ PP(pp_multideref) } finish: { - dSP; - XPUSHs(sv); - RETURN; + if (replace) + rpp_replace_1_1_NN(sv); + else + rpp_xpush_1(sv); + return NORMAL; } /* NOTREACHED */ @@ -3862,9 +4685,8 @@ PP(pp_multideref) case MDEREF_HV_pop_rv2hv_helem: /* expr->{...} */ { - dSP; - sv = POPs; - PUTBACK; + sv = *PL_stack_sp; + replace = TRUE; goto do_HV_rv2hv_helem; } @@ -4285,7 +5107,7 @@ PP(pp_iter) * obvious way. */ /* pp_enteriter should have pre-extended the stack */ EXTEND_SKIP(PL_stack_sp, 1); - *++PL_stack_sp = &PL_sv_yes; + rpp_push_IMM(&PL_sv_yes); return PL_op->op_next; } @@ -4300,7 +5122,7 @@ PP(pp_iter) * (or for when an XS module has replaced the op_ppaddr) * but it's cheaper to just push it rather than testing first */ - *++PL_stack_sp = &PL_sv_no; + rpp_push_IMM(&PL_sv_no); if (PL_op->op_next->op_ppaddr == Perl_pp_and) { return PL_op->op_next->op_next; } @@ -4382,7 +5204,7 @@ pp_match is just a simpler version of th PP(pp_subst) { - dSP; dTARG; + dTARG; PMOP *pm = cPMOP; PMOP *rpm = pm; char *s; @@ -4406,20 +5228,35 @@ PP(pp_subst) bool was_cow; #endif SV *nsv = NULL; - /* known replacement string? */ - SV *dstr = (pm->op_pmflags & PMf_CONST) ? POPs : NULL; + SSize_t sp_offset = 0; /* number of items left on stack */ + SV *dstr; + SV *retval; PERL_ASYNC_CHECK(); - if (PL_op->op_flags & OPf_STACKED) - TARG = POPs; + if (pm->op_pmflags & PMf_CONST) { + /* known replacement string */ + dstr = *PL_stack_sp; + sp_offset++; + } + else + dstr = NULL; + + if (PL_op->op_flags & OPf_STACKED) { + /* expr =~ s///; */ + TARG = PL_stack_sp[-sp_offset]; + sp_offset++; + } else { if (ARGTARG) + /* $lex =~ s///; */ GETTARGET; else { + /* s///; */ TARG = DEFSV; } - EXTEND(SP,1); + if (!sp_offset) + rpp_extend(1); } SvGETMAGIC(TARG); /* must come before cow check */ @@ -4438,7 +5275,6 @@ PP(pp_subst) && !(SvTYPE(TARG) == SVt_PVGV && SvFAKE(TARG))))) Perl_croak_no_modify(); } - PUTBACK; orig = SvPV_nomg(TARG, len); /* note we don't (yet) force the var into being a string; if we fail @@ -4504,10 +5340,15 @@ PP(pp_subst) if (!CALLREGEXEC(rx, orig, strend, orig, 0, TARG, NULL, r_flags)) { - SPAGAIN; - PUSHs(rpm->op_pmflags & PMf_NONDESTRUCT ? TARG : &PL_sv_no); + SV *ret = rpm->op_pmflags & PMf_NONDESTRUCT ? TARG : &PL_sv_no; + if (dstr) + rpp_popfree_1_NN(); /* pop replacement string */ + if (PL_op->op_flags & OPf_STACKED) + rpp_replace_1_1_NN(ret); /* pop LHS of =~ */ + else + rpp_push_1(ret); LEAVE_SCOPE(oldsave); - RETURN; + return NORMAL; } PL_curpm = pm; @@ -4534,12 +5375,11 @@ PP(pp_subst) doutf8 = FALSE; } - /* can do inplace substitution? */ if (c #ifdef PERL_ANY_COW && !was_cow #endif - && (I32)clen <= RXp_MINLENRET(prog) + && (SSize_t)clen <= RXp_MINLENRET(prog) && ( once || !(r_flags & REXEC_COPY_STR) || (!SvGMAGICAL(dstr) && !(RXp_EXTFLAGS(prog) & RXf_EVAL_SEEN)) @@ -4548,6 +5388,7 @@ PP(pp_subst) && (!doutf8 || SvUTF8(TARG)) && !(rpm->op_pmflags & PMf_NONDESTRUCT)) { + /* known replacement string and can do in-place substitution */ #ifdef PERL_ANY_COW /* string might have got converted to COW since we set was_cow */ @@ -4573,7 +5414,7 @@ PP(pp_subst) d = orig + RXp_OFFS_END(prog,0); s = orig; if (m - s > strend - d) { /* faster to shorten from end */ - I32 i; + SSize_t i; if (clen) { Copy(c, m, clen, char); m += clen; @@ -4587,7 +5428,7 @@ PP(pp_subst) SvCUR_set(TARG, m - s); } else { /* faster from front */ - I32 i = m - s; + SSize_t i = m - s; d -= clen; if (i > 0) Move(s, d - i, i, char); @@ -4595,14 +5436,14 @@ PP(pp_subst) if (clen) Copy(c, d, clen, char); } - SPAGAIN; - PUSHs(&PL_sv_yes); + retval = &PL_sv_yes; + goto ret; } else { char *d, *m; d = s = RXp_OFFS_START(prog,0) + orig; do { - I32 i; + SSize_t i; if (UNLIKELY(iters++ > maxiters)) DIE(aTHX_ "Substitution loop"); /* run time pattern taint, eg locale */ @@ -4624,19 +5465,16 @@ PP(pp_subst) TARG, NULL, REXEC_NOT_FIRST|REXEC_IGNOREPOS|REXEC_FAIL_ON_UNDERFLOW)); if (s != d) { - I32 i = strend - s; + SSize_t i = strend - s; SvCUR_set(TARG, d - SvPVX_const(TARG) + i); Move(s, d, i+1, char); /* include the NUL */ } - SPAGAIN; assert(iters); - if (PL_op->op_private & OPpTRUEBOOL) - PUSHs(&PL_sv_yes); - else - mPUSHi(iters); + goto ret_iters; } } else { + /* not known replacement string or can't do in-place substitution) */ bool first; char *m; SV *repl; @@ -4665,8 +5503,8 @@ PP(pp_subst) dstr = newSVpvn_flags(orig, s-orig, SVs_TEMP | (DO_UTF8(TARG) ? SVf_UTF8 : 0)); if (!c) { + /* not known replacement string - call out to ops and OP_SUBSTCONT */ PERL_CONTEXT *cx; - SPAGAIN; m = orig; /* note that a whole bunch of local vars are saved here for * use by pp_substcont: here's a list of them in case you're @@ -4674,8 +5512,12 @@ PP(pp_subst) * iters maxiters r_flags oldsave rxtainted orig dstr targ * s m strend rx once */ CX_PUSHSUBST(cx); - RETURNOP(cPMOP->op_pmreplrootu.op_pmreplroot); + return cPMOP->op_pmreplrootu.op_pmreplroot; } + + /* We get here if it's a known replacement string, but can't + * substitute in-place */ + first = TRUE; do { if (UNLIKELY(iters++ > maxiters)) @@ -4716,8 +5558,8 @@ PP(pp_subst) /* From here on down we're using the copy, and leaving the original untouched. */ TARG = dstr; - SPAGAIN; - PUSHs(dstr); + retval = dstr; + goto ret; } else { #ifdef PERL_ANY_COW /* The match may make the string COW. If so, brilliant, because @@ -4737,15 +5579,26 @@ PP(pp_subst) SvLEN_set(TARG, SvLEN(dstr)); SvFLAGS(TARG) |= SvUTF8(dstr); SvPV_set(dstr, NULL); - - SPAGAIN; - if (PL_op->op_private & OPpTRUEBOOL) - PUSHs(&PL_sv_yes); - else - mPUSHi(iters); + goto ret_iters; } } + ret_iters: + if (PL_op->op_private & OPpTRUEBOOL) + retval = &PL_sv_yes; + else { + retval = sv_newmortal(); + sv_setiv(retval, iters); + } + + ret: + if (dstr) + rpp_popfree_1_NN(); /* pop replacement string */ + if (PL_op->op_flags & OPf_STACKED) + rpp_replace_1_1_NN(retval); /* pop LHS of =~ */ + else + rpp_push_1(retval); + if (!(rpm->op_pmflags & PMf_NONDESTRUCT)) { (void)SvPOK_only_UTF8(TARG); } @@ -4761,9 +5614,9 @@ PP(pp_subst) if (!(rxtainted & SUBST_TAINT_BOOLRET) && (rxtainted & (SUBST_TAINT_STR|SUBST_TAINT_PAT)) ) - SvTAINTED_on(TOPs); /* taint return value */ + SvTAINTED_on(retval); /* taint return value */ else - SvTAINTED_off(TOPs); /* may have got tainted earlier */ + SvTAINTED_off(retval); /* may have got tainted earlier */ /* needed for mg_set below */ TAINT_set( @@ -4774,9 +5627,10 @@ PP(pp_subst) SvSETMAGIC(TARG); /* PL_tainted must be correctly set for this mg_set */ TAINT_NOT; LEAVE_SCOPE(oldsave); - RETURN; + return NORMAL; } + PP(pp_grepwhile) { /* Understanding the stack during a grep. @@ -4830,36 +5684,55 @@ PP(pp_grepwhile) * */ - dSP; - dPOPss; + bool match = SvTRUE_NN(*PL_stack_sp); + rpp_popfree_1_NN(); + + if (match) { + SV **from_p = PL_stack_base + PL_markstack_ptr[0]; + SV **to_p = PL_stack_base + PL_markstack_ptr[-1]++; + SV *from = *from_p; + SV *to = *to_p; + + if (from != to) { + *to_p = from; +#ifdef PERL_RC_STACK + SvREFCNT_inc_simple_void_NN(from); + SvREFCNT_dec(to); +#endif + } + } - if (SvTRUE_NN(sv)) - PL_stack_base[PL_markstack_ptr[-1]++] = PL_stack_base[*PL_markstack_ptr]; ++*PL_markstack_ptr; FREETMPS; LEAVE_with_name("grep_item"); /* exit inner scope */ /* All done yet? */ - if (UNLIKELY(PL_stack_base + *PL_markstack_ptr > SP)) { - I32 items; + if (UNLIKELY(PL_stack_base + *PL_markstack_ptr > PL_stack_sp)) { + SSize_t items; const U8 gimme = GIMME_V; LEAVE_with_name("grep"); /* exit outer scope */ (void)POPMARK; /* pop src */ items = --*PL_markstack_ptr - PL_markstack_ptr[-1]; (void)POPMARK; /* pop dst */ - SP = PL_stack_base + POPMARK; /* pop original mark */ - if (gimme == G_SCALAR) { - if (PL_op->op_private & OPpTRUEBOOL) - PUSHs(items ? &PL_sv_yes : &PL_sv_zero); - else { - dTARGET; - PUSHi(items); + SV **base = PL_stack_base + POPMARK; /* pop original mark */ + + if (gimme == G_LIST) + rpp_popfree_to_NN(base + items); + else { + rpp_popfree_to_NN(base); + if (gimme == G_SCALAR) { + if (PL_op->op_private & OPpTRUEBOOL) + rpp_push_IMM(items ? &PL_sv_yes : &PL_sv_zero); + else { + dTARGET; + TARGi(items,1); + rpp_push_1(TARG); + } } } - else if (gimme == G_LIST) - SP += items; - RETURN; + + return NORMAL; } else { SV *src; @@ -4869,16 +5742,23 @@ PP(pp_grepwhile) src = PL_stack_base[TOPMARK]; if (SvPADTMP(src)) { - src = PL_stack_base[TOPMARK] = sv_mortalcopy(src); + SV *newsrc = sv_mortalcopy(src); + PL_stack_base[TOPMARK] = newsrc; +#ifdef PERL_RC_STACK + SvREFCNT_inc_simple_void_NN(newsrc); + SvREFCNT_dec(src); +#endif + src = newsrc; PL_tmps_floor++; } SvTEMP_off(src); DEFSV_set(src); - RETURNOP(cLOGOP->op_other); + return cLOGOP->op_other; } } + /* leave_adjust_stacks(): * * Process a scope's return args (in the range from_sp+1 .. PL_stack_sp), @@ -4942,7 +5822,6 @@ PP(pp_grepwhile) void Perl_leave_adjust_stacks(pTHX_ SV **from_sp, SV **to_sp, U8 gimme, int pass) { - dSP; SSize_t tmps_base; /* lowest index into tmps stack that needs freeing now */ SSize_t nargs; @@ -4951,23 +5830,37 @@ Perl_leave_adjust_stacks(pTHX_ SV **from TAINT_NOT; if (gimme == G_LIST) { - nargs = SP - from_sp; + nargs = PL_stack_sp - from_sp; from_sp++; } else { assert(gimme == G_SCALAR); - if (UNLIKELY(from_sp >= SP)) { + if (UNLIKELY(from_sp >= PL_stack_sp)) { /* no return args */ - assert(from_sp == SP); - EXTEND(SP, 1); - *++SP = &PL_sv_undef; + assert(from_sp == PL_stack_sp); + rpp_xpush_IMM(&PL_sv_undef); } - from_sp = SP; + from_sp = PL_stack_sp; nargs = 1; } /* common code for G_SCALAR and G_LIST */ +#ifdef PERL_RC_STACK + { + /* free any items from the stack which are about to get + * over-written */ + SV **p = from_sp - 1; + assert(p >= to_sp); + while (p > to_sp) { + SV *sv = *p; + *p-- = NULL; + SvREFCNT_dec(sv); + } + } +#endif + + tmps_base = PL_tmps_floor + 1; assert(nargs >= 0); @@ -5016,13 +5909,17 @@ Perl_leave_adjust_stacks(pTHX_ SV **from #endif if ( - pass == 0 ? (SvTEMP(sv) && !SvMAGICAL(sv) && SvREFCNT(sv) == 1) + pass == 0 ? (rpp_is_lone(sv) && !SvMAGICAL(sv)) : pass == 1 ? ((SvTEMP(sv) || SvPADTMP(sv)) && !SvMAGICAL(sv) && SvREFCNT(sv) == 1) : pass == 2 ? (!SvPADTMP(sv)) : 1) { /* pass through: skip copy for logic or optimisation * reasons; instead mortalise it, except that ... */ + +#ifdef PERL_RC_STACK + from_sp[-1] = NULL; +#endif *++to_sp = sv; if (SvTEMP(sv)) { @@ -5100,7 +5997,6 @@ Perl_leave_adjust_stacks(pTHX_ SV **from PL_tmps_stack[++PL_tmps_ix] = *tmps_basep; /* put it on the tmps stack early so it gets freed if we die */ *tmps_basep++ = newsv; - *++to_sp = newsv; if (SvTYPE(sv) <= SVt_IV) { /* arg must be one of undef, IV/UV, or RV: skip @@ -5154,6 +6050,17 @@ Perl_leave_adjust_stacks(pTHX_ SV **from TAINT_NOT; /* Each item is independent */ } + +#ifdef PERL_RC_STACK + from_sp[-1] = NULL; + SvREFCNT_dec_NN(sv); + assert(!to_sp[1]); + *++to_sp = newsv; + SvREFCNT_inc_simple_void_NN(newsv); +#else + *++to_sp = newsv; +#endif + } } while (--nargs); @@ -5220,7 +6127,7 @@ PP(pp_leavesub) oldsp = PL_stack_base + cx->blk_oldsp; /* last arg of previous frame */ if (gimme == G_VOID) - PL_stack_sp = oldsp; + rpp_popfree_to_NN(oldsp); else leave_adjust_stacks(oldsp, oldsp, gimme, 0); @@ -5242,16 +6149,25 @@ Perl_clear_defarray(pTHX_ AV* av, bool a { PERL_ARGS_ASSERT_CLEAR_DEFARRAY; - if (LIKELY(!abandon && SvREFCNT(av) == 1 && !SvMAGICAL(av))) { - av_clear(av); + if (LIKELY(!abandon && SvREFCNT(av) == 1 && !SvMAGICAL(av)) +#ifndef PERL_RC_STACK + && !AvREAL(av) +#endif + ) { + clear_defarray_simple(av); +#ifndef PERL_RC_STACK AvREIFY_only(av); +#endif } else { + /* abandon */ const SSize_t size = AvFILLp(av) + 1; /* The ternary gives consistency with av_extend() */ - AV *newav = newAV_alloc_x(size < PERL_ARRAY_NEW_MIN_KEY ? + AV *newav = newAV_alloc_xz(size < PERL_ARRAY_NEW_MIN_KEY ? PERL_ARRAY_NEW_MIN_KEY : size); +#ifndef PERL_RC_STACK AvREIFY_only(newav); +#endif PAD_SVl(0) = MUTABLE_SV(newav); SvREFCNT_dec_NN(av); } @@ -5260,11 +6176,11 @@ Perl_clear_defarray(pTHX_ AV* av, bool a PP(pp_entersub) { - dSP; dPOPss; GV *gv; CV *cv; PERL_CONTEXT *cx; I32 old_savestack_ix; + SV *sv = *PL_stack_sp; if (UNLIKELY(!sv)) goto do_die; @@ -5312,7 +6228,6 @@ PP(pp_entersub) do_ref: if (UNLIKELY(SvAMAGIC(sv))) { sv = amagic_deref_call(sv, to_cv_amg); - /* Don't SPAGAIN here. */ } } else { @@ -5406,6 +6321,8 @@ PP(pp_entersub) DIE(aTHX_ "No DB::sub routine defined"); } + rpp_popfree_1_NN(); /* finished with sv now */ + if (!(CvISXSUB(cv))) { /* This path taken at least 75% of the time */ dMARK; @@ -5421,12 +6338,20 @@ PP(pp_entersub) */ { SV **svp = MARK; - while (svp < SP) { + while (svp < PL_stack_sp) { SV *sv = *++svp; if (!sv) continue; - if (SvPADTMP(sv)) - *svp = sv = sv_mortalcopy(sv); + if (SvPADTMP(sv)) { + SV *newsv = sv_mortalcopy(sv); + *svp = newsv; +#ifdef PERL_RC_STACK + /* should just skip the mortalisation instead */ + SvREFCNT_inc_simple_void_NN(newsv); + SvREFCNT_dec_NN(sv); +#endif + sv = newsv; + } SvTEMP_off(sv); } } @@ -5452,9 +6377,15 @@ PP(pp_entersub) /* it's the responsibility of whoever leaves a sub to ensure * that a clean, empty AV is left in pad[0]. This is normally * done by cx_popsub() */ - assert(!AvREAL(av) && AvFILLp(av) == -1); - items = SP - MARK; +#ifdef PERL_RC_STACK + assert(AvREAL(av)); +#else + assert(!AvREAL(av)); +#endif + assert(AvFILLp(av) == -1); + + items = PL_stack_sp - MARK; if (UNLIKELY(items - 1 > AvMAX(av))) { SV **ary = AvALLOC(av); Renew(ary, items, SV*); @@ -5466,6 +6397,10 @@ PP(pp_entersub) if (items) Copy(MARK+1,AvARRAY(av),items,SV*); AvFILLp(av) = items - 1; +#ifdef PERL_RC_STACK + /* transfer ownership of the arguments' refcounts to av */ + PL_stack_sp = MARK; +#endif } if (UNLIKELY((cx->blk_u16 & OPpENTERSUB_LVAL_MASK) == OPpLVAL_INTRO && !CvLVALUE(cv))) @@ -5479,7 +6414,7 @@ PP(pp_entersub) && ckWARN(WARN_RECURSION) && !(PERLDB_SUB && cv == GvCV(PL_DBsub)))) sub_crush_depth(cv); - RETURNOP(CvSTART(cv)); + return CvSTART(cv); } else { SSize_t markix = TOPMARK; @@ -5490,7 +6425,6 @@ PP(pp_entersub) PL_scopestack[PL_scopestack_ix - 1] = old_savestack_ix; SAVETMPS; - PUTBACK; if (UNLIKELY(((PL_op->op_private & CX_PUSHSUB_GET_LVALUE_MASK(Perl_is_lvalue_sub) @@ -5510,7 +6444,7 @@ PP(pp_entersub) SSize_t i = 0; const bool m = cBOOL(SvRMAGICAL(av)); /* Mark is at the end of the stack. */ - EXTEND(SP, items); + rpp_extend(items); for (; i < items; ++i) { SV *sv; @@ -5518,26 +6452,31 @@ PP(pp_entersub) SV ** const svp = av_fetch(av, i, 0); sv = svp ? *svp : NULL; } - else sv = AvARRAY(av)[i]; - if (sv) SP[i+1] = sv; - else { - SP[i+1] = av_nonelem(av, i); - } + else + sv = AvARRAY(av)[i]; + + rpp_push_1(sv ? sv : av_nonelem(av, i)); } - SP += items; - PUTBACK ; } } else { SV **mark = PL_stack_base + markix; - SSize_t items = SP - mark; + SSize_t items = PL_stack_sp - mark; while (items--) { mark++; if (*mark && SvPADTMP(*mark)) { - *mark = sv_mortalcopy(*mark); + SV *oldsv = *mark; + SV *newsv = sv_mortalcopy(oldsv); + *mark = newsv; +#ifdef PERL_RC_STACK + /* should just skip the mortalisation instead */ + SvREFCNT_inc_simple_void_NN(newsv); + SvREFCNT_dec_NN(oldsv); +#endif } } } + /* We assume first XSUB in &DB::sub is the called one. */ if (UNLIKELY(PL_curcopdb)) { SAVEVPTR(PL_curcop); @@ -5552,9 +6491,10 @@ PP(pp_entersub) /* CvXSUB(cv) must not be NULL because newXS() refuses NULL xsub address */ assert(CvXSUB(cv)); - CvXSUB(cv)(aTHX_ cv); -#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY + rpp_invoke_xs(cv); + +#ifdef PERL_USE_HWM /* This duplicates the check done in runops_debug(), but provides more * information in the common case of the fault being with an XSUB. * @@ -5573,8 +6513,21 @@ PP(pp_entersub) if (is_scalar) { SV **svp = PL_stack_base + markix + 1; if (svp != PL_stack_sp) { +#ifdef PERL_RC_STACK + if (svp < PL_stack_sp) { + /* move return value to bottom of stack frame + * and free everything else */ + SV* retsv = *PL_stack_sp; + *PL_stack_sp = *svp; + *svp = retsv; + rpp_popfree_to_NN(svp); + } + else + rpp_push_IMM(&PL_sv_undef); +#else *svp = svp > PL_stack_sp ? &PL_sv_undef : *PL_stack_sp; PL_stack_sp = svp; +#endif } } LEAVE; @@ -5619,23 +6572,25 @@ Perl_croak_caller(const char *pat, ...) PP(pp_aelem) { - dSP; SV** svp; - SV* const elemsv = POPs; + SV* const elemsv = PL_stack_sp[0]; IV elem = SvIV(elemsv); - AV *const av = MUTABLE_AV(POPs); + AV *const av = MUTABLE_AV(PL_stack_sp[-1]); const U32 lval = PL_op->op_flags & OPf_MOD || LVRET; const U32 defer = PL_op->op_private & OPpLVAL_DEFER; const bool localizing = PL_op->op_private & OPpLVAL_INTRO; bool preeminent = TRUE; SV *sv; + SV *retsv; if (UNLIKELY(SvROK(elemsv) && !SvGAMAGIC(elemsv) && ckWARN(WARN_MISC))) Perl_warner(aTHX_ packWARN(WARN_MISC), "Use of reference \"%" SVf "\" as array index", SVfARG(elemsv)); - if (UNLIKELY(SvTYPE(av) != SVt_PVAV)) - RETPUSHUNDEF; + if (UNLIKELY(SvTYPE(av) != SVt_PVAV)) { + retsv = &PL_sv_undef; + goto ret; + } if (UNLIKELY(localizing)) { MAGIC *mg; @@ -5672,13 +6627,13 @@ PP(pp_aelem) elem = len + elem; if (elem >= 0 && elem <= len) /* Falls within the array. */ - PUSHs(av_nonelem(av,elem)); + retsv = av_nonelem(av, elem); else /* Falls outside the array. If it is negative, magic_setdefelem will use the index for error reporting. */ - mPUSHs(newSVavdefelem(av, elem, 1)); - RETURN; + retsv = sv_2mortal(newSVavdefelem(av, elem, 1)); + goto ret; } if (UNLIKELY(localizing)) { if (preeminent) @@ -5687,15 +6642,18 @@ PP(pp_aelem) SAVEADELETE(av, elem); } else if (PL_op->op_private & OPpDEREF) { - PUSHs(vivify_ref(*svp, PL_op->op_private & OPpDEREF)); - RETURN; + retsv = vivify_ref(*svp, PL_op->op_private & OPpDEREF); + goto ret; } } sv = (svp ? *svp : &PL_sv_undef); if (!lval && SvRMAGICAL(av) && SvGMAGICAL(sv)) /* see note in pp_helem() */ mg_get(sv); - PUSHs(sv); - RETURN; + retsv = sv; + + ret: + rpp_replace_2_1_NN(retsv); + return NORMAL; } SV* @@ -5772,7 +6730,19 @@ S_opmethod_stash(pTHX_ SV* meth) ob = LvTARG(ob); assert(ob); } - *(PL_stack_base + TOPMARK + 1) = sv_2mortal(newRV(ob)); + /* Replace the object at the base of the stack frame. + * This is "below" whatever pp_wrap has wrapped, so needs freeing. + */ + SV *newsv = sv_2mortal(newRV(ob)); + SV **svp = (PL_stack_base + TOPMARK + 1); +#ifdef PERL_RC_STACK + SV *oldsv = *svp; +#endif + *svp = newsv; +#ifdef PERL_RC_STACK + SvREFCNT_inc_simple_void_NN(newsv); + SvREFCNT_dec_NN(oldsv); +#endif } else { /* this isn't a reference */ @@ -5783,7 +6753,8 @@ S_opmethod_stash(pTHX_ SV* meth) stash = gv_stashpvn(packname, packlen, packname_utf8 | GV_CACHE_ONLY); if (stash) return stash; - if (!(iogv = gv_fetchpvn_flags( + if ((PL_op->op_private & OPpMETH_NO_BAREWORD_IO) || + !(iogv = gv_fetchpvn_flags( packname, packlen, packname_utf8, SVt_PVIO )) || !(ob=MUTABLE_SV(GvIO(iogv)))) @@ -5800,8 +6771,20 @@ S_opmethod_stash(pTHX_ SV* meth) if (stash) return stash; else return MUTABLE_HV(sv); } - /* it _is_ a filehandle name -- replace with a reference */ - *(PL_stack_base + TOPMARK + 1) = sv_2mortal(newRV(MUTABLE_SV(iogv))); + /* it _is_ a filehandle name -- replace with a reference. + * Replace the object at the base of the stack frame. + * This is "below" whatever pp_wrap has wrapped, so needs freeing. + */ + SV *newsv = sv_2mortal(newRV(MUTABLE_SV(iogv))); + SV **svp = (PL_stack_base + TOPMARK + 1); +#ifdef PERL_RC_STACK + SV *oldsv = *svp; +#endif + *svp = newsv; +#ifdef PERL_RC_STACK + SvREFCNT_inc_simple_void_NN(newsv); + SvREFCNT_dec_NN(oldsv); +#endif } /* if we got here, ob should be an object or a glob */ @@ -5821,16 +6804,15 @@ S_opmethod_stash(pTHX_ SV* meth) PP(pp_method) { - dSP; GV* gv; HV* stash; - SV* const meth = TOPs; + SV* const meth = *PL_stack_sp; if (SvROK(meth)) { SV* const rmeth = SvRV(meth); if (SvTYPE(rmeth) == SVt_PVCV) { - SETs(rmeth); - RETURN; + rpp_replace_1_1_NN(rmeth); + return NORMAL; } } @@ -5839,8 +6821,8 @@ PP(pp_method) gv = gv_fetchmethod_sv_flags(stash, meth, GV_AUTOLOAD|GV_CROAK); assert(gv); - SETs(isGV(gv) ? MUTABLE_SV(GvCV(gv)) : MUTABLE_SV(gv)); - RETURN; + rpp_replace_1_1_NN(isGV(gv) ? MUTABLE_SV(GvCV(gv)) : MUTABLE_SV(gv)); + return NORMAL; } #define METHOD_CHECK_CACHE(stash,cache,meth) \ @@ -5850,14 +6832,13 @@ PP(pp_method) if (isGV(gv) && GvCV(gv) && (!GvCVGEN(gv) || GvCVGEN(gv) \ == (PL_sub_generation + HvMROMETA(stash)->cache_gen))) \ { \ - XPUSHs(MUTABLE_SV(GvCV(gv))); \ - RETURN; \ + rpp_xpush_1(MUTABLE_SV(GvCV(gv))); \ + return NORMAL; \ } \ } \ PP(pp_method_named) { - dSP; GV* gv; SV* const meth = cMETHOP_meth; HV* const stash = opmethod_stash(meth); @@ -5869,13 +6850,12 @@ PP(pp_method_named) gv = gv_fetchmethod_sv_flags(stash, meth, GV_AUTOLOAD|GV_CROAK); assert(gv); - XPUSHs(isGV(gv) ? MUTABLE_SV(GvCV(gv)) : MUTABLE_SV(gv)); - RETURN; + rpp_xpush_1(isGV(gv) ? MUTABLE_SV(GvCV(gv)) : MUTABLE_SV(gv)); + return NORMAL; } PP(pp_method_super) { - dSP; GV* gv; HV* cache; SV* const meth = cMETHOP_meth; @@ -5892,13 +6872,12 @@ PP(pp_method_super) gv = gv_fetchmethod_sv_flags(stash, meth, GV_AUTOLOAD|GV_CROAK|GV_SUPER); assert(gv); - XPUSHs(isGV(gv) ? MUTABLE_SV(GvCV(gv)) : MUTABLE_SV(gv)); - RETURN; + rpp_xpush_1(isGV(gv) ? MUTABLE_SV(GvCV(gv)) : MUTABLE_SV(gv)); + return NORMAL; } PP(pp_method_redir) { - dSP; GV* gv; SV* const meth = cMETHOP_meth; HV* stash = gv_stashsv(cMETHOP_rclass, 0); @@ -5910,13 +6889,12 @@ PP(pp_method_redir) gv = gv_fetchmethod_sv_flags(stash, meth, GV_AUTOLOAD|GV_CROAK); assert(gv); - XPUSHs(isGV(gv) ? MUTABLE_SV(GvCV(gv)) : MUTABLE_SV(gv)); - RETURN; + rpp_xpush_1(isGV(gv) ? MUTABLE_SV(GvCV(gv)) : MUTABLE_SV(gv)); + return NORMAL; } PP(pp_method_redir_super) { - dSP; GV* gv; HV* cache; SV* const meth = cMETHOP_meth; @@ -5931,8 +6909,8 @@ PP(pp_method_redir_super) gv = gv_fetchmethod_sv_flags(stash, meth, GV_AUTOLOAD|GV_CROAK|GV_SUPER); assert(gv); - XPUSHs(isGV(gv) ? MUTABLE_SV(GvCV(gv)) : MUTABLE_SV(gv)); - RETURN; + rpp_xpush_1(isGV(gv) ? MUTABLE_SV(GvCV(gv)) : MUTABLE_SV(gv)); + return NORMAL; } /* Index: gnu/usr.bin/perl/pp_pack.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/pp_pack.c,v diff -u -p -a -u -p -r1.9 pp_pack.c --- gnu/usr.bin/perl/pp_pack.c 14 May 2024 19:38:54 -0000 1.9 +++ gnu/usr.bin/perl/pp_pack.c 22 Jan 2025 00:37:45 -0000 @@ -1849,7 +1849,7 @@ S_unpack_rec(pTHX_ tempsym_t* symptr, co return SP - PL_stack_base - start_sp_offset; } -PP(pp_unpack) +PP_wrapped(pp_unpack, 2, 0) { dSP; dPOPPOPssrl; @@ -3064,7 +3064,13 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* sym * of pack() (and all copies of the result) are * gone. */ - if (((SvTEMP(fromstr) && SvREFCNT(fromstr) == 1) + if (((SvTEMP(fromstr) && SvREFCNT(fromstr) <= +#ifdef PERL_RC_STACK + 2 +#else + 1 +#endif + ) || (SvPADTMP(fromstr) && !SvREADONLY(fromstr)))) { Perl_ck_warner(aTHX_ packWARN(WARN_PACK), @@ -3137,7 +3143,7 @@ S_pack_rec(pTHX_ SV *cat, tempsym_t* sym #undef NEXTFROM -PP(pp_pack) +PP_wrapped(pp_pack, 0, 1) { dSP; dMARK; dORIGMARK; dTARGET; SV *cat = TARG; Index: gnu/usr.bin/perl/pp_proto.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/pp_proto.h,v diff -u -p -a -u -p -r1.6 pp_proto.h --- gnu/usr.bin/perl/pp_proto.h 14 May 2024 19:38:54 -0000 1.6 +++ gnu/usr.bin/perl/pp_proto.h 22 Jan 2025 00:37:45 -0000 @@ -43,6 +43,7 @@ PERL_CALLCONV PP(pp_chop) __attribute__v PERL_CALLCONV PP(pp_chown) __attribute__visibility__("hidden"); PERL_CALLCONV PP(pp_chr) __attribute__visibility__("hidden"); PERL_CALLCONV PP(pp_chroot) __attribute__visibility__("hidden"); +PERL_CALLCONV PP(pp_classname) __attribute__visibility__("hidden"); PERL_CALLCONV PP(pp_clonecv) __attribute__visibility__("hidden"); PERL_CALLCONV PP(pp_close) __attribute__visibility__("hidden"); PERL_CALLCONV PP(pp_closedir) __attribute__visibility__("hidden"); Index: gnu/usr.bin/perl/pp_sort.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/pp_sort.c,v diff -u -p -a -u -p -r1.6 pp_sort.c --- gnu/usr.bin/perl/pp_sort.c 14 May 2024 19:38:54 -0000 1.6 +++ gnu/usr.bin/perl/pp_sort.c 22 Jan 2025 00:37:45 -0000 @@ -688,7 +688,7 @@ Perl_sortsv(pTHX_ SV **array, size_t nme PP(pp_sort) { - dSP; dMARK; dORIGMARK; + dMARK; dORIGMARK; SV **p1 = ORIGMARK+1, **p2; SSize_t max, i; AV* av = NULL; @@ -697,7 +697,7 @@ PP(pp_sort) U8 gimme = GIMME_V; OP* const nextop = PL_op->op_next; I32 overloading = 0; - bool hasargs = FALSE; + bool hasargs = FALSE; /* the sort sub has proto($$)? */ bool copytmps; I32 is_xsub = 0; const U8 priv = PL_op->op_private; @@ -709,9 +709,9 @@ PP(pp_sort) descending = 1; if (gimme != G_LIST) { - SP = MARK; - EXTEND(SP,1); - RETPUSHUNDEF; + rpp_popfree_to_NN(mark); + rpp_xpush_IMM(&PL_sv_undef); + return NORMAL; } ENTER; @@ -741,9 +741,23 @@ PP(pp_sort) PL_sortcop = nullop->op_next; } else { + /* sort list */ GV *autogv = NULL; HV *stash; - cv = sv_2cv(*++MARK, &stash, &gv, GV_ADD); + SV *fn = *++MARK; + cv = sv_2cv(fn, &stash, &gv, GV_ADD); + + /* want to remove the function name from the stack, + * but mustn't trigger cv being freed at the same time. + * Normally the name is a PV while cv is CV (duh!) but + * for lexical subs, fn can already be the CV (but is kept + * alive by a reference from the pad */ +#ifdef PERL_RC_STACK + assert(fn != (SV*)cv || SvREFCNT(fn) > 1); + SvREFCNT_dec(fn); +#endif + *MARK = NULL; + check_cv: if (cv && SvPOK(cv)) { const char * const proto = SvPV_nolen_const(MUTABLE_SV(cv)); @@ -796,69 +810,103 @@ PP(pp_sort) * push (@a) onto stack, then assign result back to @a at the end of * this function */ if (priv & OPpSORT_INPLACE) { - assert( MARK+1 == SP && *SP && SvTYPE(*SP) == SVt_PVAV); + assert( MARK+1 == PL_stack_sp + && *PL_stack_sp + && SvTYPE(*PL_stack_sp) == SVt_PVAV); (void)POPMARK; /* remove mark associated with ex-OP_AASSIGN */ - av = MUTABLE_AV((*SP)); + av = MUTABLE_AV((*PL_stack_sp)); if (SvREADONLY(av)) Perl_croak_no_modify(); max = AvFILL(av) + 1; - MEXTEND(SP, max); + + I32 oldmark = MARK - PL_stack_base; + rpp_extend(max); + MARK = PL_stack_base + oldmark; + if (SvMAGICAL(av)) { for (i=0; i < max; i++) { SV **svp = av_fetch(av, i, FALSE); - *SP++ = (svp) ? *svp : NULL; + SV *sv; + if (svp) { + sv = *svp; +#ifdef PERL_RC_STACK + SvREFCNT_inc_simple_void_NN(sv); +#endif + } + else + sv = NULL; + *++PL_stack_sp = sv; } } else { SV **svp = AvARRAY(av); assert(svp || max == 0); - for (i = 0; i < max; i++) - *SP++ = *svp++; + for (i = 0; i < max; i++) { + SV *sv = *svp++; +#ifdef PERL_RC_STACK + SvREFCNT_inc_simple_void(sv); +#endif + *++PL_stack_sp = sv; + } } - SP--; - p1 = p2 = SP - (max-1); + p1 = p2 = PL_stack_sp - (max-1); + /* we've kept av on the stacck (just below the pushed contents) so + * that a reference-counted stack keeps a reference to it for now + */ + assert((SV*)av == p1[-1]); } else { p2 = MARK+1; - max = SP - MARK; + max = PL_stack_sp - MARK; } /* shuffle stack down, removing optional initial cv (p1!=p2), plus * any nulls; also stringify or converting to integer or number as * required any args */ + + /* no ref-counted SVs at base to be overwritten */ + assert(p1 == p2 || (p1+1 == p2 && !*p1)); + copytmps = cBOOL(PL_sortcop); for (i=max; i > 0 ; i--) { - if ((*p1 = *p2++)) { /* Weed out nulls. */ - if (copytmps && SvPADTMP(*p1)) { - *p1 = sv_mortalcopy(*p1); + SV *sv = *p2++; + if (sv) { /* Weed out nulls. */ + if (copytmps && SvPADTMP(sv)) { + SV *nsv = sv_mortalcopy(sv); +#ifdef PERL_RC_STACK + SvREFCNT_dec_NN(sv); + SvREFCNT_inc_simple_void_NN(nsv); +#endif + sv = nsv; } - SvTEMP_off(*p1); + SvTEMP_off(sv); if (!PL_sortcop) { if (priv & OPpSORT_NUMERIC) { if (priv & OPpSORT_INTEGER) { - if (!SvIOK(*p1)) - (void)sv_2iv_flags(*p1, SV_GMAGIC|SV_SKIP_OVERLOAD); + if (!SvIOK(sv)) + (void)sv_2iv_flags(sv, SV_GMAGIC|SV_SKIP_OVERLOAD); } else { - if (!SvNSIOK(*p1)) - (void)sv_2nv_flags(*p1, SV_GMAGIC|SV_SKIP_OVERLOAD); - if (all_SIVs && !SvSIOK(*p1)) + if (!SvNSIOK(sv)) + (void)sv_2nv_flags(sv, SV_GMAGIC|SV_SKIP_OVERLOAD); + if (all_SIVs && !SvSIOK(sv)) all_SIVs = 0; } } else { - if (!SvPOK(*p1)) - (void)sv_2pv_flags(*p1, 0, + if (!SvPOK(sv)) + (void)sv_2pv_flags(sv, 0, SV_GMAGIC|SV_CONST_RETURN|SV_SKIP_OVERLOAD); } - if (SvAMAGIC(*p1)) + if (SvAMAGIC(sv)) overloading = 1; } - p1++; + *p1++ = sv; } else max--; } + if (max > 1) { SV **start; if (PL_sortcop) { @@ -869,8 +917,10 @@ PP(pp_sort) SAVEOP(); CATCH_SET(TRUE); - PUSHSTACKi(PERLSI_SORT); + push_stackinfo(PERLSI_SORT, 1); + if (!hasargs && !is_xsub) { + /* standard perl sub with values passed as $a and $b */ SAVEGENERICSV(PL_firstgv); SAVEGENERICSV(PL_secondgv); PL_firstgv = MUTABLE_GV(SvREFCNT_inc( @@ -923,7 +973,10 @@ PP(pp_sort) /* Reset cx, in case the context stack has been reallocated. */ cx = CX_CUR(); - PL_stack_sp = PL_stack_base + cx->blk_oldsp; + /* the code used to think this could be > 0 */ + assert(cx->blk_oldsp == 0); + + rpp_popfree_to_NN(PL_stack_base); CX_LEAVE_SCOPE(cx); if (!(flags & OPf_SPECIAL)) { @@ -936,12 +989,17 @@ PP(pp_sort) cx_popblock(cx); CX_POP(cx); - POPSTACK; + pop_stackinfo(); CATCH_SET(oldcatch); } else { - MEXTEND(SP, 20); /* Can't afford stack realloc on signal. */ - start = ORIGMARK+1; + /* call one of the built-in sort functions */ + + /* XXX this extend has been here since perl5.000. With safe + * signals, I don't think it's needed any more - DAPM. + MEXTEND(SP, 20); Can't afford stack realloc on signal. + */ + start = p1 - max; if (priv & OPpSORT_NUMERIC) { if ((priv & OPpSORT_INTEGER) || all_SIVs) { if (overloading) @@ -1005,13 +1063,29 @@ PP(pp_sort) } } - if (av) { - /* copy back result to the array */ - SV** const base = MARK+1; + if (!av) { + LEAVE; + PL_stack_sp = ORIGMARK + max; + return nextop; + } + + /* OPpSORT_INPLACE: copy back result to the array */ + { + SV** const base = MARK+2; SSize_t max_minus_one = max - 1; /* attempt to work around mingw bug */ + + /* we left the AV there so on a refcounted stack it wouldn't be + * prematurely freed */ + assert(base[-1] == (SV*)av); + if (SvMAGICAL(av)) { - for (i = 0; i <= max_minus_one; i++) - base[i] = newSVsv(base[i]); + for (i = 0; i <= max_minus_one; i++) { + SV *sv = base[i]; + base[i] = newSVsv(sv); +#ifdef PERL_RC_STACK + SvREFCNT_dec_NN(sv); +#endif + } av_clear(av); if (max_minus_one >= 0) av_extend(av, max_minus_one); @@ -1020,24 +1094,45 @@ PP(pp_sort) SV ** const didstore = av_store(av, i, sv); if (SvSMAGICAL(sv)) mg_set(sv); +#ifdef PERL_RC_STACK + if (didstore) + SvREFCNT_inc_simple_void_NN(sv); +#else if (!didstore) sv_2mortal(sv); +#endif } } else { /* the elements of av are likely to be the same as the * (non-refcounted) elements on the stack, just in a different * order. However, its possible that someone's messed with av - * in the meantime. So bump and unbump the relevant refcounts - * first. + * in the meantime. + * So to avoid freeing most/all the stack elements when + * doing av_clear(), first bump the count on each element. + * In addition, normally a *copy* of each sv should be + * assigned to each array element; but if the only reference + * to that sv was from the array, then we can skip the copy. + * + * For a refcounted stack, it's not necessary to bump the + * refcounts initially, as the stack itself keeps the + * elements alive during av_clear(). + * */ for (i = 0; i <= max_minus_one; i++) { SV *sv = base[i]; assert(sv); +#ifdef PERL_RC_STACK + if (SvREFCNT(sv) > 2) { + base[i] = newSVsv(sv); + SvREFCNT_dec_NN(sv); + } +#else if (SvREFCNT(sv) > 1) base[i] = newSVsv(sv); else SvREFCNT_inc_simple_void_NN(sv); +#endif } av_clear(av); if (max_minus_one >= 0) { @@ -1048,12 +1143,26 @@ PP(pp_sort) AvREIFY_off(av); AvREAL_on(av); } + /* sort is only ever optimised with OPpSORT_INPLACE when the + * (@a = sort @a) is in void context. (As an aside: the context + * flag aught to be copied to the sort op: then we could assert + * here that it's void). + * Thus we can simply discard the stack elements now: their + * reference counts have already claimed by av - hence not using + * rpp_popfree_to() here. + */ + PL_stack_sp = ORIGMARK; +#ifdef PERL_RC_STACK + SvREFCNT_dec_NN(av); +#endif + LEAVE; + return nextop; } - LEAVE; - PL_stack_sp = ORIGMARK + max; - return nextop; } + +/* call a traditional perl compare function, setting $a and $b */ + static I32 S_sortcv(pTHX_ SV *const a, SV *const b) { @@ -1065,13 +1174,17 @@ S_sortcv(pTHX_ SV *const a, SV *const b) PERL_ARGS_ASSERT_SORTCV; +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); +#endif + olda = GvSV(PL_firstgv); GvSV(PL_firstgv) = SvREFCNT_inc_simple_NN(a); SvREFCNT_dec(olda); oldb = GvSV(PL_secondgv); GvSV(PL_secondgv) = SvREFCNT_inc_simple_NN(b); SvREFCNT_dec(oldb); - PL_stack_sp = PL_stack_base; + assert(PL_stack_sp == PL_stack_base); PL_op = PL_sortcop; CALLRUNOPS(aTHX); PL_curcop = cop; @@ -1079,12 +1192,16 @@ S_sortcv(pTHX_ SV *const a, SV *const b) * simplifies converting a '()' return into undef in scalar context */ assert(PL_stack_sp > PL_stack_base || *PL_stack_base == &PL_sv_undef); result = SvIV(*PL_stack_sp); + rpp_popfree_to_NN(PL_stack_base); LEAVE_SCOPE(oldsaveix); PL_curpm = pm; return result; } + +/* call a perl compare function that has a ($$) prototype, setting @_ */ + static I32 S_sortcv_stacked(pTHX_ SV *const a, SV *const b) { @@ -1096,11 +1213,21 @@ S_sortcv_stacked(pTHX_ SV *const a, SV * PERL_ARGS_ASSERT_SORTCV_STACKED; +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); +#endif + +#ifdef PERL_RC_STACK + assert(AvREAL(av)); + av_clear(av); +#else if (AvREAL(av)) { av_clear(av); AvREAL_off(av); AvREIFY_on(av); } +#endif + if (AvMAX(av) < 1) { SV **ary = AvALLOC(av); if (AvARRAY(av) != ary) { @@ -1118,7 +1245,11 @@ S_sortcv_stacked(pTHX_ SV *const a, SV * AvARRAY(av)[0] = a; AvARRAY(av)[1] = b; - PL_stack_sp = PL_stack_base; +#ifdef PERL_RC_STACK + SvREFCNT_inc_simple_void_NN(a); + SvREFCNT_inc_simple_void_NN(b); +#endif + assert(PL_stack_sp == PL_stack_base); PL_op = PL_sortcop; CALLRUNOPS(aTHX); PL_curcop = cop; @@ -1126,16 +1257,20 @@ S_sortcv_stacked(pTHX_ SV *const a, SV * * simplifies converting a '()' return into undef in scalar context */ assert(PL_stack_sp > PL_stack_base || *PL_stack_base == &PL_sv_undef); result = SvIV(*PL_stack_sp); + rpp_popfree_to_NN(PL_stack_base); LEAVE_SCOPE(oldsaveix); PL_curpm = pm; return result; } + +/* call an XS compare function. (The two args are always passed on the + * stack, regardless of whether it has a ($$) prototype or not.) */ + static I32 S_sortcv_xsub(pTHX_ SV *const a, SV *const b) { - dSP; const I32 oldsaveix = PL_savestack_ix; CV * const cv=MUTABLE_CV(PL_sortcop); I32 result; @@ -1143,17 +1278,21 @@ S_sortcv_xsub(pTHX_ SV *const a, SV *con PERL_ARGS_ASSERT_SORTCV_XSUB; - SP = PL_stack_base; - PUSHMARK(SP); - EXTEND(SP, 2); - *++SP = a; - *++SP = b; - PUTBACK; - (void)(*CvXSUB(cv))(aTHX_ cv); +#ifdef PERL_RC_STACK + assert(rpp_stack_is_rc()); +#endif + + assert(PL_stack_sp == PL_stack_base); + PUSHMARK(PL_stack_sp); + rpp_xpush_2(a, b); + + rpp_invoke_xs(cv); + /* entry zero of a stack is always PL_sv_undef, which * simplifies converting a '()' return into undef in scalar context */ assert(PL_stack_sp > PL_stack_base || *PL_stack_base == &PL_sv_undef); result = SvIV(*PL_stack_sp); + rpp_popfree_to_NN(PL_stack_base); LEAVE_SCOPE(oldsaveix); PL_curpm = pm; Index: gnu/usr.bin/perl/pp_sys.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/pp_sys.c,v diff -u -p -a -u -p -r1.27 pp_sys.c --- gnu/usr.bin/perl/pp_sys.c 14 May 2024 19:39:39 -0000 1.27 +++ gnu/usr.bin/perl/pp_sys.c 22 Jan 2025 00:37:45 -0000 @@ -71,7 +71,7 @@ compiling multithreaded and singlethreaded ($ccflags et al). HOST_NOT_FOUND is typically defined in . */ -#if defined(HOST_NOT_FOUND) && !defined(h_errno) && !defined(__CYGWIN__) +#if defined(HOST_NOT_FOUND) && !defined(h_errno) && !defined(__CYGWIN__) && !defined(__serenity__) extern int h_errno; #endif @@ -282,9 +282,9 @@ S_emulate_eaccess(pTHX_ const char* path PP(pp_backtick) { - dSP; dTARGET; + dTARGET; PerlIO *fp; - const char * const tmps = POPpconstx; + const char * const tmps = SvPV_nolen(*PL_stack_sp); const U8 gimme = GIMME_V; const char *mode = "r"; @@ -294,6 +294,7 @@ PP(pp_backtick) else if (PL_op->op_private & OPpOPEN_IN_CRLF) mode = "rt"; fp = PerlProc_popen(tmps, mode); + rpp_popfree_1(); if (fp) { const char * const type = Perl_PerlIO_context_layers(aTHX_ NULL); if (type && *type) @@ -312,7 +313,7 @@ PP(pp_backtick) while (sv_gets(TARG, fp, SvCUR(TARG)) != NULL) NOOP; LEAVE_with_name("backtick"); - XPUSHs(TARG); + rpp_push_1(TARG); SvTAINTED_on(TARG); } else { @@ -322,7 +323,8 @@ PP(pp_backtick) SvREFCNT_dec(sv); break; } - mXPUSHs(sv); + rpp_extend(1); + rpp_push_1_norc(sv); if (SvLEN(sv) - SvCUR(sv) > 20) { SvPV_shrink_to_cur(sv); } @@ -335,35 +337,157 @@ PP(pp_backtick) else { STATUS_NATIVE_CHILD_SET(-1); if (gimme == G_SCALAR) - RETPUSHUNDEF; + rpp_push_1(&PL_sv_undef); } - RETURN; + return NORMAL; } + +/* Implement glob('*.h'), and also in the cases where the X is seen by + * the parser as glob-ish rather than file-handle-ish. + * + * The first arg is the wildcard. + * + * The second arg is a gv which is just an empty + * placeholder to temporarily assign to PL_last_in_gv. It's a GV unique to + * this op with only a plain PVIO attached, which is in stash IO::File. + * This is because do_readline() expects PL_last_in_gv to be set by the + * caller. In addition, when built with PERL_EXTERNAL_GLOB (e.g. in + * miniperl), a pipe filehandle is opened to an external glob program, and + * this is stored in the PVIO for subsequent iterations in scalar context. + * + * With OPf_SPECIAL, the second arg isn't present, but a stack MARK is, + * and the glob is done by following on in op_next to a perl-level + * function call. + * + * Normally, the actual glob work is done within a tail-call to + * do_readline(). + * + * The parser decides whether '' in the perl src code causes an + * OP_GLOB or an OPREADLINE op to be planted. + */ + PP(pp_glob) { OP *result; - dSP; - GV * const gv = (PL_op->op_flags & OPf_SPECIAL) ? NULL : (GV *)POPs; + GV *gv; + if (UNLIKELY(PL_op->op_flags & OPf_SPECIAL)) { + /* no GV on stack */ + gv = NULL; + } + else { + gv = (GV*)*PL_stack_sp; + /* Normally things can't just be popped off the stack without risk + * of premature freeing, but in this case the GV is always + * referenced by a preceding OP_GV. */ + assert(!rpp_is_lone((SV*)gv)); + rpp_popfree_1_NN(); + } - PUTBACK; /* make a copy of the pattern if it is gmagical, to ensure that magic * is called once and only once */ - if (SvGMAGICAL(TOPs)) TOPs = sv_2mortal(newSVsv(TOPs)); + SV *arg = *PL_stack_sp; + if (SvGMAGICAL(arg)) + rpp_replace_at_norc(PL_stack_sp, ((arg = newSVsv(arg)) )); + + /* unrolled + tryAMAGICunTARGETlist(iter_amg, (PL_op->op_flags & OPf_SPECIAL)); */ + SV *tmpsv; + U8 gimme = GIMME_V; + if (UNLIKELY(SvAMAGIC(arg) && + (tmpsv = amagic_call(arg, &PL_sv_undef, iter_amg, + AMGf_want_list | AMGf_noright + |AMGf_unary)))) + { + if (gimme == G_VOID) { + NOOP; + } + else if (gimme == G_LIST) { + SSize_t i; + SSize_t len; + assert(SvTYPE(tmpsv) == SVt_PVAV); + len = av_count((AV *)tmpsv); + assert(*PL_stack_sp == arg); + rpp_popfree_1_NN(); /* pop the original wildcard arg */ + rpp_extend(len); + for (i = 0; i < len; ++i) + /* amagic_call() naughtily doesn't increment the ref counts + * of the items it pushes onto the temporary array. So we + * don't need to decrement them when shifting off. */ + rpp_push_1(av_shift((AV *)tmpsv)); + } + else { /* AMGf_want_scalar */ + SV *targ = PAD_SV(PL_op->op_targ); + sv_setsv(targ, tmpsv); + SvSETMAGIC(targ); + /* replace the original wildcard arg with result */ + assert(*PL_stack_sp == arg); + rpp_replace_1_1_NN(targ); + } + + if (PL_op->op_flags & OPf_SPECIAL) { + /* skip the following gv(CORE::GLOBAL::glob), entersub ops */ + OP *jump_o = PL_op->op_next->op_next; + while (jump_o->op_type == OP_NULL) + jump_o = jump_o->op_next; + assert(jump_o->op_type == OP_ENTERSUB); + (void)POPMARK; + return jump_o->op_next; + } + + return NORMAL; + } + /* end of unrolled tryAMAGICunTARGETlist */ - tryAMAGICunTARGETlist(iter_amg, (PL_op->op_flags & OPf_SPECIAL)); if (PL_op->op_flags & OPf_SPECIAL) { - /* call Perl-level glob function instead. Stack args are: - * MARK, wildcard + /* call Perl-level glob function instead. E.g. + * use File::DosGlob 'glob'; @files = glob('*.h'); + * Stack args are: [MARK] wildcard * and following OPs should be: gv(CORE::GLOBAL::glob), entersub * */ return NORMAL; } + if (PL_globhook) { +#ifdef PERL_RC_STACK + /* Likely calling csh_glob_iter() in File::Glob, which doesn't + * understand PERL_RC_STACK yet. If it was an XS function we could + * use rpp_invoke_xs(); but as it's just a "raw" static function, + * wrap it ourselves. There's always one arg, and it will return + * one value in void/scalar context (possibly PL_sv_undef), or 0+ + * values in list cxt. */ + + assert(AvREAL(PL_curstack)); + assert(!PL_curstackinfo->si_stack_nonrc_base); + + rpp_extend(1); + PL_stack_sp[1] = PL_stack_sp[0]; + PL_stack_sp++; + PL_curstackinfo->si_stack_nonrc_base = PL_stack_sp - PL_stack_base; + PL_globhook(aTHX); + + I32 nret = (I32)(PL_stack_sp - PL_stack_base) + - PL_curstackinfo->si_stack_nonrc_base + 1; + assert(nret >= 0); + + /* bump any returned values */ + for (I32 i = 0; i< nret; i++) + SvREFCNT_inc(PL_stack_sp[-i]); + PL_curstackinfo->si_stack_nonrc_base = 0; + + /* free the original arg and shift the returned values down */ + SV *arg = PL_stack_sp[-nret]; + if (nret) + Move(PL_stack_sp - nret + 1, PL_stack_sp - nret, nret, SV*); + PL_stack_sp--; + SvREFCNT_dec_NN(arg); +#else + PL_globhook(aTHX); +#endif return NORMAL; } @@ -400,13 +524,19 @@ PP(pp_glob) return result; } + +/* $x .= + * Where $x is on the stack and FOO is the GV attached to the op. + */ + PP(pp_rcatline) { PL_last_in_gv = cGVOP_gv; return do_readline(); } -PP(pp_warn) + +PP_wrapped(pp_warn, 0, 1) { dSP; dMARK; SV *exsv; @@ -455,7 +585,7 @@ PP(pp_warn) RETSETYES; } -PP(pp_die) +PP_wrapped(pp_die, 0, 1) { dSP; dMARK; SV *exsv; @@ -513,15 +643,42 @@ PP(pp_die) return NULL; /* avoid missing return from non-void function warning */ } -/* I/O. */ + +/* tied_method(): call a tied method (typically for a filehandle). + * A variable number of args may be supplied to the method, obtained + * either via the stack or as varargs to this function. + * + * With TIED_METHOD_ARGUMENTS_ON_STACK, tied_method() expects the stack to + * look like this on entry: + * - X A0 A1 A2 ... + * | + * mark + * + * where X is an SV to be thrown away (it's typically the original + * filehandle), then the method is called (on a new stack) with args: + * (tied_obj(sv), A0, A1, ...) + * where there are (argc) arguments, not including the object. + * + * Without TIED_METHOD_ARGUMENTS_ON_STACK, the (argc) number of args are + * taken as extra arguments to the function following argc. + * + * The current value of PL_stack_sp is ignored (it's not assumed that + * the caller did a PUTBACK or whatever). + * + * On return, any original values on the stack above mark are discarded, + * and any return values from the method call are pushed above mark. + * + */ OP * -Perl_tied_method(pTHX_ SV *methname, SV **sp, SV *const sv, +Perl_tied_method(pTHX_ SV *methname, SV **mark, SV *const sv, const MAGIC *const mg, const U32 flags, U32 argc, ...) { - SV **orig_sp = sp; I32 ret_args; SSize_t extend_size; +#ifdef PERL_RC_STACK + bool was_rc = rpp_stack_is_rc(); +#endif PERL_ARGS_ASSERT_TIED_METHOD; @@ -530,8 +687,31 @@ Perl_tied_method(pTHX_ SV *methname, SV STATIC_ASSERT_STMT((TIED_METHOD_ARGUMENTS_ON_STACK & G_WANT) == 0); STATIC_ASSERT_STMT((TIED_METHOD_SAY & G_WANT) == 0); - PUTBACK; /* sp is at *foot* of args, so this pops args from old stack */ - PUSHSTACKi(PERLSI_MAGIC); + if (flags & TIED_METHOD_ARGUMENTS_ON_STACK) { + /* Notionally pop all the args from the old stack. In fact they're + * still there, and very shortly they'll be copied across to the + * new stack, with (for PERL_RC_STACK) the ownership of one ref + * count being taken over as appropriate. Leave the unused SV (the + * 'X' in the comments above) at the base of the stack frame so it + * will be freed on croak. Otherwise it will be freed at the end. + */ + PL_stack_sp = mark + 1; + } + else if (rpp_stack_is_rc()) + rpp_popfree_to_NN(mark); + else + PL_stack_sp = mark; + + /* Push a new stack for the method call. Make it ref-counted, and if + * our caller wasn't, then we'll need to adjust when copying the args + * and results between the two stacks. + */ +#ifdef PERL_RC_STACK + push_stackinfo(PERLSI_MAGIC, 1); +#else + push_stackinfo(PERLSI_MAGIC, 0); +#endif + /* extend for object + args. If argc might wrap/truncate when cast * to SSize_t and incremented, set to -1, which will trigger a panic in * EXTEND(). @@ -545,12 +725,24 @@ Perl_tied_method(pTHX_ SV *methname, SV extend_size = (argc > (sizeof(argc) >= sizeof(SSize_t) ? SSize_t_MAX - 1 : argc)) ? -1 : (SSize_t)argc + 1; - EXTEND(SP, extend_size); - PUSHMARK(sp); - PUSHs(SvTIED_obj(sv, mg)); + rpp_extend(extend_size); + + PUSHMARK(PL_stack_sp); + rpp_push_1(SvTIED_obj(sv, mg)); if (flags & TIED_METHOD_ARGUMENTS_ON_STACK) { - Copy(orig_sp + 2, sp + 1, argc, SV*); /* copy args to new stack */ - sp += argc; + /* copy args to new stack */ + Copy(mark + 2, PL_stack_sp + 1, argc, SV*); +#ifdef PERL_RC_STACK + if (was_rc) + PL_stack_sp += argc; + else { + U32 i = argc; + while (i--) + SvREFCNT_inc(*++PL_stack_sp); + } +#else + PL_stack_sp += argc; +#endif } else if (argc) { const U32 mortalize_not_needed @@ -560,14 +752,13 @@ Perl_tied_method(pTHX_ SV *methname, SV do { SV *const arg = va_arg(args, SV *); if(mortalize_not_needed) - PUSHs(arg); + rpp_push_1(arg); else - mPUSHs(arg); + rpp_push_1_norc(arg); } while (--argc); va_end(args); } - PUTBACK; ENTER_with_name("call_tied_method"); if (flags & TIED_METHOD_SAY) { /* local $\ = "\n" */ @@ -575,20 +766,43 @@ Perl_tied_method(pTHX_ SV *methname, SV PL_ors_sv = newSVpvs("\n"); } ret_args = call_sv(methname, (flags & G_WANT)|G_METHOD_NAMED); - SPAGAIN; - orig_sp = sp; - POPSTACK; - SPAGAIN; + SV **orig_sp = PL_stack_sp; + /* Ensure that the old stack is marked as empty before we abandon it. + * Otherwise, if it's AvREAL(), items could be double-freed some time + * after we copy the return SVs to the caller's stack. */ + PL_stack_sp = PL_stack_base; + pop_stackinfo(); + /* pop and free the spare SV (the 'X' in the comments above */ + if (flags & TIED_METHOD_ARGUMENTS_ON_STACK) { +#ifdef PERL_RC_STACK + if (was_rc) + rpp_popfree_1(); + else +#endif + PL_stack_sp--; + } + if (ret_args) { /* copy results back to original stack */ - EXTEND(sp, ret_args); - Copy(orig_sp - ret_args + 1, sp + 1, ret_args, SV*); - sp += ret_args; - PUTBACK; + rpp_extend(ret_args); + Copy(orig_sp - ret_args + 1, PL_stack_sp + 1, ret_args, SV*); +#ifdef PERL_RC_STACK + if (was_rc) + PL_stack_sp += ret_args; + else + { + I32 i = ret_args; + while (i--) + sv_2mortal(*++PL_stack_sp); + } +#else + PL_stack_sp += ret_args; +#endif } LEAVE_with_name("call_tied_method"); return NORMAL; } + #define tied_method0(a,b,c,d) \ Perl_tied_method(aTHX_ a,b,c,d,G_SCALAR,0) #define tied_method1(a,b,c,d,e) \ @@ -596,7 +810,7 @@ Perl_tied_method(pTHX_ SV *methname, SV #define tied_method2(a,b,c,d,e,f) \ Perl_tied_method(aTHX_ a,b,c,d,G_SCALAR,2,e,f) -PP(pp_open) +PP_wrapped(pp_open, 0, 1) { dSP; dMARK; dORIGMARK; @@ -649,7 +863,7 @@ PP(pp_open) RETURN; } -PP(pp_close) +PP_wrapped(pp_close, MAXARG, 0) { dSP; /* pp_coreargs pushes a NULL to indicate no args passed to @@ -673,7 +887,7 @@ PP(pp_close) RETURN; } -PP(pp_pipe_op) +PP_wrapped(pp_pipe_op, 2, 0) { #ifdef HAS_PIPE dSP; @@ -722,7 +936,7 @@ PP(pp_pipe_op) #endif } -PP(pp_fileno) +PP_wrapped(pp_fileno, MAXARG, 0) { dSP; dTARGET; GV *gv; @@ -770,7 +984,7 @@ PP(pp_fileno) RETURN; } -PP(pp_umask) +PP_wrapped(pp_umask, MAXARG, 0) { dSP; #ifdef HAS_UMASK @@ -800,7 +1014,7 @@ PP(pp_umask) RETURN; } -PP(pp_binmode) +PP_wrapped(pp_binmode, MAXARG, 0) { dSP; GV *gv; @@ -861,16 +1075,16 @@ PP(pp_binmode) } } -PP(pp_tie) +PP_wrapped(pp_tie, 0, 1) { dSP; dMARK; HV* stash; GV *gv = NULL; SV *sv; - const I32 markoff = MARK - PL_stack_base; + const SSize_t markoff = MARK - PL_stack_base; const char *methname; int how = PERL_MAGIC_tied; - U32 items; + SSize_t items; SV *varsv = *++MARK; switch(SvTYPE(varsv)) { @@ -923,7 +1137,7 @@ PP(pp_tie) ENTER_with_name("call_TIE"); PUSHSTACKi(PERLSI_MAGIC); PUSHMARK(SP); - EXTEND(SP,(I32)items); + EXTEND(SP, items); while (items--) PUSHs(*MARK++); PUTBACK; @@ -973,7 +1187,7 @@ PP(pp_tie) ENTER_with_name("call_TIE"); PUSHSTACKi(PERLSI_MAGIC); PUSHMARK(SP); - EXTEND(SP,(I32)items); + EXTEND(SP, items); while (items--) PUSHs(*MARK++); PUTBACK; @@ -1002,7 +1216,7 @@ PP(pp_tie) /* also used for: pp_dbmclose() */ -PP(pp_untie) +PP_wrapped(pp_untie, 1, 0) { dSP; MAGIC *mg; @@ -1054,7 +1268,7 @@ PP(pp_untie) RETPUSHYES; } -PP(pp_tied) +PP_wrapped(pp_tied, 1, 0) { dSP; const MAGIC *mg; @@ -1077,7 +1291,7 @@ PP(pp_tied) return NORMAL; } -PP(pp_dbmopen) +PP_wrapped(pp_dbmopen, 3, 0) { dSP; dPOPPOPssrl; @@ -1135,7 +1349,7 @@ PP(pp_dbmopen) RETURN; } -PP(pp_sselect) +PP_wrapped(pp_sselect, 4, 0) { #ifdef HAS_SELECT dSP; dTARGET; @@ -1230,7 +1444,7 @@ PP(pp_sselect) value = SvNV_nomg(sv); if (value < 0.0) value = 0.0; - timebuf.tv_sec = (long)value; + timebuf.tv_sec = (time_t)value; value -= (NV)timebuf.tv_sec; timebuf.tv_usec = (long)(value * 1000000.0); } @@ -1343,7 +1557,7 @@ Perl_setdefout(pTHX_ GV *gv) SvREFCNT_dec(oldgv); } -PP(pp_select) +PP_wrapped(pp_select, MAXARG, 0) { dSP; dTARGET; HV *hv; @@ -1374,7 +1588,7 @@ PP(pp_select) RETURN; } -PP(pp_getc) +PP_wrapped(pp_getc, MAXARG, 0) { dSP; dTARGET; /* pp_coreargs pushes a NULL to indicate no args passed to @@ -1443,26 +1657,35 @@ S_doform(pTHX_ CV *cv, GV *gv, OP *retop return CvSTART(cv); } + PP(pp_enterwrite) { - dSP; GV *gv; IO *io; GV *fgv; CV *cv = NULL; if (MAXARG == 0) { - EXTEND(SP, 1); + rpp_extend(1); gv = PL_defoutgv; } else { - gv = MUTABLE_GV(POPs); + gv = MUTABLE_GV(*PL_stack_sp); + /* NB: in principle, decrementing gv's ref count could free it, + * and we aught to make the gv field of the struct block_format + * reference counted to compensate; in practice, since formats + * invariably use named GVs in the source which link to the GV, + * it's almost impossible to free a GV during format processing. + */ + rpp_popfree_1(); if (!gv) gv = PL_defoutgv; } io = GvIO(gv); if (!io) { - RETPUSHNO; + rpp_push_IMM(&PL_sv_no); + return NORMAL; + } if (IoFMT_GV(io)) fgv = IoFMT_GV(io); @@ -1478,12 +1701,12 @@ PP(pp_enterwrite) DIE(aTHX_ "Undefined format \"%" SVf "\" called", SVfARG(tmpsv)); } IoFLAGS(io) &= ~IOf_DIDTOP; - RETURNOP(doform(cv,gv,PL_op->op_next)); + return doform(cv,gv,PL_op->op_next); } + PP(pp_leavewrite) { - dSP; GV * const gv = CX_CUR()->blk_format.gv; IO * const io = GvIOp(gv); PerlIO *ofp; @@ -1567,72 +1790,78 @@ PP(pp_leavewrite) forget_top: cx = CX_CUR(); assert(CxTYPE(cx) == CXt_FORMAT); - SP = PL_stack_base + cx->blk_oldsp; /* ignore retval of formline */ + rpp_popfree_to_NN(PL_stack_base + cx->blk_oldsp); /* ignore retval of formline */ CX_LEAVE_SCOPE(cx); cx_popformat(cx); cx_popblock(cx); retop = cx->blk_sub.retop; CX_POP(cx); - EXTEND(SP, 1); + rpp_extend(1); if (is_return) /* XXX the semantics of doing 'return' in a format aren't documented. * Currently we ignore any args to 'return' and just return * a single undef in both scalar and list contexts */ - PUSHs(&PL_sv_undef); + rpp_push_IMM(&PL_sv_undef); else if (!io || !(fp = IoOFP(io))) { if (io && IoIFP(io)) report_wrongway_fh(gv, '<'); else report_evil_fh(gv); - PUSHs(&PL_sv_no); + rpp_push_IMM(&PL_sv_no); } else { if ((IoLINES_LEFT(io) -= FmLINES(PL_formtarget)) < 0) { Perl_ck_warner(aTHX_ packWARN(WARN_IO), "page overflow"); } if (!do_print(PL_formtarget, fp)) - PUSHs(&PL_sv_no); + rpp_push_IMM(&PL_sv_no); else { FmLINES(PL_formtarget) = 0; SvCUR_set(PL_formtarget, 0); *SvEND(PL_formtarget) = '\0'; if (IoFLAGS(io) & IOf_FLUSH) (void)PerlIO_flush(fp); - PUSHs(&PL_sv_yes); + rpp_push_IMM(&PL_sv_yes); } } PL_formtarget = PL_bodytarget; - RETURNOP(retop); + return retop; } + PP(pp_prtf) { - dSP; dMARK; dORIGMARK; + dMARK; dORIGMARK; PerlIO *fp; + /* OPf_STACKED if first argument is a file handle */ GV * const gv = (PL_op->op_flags & OPf_STACKED) ? MUTABLE_GV(*++MARK) : PL_defoutgv; IO *const io = GvIO(gv); /* Treat empty list as "" */ - if (MARK == SP) XPUSHs(&PL_sv_no); + if (MARK == PL_stack_sp) + rpp_xpush_IMM(&PL_sv_no); + SV * retval = &PL_sv_undef; if (io) { const MAGIC * const mg = SvTIED_mg((const SV *)io, PERL_MAGIC_tiedscalar); if (mg) { if (MARK == ORIGMARK) { - MEXTEND(SP, 1); - ++MARK; - Move(MARK, MARK + 1, (SP - MARK) + 1, SV*); - ++SP; + /* insert NULL hole at base of argument list if no FH */ + rpp_extend(1); + MARK = ORIGMARK + 1; + Move(MARK, MARK + 1, (PL_stack_sp - MARK) + 1, SV*); + *MARK = NULL; + ++PL_stack_sp; } return Perl_tied_method(aTHX_ SV_CONST(PRINTF), mark - 1, MUTABLE_SV(io), mg, G_SCALAR | TIED_METHOD_ARGUMENTS_ON_STACK, - sp - mark); + PL_stack_sp - mark); } } @@ -1651,7 +1880,7 @@ PP(pp_prtf) } else { SV *sv = sv_newmortal(); - do_sprintf(sv, SP - MARK, MARK + 1); + do_sprintf(sv, PL_stack_sp - MARK, MARK + 1); if (!do_print(sv, fp)) goto just_say_no; @@ -1659,17 +1888,16 @@ PP(pp_prtf) if (PerlIO_flush(fp) == EOF) goto just_say_no; } - SP = ORIGMARK; - PUSHs(&PL_sv_yes); - RETURN; + retval = &PL_sv_yes;; just_say_no: - SP = ORIGMARK; - PUSHs(&PL_sv_undef); - RETURN; + rpp_popfree_to_NN(ORIGMARK); + rpp_push_IMM(retval); + return NORMAL; } -PP(pp_sysopen) + +PP_wrapped(pp_sysopen, MAXARG, 0) { dSP; const int perm = (MAXARG > 3 && (TOPs || POPs)) ? POPi : 0666; @@ -1693,7 +1921,7 @@ PP(pp_sysopen) /* also used for: pp_read() and pp_recv() (where supported) */ -PP(pp_sysread) +PP_wrapped(pp_sysread, 0, 1) { dSP; dMARK; dORIGMARK; dTARGET; SSize_t offset; @@ -1956,7 +2184,7 @@ PP(pp_sysread) /* also used for: pp_send() where defined */ -PP(pp_syswrite) +PP_wrapped(pp_syswrite, 0, 1) { dSP; dMARK; dORIGMARK; dTARGET; SV *bufsv; @@ -2110,7 +2338,7 @@ PP(pp_syswrite) RETPUSHUNDEF; } -PP(pp_eof) +PP_wrapped(pp_eof, MAXARG, 0) { dSP; GV *gv; @@ -2177,7 +2405,7 @@ PP(pp_eof) RETURN; } -PP(pp_tell) +PP_wrapped(pp_tell, MAXARG, 0) { dSP; dTARGET; GV *gv; @@ -2214,7 +2442,7 @@ PP(pp_tell) /* also used for: pp_seek() */ -PP(pp_sysseek) +PP_wrapped(pp_sysseek, 3, 0) { dSP; const int whence = POPi; @@ -2261,7 +2489,7 @@ PP(pp_sysseek) RETURN; } -PP(pp_truncate) +PP_wrapped(pp_truncate, 2, 0) { dSP; /* There seems to be no consensus on the length type of truncate() @@ -2371,7 +2599,7 @@ PP(pp_truncate) /* also used for: pp_fcntl() */ -PP(pp_ioctl) +PP_wrapped(pp_ioctl, 3, 0) { dSP; dTARGET; SV * const argsv = POPs; @@ -2444,7 +2672,7 @@ PP(pp_ioctl) RETURN; } -PP(pp_flock) +PP_wrapped(pp_flock, 2, 0) { #ifdef FLOCK dSP; dTARGET; @@ -2475,7 +2703,7 @@ PP(pp_flock) #ifdef HAS_SOCKET -PP(pp_socket) +PP_wrapped(pp_socket, 4, 0) { dSP; const int protocol = POPi; @@ -2507,7 +2735,7 @@ PP(pp_socket) } #endif -PP(pp_sockpair) +PP_wrapped(pp_sockpair, 5, 0) { #if defined (HAS_SOCKETPAIR) || (defined (HAS_SOCKET) && defined(SOCK_DGRAM) && defined(AF_INET) && defined(PF_INET)) dSP; @@ -2555,7 +2783,7 @@ PP(pp_sockpair) /* also used for: pp_connect() */ -PP(pp_bind) +PP_wrapped(pp_bind, 2, 0) { dSP; SV * const addrsv = POPs; @@ -2590,7 +2818,7 @@ PP(pp_bind) RETPUSHUNDEF; } -PP(pp_listen) +PP_wrapped(pp_listen, 2, 0) { dSP; const int backlog = POPi; @@ -2611,7 +2839,7 @@ PP(pp_listen) RETPUSHUNDEF; } -PP(pp_accept) +PP_wrapped(pp_accept, 2, 0) { dSP; dTARGET; IO *nstio; @@ -2672,7 +2900,7 @@ PP(pp_accept) } -PP(pp_shutdown) +PP_wrapped(pp_shutdown, 2, 0) { dSP; dTARGET; const int how = POPi; @@ -2697,7 +2925,7 @@ PP(pp_shutdown) /* also used for: pp_gsockopt() */ -PP(pp_ssockopt) +PP_wrapped(pp_ssockopt,(PL_op->op_type == OP_GSOCKOPT) ? 3 : 4 , 0) { dSP; const int optype = PL_op->op_type; @@ -2767,7 +2995,7 @@ PP(pp_ssockopt) /* also used for: pp_getsockname() */ -PP(pp_getpeername) +PP_wrapped(pp_getpeername, 1, 0) { dSP; const int optype = PL_op->op_type; @@ -2837,7 +3065,7 @@ PP(pp_getpeername) /* also used for: pp_lstat() */ -PP(pp_stat) +PP_wrapped(pp_stat, !(PL_op->op_flags & OPf_REF), 0) { dSP; GV *gv = NULL; @@ -3080,9 +3308,7 @@ PP(pp_stat) /* All filetest ops avoid manipulating the perl stack pointer in their main bodies (since commit d2c4d2d1e22d3125), and return using either S_ft_return_false() or S_ft_return_true(). These two helper functions are - the only two which manipulate the perl stack. To ensure that no stack - manipulation macros are used, the filetest ops avoid defining a local copy - of the stack pointer with dSP. */ + the only two which manipulate the perl stack. */ /* If the next filetest is stacked up with this one (PL_op->op_private & OPpFT_STACKING), we leave @@ -3094,11 +3320,12 @@ PP(pp_stat) static OP * S_ft_return_false(pTHX_ SV *ret) { OP *next = NORMAL; - dSP; - if (PL_op->op_flags & OPf_REF) XPUSHs(ret); - else SETs(ret); - PUTBACK; + if (PL_op->op_flags & OPf_REF) { + rpp_xpush_1(ret); + } + else + rpp_replace_1_1(ret); if (PL_op->op_private & OPpFT_STACKING) { while (next && OP_IS_FILETEST(next->op_type) @@ -3110,12 +3337,12 @@ S_ft_return_false(pTHX_ SV *ret) { PERL_STATIC_INLINE OP * S_ft_return_true(pTHX_ SV *ret) { - dSP; - if (PL_op->op_flags & OPf_REF) - XPUSHs(PL_op->op_private & OPpFT_STACKING ? (SV *)cGVOP_gv : (ret)); + if (PL_op->op_flags & OPf_REF) { + rpp_xpush_1((PL_op->op_private & OPpFT_STACKING) + ? (SV*)cGVOP_gv : ret); + } else if (!(PL_op->op_private & OPpFT_STACKING)) - SETs(ret); - PUTBACK; + rpp_replace_1_1(ret); return NORMAL; } @@ -3675,7 +3902,7 @@ PP(pp_fttext) /* File calls. */ -PP(pp_chdir) +PP_wrapped(pp_chdir, MAXARG, 0) { dSP; dTARGET; const char *tmps = NULL; @@ -3767,17 +3994,17 @@ PP(pp_chdir) /* also used for: pp_chmod() pp_kill() pp_unlink() pp_utime() */ -PP(pp_chown) +PP_wrapped(pp_chown, 0, 1) { dSP; dMARK; dTARGET; - const I32 value = (I32)apply(PL_op->op_type, MARK, SP); + const IV value = apply(PL_op->op_type, MARK, SP); SP = MARK; XPUSHi(value); RETURN; } -PP(pp_chroot) +PP_wrapped(pp_chroot, 1, 0) { #ifdef HAS_CHROOT dSP; dTARGET; @@ -3790,7 +4017,7 @@ PP(pp_chroot) #endif } -PP(pp_rename) +PP_wrapped(pp_rename, 2, 0) { dSP; dTARGET; int anum; @@ -3822,7 +4049,7 @@ PP(pp_rename) /* also used for: pp_symlink() */ #if defined(HAS_LINK) || defined(HAS_SYMLINK) -PP(pp_link) +PP_wrapped(pp_link, 2, 0) { dSP; dTARGET; const int op_type = PL_op->op_type; @@ -3869,7 +4096,7 @@ PP(pp_link) } #endif -PP(pp_readlink) +PP_wrapped(pp_readlink, 1, 0) { dSP; #ifdef HAS_SYMLINK @@ -4000,7 +4227,7 @@ S_dooneliner(pTHX_ const char *cmd, cons (copy) = TRUE; \ } -PP(pp_mkdir) +PP_wrapped(pp_mkdir, MAXARG, 0) { dSP; dTARGET; STRLEN len; @@ -4027,7 +4254,7 @@ PP(pp_mkdir) RETURN; } -PP(pp_rmdir) +PP_wrapped(pp_rmdir, 1, 0) { dSP; dTARGET; STRLEN len; @@ -4048,7 +4275,7 @@ PP(pp_rmdir) /* Directory calls. */ -PP(pp_open_dir) +PP_wrapped(pp_open_dir, 2, 0) { #if defined(Direntry_t) && defined(HAS_READDIR) dSP; @@ -4074,7 +4301,7 @@ PP(pp_open_dir) #endif } -PP(pp_readdir) +PP_wrapped(pp_readdir, 1, 0) { #if !defined(Direntry_t) || !defined(HAS_READDIR) DIE(aTHX_ PL_no_dir_func, "readdir"); @@ -4126,7 +4353,7 @@ PP(pp_readdir) #endif } -PP(pp_telldir) +PP_wrapped(pp_telldir, 1, 0) { #if defined(HAS_TELLDIR) || defined(telldir) dSP; dTARGET; @@ -4158,7 +4385,7 @@ PP(pp_telldir) #endif } -PP(pp_seekdir) +PP_wrapped(pp_seekdir, 2, 0) { #if defined(HAS_SEEKDIR) || defined(seekdir) dSP; @@ -4184,7 +4411,7 @@ PP(pp_seekdir) #endif } -PP(pp_rewinddir) +PP_wrapped(pp_rewinddir, 1, 0) { #if defined(HAS_REWINDDIR) || defined(rewinddir) dSP; @@ -4208,7 +4435,7 @@ PP(pp_rewinddir) #endif } -PP(pp_closedir) +PP_wrapped(pp_closedir, 1, 0) { #if defined(Direntry_t) && defined(HAS_READDIR) dSP; @@ -4243,7 +4470,7 @@ PP(pp_closedir) /* Process control. */ -PP(pp_fork) +PP_wrapped(pp_fork, 0, 0) { #ifdef HAS_FORK dSP; dTARGET; @@ -4315,7 +4542,7 @@ PP(pp_fork) #endif } -PP(pp_wait) +PP_wrapped(pp_wait, 0, 0) { #if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(__LIBCATAMOUNT__) dSP; dTARGET; @@ -4343,7 +4570,7 @@ PP(pp_wait) #endif } -PP(pp_waitpid) +PP_wrapped(pp_waitpid, 2, 0) { #if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(__LIBCATAMOUNT__) dSP; dTARGET; @@ -4380,7 +4607,7 @@ PP(pp_waitpid) #endif } -PP(pp_system) +PP_wrapped(pp_system, 0, 1) { dSP; dMARK; dORIGMARK; dTARGET; #if defined(__LIBCATAMOUNT__) @@ -4437,7 +4664,7 @@ PP(pp_system) TAINT_PROPER("system"); } PERL_FLUSHALL_FOR_CHILD; -#if (defined(HAS_FORK) || defined(__amigaos4__)) && !defined(VMS) && !defined(OS2) || defined(PERL_MICRO) +#if (defined(HAS_FORK) || defined(__amigaos4__)) && !defined(VMS) && !defined(OS2) { #ifdef __amigaos4__ struct UserData userdata; @@ -4495,10 +4722,8 @@ PP(pp_system) if (did_pipes) PerlLIO_close(pp[1]); #endif -#ifndef PERL_MICRO rsignal_save(SIGINT, (Sighandler_t) SIG_IGN, &ihand); rsignal_save(SIGQUIT, (Sighandler_t) SIG_IGN, &qhand); -#endif #ifdef __amigaos4__ result = pthread_join(proc, (void **)&status); #else @@ -4506,13 +4731,11 @@ PP(pp_system) result = wait4pid(childpid, &status, 0); } while (result == -1 && errno == EINTR); #endif -#ifndef PERL_MICRO #ifdef HAS_SIGPROCMASK sigprocmask(SIG_SETMASK, &oldset, NULL); #endif (void)rsignal_restore(SIGINT, &ihand); (void)rsignal_restore(SIGQUIT, &qhand); -#endif STATUS_NATIVE_CHILD_SET(result == -1 ? -1 : status); SP = ORIGMARK; if (did_pipes) { @@ -4594,7 +4817,7 @@ PP(pp_system) RETURN; } -PP(pp_exec) +PP_wrapped(pp_exec, 0, 1) { dSP; dMARK; dORIGMARK; dTARGET; I32 value; @@ -4636,15 +4859,16 @@ PP(pp_exec) PP(pp_getppid) { #ifdef HAS_GETPPID - dSP; dTARGET; - XPUSHi( getppid() ); - RETURN; + dTARGET; + TARGi(getppid(), 1); + rpp_xpush_1(targ); + return NORMAL; #else DIE(aTHX_ PL_no_func, "getppid"); #endif } -PP(pp_getpgrp) +PP_wrapped(pp_getpgrp, MAXARG, 0) { #ifdef HAS_GETPGRP dSP; dTARGET; @@ -4666,7 +4890,7 @@ PP(pp_getpgrp) #endif } -PP(pp_setpgrp) +PP_wrapped(pp_setpgrp, MAXARG, 0) { #ifdef HAS_SETPGRP dSP; dTARGET; @@ -4708,7 +4932,7 @@ PP(pp_setpgrp) # define PRIORITY_WHICH_T(which) which #endif -PP(pp_getpriority) +PP_wrapped(pp_getpriority, 2, 0) { #ifdef HAS_GETPRIORITY dSP; dTARGET; @@ -4721,7 +4945,7 @@ PP(pp_getpriority) #endif } -PP(pp_setpriority) +PP_wrapped(pp_setpriority, 3, 0) { #ifdef HAS_SETPRIORITY dSP; dTARGET; @@ -4742,16 +4966,17 @@ PP(pp_setpriority) PP(pp_time) { - dSP; dTARGET; + dTARGET; #ifdef BIG_TIME - XPUSHn( (NV)time(NULL) ); + TARGn((NV)time(NULL),1); #else - XPUSHu( (UV)time(NULL) ); + TARGu((UV)time(NULL),1); #endif - RETURN; + rpp_xpush_1(TARG); + return NORMAL; } -PP(pp_tms) +PP_wrapped(pp_tms, 0, 0) { #ifdef HAS_TIMES dSP; @@ -4767,16 +4992,6 @@ PP(pp_tms) mPUSHn(((NV)timesbuf.tms_cstime)/(NV)PL_clocktick); } RETURN; -#elif defined(PERL_MICRO) - dSP; - mPUSHn(0.0); - EXTEND(SP, 4); - if (GIMME_V == G_LIST) { - mPUSHn(0.0); - mPUSHn(0.0); - mPUSHn(0.0); - } - RETURN; #else DIE(aTHX_ "times not implemented"); #endif /* HAS_TIMES */ @@ -4794,7 +5009,7 @@ PP(pp_tms) /* also used for: pp_localtime() */ -PP(pp_gmtime) +PP_wrapped(pp_gmtime, MAXARG, 0) { dSP; Time64_T when; @@ -4890,7 +5105,7 @@ PP(pp_gmtime) RETURN; } -PP(pp_alarm) +PP_wrapped(pp_alarm, 1, 0) { #ifdef HAS_ALARM dSP; dTARGET; @@ -4923,7 +5138,7 @@ PP(pp_alarm) #endif } -PP(pp_sleep) +PP_wrapped(pp_sleep, MAXARG, 0) { dSP; dTARGET; Time_t lasttime; @@ -4955,7 +5170,7 @@ PP(pp_sleep) /* also used for: pp_msgrcv() pp_msgsnd() pp_semop() pp_shmread() */ -PP(pp_shmwrite) +PP_wrapped(pp_shmwrite, 0, 1) { #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) dSP; dMARK; dTARGET; @@ -4989,7 +5204,7 @@ PP(pp_shmwrite) /* also used for: pp_msgget() pp_shmget() */ -PP(pp_semget) +PP_wrapped(pp_semget, 0, 1) { #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) dSP; dMARK; dTARGET; @@ -5006,7 +5221,7 @@ PP(pp_semget) /* also used for: pp_msgctl() pp_shmctl() */ -PP(pp_semctl) +PP_wrapped(pp_semctl, 0, 1) { #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) dSP; dMARK; dTARGET; @@ -5051,7 +5266,10 @@ S_space_join_names_mortal(pTHX_ char *co /* also used for: pp_ghbyaddr() pp_ghbyname() */ -PP(pp_ghostent) +PP_wrapped(pp_ghostent, + ((PL_op->op_type == OP_GHBYNAME) ? 1 : + (PL_op->op_type == OP_GHBYADDR) ? 2 : 0), + 0) { #if defined(HAS_GETHOSTBYNAME) || defined(HAS_GETHOSTBYADDR) || defined(HAS_GETHOSTENT) dSP; @@ -5145,7 +5363,10 @@ PP(pp_ghostent) /* also used for: pp_gnbyaddr() pp_gnbyname() */ -PP(pp_gnetent) +PP_wrapped(pp_gnetent, + ((PL_op->op_type == OP_GNBYNAME) ? 1 : + (PL_op->op_type == OP_GNBYADDR) ? 2 : 0), + 0) { #if defined(HAS_GETNETBYNAME) || defined(HAS_GETNETBYADDR) || defined(HAS_GETNETENT) dSP; @@ -5221,7 +5442,10 @@ PP(pp_gnetent) /* also used for: pp_gpbyname() pp_gpbynumber() */ -PP(pp_gprotoent) +PP_wrapped(pp_gprotoent, + ((PL_op->op_type == OP_GPBYNAME) ? 1 : + (PL_op->op_type == OP_GPBYNUMBER) ? 1 : 0), + 0) { #if defined(HAS_GETPROTOBYNAME) || defined(HAS_GETPROTOBYNUMBER) || defined(HAS_GETPROTOENT) dSP; @@ -5284,7 +5508,10 @@ PP(pp_gprotoent) /* also used for: pp_gsbyname() pp_gsbyport() */ -PP(pp_gservent) +PP_wrapped(pp_gservent, + ((PL_op->op_type == OP_GSBYNAME) ? 2 : + (PL_op->op_type == OP_GSBYPORT) ? 2 : 0), + 0) { #if defined(HAS_GETSERVBYNAME) || defined(HAS_GETSERVBYPORT) || defined(HAS_GETSERVENT) dSP; @@ -5352,7 +5579,7 @@ PP(pp_gservent) /* also used for: pp_snetent() pp_sprotoent() pp_sservent() */ -PP(pp_shostent) +PP_wrapped(pp_shostent, 1, 0) { dSP; const int stayopen = TOPi; @@ -5395,7 +5622,6 @@ PP(pp_shostent) PP(pp_ehostent) { - dSP; switch(PL_op->op_type) { case OP_EHOSTENT: #ifdef HAS_ENDHOSTENT @@ -5454,14 +5680,17 @@ PP(pp_ehostent) #endif break; } - EXTEND(SP,1); - RETPUSHYES; + rpp_xpush_IMM(&PL_sv_yes); + return NORMAL; } /* also used for: pp_gpwnam() pp_gpwuid() */ -PP(pp_gpwent) +PP_wrapped(pp_gpwent, + ((PL_op->op_type == OP_GPWNAM) ? 1 : + (PL_op->op_type == OP_GPWUID) ? 1 : 0), + 0) { #ifdef HAS_PASSWD dSP; @@ -5688,7 +5917,10 @@ PP(pp_gpwent) /* also used for: pp_ggrgid() pp_ggrnam() */ -PP(pp_ggrent) +PP_wrapped(pp_ggrent, + ((PL_op->op_type == OP_GGRNAM) ? 1 : + (PL_op->op_type == OP_GGRGID) ? 1 : 0), + 0) { #ifdef HAS_GROUP dSP; @@ -5763,14 +5995,16 @@ PP(pp_ggrent) PP(pp_getlogin) { #ifdef HAS_GETLOGIN - dSP; dTARGET; + dTARGET; char *tmps; - EXTEND(SP, 1); - if (!(tmps = PerlProc_getlogin())) - RETPUSHUNDEF; + rpp_extend(1); + if (!(tmps = PerlProc_getlogin())) { + rpp_push_IMM(&PL_sv_undef); + return NORMAL; + } sv_setpv_mg(TARG, tmps); - PUSHs(TARG); - RETURN; + rpp_push_1(TARG); + return NORMAL; #else DIE(aTHX_ PL_no_func, "getlogin"); #endif @@ -5778,11 +6012,11 @@ PP(pp_getlogin) /* Miscellaneous. */ -PP(pp_syscall) +PP_wrapped(pp_syscall, 0, 1) { #ifdef HAS_SYSCALL dSP; dMARK; dORIGMARK; dTARGET; - I32 items = SP - MARK; + SSize_t items = SP - MARK; unsigned long a[20]; I32 i = 0; IV retval = -1; Index: gnu/usr.bin/perl/proto.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/proto.h,v diff -u -p -a -u -p -r1.31 proto.h --- gnu/usr.bin/perl/proto.h 14 May 2024 19:38:54 -0000 1.31 +++ gnu/usr.bin/perl/proto.h 22 Jan 2025 00:37:45 -0000 @@ -57,6 +57,15 @@ Perl_PerlLIO_open_cloexec(pTHX_ const ch /* PERL_CALLCONV const XOP * Perl_custom_op_xop(pTHX_ const OP *o); */ +PERL_CALLCONV const char * +Perl_langinfo(const nl_item item); +#define PERL_ARGS_ASSERT_PERL_LANGINFO + +PERL_CALLCONV const char * +Perl_langinfo8(const nl_item item, utf8ness_t *utf8ness); +#define PERL_ARGS_ASSERT_PERL_LANGINFO8 \ + assert(utf8ness) + PERL_CALLCONV HV * Perl_localeconv(pTHX); #define PERL_ARGS_ASSERT_PERL_LOCALECONV @@ -78,10 +87,9 @@ Perl_Slab_Free(pTHX_ void *op); /* PERL_CALLCONV void SvREFCNT_dec_set_NULL(pTHX_ SV *sv); */ -PERL_CALLCONV char * +PERL_CALLCONV const char * Perl__byte_dump_string(pTHX_ const U8 * const start, const STRLEN len, const bool format); -#define PERL_ARGS_ASSERT__BYTE_DUMP_STRING \ - assert(start) +#define PERL_ARGS_ASSERT__BYTE_DUMP_STRING PERL_CALLCONV void Perl__force_out_malformed_utf8_message(pTHX_ const U8 * const p, const U8 * const e, const U32 flags, const bool die_here); @@ -161,10 +169,6 @@ Perl__utf8n_to_uvchr_msgs_helper(const U #define PERL_ARGS_ASSERT__UTF8N_TO_UVCHR_MSGS_HELPER \ assert(s) -PERL_CALLCONV void -Perl__warn_problematic_locale(void); -#define PERL_ARGS_ASSERT__WARN_PROBLEMATIC_LOCALE - PERL_CALLCONV_NO_RET void Perl_abort_execution(pTHX_ SV *msg_sv, const char * const name) __attribute__noreturn__ @@ -203,7 +207,7 @@ Perl_amagic_is_enabled(pTHX_ int method) __attribute__visibility__("hidden"); #define PERL_ARGS_ASSERT_AMAGIC_IS_ENABLED -PERL_CALLCONV I32 +PERL_CALLCONV SSize_t Perl_apply(pTHX_ I32 type, SV **mark, SV **sp) __attribute__visibility__("hidden"); #define PERL_ARGS_ASSERT_APPLY \ @@ -424,7 +428,7 @@ Perl_bytes_to_utf8(pTHX_ const U8 *s, ST #define PERL_ARGS_ASSERT_BYTES_TO_UTF8 \ assert(s); assert(lenp) -PERL_CALLCONV I32 +PERL_CALLCONV SSize_t Perl_call_argv(pTHX_ const char *sub_name, I32 flags, char **argv); #define PERL_ARGS_ASSERT_CALL_ARGV \ assert(sub_name); assert(argv) @@ -438,18 +442,18 @@ Perl_call_list(pTHX_ I32 oldscope, AV *p #define PERL_ARGS_ASSERT_CALL_LIST \ assert(paramList) -PERL_CALLCONV I32 +PERL_CALLCONV SSize_t Perl_call_method(pTHX_ const char *methname, I32 flags); #define PERL_ARGS_ASSERT_CALL_METHOD \ assert(methname) -PERL_CALLCONV I32 +PERL_CALLCONV SSize_t Perl_call_pv(pTHX_ const char *sub_name, I32 flags); #define PERL_ARGS_ASSERT_CALL_PV \ assert(sub_name) -PERL_CALLCONV I32 -Perl_call_sv(pTHX_ SV *sv, volatile I32 flags); +PERL_CALLCONV SSize_t +Perl_call_sv(pTHX_ SV *sv, I32 flags); #define PERL_ARGS_ASSERT_CALL_SV \ assert(sv) @@ -600,9 +604,10 @@ Perl_coresub_op(pTHX_ SV * const corearg assert(coreargssv) PERL_CALLCONV void -Perl_create_eval_scope(pTHX_ OP *retop, U32 flags) +Perl_create_eval_scope(pTHX_ OP *retop, SV **sp, U32 flags) __attribute__visibility__("hidden"); -#define PERL_ARGS_ASSERT_CREATE_EVAL_SCOPE +#define PERL_ARGS_ASSERT_CREATE_EVAL_SCOPE \ + assert(sp) PERL_CALLCONV_NO_RET void Perl_croak(pTHX_ const char *pat, ...) @@ -629,6 +634,13 @@ Perl_croak_no_mem(void) #define PERL_ARGS_ASSERT_CROAK_NO_MEM PERL_CALLCONV_NO_RET void +Perl_croak_no_mem_ext(const char *context, STRLEN len) + __attribute__noreturn__ + __attribute__visibility__("hidden"); +#define PERL_ARGS_ASSERT_CROAK_NO_MEM_EXT \ + assert(context) + +PERL_CALLCONV_NO_RET void Perl_croak_no_modify(void) __attribute__noreturn__; #define PERL_ARGS_ASSERT_CROAK_NO_MODIFY @@ -1096,12 +1108,18 @@ Perl_eval_pv(pTHX_ const char *p, I32 cr #define PERL_ARGS_ASSERT_EVAL_PV \ assert(p) -PERL_CALLCONV I32 +PERL_CALLCONV SSize_t Perl_eval_sv(pTHX_ SV *sv, I32 flags); #define PERL_ARGS_ASSERT_EVAL_SV \ assert(sv) PERL_CALLCONV void +Perl_fatal_warner(pTHX_ U32 err, const char *pat, ...) + __attribute__format__(__printf__,pTHX_2,pTHX_3); +#define PERL_ARGS_ASSERT_FATAL_WARNER \ + assert(pat) + +PERL_CALLCONV void Perl_fbm_compile(pTHX_ SV *sv, U32 flags); #define PERL_ARGS_ASSERT_FBM_COMPILE \ assert(sv) @@ -1167,7 +1185,7 @@ Perl_forbid_outofblock_ops(pTHX_ OP *o, assert(o); assert(blockname) PERL_CALLCONV void -Perl_force_locale_unlock(void) +Perl_force_locale_unlock(pTHX) __attribute__visibility__("hidden"); #define PERL_ARGS_ASSERT_FORCE_LOCALE_UNLOCK @@ -1984,10 +2002,10 @@ Perl_load_module(pTHX_ U32 flags, SV *na assert(name) PERL_CALLCONV_NO_RET void -Perl_locale_panic(const char *msg, const char *file_name, const line_t line, const int errnum) +Perl_locale_panic(const char *msg, const line_t immediate_caller_line, const char * const higher_caller_file, const line_t higher_caller_line) __attribute__noreturn__; #define PERL_ARGS_ASSERT_LOCALE_PANIC \ - assert(msg); assert(file_name) + assert(msg); assert(higher_caller_file) PERL_CALLCONV OP * Perl_localize(pTHX_ OP *o, I32 lex) @@ -2383,7 +2401,7 @@ Perl_malloc(MEM_SIZE nbytes) __attribute__warn_unused_result__; #define PERL_ARGS_ASSERT_MALLOC -PERL_CALLCONV I32 * +PERL_CALLCONV Stack_off_t * Perl_markstack_grow(pTHX); #define PERL_ARGS_ASSERT_MARKSTACK_GROW @@ -2668,12 +2686,6 @@ Perl_my_strftime(pTHX_ const char *fmt, #define PERL_ARGS_ASSERT_MY_STRFTIME \ assert(fmt) -PERL_CALLCONV char * -Perl_my_strftime8_temp(pTHX_ const char *fmt, int sec, int min, int hour, int mday, int mon, int year, int wday, int yday, int isdst, utf8ness_t *utf8ness) - __attribute__format__(__strftime__,pTHX_1,0); -#define PERL_ARGS_ASSERT_MY_STRFTIME8_TEMP \ - assert(fmt) - PERL_CALLCONV NV Perl_my_strtod(const char * const s, char **e) __attribute__warn_unused_result__; @@ -2740,6 +2752,10 @@ newAV_alloc_x(pTHX_ SSize_t size) newAV_alloc_xz(pTHX_ SSize_t size) __attribute__warn_unused_result__; */ +/* PERL_CALLCONV AV * +newAV_mortal(pTHX) + __attribute__warn_unused_result__; */ + PERL_CALLCONV AV * Perl_newAVav(pTHX_ AV *oav) __attribute__warn_unused_result__; @@ -2843,6 +2859,11 @@ Perl_newLISTOP(pTHX_ I32 type, I32 flags #define PERL_ARGS_ASSERT_NEWLISTOP PERL_CALLCONV OP * +Perl_newLISTOPn(pTHX_ I32 type, I32 flags, ...) + __attribute__warn_unused_result__; +#define PERL_ARGS_ASSERT_NEWLISTOPN + +PERL_CALLCONV OP * Perl_newLOGOP(pTHX_ I32 optype, I32 flags, OP *first, OP *other) __attribute__warn_unused_result__; #define PERL_ARGS_ASSERT_NEWLOGOP \ @@ -3110,6 +3131,11 @@ Perl_new_stackinfo(pTHX_ I32 stitems, I3 __attribute__warn_unused_result__; #define PERL_ARGS_ASSERT_NEW_STACKINFO +PERL_CALLCONV PERL_SI * +Perl_new_stackinfo_flags(pTHX_ I32 stitems, I32 cxitems, UV flags) + __attribute__warn_unused_result__; +#define PERL_ARGS_ASSERT_NEW_STACKINFO_FLAGS + PERL_CALLCONV SV * Perl_new_version(pTHX_ SV *ver); #define PERL_ARGS_ASSERT_NEW_VERSION \ @@ -3771,7 +3797,7 @@ Perl_reginitcolors(pTHX); #define PERL_ARGS_ASSERT_REGINITCOLORS PERL_CALLCONV void -Perl_repeatcpy(char *to, const char *from, I32 len, IV count); +Perl_repeatcpy(char *to, const char *from, SSize_t len, IV count); #define PERL_ARGS_ASSERT_REPEATCPY \ assert(to); assert(from) @@ -3817,6 +3843,15 @@ Perl_rpeep(pTHX_ OP *o) __attribute__visibility__("hidden"); #define PERL_ARGS_ASSERT_RPEEP +PERL_CALLCONV void +Perl_rpp_free_2_(pTHX_ SV * const sv1, SV * const sv2, const U32 rc1, const U32 rc2); +#define PERL_ARGS_ASSERT_RPP_FREE_2_ \ + assert(sv1); assert(sv2) + +PERL_CALLCONV void +Perl_rpp_obliterate_stack_to(pTHX_ I32 ix); +#define PERL_ARGS_ASSERT_RPP_OBLITERATE_STACK_TO + PERL_CALLCONV Sighandler_t Perl_rsignal(pTHX_ int i, Sighandler_t t); #define PERL_ARGS_ASSERT_RSIGNAL @@ -4169,12 +4204,14 @@ Perl_set_context(void *t); assert(t) PERL_CALLCONV void -Perl_set_numeric_standard(pTHX); -#define PERL_ARGS_ASSERT_SET_NUMERIC_STANDARD +Perl_set_numeric_standard(pTHX_ const char *file, const line_t caller_line); +#define PERL_ARGS_ASSERT_SET_NUMERIC_STANDARD \ + assert(file) PERL_CALLCONV void -Perl_set_numeric_underlying(pTHX); -#define PERL_ARGS_ASSERT_SET_NUMERIC_UNDERLYING +Perl_set_numeric_underlying(pTHX_ const char *file, const line_t caller_line); +#define PERL_ARGS_ASSERT_SET_NUMERIC_UNDERLYING \ + assert(file) PERL_CALLCONV void Perl_setdefout(pTHX_ GV *gv); @@ -4381,7 +4418,7 @@ Perl_sv_chop(pTHX_ SV * const sv, const #define PERL_ARGS_ASSERT_SV_CHOP \ assert(sv) -PERL_CALLCONV I32 +PERL_CALLCONV SSize_t Perl_sv_clean_all(pTHX) __attribute__visibility__("hidden"); #define PERL_ARGS_ASSERT_SV_CLEAN_ALL @@ -4570,6 +4607,10 @@ PERL_CALLCONV int Perl_sv_isobject(pTHX_ SV *sv); #define PERL_ARGS_ASSERT_SV_ISOBJECT +PERL_CALLCONV SV * +Perl_sv_langinfo(pTHX_ const nl_item item); +#define PERL_ARGS_ASSERT_SV_LANGINFO + PERL_CALLCONV STRLEN Perl_sv_len(pTHX_ SV * const sv); #define PERL_ARGS_ASSERT_SV_LEN @@ -4867,6 +4908,16 @@ Perl_sv_streq_flags(pTHX_ SV *sv1, SV *s #define PERL_ARGS_ASSERT_SV_STREQ_FLAGS PERL_CALLCONV SV * +Perl_sv_strftime_ints(pTHX_ SV *fmt, int sec, int min, int hour, int mday, int mon, int year, int wday, int yday, int isdst); +#define PERL_ARGS_ASSERT_SV_STRFTIME_INTS \ + assert(fmt) + +PERL_CALLCONV SV * +Perl_sv_strftime_tm(pTHX_ SV *fmt, const struct tm *mytm); +#define PERL_ARGS_ASSERT_SV_STRFTIME_TM \ + assert(fmt); assert(mytm) + +PERL_CALLCONV SV * Perl_sv_string_from_errnum(pTHX_ int errnum, SV *tgtsv); #define PERL_ARGS_ASSERT_SV_STRING_FROM_ERRNUM @@ -5011,19 +5062,11 @@ Perl_taint_proper(pTHX_ const char *f, c #define PERL_ARGS_ASSERT_TAINT_PROPER \ assert(s) -PERL_CALLCONV void -Perl_thread_locale_init(pTHX); -#define PERL_ARGS_ASSERT_THREAD_LOCALE_INIT - -PERL_CALLCONV void -Perl_thread_locale_term(pTHX); -#define PERL_ARGS_ASSERT_THREAD_LOCALE_TERM - PERL_CALLCONV OP * -Perl_tied_method(pTHX_ SV *methname, SV **sp, SV * const sv, const MAGIC * const mg, const U32 flags, U32 argc, ...) +Perl_tied_method(pTHX_ SV *methname, SV **mark, SV * const sv, const MAGIC * const mg, const U32 flags, U32 argc, ...) __attribute__visibility__("hidden"); #define PERL_ARGS_ASSERT_TIED_METHOD \ - assert(methname); assert(sp); assert(sv); assert(mg) + assert(methname); assert(mark); assert(sv); assert(mg) PERL_CALLCONV SSize_t Perl_tmps_grow_p(pTHX_ SSize_t ix); @@ -5144,11 +5187,6 @@ Perl_uvoffuni_to_utf8_flags_msgs(pTHX_ U #define PERL_ARGS_ASSERT_UVOFFUNI_TO_UTF8_FLAGS_MSGS \ assert(d) -PERL_CALLCONV U8 * -Perl_uvuni_to_utf8(pTHX_ U8 *d, UV uv); -#define PERL_ARGS_ASSERT_UVUNI_TO_UTF8 \ - assert(d) - PERL_CALLCONV bool Perl_validate_proto(pTHX_ SV *name, SV *proto, bool warn, bool curstash); #define PERL_ARGS_ASSERT_VALIDATE_PROTO \ @@ -5169,6 +5207,11 @@ Perl_vdeb(pTHX_ const char *pat, va_list #define PERL_ARGS_ASSERT_VDEB \ assert(pat) +PERL_CALLCONV void +Perl_vfatal_warner(pTHX_ U32 err, const char *pat, va_list *args); +#define PERL_ARGS_ASSERT_VFATAL_WARNER \ + assert(pat) + PERL_CALLCONV char * Perl_vform(pTHX_ const char *pat, va_list *args); #define PERL_ARGS_ASSERT_VFORM \ @@ -5306,10 +5349,10 @@ Perl_write_to_stderr(pTHX_ SV *msv) assert(msv) PERL_CALLCONV void -Perl_xs_boot_epilog(pTHX_ const I32 ax); +Perl_xs_boot_epilog(pTHX_ const SSize_t ax); #define PERL_ARGS_ASSERT_XS_BOOT_EPILOG -PERL_CALLCONV I32 +PERL_CALLCONV Stack_off_t Perl_xs_handshake(const U32 key, void *v_my_perl, const char *file, ...); #define PERL_ARGS_ASSERT_XS_HANDSHAKE \ assert(v_my_perl); assert(file) @@ -5440,7 +5483,7 @@ Perl_do_ipcget(pTHX_ I32 optype, SV **ma # define PERL_ARGS_ASSERT_DO_IPCGET \ assert(mark); assert(sp) -PERL_CALLCONV I32 +PERL_CALLCONV SSize_t Perl_do_msgrcv(pTHX_ SV **mark, SV **sp) __attribute__visibility__("hidden"); # define PERL_ARGS_ASSERT_DO_MSGRCV \ @@ -5465,25 +5508,6 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mar assert(mark); assert(sp) #endif /* defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) */ -#if defined(HAS_NL_LANGINFO) && defined(PERL_LANGINFO_H) -PERL_CALLCONV const char * -Perl_langinfo(const nl_item item); -# define PERL_ARGS_ASSERT_PERL_LANGINFO - -PERL_CALLCONV const char * -Perl_langinfo8(const nl_item item, utf8ness_t *utf8ness); -# define PERL_ARGS_ASSERT_PERL_LANGINFO8 - -#else -PERL_CALLCONV const char * -Perl_langinfo(const int item); -# define PERL_ARGS_ASSERT_PERL_LANGINFO - -PERL_CALLCONV const char * -Perl_langinfo8(const int item, utf8ness_t *utf8ness); -# define PERL_ARGS_ASSERT_PERL_LANGINFO8 - -#endif #if defined(HAS_PIPE) PERL_CALLCONV int Perl_PerlProc_pipe_cloexec(pTHX_ int *pipefd) @@ -6015,6 +6039,12 @@ Perl_utf8n_to_uvuni(pTHX_ const U8 *s, S # define PERL_ARGS_ASSERT_UTF8N_TO_UVUNI \ assert(s) +PERL_CALLCONV U8 * +Perl_uvuni_to_utf8(pTHX_ U8 *d, UV uv) + __attribute__deprecated__; +# define PERL_ARGS_ASSERT_UVUNI_TO_UTF8 \ + assert(d) + # if defined(PERL_DONT_CREATE_GVSV) PERL_CALLCONV GV * Perl_gv_SVadd(pTHX_ GV *gv); @@ -6176,360 +6206,122 @@ S_get_aux_mg(pTHX_ AV *av); assert(av) #endif -#if defined(PERL_IN_CLASS_C) || defined(PERL_IN_OP_C) || \ - defined(PERL_IN_PAD_C) || defined(PERL_IN_PERLY_C) || \ - defined(PERL_IN_TOKE_C) +#if defined(PERL_IN_BUILTIN_C) || defined(PERL_IN_OP_C) PERL_CALLCONV void -Perl_class_add_ADJUST(pTHX_ HV *stash, CV *cv); -# define PERL_ARGS_ASSERT_CLASS_ADD_ADJUST \ - assert(stash); assert(cv) - -PERL_CALLCONV void -Perl_class_add_field(pTHX_ HV *stash, PADNAME *pn); -# define PERL_ARGS_ASSERT_CLASS_ADD_FIELD \ - assert(stash); assert(pn) +Perl_finish_export_lexical(pTHX) + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_FINISH_EXPORT_LEXICAL PERL_CALLCONV void -Perl_class_apply_attributes(pTHX_ HV *stash, OP *attrlist); -# define PERL_ARGS_ASSERT_CLASS_APPLY_ATTRIBUTES \ - assert(stash) +Perl_import_builtin_bundle(pTHX_ U16 ver) + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_IMPORT_BUILTIN_BUNDLE PERL_CALLCONV void -Perl_class_apply_field_attributes(pTHX_ PADNAME *pn, OP *attrlist); -# define PERL_ARGS_ASSERT_CLASS_APPLY_FIELD_ATTRIBUTES \ - assert(pn) +Perl_prepare_export_lexical(pTHX) + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_PREPARE_EXPORT_LEXICAL -PERL_CALLCONV void -Perl_class_prepare_initfield_parse(pTHX); -# define PERL_ARGS_ASSERT_CLASS_PREPARE_INITFIELD_PARSE +#endif /* defined(PERL_IN_BUILTIN_C) || defined(PERL_IN_OP_C) */ +#if defined(PERL_IN_CLASS_C) || defined(PERL_IN_GLOBALS_C) || \ + defined(PERL_IN_OP_C) || defined(PERL_IN_PEEP_C) +PERL_CALLCONV OP * +Perl_ck_anoncode(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_ANONCODE \ + assert(o) -PERL_CALLCONV void -Perl_class_prepare_method_parse(pTHX_ CV *cv); -# define PERL_ARGS_ASSERT_CLASS_PREPARE_METHOD_PARSE \ - assert(cv) +PERL_CALLCONV OP * +Perl_ck_backtick(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_BACKTICK \ + assert(o) -PERL_CALLCONV void -Perl_class_seal_stash(pTHX_ HV *stash); -# define PERL_ARGS_ASSERT_CLASS_SEAL_STASH \ - assert(stash) +PERL_CALLCONV OP * +Perl_ck_bitop(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_BITOP \ + assert(o) -PERL_CALLCONV void -Perl_class_set_field_defop(pTHX_ PADNAME *pn, OPCODE defmode, OP *defop); -# define PERL_ARGS_ASSERT_CLASS_SET_FIELD_DEFOP \ - assert(pn); assert(defop) +PERL_CALLCONV OP * +Perl_ck_classname(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_CLASSNAME \ + assert(o) -PERL_CALLCONV void -Perl_class_setup_stash(pTHX_ HV *stash); -# define PERL_ARGS_ASSERT_CLASS_SETUP_STASH \ - assert(stash) +PERL_CALLCONV OP * +Perl_ck_cmp(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_CMP \ + assert(o) PERL_CALLCONV OP * -Perl_class_wrap_method_body(pTHX_ OP *o); -# define PERL_ARGS_ASSERT_CLASS_WRAP_METHOD_BODY +Perl_ck_concat(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_CONCAT \ + assert(o) -PERL_CALLCONV void -Perl_croak_kw_unless_class(pTHX_ const char *kw); -# define PERL_ARGS_ASSERT_CROAK_KW_UNLESS_CLASS \ - assert(kw) +PERL_CALLCONV OP * +Perl_ck_defined(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_DEFINED \ + assert(o) -#endif /* defined(PERL_IN_CLASS_C) || defined(PERL_IN_OP_C) || - defined(PERL_IN_PAD_C) || defined(PERL_IN_PERLY_C) || - defined(PERL_IN_TOKE_C) */ -#if defined(PERL_IN_DEB_C) -STATIC void -S_deb_stack_n(pTHX_ SV **stack_base, I32 stack_min, I32 stack_max, I32 mark_min, I32 mark_max); -# define PERL_ARGS_ASSERT_DEB_STACK_N \ - assert(stack_base) +PERL_CALLCONV OP * +Perl_ck_delete(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_DELETE \ + assert(o) -#endif -#if defined(PERL_IN_DOIO_C) -STATIC bool -S_argvout_final(pTHX_ MAGIC *mg, IO *io, bool is_explicit); -# define PERL_ARGS_ASSERT_ARGVOUT_FINAL \ - assert(mg); assert(io) +PERL_CALLCONV OP * +Perl_ck_each(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_EACH \ + assert(o) -STATIC void -S_exec_failed(pTHX_ const char *cmd, int fd, int do_report); -# define PERL_ARGS_ASSERT_EXEC_FAILED \ - assert(cmd) +PERL_CALLCONV OP * +Perl_ck_eof(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_EOF \ + assert(o) -STATIC bool -S_ingroup(pTHX_ Gid_t testgid, bool effective) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT_INGROUP +PERL_CALLCONV OP * +Perl_ck_eval(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_EVAL \ + assert(o) -STATIC bool -S_openn_cleanup(pTHX_ GV *gv, IO *io, PerlIO *fp, char *mode, const char *oname, PerlIO *saveifp, PerlIO *saveofp, int savefd, char savetype, int writing, bool was_fdopen, const char *type, Stat_t *statbufp); -# define PERL_ARGS_ASSERT_OPENN_CLEANUP \ - assert(gv); assert(io); assert(mode); assert(oname) +PERL_CALLCONV OP * +Perl_ck_exec(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_EXEC \ + assert(o) -STATIC IO * -S_openn_setup(pTHX_ GV *gv, char *mode, PerlIO **saveifp, PerlIO **saveofp, int *savefd, char *savetype); -# define PERL_ARGS_ASSERT_OPENN_SETUP \ - assert(gv); assert(mode); assert(saveifp); assert(saveofp); assert(savefd); \ - assert(savetype) +PERL_CALLCONV OP * +Perl_ck_exists(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_EXISTS \ + assert(o) -#endif /* defined(PERL_IN_DOIO_C) */ -#if defined(PERL_IN_DOOP_C) -STATIC Size_t -S_do_trans_complex(pTHX_ SV * const sv, const OPtrans_map * const tbl) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT_DO_TRANS_COMPLEX \ - assert(sv); assert(tbl) - -STATIC Size_t -S_do_trans_count(pTHX_ SV * const sv, const OPtrans_map * const tbl) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT_DO_TRANS_COUNT \ - assert(sv); assert(tbl) - -STATIC Size_t -S_do_trans_count_invmap(pTHX_ SV * const sv, AV * const map) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT_DO_TRANS_COUNT_INVMAP \ - assert(sv); assert(map) - -STATIC Size_t -S_do_trans_invmap(pTHX_ SV * const sv, AV * const map) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT_DO_TRANS_INVMAP \ - assert(sv); assert(map) - -STATIC Size_t -S_do_trans_simple(pTHX_ SV * const sv, const OPtrans_map * const tbl) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT_DO_TRANS_SIMPLE \ - assert(sv); assert(tbl) - -#endif /* defined(PERL_IN_DOOP_C) */ -#if defined(PERL_IN_DOOP_C) || defined(PERL_IN_OP_C) || \ - defined(PERL_IN_PP_C) || defined(PERL_IN_REGCOMP_ANY) || \ - defined(PERL_IN_REGEXEC_C) || defined(PERL_IN_TOKE_C) || \ - defined(PERL_IN_UTF8_C) - -PERL_CALLCONV SSize_t -Perl__invlist_search(SV * const invlist, const UV cp) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT__INVLIST_SEARCH \ - assert(invlist) - -#endif /* defined(PERL_IN_DOOP_C) || defined(PERL_IN_OP_C) || - defined(PERL_IN_PP_C) || defined(PERL_IN_REGCOMP_ANY) || - defined(PERL_IN_REGEXEC_C) || defined(PERL_IN_TOKE_C) || - defined(PERL_IN_UTF8_C) */ -#if defined(PERL_IN_DOOP_C) || defined(PERL_IN_OP_C) || \ - defined(PERL_IN_REGCOMP_ANY) - -#endif -#if defined(PERL_IN_DOOP_C) || defined(PERL_IN_OP_C) || \ - defined(PERL_IN_REGCOMP_ANY) || defined(PERL_IN_UTF8_C) -PERL_CALLCONV SV * -Perl__add_range_to_invlist(pTHX_ SV *invlist, UV start, UV end) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT__ADD_RANGE_TO_INVLIST - -/* PERL_CALLCONV void -_invlist_intersection(pTHX_ SV * const a, SV * const b, SV **i); */ - -PERL_CALLCONV void -Perl__invlist_intersection_maybe_complement_2nd(pTHX_ SV * const a, SV * const b, const bool complement_b, SV **i); -# define PERL_ARGS_ASSERT__INVLIST_INTERSECTION_MAYBE_COMPLEMENT_2ND \ - assert(b); assert(i) - -PERL_CALLCONV void -Perl__invlist_invert(pTHX_ SV * const invlist); -# define PERL_ARGS_ASSERT__INVLIST_INVERT \ - assert(invlist) - -/* PERL_CALLCONV void -_invlist_subtract(pTHX_ SV * const a, SV * const b, SV **result); */ - -/* PERL_CALLCONV void -_invlist_union(pTHX_ SV * const a, SV * const b, SV **output); */ - -PERL_CALLCONV void -Perl__invlist_union_maybe_complement_2nd(pTHX_ SV * const a, SV * const b, const bool complement_b, SV **output); -# define PERL_ARGS_ASSERT__INVLIST_UNION_MAYBE_COMPLEMENT_2ND \ - assert(b); assert(output) - -PERL_CALLCONV SV * -Perl__new_invlist(pTHX_ IV initial_size) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT__NEW_INVLIST - -PERL_CALLCONV SV * -Perl__setup_canned_invlist(pTHX_ const STRLEN size, const UV element0, UV **other_elements_ptr) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT__SETUP_CANNED_INVLIST \ - assert(other_elements_ptr) - -#endif /* defined(PERL_IN_DOOP_C) || defined(PERL_IN_OP_C) || - defined(PERL_IN_REGCOMP_ANY) || defined(PERL_IN_UTF8_C) */ -#if defined(PERL_IN_DQUOTE_C) || defined(PERL_IN_REGCOMP_C) || \ - defined(PERL_IN_TOKE_C) -PERL_CALLCONV const char * -Perl_form_alien_digit_msg(pTHX_ const U8 which, const STRLEN valids_len, const char * const first_bad, const char * const send, const bool UTF, const bool braced) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT_FORM_ALIEN_DIGIT_MSG \ - assert(first_bad); assert(send) - -PERL_CALLCONV bool -Perl_grok_bslash_c(pTHX_ const char source, U8 *result, const char **message, U32 *packed_warn) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT_GROK_BSLASH_C \ - assert(result); assert(message) - -PERL_CALLCONV bool -Perl_grok_bslash_o(pTHX_ char **s, const char * const send, UV *uv, const char **message, U32 *packed_warn, const bool strict, const bool allow_UV_MAX, const bool utf8) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT_GROK_BSLASH_O \ - assert(s); assert(send); assert(uv); assert(message) - -PERL_CALLCONV bool -Perl_grok_bslash_x(pTHX_ char **s, const char * const send, UV *uv, const char **message, U32 *packed_warn, const bool strict, const bool allow_UV_MAX, const bool utf8) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT_GROK_BSLASH_X \ - assert(s); assert(send); assert(uv); assert(message) - -#endif /* defined(PERL_IN_DQUOTE_C) || defined(PERL_IN_REGCOMP_C) || - defined(PERL_IN_TOKE_C) */ -#if defined(PERL_IN_DQUOTE_C) || defined(PERL_IN_REGCOMP_C) || \ - defined(PERL_IN_TOKE_C) || defined(PERL_IN_UTF8_C) -PERL_CALLCONV const char * -Perl_form_cp_too_large_msg(pTHX_ const U8 which, const char *string, const Size_t len, const UV cp) - __attribute__warn_unused_result__; -# define PERL_ARGS_ASSERT_FORM_CP_TOO_LARGE_MSG - -#endif -#if defined(PERL_IN_DUMP_C) -STATIC CV * -S_deb_curcv(pTHX_ I32 ix); -# define PERL_ARGS_ASSERT_DEB_CURCV - -STATIC void -S_debprof(pTHX_ const OP *o); -# define PERL_ARGS_ASSERT_DEBPROF \ - assert(o) - -STATIC SV * -S_pm_description(pTHX_ const PMOP *pm); -# define PERL_ARGS_ASSERT_PM_DESCRIPTION \ - assert(pm) - -STATIC UV -S_sequence_num(pTHX_ const OP *o); -# define PERL_ARGS_ASSERT_SEQUENCE_NUM - -#endif /* defined(PERL_IN_DUMP_C) */ -#if defined(PERL_IN_DUMP_C) || defined(PERL_IN_HV_C) || \ - defined(PERL_IN_SCOPE_C) || defined(PERL_IN_SV_C) -PERL_CALLCONV void -Perl_hv_kill_backrefs(pTHX_ HV *hv) - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_HV_KILL_BACKREFS \ - assert(hv) - -#endif -#if defined(PERL_IN_DUMP_C) || defined(PERL_IN_OP_C) || \ - defined(PERL_IN_REGCOMP_ANY) -PERL_CALLCONV void -Perl__invlist_dump(pTHX_ PerlIO *file, I32 level, const char * const indent, SV * const invlist); -# define PERL_ARGS_ASSERT__INVLIST_DUMP \ - assert(file); assert(indent); assert(invlist) - -#endif -#if defined(PERL_IN_GLOBALS_C) || defined(PERL_IN_OP_C) || \ - defined(PERL_IN_PEEP_C) -PERL_CALLCONV OP * -Perl_ck_anoncode(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_ANONCODE \ - assert(o) - -PERL_CALLCONV OP * -Perl_ck_backtick(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_BACKTICK \ - assert(o) - -PERL_CALLCONV OP * -Perl_ck_bitop(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_BITOP \ - assert(o) - -PERL_CALLCONV OP * -Perl_ck_cmp(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_CMP \ - assert(o) - -PERL_CALLCONV OP * -Perl_ck_concat(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_CONCAT \ - assert(o) - -PERL_CALLCONV OP * -Perl_ck_defined(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_DEFINED \ - assert(o) - -PERL_CALLCONV OP * -Perl_ck_delete(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_DELETE \ - assert(o) - -PERL_CALLCONV OP * -Perl_ck_each(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_EACH \ - assert(o) - -PERL_CALLCONV OP * -Perl_ck_eof(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_EOF \ - assert(o) - -PERL_CALLCONV OP * -Perl_ck_eval(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_EVAL \ - assert(o) - -PERL_CALLCONV OP * -Perl_ck_exec(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_EXEC \ - assert(o) - -PERL_CALLCONV OP * -Perl_ck_exists(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_EXISTS \ - assert(o) - -PERL_CALLCONV OP * -Perl_ck_ftst(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_FTST \ - assert(o) +PERL_CALLCONV OP * +Perl_ck_ftst(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_FTST \ + assert(o) PERL_CALLCONV OP * Perl_ck_fun(pTHX_ OP *o) @@ -6748,43 +6540,312 @@ Perl_ck_subr(pTHX_ OP *o) # define PERL_ARGS_ASSERT_CK_SUBR \ assert(o) -PERL_CALLCONV OP * -Perl_ck_substr(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_SUBSTR \ +PERL_CALLCONV OP * +Perl_ck_substr(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_SUBSTR \ + assert(o) + +PERL_CALLCONV OP * +Perl_ck_svconst(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_SVCONST \ + assert(o) + +PERL_CALLCONV OP * +Perl_ck_tell(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_TELL \ + assert(o) + +PERL_CALLCONV OP * +Perl_ck_trunc(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_TRUNC \ + assert(o) + +PERL_CALLCONV OP * +Perl_ck_trycatch(pTHX_ OP *o) + __attribute__warn_unused_result__ + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_CK_TRYCATCH \ + assert(o) + +#endif /* defined(PERL_IN_CLASS_C) || defined(PERL_IN_GLOBALS_C) || + defined(PERL_IN_OP_C) || defined(PERL_IN_PEEP_C) */ +#if defined(PERL_IN_CLASS_C) || defined(PERL_IN_OP_C) || \ + defined(PERL_IN_PAD_C) || defined(PERL_IN_PERLY_C) || \ + defined(PERL_IN_TOKE_C) +PERL_CALLCONV void +Perl_class_add_ADJUST(pTHX_ HV *stash, CV *cv); +# define PERL_ARGS_ASSERT_CLASS_ADD_ADJUST \ + assert(stash); assert(cv) + +PERL_CALLCONV void +Perl_class_add_field(pTHX_ HV *stash, PADNAME *pn); +# define PERL_ARGS_ASSERT_CLASS_ADD_FIELD \ + assert(stash); assert(pn) + +PERL_CALLCONV void +Perl_class_apply_attributes(pTHX_ HV *stash, OP *attrlist); +# define PERL_ARGS_ASSERT_CLASS_APPLY_ATTRIBUTES \ + assert(stash) + +PERL_CALLCONV void +Perl_class_apply_field_attributes(pTHX_ PADNAME *pn, OP *attrlist); +# define PERL_ARGS_ASSERT_CLASS_APPLY_FIELD_ATTRIBUTES \ + assert(pn) + +PERL_CALLCONV void +Perl_class_prepare_initfield_parse(pTHX); +# define PERL_ARGS_ASSERT_CLASS_PREPARE_INITFIELD_PARSE + +PERL_CALLCONV void +Perl_class_prepare_method_parse(pTHX_ CV *cv); +# define PERL_ARGS_ASSERT_CLASS_PREPARE_METHOD_PARSE \ + assert(cv) + +PERL_CALLCONV void +Perl_class_seal_stash(pTHX_ HV *stash); +# define PERL_ARGS_ASSERT_CLASS_SEAL_STASH \ + assert(stash) + +PERL_CALLCONV void +Perl_class_set_field_defop(pTHX_ PADNAME *pn, OPCODE defmode, OP *defop); +# define PERL_ARGS_ASSERT_CLASS_SET_FIELD_DEFOP \ + assert(pn); assert(defop) + +PERL_CALLCONV void +Perl_class_setup_stash(pTHX_ HV *stash); +# define PERL_ARGS_ASSERT_CLASS_SETUP_STASH \ + assert(stash) + +PERL_CALLCONV OP * +Perl_class_wrap_method_body(pTHX_ OP *o); +# define PERL_ARGS_ASSERT_CLASS_WRAP_METHOD_BODY + +PERL_CALLCONV void +Perl_croak_kw_unless_class(pTHX_ const char *kw); +# define PERL_ARGS_ASSERT_CROAK_KW_UNLESS_CLASS \ + assert(kw) + +#endif /* defined(PERL_IN_CLASS_C) || defined(PERL_IN_OP_C) || + defined(PERL_IN_PAD_C) || defined(PERL_IN_PERLY_C) || + defined(PERL_IN_TOKE_C) */ +#if defined(PERL_IN_DEB_C) +STATIC void +S_deb_stack_n(pTHX_ SV **stack_base, SSize_t stack_min, SSize_t stack_max, SSize_t mark_min, SSize_t mark_max, SSize_t nonrc_base); +# define PERL_ARGS_ASSERT_DEB_STACK_N \ + assert(stack_base) + +#endif +#if defined(PERL_IN_DOIO_C) +STATIC bool +S_argvout_final(pTHX_ MAGIC *mg, IO *io, bool is_explicit); +# define PERL_ARGS_ASSERT_ARGVOUT_FINAL \ + assert(mg); assert(io) + +STATIC void +S_exec_failed(pTHX_ const char *cmd, int fd, int do_report); +# define PERL_ARGS_ASSERT_EXEC_FAILED \ + assert(cmd) + +STATIC bool +S_is_fork_open(const char *name); +# define PERL_ARGS_ASSERT_IS_FORK_OPEN \ + assert(name) + +STATIC bool +S_openn_cleanup(pTHX_ GV *gv, IO *io, PerlIO *fp, char *mode, const char *oname, PerlIO *saveifp, PerlIO *saveofp, int savefd, char savetype, int writing, bool was_fdopen, const char *type, Stat_t *statbufp); +# define PERL_ARGS_ASSERT_OPENN_CLEANUP \ + assert(gv); assert(io); assert(mode); assert(oname) + +STATIC IO * +S_openn_setup(pTHX_ GV *gv, char *mode, PerlIO **saveifp, PerlIO **saveofp, int *savefd, char *savetype); +# define PERL_ARGS_ASSERT_OPENN_SETUP \ + assert(gv); assert(mode); assert(saveifp); assert(saveofp); assert(savefd); \ + assert(savetype) + +# if !defined(DOSISH) +STATIC bool +S_ingroup(pTHX_ Gid_t testgid, bool effective) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT_INGROUP + +# endif +#endif /* defined(PERL_IN_DOIO_C) */ +#if defined(PERL_IN_DOOP_C) +STATIC Size_t +S_do_trans_complex(pTHX_ SV * const sv, const OPtrans_map * const tbl) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT_DO_TRANS_COMPLEX \ + assert(sv); assert(tbl) + +STATIC Size_t +S_do_trans_count(pTHX_ SV * const sv, const OPtrans_map * const tbl) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT_DO_TRANS_COUNT \ + assert(sv); assert(tbl) + +STATIC Size_t +S_do_trans_count_invmap(pTHX_ SV * const sv, AV * const map) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT_DO_TRANS_COUNT_INVMAP \ + assert(sv); assert(map) + +STATIC Size_t +S_do_trans_invmap(pTHX_ SV * const sv, AV * const map) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT_DO_TRANS_INVMAP \ + assert(sv); assert(map) + +STATIC Size_t +S_do_trans_simple(pTHX_ SV * const sv, const OPtrans_map * const tbl) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT_DO_TRANS_SIMPLE \ + assert(sv); assert(tbl) + +#endif /* defined(PERL_IN_DOOP_C) */ +#if defined(PERL_IN_DOOP_C) || defined(PERL_IN_OP_C) || \ + defined(PERL_IN_PP_C) || defined(PERL_IN_REGCOMP_ANY) || \ + defined(PERL_IN_REGEXEC_C) || defined(PERL_IN_TOKE_C) || \ + defined(PERL_IN_UTF8_C) + +PERL_CALLCONV SSize_t +Perl__invlist_search(SV * const invlist, const UV cp) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT__INVLIST_SEARCH \ + assert(invlist) + +#endif /* defined(PERL_IN_DOOP_C) || defined(PERL_IN_OP_C) || + defined(PERL_IN_PP_C) || defined(PERL_IN_REGCOMP_ANY) || + defined(PERL_IN_REGEXEC_C) || defined(PERL_IN_TOKE_C) || + defined(PERL_IN_UTF8_C) */ +#if defined(PERL_IN_DOOP_C) || defined(PERL_IN_OP_C) || \ + defined(PERL_IN_REGCOMP_ANY) + +#endif +#if defined(PERL_IN_DOOP_C) || defined(PERL_IN_OP_C) || \ + defined(PERL_IN_REGCOMP_ANY) || defined(PERL_IN_UTF8_C) +PERL_CALLCONV SV * +Perl__add_range_to_invlist(pTHX_ SV *invlist, UV start, UV end) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT__ADD_RANGE_TO_INVLIST + +/* PERL_CALLCONV void +_invlist_intersection(pTHX_ SV * const a, SV * const b, SV **i); */ + +PERL_CALLCONV void +Perl__invlist_intersection_maybe_complement_2nd(pTHX_ SV * const a, SV * const b, const bool complement_b, SV **i); +# define PERL_ARGS_ASSERT__INVLIST_INTERSECTION_MAYBE_COMPLEMENT_2ND \ + assert(b); assert(i) + +PERL_CALLCONV void +Perl__invlist_invert(pTHX_ SV * const invlist); +# define PERL_ARGS_ASSERT__INVLIST_INVERT \ + assert(invlist) + +/* PERL_CALLCONV void +_invlist_subtract(pTHX_ SV * const a, SV * const b, SV **result); */ + +/* PERL_CALLCONV void +_invlist_union(pTHX_ SV * const a, SV * const b, SV **output); */ + +PERL_CALLCONV void +Perl__invlist_union_maybe_complement_2nd(pTHX_ SV * const a, SV * const b, const bool complement_b, SV **output); +# define PERL_ARGS_ASSERT__INVLIST_UNION_MAYBE_COMPLEMENT_2ND \ + assert(b); assert(output) + +PERL_CALLCONV SV * +Perl__new_invlist(pTHX_ IV initial_size) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT__NEW_INVLIST + +PERL_CALLCONV SV * +Perl__setup_canned_invlist(pTHX_ const STRLEN size, const UV element0, UV **other_elements_ptr) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT__SETUP_CANNED_INVLIST \ + assert(other_elements_ptr) + +#endif /* defined(PERL_IN_DOOP_C) || defined(PERL_IN_OP_C) || + defined(PERL_IN_REGCOMP_ANY) || defined(PERL_IN_UTF8_C) */ +#if defined(PERL_IN_DQUOTE_C) || defined(PERL_IN_REGCOMP_C) || \ + defined(PERL_IN_TOKE_C) +PERL_CALLCONV const char * +Perl_form_alien_digit_msg(pTHX_ const U8 which, const STRLEN valids_len, const char * const first_bad, const char * const send, const bool UTF, const bool braced) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT_FORM_ALIEN_DIGIT_MSG \ + assert(first_bad); assert(send) + +PERL_CALLCONV bool +Perl_grok_bslash_c(pTHX_ const char source, U8 *result, const char **message, U32 *packed_warn) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT_GROK_BSLASH_C \ + assert(result); assert(message) + +PERL_CALLCONV bool +Perl_grok_bslash_o(pTHX_ char **s, const char * const send, UV *uv, const char **message, U32 *packed_warn, const bool strict, const bool allow_UV_MAX, const bool utf8) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT_GROK_BSLASH_O \ + assert(s); assert(send); assert(uv); assert(message) + +PERL_CALLCONV bool +Perl_grok_bslash_x(pTHX_ char **s, const char * const send, UV *uv, const char **message, U32 *packed_warn, const bool strict, const bool allow_UV_MAX, const bool utf8) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT_GROK_BSLASH_X \ + assert(s); assert(send); assert(uv); assert(message) + +#endif /* defined(PERL_IN_DQUOTE_C) || defined(PERL_IN_REGCOMP_C) || + defined(PERL_IN_TOKE_C) */ +#if defined(PERL_IN_DQUOTE_C) || defined(PERL_IN_REGCOMP_C) || \ + defined(PERL_IN_TOKE_C) || defined(PERL_IN_UTF8_C) +PERL_CALLCONV const char * +Perl_form_cp_too_large_msg(pTHX_ const U8 which, const char *string, const Size_t len, const UV cp) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT_FORM_CP_TOO_LARGE_MSG + +#endif +#if defined(PERL_IN_DUMP_C) +STATIC CV * +S_deb_curcv(pTHX_ I32 ix); +# define PERL_ARGS_ASSERT_DEB_CURCV + +STATIC void +S_debprof(pTHX_ const OP *o); +# define PERL_ARGS_ASSERT_DEBPROF \ assert(o) -PERL_CALLCONV OP * -Perl_ck_svconst(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_SVCONST \ - assert(o) +STATIC SV * +S_pm_description(pTHX_ const PMOP *pm); +# define PERL_ARGS_ASSERT_PM_DESCRIPTION \ + assert(pm) -PERL_CALLCONV OP * -Perl_ck_tell(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_TELL \ - assert(o) +STATIC UV +S_sequence_num(pTHX_ const OP *o); +# define PERL_ARGS_ASSERT_SEQUENCE_NUM -PERL_CALLCONV OP * -Perl_ck_trunc(pTHX_ OP *o) - __attribute__warn_unused_result__ +#endif /* defined(PERL_IN_DUMP_C) */ +#if defined(PERL_IN_DUMP_C) || defined(PERL_IN_HV_C) || \ + defined(PERL_IN_SCOPE_C) || defined(PERL_IN_SV_C) +PERL_CALLCONV void +Perl_hv_kill_backrefs(pTHX_ HV *hv) __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_TRUNC \ - assert(o) +# define PERL_ARGS_ASSERT_HV_KILL_BACKREFS \ + assert(hv) -PERL_CALLCONV OP * -Perl_ck_trycatch(pTHX_ OP *o) - __attribute__warn_unused_result__ - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_CK_TRYCATCH \ - assert(o) +#endif +#if defined(PERL_IN_DUMP_C) || defined(PERL_IN_OP_C) || \ + defined(PERL_IN_REGCOMP_ANY) +PERL_CALLCONV void +Perl__invlist_dump(pTHX_ PerlIO *file, I32 level, const char * const indent, SV * const invlist); +# define PERL_ARGS_ASSERT__INVLIST_DUMP \ + assert(file); assert(indent); assert(invlist) -#endif /* defined(PERL_IN_GLOBALS_C) || defined(PERL_IN_OP_C) || - defined(PERL_IN_PEEP_C) */ +#endif #if defined(PERL_IN_GV_C) STATIC bool S_find_default_stash(pTHX_ HV **stash, const char *name, STRLEN len, const U32 is_utf8, const I32 add, const svtype sv_type); @@ -6942,79 +7003,140 @@ Perl_hfree_next_entry(pTHX_ HV *hv, STRL #endif #if defined(PERL_IN_LOCALE_C) STATIC utf8ness_t -S_get_locale_string_utf8ness_i(pTHX_ const char *string, const locale_utf8ness_t known_utf8, const char *locale, const unsigned cat_index); +S_get_locale_string_utf8ness_i(pTHX_ const char *string, const locale_utf8ness_t known_utf8, const char *locale, const locale_category_index cat_index); # define PERL_ARGS_ASSERT_GET_LOCALE_STRING_UTF8NESS_I +STATIC void +S_ints_to_tm(pTHX_ struct tm *my_tm, const char *locale, int sec, int min, int hour, int mday, int mon, int year, int wday, int yday, int isdst); +# define PERL_ARGS_ASSERT_INTS_TO_TM \ + assert(my_tm); assert(locale) + STATIC bool S_is_locale_utf8(pTHX_ const char *locale); # define PERL_ARGS_ASSERT_IS_LOCALE_UTF8 \ assert(locale) -# if defined(HAS_LOCALECONV) STATIC HV * S_my_localeconv(pTHX_ const int item); -# define PERL_ARGS_ASSERT_MY_LOCALECONV +# define PERL_ARGS_ASSERT_MY_LOCALECONV STATIC void -S_populate_hash_from_localeconv(pTHX_ HV *hv, const char *locale, const U32 which_mask, const lconv_offset_t *strings[2], const lconv_offset_t *integers); -# define PERL_ARGS_ASSERT_POPULATE_HASH_FROM_LOCALECONV \ - assert(hv); assert(locale); assert(strings) +S_populate_hash_from_C_localeconv(pTHX_ HV *hv, const char *locale, const U32 which_mask, const lconv_offset_t *strings[2], const lconv_offset_t *integers[2]); +# define PERL_ARGS_ASSERT_POPULATE_HASH_FROM_C_LOCALECONV \ + assert(hv); assert(locale); assert(strings); assert(integers) + +STATIC bool +S_strftime8(pTHX_ const char *fmt, SV *sv, const char *locale, const struct tm *mytm, const utf8ness_t fmt_utf8ness, utf8ness_t *result_utf8ness, const bool called_externally); +# define PERL_ARGS_ASSERT_STRFTIME8 \ + assert(fmt); assert(sv); assert(locale); assert(mytm); assert(result_utf8ness) + +STATIC bool +S_strftime_tm(pTHX_ const char *fmt, SV *sv, const char *locale, const struct tm *mytm) + __attribute__format__(__strftime__,pTHX_1,0); +# define PERL_ARGS_ASSERT_STRFTIME_TM \ + assert(fmt); assert(sv); assert(locale); assert(mytm) + +STATIC SV * +S_sv_strftime_common(pTHX_ SV *fmt, const char *locale, const struct tm *mytm); +# define PERL_ARGS_ASSERT_SV_STRFTIME_COMMON \ + assert(fmt); assert(locale); assert(mytm) + +# if defined(HAS_MISSING_LANGINFO_ITEM_) || !defined(HAS_NL_LANGINFO) +STATIC const char * +S_emulate_langinfo(pTHX_ const PERL_INTMAX_T item, const char *locale, SV *sv, utf8ness_t *utf8ness); +# define PERL_ARGS_ASSERT_EMULATE_LANGINFO \ + assert(locale); assert(sv) -# endif /* defined(HAS_LOCALECONV) */ +# endif # if defined(USE_LOCALE) -STATIC unsigned int -S_get_category_index(const int category, const char *locale); -# define PERL_ARGS_ASSERT_GET_CATEGORY_INDEX +STATIC const char * +S_calculate_LC_ALL_string(pTHX_ const char **category_locales_list, const calc_LC_ALL_format format, const calc_LC_ALL_return returning, const line_t caller_line); +# define PERL_ARGS_ASSERT_CALCULATE_LC_ALL_STRING -STATIC int -S_get_category_index_nowarn(const int category); -# define PERL_ARGS_ASSERT_GET_CATEGORY_INDEX_NOWARN +STATIC const char * +S_external_call_langinfo(pTHX_ const nl_item item, SV *sv, utf8ness_t *utf8ness); +# define PERL_ARGS_ASSERT_EXTERNAL_CALL_LANGINFO \ + assert(sv) + +STATIC locale_category_index +S_get_category_index_helper(pTHX_ const int category, bool *success, const line_t caller_line) + __attribute__warn_unused_result__; +# define PERL_ARGS_ASSERT_GET_CATEGORY_INDEX_HELPER + +STATIC const char * +S_native_querylocale_i(pTHX_ const locale_category_index cat_index); +# define PERL_ARGS_ASSERT_NATIVE_QUERYLOCALE_I + +STATIC void +S_new_LC_ALL(pTHX_ const char *lc_all, bool force); +# define PERL_ARGS_ASSERT_NEW_LC_ALL \ + assert(lc_all) STATIC void -S_new_LC_ALL(pTHX_ const char *unused, bool force); -# define PERL_ARGS_ASSERT_NEW_LC_ALL +S_output_check_environment_warning(pTHX_ const char * const language, const char * const lc_all, const char * const lang); +# define PERL_ARGS_ASSERT_OUTPUT_CHECK_ENVIRONMENT_WARNING + +STATIC parse_LC_ALL_string_return +S_parse_LC_ALL_string(pTHX_ const char *string, const char **output, const parse_LC_ALL_STRING_action, bool always_use_full_array, const bool panic_on_error, const line_t caller_line); +# define PERL_ARGS_ASSERT_PARSE_LC_ALL_STRING \ + assert(string); assert(output) STATIC void -S_restore_toggled_locale_i(pTHX_ const unsigned cat_index, const char *original_locale, const line_t caller_line); +S_restore_toggled_locale_i(pTHX_ const locale_category_index cat_index, const char *original_locale, const line_t caller_line); # define PERL_ARGS_ASSERT_RESTORE_TOGGLED_LOCALE_I STATIC const char * -S_save_to_buffer(const char *string, const char **buf, Size_t *buf_size); +S_save_to_buffer(pTHX_ const char *string, char **buf, Size_t *buf_size); # define PERL_ARGS_ASSERT_SAVE_TO_BUFFER +STATIC void +S_set_save_buffer_min_size(pTHX_ const Size_t min_len, char **buf, Size_t *buf_size); +# define PERL_ARGS_ASSERT_SET_SAVE_BUFFER_MIN_SIZE + PERL_STATIC_NO_RET void -S_setlocale_failure_panic_i(pTHX_ const unsigned int cat_index, const char *current, const char *failed, const line_t caller_0_line, const line_t caller_1_line) +S_setlocale_failure_panic_via_i(pTHX_ const locale_category_index cat_index, const char *current, const char *failed, const line_t proxy_caller_line, const line_t immediate_caller_line, const char *higher_caller_file, const line_t higher_caller_line) __attribute__noreturn__; -# define PERL_ARGS_ASSERT_SETLOCALE_FAILURE_PANIC_I \ - assert(failed) +# define PERL_ARGS_ASSERT_SETLOCALE_FAILURE_PANIC_VIA_I \ + assert(failed); assert(higher_caller_file) STATIC const char * -S_stdize_locale(pTHX_ const int category, const char *input_locale, const char **buf, Size_t *buf_size, line_t caller_line); -# define PERL_ARGS_ASSERT_STDIZE_LOCALE - -STATIC const char * -S_toggle_locale_i(pTHX_ const unsigned switch_cat_index, const char *new_locale, const line_t caller_line); +S_toggle_locale_i(pTHX_ const locale_category_index cat_index, const char *new_locale, const line_t caller_line); # define PERL_ARGS_ASSERT_TOGGLE_LOCALE_I \ assert(new_locale) # if defined(DEBUGGING) STATIC char * -S_my_setlocale_debug_string_i(pTHX_ const unsigned cat_index, const char *locale, const char *retval, const line_t line) +S_my_setlocale_debug_string_i(pTHX_ const locale_category_index cat_index, const char *locale, const char *retval, const line_t line) __attribute__warn_unused_result__; # define PERL_ARGS_ASSERT_MY_SETLOCALE_DEBUG_STRING_I # endif -# if defined(HAS_NL_LANGINFO) || defined(HAS_NL_LANGINFO_L) +# if defined(HAS_LOCALECONV) && \ + ( defined(USE_LOCALE_MONETARY) || defined(USE_LOCALE_NUMERIC) ) +STATIC void +S_populate_hash_from_localeconv(pTHX_ HV *hv, const char *locale, const U32 which_mask, const lconv_offset_t *strings[2], const lconv_offset_t *integers[2]); +# define PERL_ARGS_ASSERT_POPULATE_HASH_FROM_LOCALECONV \ + assert(hv); assert(locale); assert(strings); assert(integers) + +# endif +# if defined(HAS_NL_LANGINFO) STATIC const char * -S_my_langinfo_i(pTHX_ const nl_item item, const unsigned int cat_index, const char *locale, const char **retbufp, Size_t *retbuf_sizep, utf8ness_t *utf8ness); -# define PERL_ARGS_ASSERT_MY_LANGINFO_I \ - assert(locale); assert(retbufp) +S_langinfo_sv_i(pTHX_ const nl_item item, locale_category_index cat_index, const char *locale, SV *sv, utf8ness_t *utf8ness); +# define PERL_ARGS_ASSERT_LANGINFO_SV_I \ + assert(locale); assert(sv) + +# endif +# if defined(LC_ALL) +STATIC void +S_give_perl_locale_control(pTHX_ const char *lc_all_string, const line_t caller_line); +# define PERL_ARGS_ASSERT_GIVE_PERL_LOCALE_CONTROL \ + assert(lc_all_string) # else -STATIC const char * -S_my_langinfo_i(pTHX_ const int item, const unsigned int cat_index, const char *locale, const char **retbufp, Size_t *retbuf_sizep, utf8ness_t *utf8ness); -# define PERL_ARGS_ASSERT_MY_LANGINFO_I \ - assert(locale); assert(retbufp) +STATIC void +S_give_perl_locale_control(pTHX_ const char **curlocales, const line_t caller_line); +# define PERL_ARGS_ASSERT_GIVE_PERL_LOCALE_CONTROL \ + assert(curlocales) # endif # if !defined(PERL_NO_INLINE_FUNCTIONS) @@ -7064,31 +7186,22 @@ S_get_LC_ALL_display(pTHX); # endif # if defined(USE_POSIX_2008_LOCALE) -STATIC const char * -S_emulate_setlocale_i(pTHX_ const unsigned int index, const char *new_locale, const recalc_lc_all_t recalc_LC_ALL, const line_t line); -# define PERL_ARGS_ASSERT_EMULATE_SETLOCALE_I - -STATIC const char * -S_my_querylocale_i(pTHX_ const unsigned int index); -# define PERL_ARGS_ASSERT_MY_QUERYLOCALE_I +STATIC bool +S_bool_setlocale_2008_i(pTHX_ const locale_category_index index, const char *new_locale, const line_t caller_line); +# define PERL_ARGS_ASSERT_BOOL_SETLOCALE_2008_I \ + assert(new_locale) STATIC const char * -S_setlocale_from_aggregate_LC_ALL(pTHX_ const char *locale, const line_t line); -# define PERL_ARGS_ASSERT_SETLOCALE_FROM_AGGREGATE_LC_ALL \ - assert(locale) +S_querylocale_2008_i(pTHX_ const locale_category_index index, const line_t line); +# define PERL_ARGS_ASSERT_QUERYLOCALE_2008_I STATIC locale_t S_use_curlocale_scratch(pTHX); # define PERL_ARGS_ASSERT_USE_CURLOCALE_SCRATCH -# if defined(USE_QUERYLOCALE) -STATIC const char * -S_calculate_LC_ALL(pTHX_ const locale_t cur_obj); -# define PERL_ARGS_ASSERT_CALCULATE_LC_ALL - -# else -STATIC const char * -S_update_PL_curlocales_i(pTHX_ const unsigned int index, const char *new_locale, recalc_lc_all_t recalc_LC_ALL); +# if !defined(USE_QUERYLOCALE) +STATIC void +S_update_PL_curlocales_i(pTHX_ const locale_category_index index, const char *new_locale, const line_t caller_line); # define PERL_ARGS_ASSERT_UPDATE_PL_CURLOCALES_I \ assert(new_locale) @@ -7097,36 +7210,20 @@ S_update_PL_curlocales_i(pTHX_ const uns !defined(USE_THREAD_SAFE_LOCALE) && \ !defined(USE_THREAD_SAFE_LOCALE_EMULATION) /* && !defined(USE_POSIX_2008_LOCALE) */ -STATIC const char * -S_less_dicey_setlocale_r(pTHX_ const int category, const char *locale); -# define PERL_ARGS_ASSERT_LESS_DICEY_SETLOCALE_R - -STATIC void -S_less_dicey_void_setlocale_i(pTHX_ const unsigned cat_index, const char *locale, const line_t line); -# define PERL_ARGS_ASSERT_LESS_DICEY_VOID_SETLOCALE_I \ - assert(locale) - -# if 0 STATIC bool S_less_dicey_bool_setlocale_r(pTHX_ const int cat, const char *locale); -# define PERL_ARGS_ASSERT_LESS_DICEY_BOOL_SETLOCALE_R \ +# define PERL_ARGS_ASSERT_LESS_DICEY_BOOL_SETLOCALE_R \ assert(locale) -# endif +STATIC const char * +S_less_dicey_setlocale_r(pTHX_ const int category, const char *locale); +# define PERL_ARGS_ASSERT_LESS_DICEY_SETLOCALE_R + # endif /* defined(USE_LOCALE_THREADS) && !defined(USE_POSIX_2008_LOCALE) && !defined(USE_THREAD_SAFE_LOCALE) && !defined(USE_THREAD_SAFE_LOCALE_EMULATION) */ -# if !( defined(USE_POSIX_2008_LOCALE) && defined(USE_QUERYLOCALE) ) && \ - ( !defined(LC_ALL) || defined(USE_POSIX_2008_LOCALE) || \ - defined(WIN32) ) -STATIC const char * -S_calculate_LC_ALL(pTHX_ const char **individ_locales); -# define PERL_ARGS_ASSERT_CALCULATE_LC_ALL \ - assert(individ_locales) - -# endif -# if defined(WIN32) +# if defined(WIN32) || defined(WIN32_USE_FAKE_OLD_MINGW_LOCALES) STATIC wchar_t * S_Win_byte_string_to_wstring(const UINT code_page, const char *byte_string); # define PERL_ARGS_ASSERT_WIN_BYTE_STRING_TO_WSTRING @@ -7143,16 +7240,16 @@ STATIC const char * S_wrap_wsetlocale(pTHX_ const int category, const char *locale); # define PERL_ARGS_ASSERT_WRAP_WSETLOCALE -# endif /* defined(WIN32) */ -# if defined(WIN32) || \ +# endif /* defined(WIN32) || defined(WIN32_USE_FAKE_OLD_MINGW_LOCALES) */ +# if defined(WIN32) || defined(WIN32_USE_FAKE_OLD_MINGW_LOCALES) || \ ( defined(USE_POSIX_2008_LOCALE) && !defined(USE_QUERYLOCALE) ) STATIC const char * -S_find_locale_from_environment(pTHX_ const unsigned int index); +S_find_locale_from_environment(pTHX_ const locale_category_index index); # define PERL_ARGS_ASSERT_FIND_LOCALE_FROM_ENVIRONMENT # endif # endif /* defined(USE_LOCALE) */ -# if defined(USE_POSIX_2008_LOCALE) || defined(DEBUGGING) +# if defined(USE_LOCALE) || defined(DEBUGGING) STATIC const char * S_get_displayable_string(pTHX_ const char * const s, const char * const e, const bool is_utf8); # define PERL_ARGS_ASSERT_GET_DISPLAYABLE_STRING \ @@ -7402,6 +7499,11 @@ S_voidnonfinal(pTHX_ OP *o); # define PERL_ARGS_ASSERT_VOIDNONFINAL # if !defined(PERL_NO_INLINE_FUNCTIONS) +PERL_STATIC_INLINE bool +S_is_standard_filehandle_name(const char *fhname); +# define PERL_ARGS_ASSERT_IS_STANDARD_FILEHANDLE_NAME \ + assert(fhname) + PERL_STATIC_INLINE OP * S_newMETHOP_internal(pTHX_ I32 type, I32 flags, OP *dynamic_meth, SV * const_meth); # define PERL_ARGS_ASSERT_NEWMETHOP_INTERNAL @@ -7644,10 +7746,10 @@ S_refto(pTHX_ SV *sv) #if defined(PERL_IN_PP_C) || defined(PERL_IN_PP_HOT_C) PERL_CALLCONV GV * -Perl_softref2xv(pTHX_ SV * const sv, const char * const what, const svtype type, SV ***spp) +Perl_softref2xv(pTHX_ SV * const sv, const char * const what, const svtype type) __attribute__warn_unused_result__; # define PERL_ARGS_ASSERT_SOFTREF2XV \ - assert(sv); assert(what); assert(spp) + assert(sv); assert(what) #endif #if defined(PERL_IN_PP_C) || defined(PERL_IN_UTF8_C) @@ -8023,12 +8125,6 @@ Perl_get_ANYOFM_contents(pTHX_ const reg # define PERL_ARGS_ASSERT_GET_ANYOFM_CONTENTS \ assert(n) -PERL_CALLCONV bool -Perl_is_ssc_worth_it(const RExC_state_t *pRExC_state, const regnode_ssc *ssc) - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_IS_SSC_WORTH_IT \ - assert(pRExC_state); assert(ssc) - PERL_CALLCONV U32 Perl_join_exact(pTHX_ RExC_state_t *pRExC_state, regnode *scan, UV *min_subtract, bool *unfolded_multi_char, U32 flags, regnode *val, U32 depth) __attribute__visibility__("hidden"); @@ -8068,12 +8164,6 @@ Perl_set_ANYOF_arg(pTHX_ RExC_state_t * assert(pRExC_state); assert(node) PERL_CALLCONV void -Perl_ssc_finalize(pTHX_ RExC_state_t *pRExC_state, regnode_ssc *ssc) - __attribute__visibility__("hidden"); -# define PERL_ARGS_ASSERT_SSC_FINALIZE \ - assert(pRExC_state); assert(ssc) - -PERL_CALLCONV void Perl_ssc_init(pTHX_ const RExC_state_t *pRExC_state, regnode_ssc *ssc) __attribute__visibility__("hidden"); # define PERL_ARGS_ASSERT_SSC_INIT \ @@ -8206,6 +8296,11 @@ S_handle_user_defined_property(pTHX_ con # define PERL_ARGS_ASSERT_HANDLE_USER_DEFINED_PROPERTY \ assert(name); assert(contents); assert(user_defined_ptr); assert(msg) +STATIC bool +S_is_ssc_worth_it(const RExC_state_t *pRExC_state, const regnode_ssc *ssc); +# define PERL_ARGS_ASSERT_IS_SSC_WORTH_IT \ + assert(pRExC_state); assert(ssc) + STATIC void S_nextchar(pTHX_ RExC_state_t *pRExC_state); # define PERL_ARGS_ASSERT_NEXTCHAR \ @@ -8330,6 +8425,11 @@ S_skip_to_be_ignored_text(pTHX_ RExC_sta # define PERL_ARGS_ASSERT_SKIP_TO_BE_IGNORED_TEXT \ assert(pRExC_state); assert(p) +STATIC void +S_ssc_finalize(pTHX_ RExC_state_t *pRExC_state, regnode_ssc *ssc); +# define PERL_ARGS_ASSERT_SSC_FINALIZE \ + assert(pRExC_state); assert(ssc) + # if defined(DEBUGGING) STATIC regnode_offset S_regnode_guts_debug(pTHX_ RExC_state_t *pRExC_state, const U8 op, const STRLEN extra_len); @@ -8992,7 +9092,7 @@ S_utf8_mg_pos_cache_update(pTHX_ SV * co # define PERL_ARGS_ASSERT_UTF8_MG_POS_CACHE_UPDATE \ assert(sv); assert(mgp) -STATIC I32 +STATIC SSize_t S_visit(pTHX_ SVFUNC_t f, const U32 flags, const U32 mask); # define PERL_ARGS_ASSERT_VISIT \ assert(f) @@ -9003,7 +9103,17 @@ S_del_sv(pTHX_ SV *p); # define PERL_ARGS_ASSERT_DEL_SV \ assert(p) -# endif +PERL_CALLCONV void +Perl_sv_mark_arenas(pTHX) + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_SV_MARK_ARENAS + +PERL_CALLCONV void +Perl_sv_sweep_arenas(pTHX) + __attribute__visibility__("hidden"); +# define PERL_ARGS_ASSERT_SV_SWEEP_ARENAS + +# endif /* defined(DEBUGGING) */ # if !defined(NV_PRESERVES_UV) # if defined(DEBUGGING) STATIC int @@ -9398,7 +9508,7 @@ S_with_queued_errors(pTHX_ SV *ex); assert(ex) STATIC void -S_xs_version_bootcheck(pTHX_ U32 items, U32 ax, const char *xs_p, STRLEN xs_len); +S_xs_version_bootcheck(pTHX_ SSize_t items, SSize_t ax, const char *xs_p, STRLEN xs_len); # define PERL_ARGS_ASSERT_XS_VERSION_BOOTCHECK \ assert(xs_p) @@ -9460,7 +9570,7 @@ Perl_CvGV(pTHX_ CV *sv); # define PERL_ARGS_ASSERT_CVGV \ assert(sv) -PERL_STATIC_INLINE I32 +PERL_STATIC_INLINE Stack_off_t Perl_POPMARK(pTHX); # define PERL_ARGS_ASSERT_POPMARK @@ -9564,7 +9674,7 @@ Perl_SvUV_nomg(pTHX_ SV *sv); # define PERL_ARGS_ASSERT_SVUV_NOMG \ assert(sv) -PERL_STATIC_INLINE I32 +PERL_STATIC_INLINE Stack_off_t Perl_TOPMARK(pTHX); # define PERL_ARGS_ASSERT_TOPMARK @@ -9595,11 +9705,21 @@ Perl_av_push_simple(pTHX_ AV *av, SV *va # define PERL_ARGS_ASSERT_AV_PUSH_SIMPLE \ assert(av); assert(val) +PERL_STATIC_INLINE void +Perl_av_remove_offset(pTHX_ AV *av); +# define PERL_ARGS_ASSERT_AV_REMOVE_OFFSET \ + assert(av) + PERL_STATIC_INLINE SV ** Perl_av_store_simple(pTHX_ AV *av, SSize_t key, SV *val); # define PERL_ARGS_ASSERT_AV_STORE_SIMPLE \ assert(av) +PERL_STATIC_INLINE void +Perl_clear_defarray_simple(pTHX_ AV *av); +# define PERL_ARGS_ASSERT_CLEAR_DEFARRAY_SIMPLE \ + assert(av) + PERL_STATIC_INLINE I32 Perl_foldEQ(pTHX_ const char *a, const char *b, I32 len); # define PERL_ARGS_ASSERT_FOLDEQ \ @@ -9731,6 +9851,165 @@ Perl_newSV_type_mortal(pTHX_ const svtyp __attribute__always_inline__; # define PERL_ARGS_ASSERT_NEWSV_TYPE_MORTAL +PERL_STATIC_INLINE void +Perl_pop_stackinfo(pTHX); +# define PERL_ARGS_ASSERT_POP_STACKINFO + +PERL_STATIC_INLINE void +Perl_push_stackinfo(pTHX_ I32 type, UV flags); +# define PERL_ARGS_ASSERT_PUSH_STACKINFO + +PERL_STATIC_INLINE void +Perl_rpp_context(pTHX_ SV **mark, U8 gimme, SSize_t extra); +# define PERL_ARGS_ASSERT_RPP_CONTEXT \ + assert(mark) + +PERL_STATIC_INLINE void +Perl_rpp_extend(pTHX_ SSize_t n); +# define PERL_ARGS_ASSERT_RPP_EXTEND + +PERL_STATIC_INLINE void +Perl_rpp_invoke_xs(pTHX_ CV *cv); +# define PERL_ARGS_ASSERT_RPP_INVOKE_XS \ + assert(cv) + +PERL_STATIC_INLINE bool +Perl_rpp_is_lone(pTHX_ SV *sv); +# define PERL_ARGS_ASSERT_RPP_IS_LONE \ + assert(sv) + +PERL_STATIC_INLINE SV * +Perl_rpp_pop_1_norc(pTHX); +# define PERL_ARGS_ASSERT_RPP_POP_1_NORC + +PERL_STATIC_INLINE void +Perl_rpp_popfree_1(pTHX); +# define PERL_ARGS_ASSERT_RPP_POPFREE_1 + +PERL_STATIC_INLINE void +Perl_rpp_popfree_1_NN(pTHX); +# define PERL_ARGS_ASSERT_RPP_POPFREE_1_NN + +PERL_STATIC_INLINE void +Perl_rpp_popfree_2(pTHX); +# define PERL_ARGS_ASSERT_RPP_POPFREE_2 + +PERL_STATIC_INLINE void +Perl_rpp_popfree_2_NN(pTHX); +# define PERL_ARGS_ASSERT_RPP_POPFREE_2_NN + +PERL_STATIC_INLINE void +Perl_rpp_popfree_to(pTHX_ SV **sp); +# define PERL_ARGS_ASSERT_RPP_POPFREE_TO \ + assert(sp) + +PERL_STATIC_INLINE void +Perl_rpp_popfree_to_NN(pTHX_ SV **sp); +# define PERL_ARGS_ASSERT_RPP_POPFREE_TO_NN \ + assert(sp) + +PERL_STATIC_INLINE void +Perl_rpp_push_1(pTHX_ SV *sv); +# define PERL_ARGS_ASSERT_RPP_PUSH_1 \ + assert(sv) + +PERL_STATIC_INLINE void +Perl_rpp_push_1_norc(pTHX_ SV *sv); +# define PERL_ARGS_ASSERT_RPP_PUSH_1_NORC \ + assert(sv) + +PERL_STATIC_INLINE void +Perl_rpp_push_2(pTHX_ SV *sv1, SV *sv2); +# define PERL_ARGS_ASSERT_RPP_PUSH_2 \ + assert(sv1); assert(sv2) + +PERL_STATIC_INLINE void +Perl_rpp_push_IMM(pTHX_ SV *sv); +# define PERL_ARGS_ASSERT_RPP_PUSH_IMM \ + assert(sv) + +PERL_STATIC_INLINE void +Perl_rpp_replace_1_1(pTHX_ SV *sv); +# define PERL_ARGS_ASSERT_RPP_REPLACE_1_1 \ + assert(sv) + +PERL_STATIC_INLINE void +Perl_rpp_replace_1_1_NN(pTHX_ SV *sv); +# define PERL_ARGS_ASSERT_RPP_REPLACE_1_1_NN \ + assert(sv) + +PERL_STATIC_INLINE void +Perl_rpp_replace_1_IMM_NN(pTHX_ SV *sv); +# define PERL_ARGS_ASSERT_RPP_REPLACE_1_IMM_NN \ + assert(sv) + +PERL_STATIC_INLINE void +Perl_rpp_replace_2_1(pTHX_ SV *sv); +# define PERL_ARGS_ASSERT_RPP_REPLACE_2_1 \ + assert(sv) + +PERL_STATIC_INLINE void +Perl_rpp_replace_2_1_COMMON(pTHX_ SV *sv); +# define PERL_ARGS_ASSERT_RPP_REPLACE_2_1_COMMON \ + assert(sv) + +PERL_STATIC_INLINE void +Perl_rpp_replace_2_1_NN(pTHX_ SV *sv); +# define PERL_ARGS_ASSERT_RPP_REPLACE_2_1_NN \ + assert(sv) + +PERL_STATIC_INLINE void +Perl_rpp_replace_2_IMM_NN(pTHX_ SV *sv); +# define PERL_ARGS_ASSERT_RPP_REPLACE_2_IMM_NN \ + assert(sv) + +PERL_STATIC_INLINE void +Perl_rpp_replace_at(pTHX_ SV **sp, SV *sv); +# define PERL_ARGS_ASSERT_RPP_REPLACE_AT \ + assert(sp); assert(sv) + +PERL_STATIC_INLINE void +Perl_rpp_replace_at_NN(pTHX_ SV **sp, SV *sv); +# define PERL_ARGS_ASSERT_RPP_REPLACE_AT_NN \ + assert(sp); assert(sv) + +PERL_STATIC_INLINE void +Perl_rpp_replace_at_norc(pTHX_ SV **sp, SV *sv); +# define PERL_ARGS_ASSERT_RPP_REPLACE_AT_NORC \ + assert(sp); assert(sv) + +PERL_STATIC_INLINE void +Perl_rpp_replace_at_norc_NN(pTHX_ SV **sp, SV *sv); +# define PERL_ARGS_ASSERT_RPP_REPLACE_AT_NORC_NN \ + assert(sp); assert(sv) + +PERL_STATIC_INLINE bool +Perl_rpp_stack_is_rc(pTHX); +# define PERL_ARGS_ASSERT_RPP_STACK_IS_RC + +PERL_STATIC_INLINE bool +Perl_rpp_try_AMAGIC_1(pTHX_ int method, int flags); +# define PERL_ARGS_ASSERT_RPP_TRY_AMAGIC_1 + +PERL_STATIC_INLINE bool +Perl_rpp_try_AMAGIC_2(pTHX_ int method, int flags); +# define PERL_ARGS_ASSERT_RPP_TRY_AMAGIC_2 + +PERL_STATIC_INLINE void +Perl_rpp_xpush_1(pTHX_ SV *sv); +# define PERL_ARGS_ASSERT_RPP_XPUSH_1 \ + assert(sv) + +PERL_STATIC_INLINE void +Perl_rpp_xpush_2(pTHX_ SV *sv1, SV *sv2); +# define PERL_ARGS_ASSERT_RPP_XPUSH_2 \ + assert(sv1); assert(sv2) + +PERL_STATIC_INLINE void +Perl_rpp_xpush_IMM(pTHX_ SV *sv); +# define PERL_ARGS_ASSERT_RPP_XPUSH_IMM \ + assert(sv) + PERL_STATIC_INLINE char * Perl_savepv(pTHX_ const char *pv) __attribute__malloc__ @@ -9782,6 +10061,11 @@ Perl_sv_setpv_freshbuf(pTHX_ SV * const # define PERL_ARGS_ASSERT_SV_SETPV_FRESHBUF \ assert(sv) +PERL_STATIC_INLINE void +Perl_switch_argstack(pTHX_ AV *to); +# define PERL_ARGS_ASSERT_SWITCH_ARGSTACK \ + assert(to) + PERL_STATIC_INLINE IV Perl_utf8_distance(pTHX_ const U8 *a, const U8 *b) __attribute__warn_unused_result__; @@ -10114,6 +10398,22 @@ Perl_get_context(void) # endif #endif /* !defined(PERL_NO_INLINE_FUNCTIONS) */ +#if defined(PERL_RC_STACK) +PERL_CALLCONV OP * +Perl_pp_wrap(pTHX_ Perl_ppaddr_t real_pp_fn, I32 nargs, int nlists); +# define PERL_ARGS_ASSERT_PP_WRAP \ + assert(real_pp_fn) + +PERL_CALLCONV int +Perl_runops_wrap(pTHX); +# define PERL_ARGS_ASSERT_RUNOPS_WRAP + +PERL_CALLCONV void +Perl_xs_wrap(pTHX_ XSUBADDR_t xsub, CV *cv); +# define PERL_ARGS_ASSERT_XS_WRAP \ + assert(xsub); assert(cv) + +#endif /* defined(PERL_RC_STACK) */ #if defined(PERL_USE_3ARG_SIGHANDLER) PERL_CALLCONV Signal_t Perl_csighandler(int sig, Siginfo_t *info, void *uap); @@ -10377,6 +10677,12 @@ Perl_mem_collxfrm_(pTHX_ const char *inp # endif #endif /* defined(USE_LOCALE_COLLATE) */ +#if defined(USE_LOCALE_CTYPE) +PERL_CALLCONV void +Perl_warn_problematic_locale(void); +# define PERL_ARGS_ASSERT_WARN_PROBLEMATIC_LOCALE + +#endif #if defined(USE_PERLIO) PERL_CALLCONV void Perl_PerlIO_clearerr(pTHX_ PerlIO *f); @@ -10485,7 +10791,7 @@ Perl_PerlIO_write(pTHX_ PerlIO *f, const #endif /* defined(USE_PERLIO) */ #if defined(USE_PERL_SWITCH_LOCALE_CONTEXT) PERL_CALLCONV void -Perl_switch_locale_context(void); +Perl_switch_locale_context(pTHX); # define PERL_ARGS_ASSERT_SWITCH_LOCALE_CONTEXT #endif @@ -10503,6 +10809,16 @@ Perl_quadmath_format_valid(const char *f assert(format) #endif /* defined(USE_QUADMATH) */ +#if defined(USE_THREADS) +PERL_CALLCONV void +Perl_thread_locale_init(pTHX); +# define PERL_ARGS_ASSERT_THREAD_LOCALE_INIT + +PERL_CALLCONV void +Perl_thread_locale_term(pTHX); +# define PERL_ARGS_ASSERT_THREAD_LOCALE_TERM + +#endif #if defined(VMS) || defined(WIN32) PERL_CALLCONV int Perl_do_aspawn(pTHX_ SV *really, SV **mark, SV **sp); Index: gnu/usr.bin/perl/reentr.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/reentr.c,v diff -u -p -a -u -p -r1.6 reentr.c --- gnu/usr.bin/perl/reentr.c 14 May 2024 19:38:54 -0000 1.6 +++ gnu/usr.bin/perl/reentr.c 22 Jan 2025 00:37:45 -0000 @@ -2,7 +2,9 @@ * * reentr.c * - * Copyright (C) 2002, 2003, 2005, 2006, 2007 by Larry Wall and others + * Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011, + * 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, + * 2024 by Larry Wall and others * * You may distribute under the terms of either the GNU General Public * License or the Artistic License, as specified in the README file. @@ -155,7 +157,7 @@ Perl_reentrant_size(pTHX) { # endif /* HAS_SETLOCALE_R */ # ifdef HAS_STRERROR_R - PL_reentrant_buffer->_strerror_size = REENTRANTSMALLSIZE; + PL_reentrant_buffer->_strerror_size = 1024; # endif /* HAS_STRERROR_R */ # ifdef HAS_TTYNAME_R Index: gnu/usr.bin/perl/reentr.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/reentr.h,v diff -u -p -a -u -p -r1.1.1.13 reentr.h --- gnu/usr.bin/perl/reentr.h 14 May 2024 19:36:00 -0000 1.1.1.13 +++ gnu/usr.bin/perl/reentr.h 22 Jan 2025 00:37:45 -0000 @@ -2,7 +2,9 @@ * * reentr.h * - * Copyright (C) 2002, 2003, 2005, 2006, 2007 by Larry Wall and others + * Copyright (C) 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011, + * 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, + * 2024 by Larry Wall and others * * You may distribute under the terms of either the GNU General Public * License or the Artistic License, as specified in the README file. @@ -1695,6 +1697,6 @@ typedef struct { #endif /* USE_REENTRANT_API */ -#endif +#endif /* File hasn't already been #included */ /* ex: set ro ft=c: */ Index: gnu/usr.bin/perl/regcharclass.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/regcharclass.h,v diff -u -p -a -u -p -r1.7 regcharclass.h --- gnu/usr.bin/perl/regcharclass.h 14 May 2024 19:38:54 -0000 1.7 +++ gnu/usr.bin/perl/regcharclass.h 22 Jan 2025 00:37:45 -0000 @@ -3850,7 +3850,7 @@ * 3f4f32ed2a577344a508114527e721d7a8b633d32f38945d47fe0c743650c585 lib/unicore/extracted/DLineBreak.txt * 710abf2d581ac9c57f244c0834f9d9969d9781e0396adccd330eaae658ac7d6b lib/unicore/extracted/DNumType.txt * 6bd30f385f3baf3ab5d5308c111a81de87bea5f494ba0ba69e8ab45263b8c34d lib/unicore/extracted/DNumValues.txt - * f7265069b38ba9a0675a18600e241b1ec6fc8c55fd806fe4c13bc5d8cb0dc508 lib/unicore/mktables + * 8968a5ee00063fa31ff15474b95ccb6b9c228e3ebad6c20bc77f4225187e2023 lib/unicore/mktables * 55d90fdc3f902e5c0b16b3378f9eaa36e970a1c09723c33de7d47d0370044012 lib/unicore/version * 0a6b5ab33bb1026531f816efe81aea1a8ffcd34a27cbea37dd6a70a63d73c844 regen/charset_translations.pl * acc94e4afc339fe2cf2ae74d6e1cbcf2c396328d78e56236ad314eadbfc84125 regen/regcharclass.pl Index: gnu/usr.bin/perl/regcomp.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/regcomp.c,v diff -u -p -a -u -p -r1.35 regcomp.c --- gnu/usr.bin/perl/regcomp.c 14 May 2024 19:38:54 -0000 1.35 +++ gnu/usr.bin/perl/regcomp.c 22 Jan 2025 00:37:45 -0000 @@ -17,7 +17,7 @@ * debugging support added, which makes "use re 'debug'" work. */ -/* NOTE: this is derived from Henry Spencer's regexp code, and should not +/* NOTE: this is derived from Henry Spencer's regexp code, and should not be * confused with the original package (see point 3 below). Thanks, Henry! */ @@ -290,6 +290,7 @@ S_edit_distance(const UV* src, /* END of edit_distance() stuff * ========================================================= */ +#ifdef PERL_RE_BUILD_AUX /* add a data member to the struct reg_data attached to this regex, it should * always return a non-zero return. the 's' argument is the type of the items * being added and the n is the number of items. The length of 's' should match @@ -340,6 +341,7 @@ Perl_reg_add_data(RExC_state_t* const pR assert(count>0); return count; } +#endif /* PERL_RE_BUILD_AUX */ /*XXX: todo make this not included in a non debugging perl, but appears to be * used anyway there, in 'use re' */ @@ -387,17 +389,9 @@ Perl_reginitcolors(pTHX) #define CHECK_RESTUDY_GOTO_butfirst #endif -/* - * pregcomp - compile a regular expression into internal code - * - * Decides which engine's compiler to call based on the hint currently in - * scope - */ - #ifndef PERL_IN_XSUB_RE /* return the currently in-scope regex engine (or the default if none) */ - regexp_engine const * Perl_current_re_engine(pTHX) { @@ -424,6 +418,13 @@ Perl_current_re_engine(pTHX) } +/* + * pregcomp - compile a regular expression into internal code + * + * Decides which engine's compiler to call based on the hint currently in + * scope + */ + REGEXP * Perl_pregcomp(pTHX_ SV * const pattern, const U32 flags) { @@ -688,7 +689,7 @@ S_concat_pat(pTHX_ RExC_state_t * const oplist = OpSIBLING(oplist); /* skip CONST */ assert(oplist); } - oplist = OpSIBLING(oplist);; + oplist = OpSIBLING(oplist); } /* apply magic and QR overloading to arg */ @@ -1211,6 +1212,120 @@ S_set_regex_pv(pTHX_ RExC_state_t *pRExC SvCUR_set(Rx, p - RX_WRAPPED(Rx)); } +STATIC void +S_ssc_finalize(pTHX_ RExC_state_t *pRExC_state, regnode_ssc *ssc) +{ + /* The inversion list in the SSC is marked mortal; now we need a more + * permanent copy, which is stored the same way that is done in a regular + * ANYOF node, with the first NUM_ANYOF_CODE_POINTS code points in a bit + * map */ + + SV* invlist = invlist_clone(ssc->invlist, NULL); + + PERL_ARGS_ASSERT_SSC_FINALIZE; + + assert(is_ANYOF_SYNTHETIC(ssc)); + + /* The code in this file assumes that all but these flags aren't relevant + * to the SSC, except SSC_MATCHES_EMPTY_STRING, which should be cleared + * by the time we reach here */ + assert(! (ANYOF_FLAGS(ssc) + & ~( ANYOF_COMMON_FLAGS + |ANYOFD_NON_UTF8_MATCHES_ALL_NON_ASCII__shared + |ANYOF_HAS_EXTRA_RUNTIME_MATCHES))); + + populate_anyof_bitmap_from_invlist( (regnode *) ssc, &invlist); + + set_ANYOF_arg(pRExC_state, (regnode *) ssc, invlist, NULL, NULL); + SvREFCNT_dec(invlist); + + /* Make sure is clone-safe */ + ssc->invlist = NULL; + + if (ANYOF_POSIXL_SSC_TEST_ANY_SET(ssc)) { + ANYOF_FLAGS(ssc) |= ANYOF_MATCHES_POSIXL; + OP(ssc) = ANYOFPOSIXL; + } + else if (RExC_contains_locale) { + OP(ssc) = ANYOFL; + } + + assert(! (ANYOF_FLAGS(ssc) & ANYOF_LOCALE_FLAGS) || RExC_contains_locale); +} + +STATIC bool +S_is_ssc_worth_it(const RExC_state_t * pRExC_state, const regnode_ssc * ssc) +{ + /* The synthetic start class is used to hopefully quickly winnow down + * places where a pattern could start a match in the target string. If it + * doesn't really narrow things down that much, there isn't much point to + * having the overhead of using it. This function uses some very crude + * heuristics to decide if to use the ssc or not. + * + * It returns TRUE if 'ssc' rules out more than half what it considers to + * be the "likely" possible matches, but of course it doesn't know what the + * actual things being matched are going to be; these are only guesses + * + * For /l matches, it assumes that the only likely matches are going to be + * in the 0-255 range, uniformly distributed, so half of that is 127 + * For /a and /d matches, it assumes that the likely matches will be just + * the ASCII range, so half of that is 63 + * For /u and there isn't anything matching above the Latin1 range, it + * assumes that that is the only range likely to be matched, and uses + * half that as the cut-off: 127. If anything matches above Latin1, + * it assumes that all of Unicode could match (uniformly), except for + * non-Unicode code points and things in the General Category "Other" + * (unassigned, private use, surrogates, controls and formats). This + * is a much large number. */ + + U32 count = 0; /* Running total of number of code points matched by + 'ssc' */ + UV start, end; /* Start and end points of current range in inversion + XXX outdated. UTF-8 locales are common, what about invert? list */ + const U32 max_code_points = (LOC) + ? 256 + : (( ! UNI_SEMANTICS + || invlist_highest(ssc->invlist) < 256) + ? 128 + : NON_OTHER_COUNT); + const U32 max_match = max_code_points / 2; + + PERL_ARGS_ASSERT_IS_SSC_WORTH_IT; + + invlist_iterinit(ssc->invlist); + while (invlist_iternext(ssc->invlist, &start, &end)) { + if (start >= max_code_points) { + break; + } + end = MIN(end, max_code_points - 1); + count += end - start + 1; + if (count >= max_match) { + invlist_iterfinish(ssc->invlist); + return FALSE; + } + } + + return TRUE; +} + +static void +release_RExC_state(pTHX_ void *vstate) { + RExC_state_t *pRExC_state = (RExC_state_t *)vstate; + + /* Any or all of these might be NULL. + + There's no point in setting them to NULL after the free, since + pRExC_state is about to be released. + */ + SvREFCNT_dec(RExC_rx_sv); + Safefree(RExC_open_parens); + Safefree(RExC_close_parens); + Safefree(RExC_logical_to_parno); + Safefree(RExC_parno_to_logical); + + Safefree(pRExC_state); +} + /* * Perl_re_op_compile - the perl internal RE engine's function to compile a * regular expression into internal code. @@ -1292,8 +1407,7 @@ Perl_re_op_compile(pTHX_ SV ** const pat bool recompile = 0; bool runtime_code = 0; scan_data_t data; - RExC_state_t RExC_state; - RExC_state_t * const pRExC_state = &RExC_state; + #ifdef TRIE_STUDY_OPT /* search for "restudy" in this file for a detailed explanation */ int restudied = 0; @@ -1305,10 +1419,25 @@ Perl_re_op_compile(pTHX_ SV ** const pat DEBUG_r(if (!PL_colorset) reginitcolors()); + RExC_state_t *pRExC_state = NULL; + /* Ensure that all members of the pRExC_state is initialized to 0 + * at the start of regex compilation. Historically we have had issues + * with people remembering to zero specific members or zeroing them + * too late, etc. Doing it in one place is saner and avoid oversight + * or error. */ + Newxz(pRExC_state, 1, RExC_state_t); - pRExC_state->warn_text = NULL; - pRExC_state->unlexed_names = NULL; - pRExC_state->code_blocks = NULL; + SAVEDESTRUCTOR_X(release_RExC_state, pRExC_state); + + DEBUG_r({ + /* and then initialize RExC_mysv1 and RExC_mysv2 early so if + * something calls regprop we don't have issues. These variables + * not being set up properly motivated the use of Newxz() to initalize + * the pRExC_state structure, as there were codepaths under -Uusedl + * that left these unitialized, and non-null as well. */ + RExC_mysv1 = sv_newmortal(); + RExC_mysv2 = sv_newmortal(); + }); if (is_bare_re) *is_bare_re = FALSE; @@ -1414,40 +1543,11 @@ Perl_re_op_compile(pTHX_ SV ** const pat /* ignore the utf8ness if the pattern is 0 length */ RExC_utf8 = RExC_orig_utf8 = (plen == 0 || IN_BYTES) ? 0 : SvUTF8(pat); - RExC_uni_semantics = 0; - RExC_contains_locale = 0; RExC_strict = cBOOL(pm_flags & RXf_PMf_STRICT); - RExC_in_script_run = 0; - RExC_study_started = 0; - pRExC_state->runtime_code_qr = NULL; - RExC_frame_head= NULL; - RExC_frame_last= NULL; - RExC_frame_count= 0; - RExC_latest_warn_offset = 0; - RExC_use_BRANCHJ = 0; - RExC_warned_WARN_EXPERIMENTAL__VLB = 0; - RExC_warned_WARN_EXPERIMENTAL__REGEX_SETS = 0; - RExC_logical_total_parens = 0; - RExC_total_parens = 0; - RExC_logical_to_parno = NULL; - RExC_parno_to_logical = NULL; - RExC_open_parens = NULL; - RExC_close_parens = NULL; - RExC_paren_names = NULL; - RExC_size = 0; - RExC_seen_d_op = FALSE; -#ifdef DEBUGGING - RExC_paren_name_list = NULL; -#endif - DEBUG_r({ - RExC_mysv1= sv_newmortal(); - RExC_mysv2= sv_newmortal(); - }); DEBUG_COMPILE_r({ - SV *dsv= sv_newmortal(); - RE_PV_QUOTED_DECL(s, RExC_utf8, dsv, exp, plen, PL_dump_re_max_len); + RE_PV_QUOTED_DECL(s, RExC_utf8, RExC_mysv, exp, plen, PL_dump_re_max_len); Perl_re_printf( aTHX_ "%sCompiling REx%s %s\n", PL_colors[4], PL_colors[5], s); }); @@ -1468,7 +1568,12 @@ Perl_re_op_compile(pTHX_ SV ** const pat * pattern. * * Things get a touch tricky as we have to compare the utf8 flag - * independently from the compile flags. */ + * independently from the compile flags. + * + * ALSO NOTE: After this point we may need to zero members of pRExC_state + * explicitly. Prior to this point they should all be zeroed as part of + * a struct wide Zero instruction. + */ if ( old_re && !recompile @@ -1479,8 +1584,7 @@ Perl_re_op_compile(pTHX_ SV ** const pat && !runtime_code /* with runtime code, always recompile */ ) { DEBUG_COMPILE_r({ - SV *dsv= sv_newmortal(); - RE_PV_QUOTED_DECL(s, RExC_utf8, dsv, exp, plen, PL_dump_re_max_len); + RE_PV_QUOTED_DECL(s, RExC_utf8, RExC_mysv, exp, plen, PL_dump_re_max_len); Perl_re_printf( aTHX_ "%sSkipping recompilation of unchanged REx%s %s\n", PL_colors[4], PL_colors[5], s); }); @@ -1494,6 +1598,8 @@ Perl_re_op_compile(pTHX_ SV ** const pat FAIL("Regexp out of space"); rx_flags = orig_rx_flags; + if (rx_flags & RXf_SPLIT) + rx_flags &= ~(RXf_PMf_EXTENDED|RXf_PMf_EXTENDED_MORE); if ( toUSE_UNI_CHARSET_NOT_DEPENDS && initial_charset == REGEX_DEPENDS_CHARSET) @@ -1706,6 +1812,7 @@ Perl_re_op_compile(pTHX_ SV ** const pat /* Clean up what we did in this parse */ SvREFCNT_dec_NN(RExC_rx_sv); + RExC_rx_sv = NULL; goto redo_parse; } @@ -1734,7 +1841,7 @@ Perl_re_op_compile(pTHX_ SV ** const pat SetProgLen(RExC_rxi,RExC_size); DEBUG_DUMP_PRE_OPTIMIZE_r({ - SV * const sv = sv_newmortal(); + SV * const sv = sv_newmortal(); /* can this use RExC_mysv? */ RXi_GET_DECL(RExC_rx, ri); DEBUG_RExC_seen(); Perl_re_printf( aTHX_ "Program before optimization:\n"); @@ -1781,12 +1888,12 @@ Perl_re_op_compile(pTHX_ SV ** const pat /* search for "restudy" in this file for a detailed explanation */ if (!restudied) { StructCopy(&zero_scan_data, &data, scan_data_t); - copyRExC_state = RExC_state; + copyRExC_state = *pRExC_state; } else { U32 seen=RExC_seen; DEBUG_OPTIMISE_r(Perl_re_printf( aTHX_ "Restudying\n")); - RExC_state = copyRExC_state; + *pRExC_state = copyRExC_state; if (seen & REG_TOP_LEVEL_BRANCHES_SEEN) RExC_seen |= REG_TOP_LEVEL_BRANCHES_SEEN; else @@ -2305,22 +2412,10 @@ Perl_re_op_compile(pTHX_ SV ** const pat regdump(RExC_rx); }); - if (RExC_open_parens) { - Safefree(RExC_open_parens); - RExC_open_parens = NULL; - } - if (RExC_close_parens) { - Safefree(RExC_close_parens); - RExC_close_parens = NULL; - } - if (RExC_logical_to_parno) { - Safefree(RExC_logical_to_parno); - RExC_logical_to_parno = NULL; - } - if (RExC_parno_to_logical) { - Safefree(RExC_parno_to_logical); - RExC_parno_to_logical = NULL; - } + /* we're returning ownership of the SV to the caller, ensure the cleanup + * doesn't release it + */ + RExC_rx_sv = NULL; #ifdef USE_ITHREADS /* under ithreads the ?pat? PMf_USED flag on the pmop is simulated @@ -7443,6 +7538,7 @@ S_regatom(pTHX_ RExC_state_t *pRExC_stat } +#ifdef PERL_RE_BUILD_AUX void Perl_populate_anyof_bitmap_from_invlist(pTHX_ regnode *node, SV** invlist_ptr) { @@ -7502,6 +7598,7 @@ Perl_populate_anyof_bitmap_from_invlist( } } } +#endif /* PERL_RE_BUILD_AUX */ /* Parse POSIX character classes: [[:foo:]], [[=foo=]], [[.foo.]]. Character classes ([:foo:]) can also be negated ([:^foo:]). @@ -7712,7 +7809,7 @@ S_handle_possible_posix(pTHX_ RExC_state /* These two constructs are not handled by perl, and if we find a * syntactically valid one, we croak. khw, who wrote this code, finds * this explanation of them very unclear: - * http://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap09.html + * https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap09.html * And searching the rest of the internet wasn't very helpful either. * It looks like just about any byte can be in these constructs, * depending on the locale. But unless the pattern is being compiled @@ -9095,6 +9192,7 @@ S_dump_regex_sets_structures(pTHX_ RExC_ #undef IS_OPERATOR #undef IS_OPERAND +#ifdef PERL_RE_BUILD_AUX void Perl_add_above_Latin1_folds(pTHX_ RExC_state_t *pRExC_state, const U8 cp, SV** invlist) { @@ -9182,6 +9280,8 @@ Perl_add_above_Latin1_folds(pTHX_ RExC_s } } } +#endif /* PERL_RE_BUILD_AUX */ + STATIC void S_output_posix_warnings(pTHX_ RExC_state_t *pRExC_state, AV* posix_warnings) @@ -9205,7 +9305,6 @@ S_output_posix_warnings(pTHX_ RExC_state array is mortal, but is a fail-safe */ (void) sv_2mortal(msg); - PREPARE_TO_DIE; } Perl_warner(aTHX_ packWARN(WARN_REGEXP), "%s", SvPVX(msg)); SvREFCNT_dec_NN(msg); @@ -11091,7 +11190,7 @@ S_regclass(pTHX_ RExC_state_t *pRExC_sta /* If optimized to something else and emitted, clean up and return */ if (ret >= 0) { - SvREFCNT_dec(cp_list);; + SvREFCNT_dec(cp_list); SvREFCNT_dec(only_utf8_locale_list); SvREFCNT_dec(upper_latin1_only_utf8_matches); return ret; @@ -11161,7 +11260,7 @@ S_regclass(pTHX_ RExC_state_t *pRExC_sta : NULL, only_utf8_locale_list); - SvREFCNT_dec(cp_list);; + SvREFCNT_dec(cp_list); SvREFCNT_dec(only_utf8_locale_list); return ret; } @@ -11632,7 +11731,7 @@ S_optimize_regclass(pTHX_ * convert to UTF-8 if not already there */ if (value > 255) { if (! UTF) { - SvREFCNT_dec(cp_list);; + SvREFCNT_dec(cp_list); REQUIRE_UTF8(flagp); } @@ -11760,7 +11859,7 @@ S_optimize_regclass(pTHX_ { U8 ANYOFM_mask; - op = ANYOFM + inverted;; + op = ANYOFM + inverted; /* We need to make the bits that differ be 0's */ ANYOFM_mask = ~ bits_differing; /* This goes into FLAGS */ @@ -12093,6 +12192,7 @@ S_optimize_regclass(pTHX_ return_OPFAIL: op = OPFAIL; + *flagp &= ~(SIMPLE|HASWIDTH); *ret = reg1node(pRExC_state, op, 0); return op; @@ -12105,6 +12205,7 @@ S_optimize_regclass(pTHX_ #undef HAS_NONLOCALE_RUNTIME_PROPERTY_DEFINITION +#ifdef PERL_RE_BUILD_AUX void Perl_set_ANYOF_arg(pTHX_ RExC_state_t* const pRExC_state, regnode* const node, @@ -12261,6 +12362,7 @@ Perl_set_ANYOF_arg(pTHX_ RExC_state_t* c RExC_rxi->data->data[n] = (void*)rv; ARG1u_SET(node, n); } +#endif /* PERL_RE_BUILD_AUX */ SV * @@ -12999,6 +13101,8 @@ S_regtail_study(pTHX_ RExC_state_t *pREx } #endif + +#ifdef PERL_RE_BUILD_AUX SV* Perl_get_ANYOFM_contents(pTHX_ const regnode * n) { @@ -13047,7 +13151,7 @@ Perl_get_ANYOFHbbm_contents(pTHX_ const UTF_CONTINUATION_MARK | 0)); return cp_list; } - +#endif /* PERL_RE_BUILD_AUX */ SV * @@ -15496,7 +15600,7 @@ S_parse_uniprop_string(pTHX_ * property hasn't been encountered yet, but at runtime, it's * an error to try to use an undefined one */ if (! deferrable) { - goto unknown_user_defined;; + goto unknown_user_defined; } goto definition_deferred; @@ -15617,7 +15721,7 @@ S_parse_uniprop_string(pTHX_ } /* Get the greatest common denominator using - http://en.wikipedia.org/wiki/Euclidean_algorithm */ + https://en.wikipedia.org/wiki/Euclidean_algorithm */ gcd = numerator; trial = denominator; while (trial != 0) { Index: gnu/usr.bin/perl/regcomp.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/regcomp.h,v diff -u -p -a -u -p -r1.21 regcomp.h --- gnu/usr.bin/perl/regcomp.h 14 May 2024 19:38:54 -0000 1.21 +++ gnu/usr.bin/perl/regcomp.h 22 Jan 2025 00:37:45 -0000 @@ -1554,7 +1554,19 @@ typedef enum { #define EVAL_OPTIMISTIC_FLAG 128 #define EVAL_FLAGS_MASK (EVAL_OPTIMISTIC_FLAG-1) - +/* We define PERL_RE_BUILD_DEBUG if we are NOT compiling the re extension and + * we are under DEBUGGING, or if we are ARE compiling the re extension + * and this is not a DEBUGGING enabled build (identified by + * DEBUGGING_RE_ONLY being defined) + */ +#if ( !defined(PERL_EXT_RE_STATIC) && defined(DEBUGGING)) || \ + ( defined(PERL_EXT_RE_BUILD) && defined(DEBUGGING_RE_ONLY)) || \ + (!defined(PERL_EXT_RE_BUILD) && defined(DEBUGGING)) +#define PERL_RE_BUILD_DEBUG +#endif +#if !defined(PERL_EXT_RE_STATIC) +#define PERL_RE_BUILD_AUX +#endif #endif /* PERL_REGCOMP_H_ */ Index: gnu/usr.bin/perl/regcomp_debug.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/regcomp_debug.c,v diff -u -p -a -u -p -r1.1.1.1 regcomp_debug.c --- gnu/usr.bin/perl/regcomp_debug.c 14 May 2024 19:36:28 -0000 1.1.1.1 +++ gnu/usr.bin/perl/regcomp_debug.c 22 Jan 2025 00:37:45 -0000 @@ -18,8 +18,7 @@ #include "unicode_constants.h" #include "regcomp_internal.h" -#ifdef DEBUGGING - +#ifdef PERL_RE_BUILD_DEBUG int Perl_re_printf(pTHX_ const char *fmt, ...) { @@ -159,22 +158,169 @@ Perl_debug_peep(pTHX_ const char *str, c }); } -#endif /* DEBUGGING */ +const regnode * +Perl_dumpuntil(pTHX_ const regexp *r, const regnode *start, const regnode *node, + const regnode *last, const regnode *plast, + SV* sv, I32 indent, U32 depth) +{ + const regnode *next; + const regnode *optstart= NULL; + + RXi_GET_DECL(r, ri); + DECLARE_AND_GET_RE_DEBUG_FLAGS; + + PERL_ARGS_ASSERT_DUMPUNTIL; + +#ifdef DEBUG_DUMPUNTIL + Perl_re_printf( aTHX_ "--- %d : %d - %d - %d\n", indent, node-start, + last ? last-start : 0, plast ? plast-start : 0); +#endif + + if (plast && plast < last) + last= plast; + + while (node && (!last || node < last)) { + const U8 op = OP(node); + + if (op == CLOSE || op == SRCLOSE || op == WHILEM) + indent--; + next = regnext((regnode *)node); + const regnode *after = regnode_after((regnode *)node,0); + + /* Where, what. */ + if (op == OPTIMIZED) { + if (!optstart && RE_DEBUG_FLAG(RE_DEBUG_COMPILE_OPTIMISE)) + optstart = node; + else + goto after_print; + } else + CLEAR_OPTSTART; + + regprop(r, sv, node, NULL, NULL); + Perl_re_printf( aTHX_ "%4" IVdf ":%*s%s", (IV)(node - start), + (int)(2*indent + 1), "", SvPVX_const(sv)); + + if (op != OPTIMIZED) { + if (next == NULL) /* Next ptr. */ + Perl_re_printf( aTHX_ " (0)"); + else if (REGNODE_TYPE(op) == BRANCH + && REGNODE_TYPE(OP(next)) != BRANCH ) + Perl_re_printf( aTHX_ " (FAIL)"); + else + Perl_re_printf( aTHX_ " (%" IVdf ")", (IV)(next - start)); + Perl_re_printf( aTHX_ "\n"); + } + + after_print: + if (REGNODE_TYPE(op) == BRANCHJ) { + assert(next); + const regnode *nnode = (OP(next) == LONGJMP + ? regnext((regnode *)next) + : next); + if (last && nnode > last) + nnode = last; + DUMPUNTIL(after, nnode); + } + else if (REGNODE_TYPE(op) == BRANCH) { + assert(next); + DUMPUNTIL(after, next); + } + else if ( REGNODE_TYPE(op) == TRIE ) { + const regnode *this_trie = node; + const U32 n = ARG1u(node); + const reg_ac_data * const ac = op>=AHOCORASICK ? + (reg_ac_data *)ri->data->data[n] : + NULL; + const reg_trie_data * const trie = + (reg_trie_data*)ri->data->data[optrie]; +#ifdef DEBUGGING + AV *const trie_words + = MUTABLE_AV(ri->data->data[n + TRIE_WORDS_OFFSET]); +#endif + const regnode *nextbranch= NULL; + I32 word_idx; + SvPVCLEAR(sv); + for (word_idx= 0; word_idx < (I32)trie->wordcount; word_idx++) { + SV ** const elem_ptr = av_fetch_simple(trie_words, word_idx, 0); + + Perl_re_indentf( aTHX_ "%s ", + indent+3, + elem_ptr + ? pv_pretty(sv, SvPV_nolen_const(*elem_ptr), + SvCUR(*elem_ptr), PL_dump_re_max_len, + PL_colors[0], PL_colors[1], + (SvUTF8(*elem_ptr) + ? PERL_PV_ESCAPE_UNI + : 0) + | PERL_PV_PRETTY_ELLIPSES + | PERL_PV_PRETTY_LTGT + ) + : "???" + ); + if (trie->jump) { + U16 dist= trie->jump[word_idx+1]; + Perl_re_printf( aTHX_ "(%" UVuf ")\n", + (UV)((dist ? this_trie + dist : next) - start)); + if (dist) { + if (!nextbranch) + nextbranch= this_trie + trie->jump[0]; + DUMPUNTIL(this_trie + dist, nextbranch); + } + if (nextbranch && REGNODE_TYPE(OP(nextbranch))==BRANCH) + nextbranch= regnext((regnode *)nextbranch); + } else { + Perl_re_printf( aTHX_ "\n"); + } + } + if (last && next > last) + node= last; + else + node= next; + } + else if ( op == CURLY ) { /* "next" might be very big: optimizer */ + DUMPUNTIL(after, after + 1); /* +1 is NOT a REGNODE_AFTER */ + } + else if (REGNODE_TYPE(op) == CURLY && op != CURLYX) { + assert(next); + DUMPUNTIL(after, next); + } + else if ( op == PLUS || op == STAR) { + DUMPUNTIL(after, after + 1); /* +1 NOT a REGNODE_AFTER */ + } + else if (REGNODE_TYPE(op) == EXACT || op == ANYOFHs) { + /* Literal string, where present. */ + node = (const regnode *)REGNODE_AFTER_varies(node); + } + else { + node = REGNODE_AFTER_opcode(node,op); + } + if (op == CURLYX || op == OPEN || op == SROPEN) + indent++; + if (REGNODE_TYPE(op) == END) + break; + } + CLEAR_OPTSTART; +#ifdef DEBUG_DUMPUNTIL + Perl_re_printf( aTHX_ "--- %d\n", (int)indent); +#endif + return node; +} + +#endif /* PERL_RE_BUILD_DEBUG */ /* - regdump - dump a regexp onto Perl_debug_log in vaguely comprehensible form */ #ifdef DEBUGGING - static void S_regdump_intflags(pTHX_ const char *lead, const U32 flags) { int bit; int set=0; - ASSUME(REG_INTFLAGS_NAME_SIZE <= sizeof(flags)*8); + STATIC_ASSERT_STMT(REG_INTFLAGS_NAME_SIZE <= sizeof(flags) * CHARBITS); - for (bit=0; bit<=REG_INTFLAGS_NAME_SIZE; bit++) { + for (bit=0; bit < REG_INTFLAGS_NAME_SIZE; bit++) { if (flags & (1< last) - nnode = last; - DUMPUNTIL(after, nnode); - } - else if (REGNODE_TYPE(op) == BRANCH) { - assert(next); - DUMPUNTIL(after, next); - } - else if ( REGNODE_TYPE(op) == TRIE ) { - const regnode *this_trie = node; - const U32 n = ARG1u(node); - const reg_ac_data * const ac = op>=AHOCORASICK ? - (reg_ac_data *)ri->data->data[n] : - NULL; - const reg_trie_data * const trie = - (reg_trie_data*)ri->data->data[optrie]; -#ifdef DEBUGGING - AV *const trie_words - = MUTABLE_AV(ri->data->data[n + TRIE_WORDS_OFFSET]); -#endif - const regnode *nextbranch= NULL; - I32 word_idx; - SvPVCLEAR(sv); - for (word_idx= 0; word_idx < (I32)trie->wordcount; word_idx++) { - SV ** const elem_ptr = av_fetch_simple(trie_words, word_idx, 0); - - Perl_re_indentf( aTHX_ "%s ", - indent+3, - elem_ptr - ? pv_pretty(sv, SvPV_nolen_const(*elem_ptr), - SvCUR(*elem_ptr), PL_dump_re_max_len, - PL_colors[0], PL_colors[1], - (SvUTF8(*elem_ptr) - ? PERL_PV_ESCAPE_UNI - : 0) - | PERL_PV_PRETTY_ELLIPSES - | PERL_PV_PRETTY_LTGT - ) - : "???" - ); - if (trie->jump) { - U16 dist= trie->jump[word_idx+1]; - Perl_re_printf( aTHX_ "(%" UVuf ")\n", - (UV)((dist ? this_trie + dist : next) - start)); - if (dist) { - if (!nextbranch) - nextbranch= this_trie + trie->jump[0]; - DUMPUNTIL(this_trie + dist, nextbranch); - } - if (nextbranch && REGNODE_TYPE(OP(nextbranch))==BRANCH) - nextbranch= regnext((regnode *)nextbranch); - } else { - Perl_re_printf( aTHX_ "\n"); - } - } - if (last && next > last) - node= last; - else - node= next; - } - else if ( op == CURLY ) { /* "next" might be very big: optimizer */ - DUMPUNTIL(after, after + 1); /* +1 is NOT a REGNODE_AFTER */ - } - else if (REGNODE_TYPE(op) == CURLY && op != CURLYX) { - assert(next); - DUMPUNTIL(after, next); - } - else if ( op == PLUS || op == STAR) { - DUMPUNTIL(after, after + 1); /* +1 NOT a REGNODE_AFTER */ - } - else if (REGNODE_TYPE(op) == EXACT || op == ANYOFHs) { - /* Literal string, where present. */ - node = (const regnode *)REGNODE_AFTER_varies(node); - } - else { - node = REGNODE_AFTER_opcode(node,op); - } - if (op == CURLYX || op == OPEN || op == SROPEN) - indent++; - if (REGNODE_TYPE(op) == END) - break; - } - CLEAR_OPTSTART; -#ifdef DEBUG_DUMPUNTIL - Perl_re_printf( aTHX_ "--- %d\n", (int)indent); -#endif - return node; -} - -#endif /* DEBUGGING */ +#endif /* DEBUGGING */ Index: gnu/usr.bin/perl/regcomp_internal.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/regcomp_internal.h,v diff -u -p -a -u -p -r1.1.1.1 regcomp_internal.h --- gnu/usr.bin/perl/regcomp_internal.h 14 May 2024 19:36:01 -0000 1.1.1.1 +++ gnu/usr.bin/perl/regcomp_internal.h 22 Jan 2025 00:37:45 -0000 @@ -155,14 +155,6 @@ struct RExC_state_t { AV *warn_text; HV *unlexed_names; SV *runtime_code_qr; /* qr with the runtime code blocks */ -#ifdef DEBUGGING - const char *lastparse; - I32 lastnum; - U32 study_chunk_recursed_count; - AV *paren_name_list; /* idx -> name */ - SV *mysv1; - SV *mysv2; -#endif bool seen_d_op; bool strict; bool study_started; @@ -170,6 +162,22 @@ struct RExC_state_t { bool use_BRANCHJ; bool sWARN_EXPERIMENTAL__VLB; bool sWARN_EXPERIMENTAL__REGEX_SETS; + /* DEBUGGING only fields, keep these LAST so that we do not + * have any weirdness with static builds. + * + * We include these if we are building a DEBUGGING perl OR if we + * are not using dynamic linking (USE_DYNAMIC_LOADING). + * + * See GH Issue #21558 and also ba6e2c38aafc23cf114f3ba0d0ff3baead34328b + */ +#if defined(DEBUGGING) || !defined(USE_DYNAMIC_LOADING) + const char *lastparse; + I32 lastnum; + U32 study_chunk_recursed_count; + AV *paren_name_list; /* idx -> name */ + SV *mysv1; + SV *mysv2; +#endif }; #ifdef DEBUGGING @@ -886,7 +894,6 @@ static const scan_data_t zero_scan_data const char *ellipses = ""; \ IV len = RExC_precomp_end - RExC_precomp; \ \ - PREPARE_TO_DIE; \ if (len > RegexLengthToShowInErrorMessages) { \ /* chop 10 shorter than the max, to ensure meaning of "..." */ \ len = RegexLengthToShowInErrorMessages - 10; \ @@ -919,7 +926,6 @@ static const scan_data_t zero_scan_data * Calls SAVEDESTRUCTOR_X if needed, then Simple_vFAIL() */ #define vFAIL(m) STMT_START { \ - PREPARE_TO_DIE; \ Simple_vFAIL(m); \ } STMT_END @@ -935,7 +941,6 @@ static const scan_data_t zero_scan_data * Calls SAVEDESTRUCTOR_X if needed, then Simple_vFAIL2(). */ #define vFAIL2(m,a1) STMT_START { \ - PREPARE_TO_DIE; \ Simple_vFAIL2(m, a1); \ } STMT_END @@ -952,7 +957,6 @@ static const scan_data_t zero_scan_data * Calls SAVEDESTRUCTOR_X if needed, then Simple_vFAIL3(). */ #define vFAIL3(m,a1,a2) STMT_START { \ - PREPARE_TO_DIE; \ Simple_vFAIL3(m, a1, a2); \ } STMT_END @@ -965,19 +969,16 @@ static const scan_data_t zero_scan_data } STMT_END #define vFAIL4(m,a1,a2,a3) STMT_START { \ - PREPARE_TO_DIE; \ Simple_vFAIL4(m, a1, a2, a3); \ } STMT_END /* A specialized version of vFAIL2 that works with UTF8f */ #define vFAIL2utf8f(m, a1) STMT_START { \ - PREPARE_TO_DIE; \ S_re_croak(aTHX_ UTF, m REPORT_LOCATION, a1, \ REPORT_LOCATION_ARGS(RExC_parse)); \ } STMT_END #define vFAIL3utf8f(m, a1, a2) STMT_START { \ - PREPARE_TO_DIE; \ S_re_croak(aTHX_ UTF, m REPORT_LOCATION, a1, a2, \ REPORT_LOCATION_ARGS(RExC_parse)); \ } STMT_END @@ -1018,8 +1019,6 @@ static const scan_data_t zero_scan_data __FILE__, __LINE__, loc); \ } \ if (TO_OUTPUT_WARNINGS(loc)) { \ - if (ckDEAD(warns)) \ - PREPARE_TO_DIE; \ code; \ UPDATE_WARNINGS_LOC(loc); \ } \ Index: gnu/usr.bin/perl/regcomp_invlist.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/regcomp_invlist.c,v diff -u -p -a -u -p -r1.1.1.1 regcomp_invlist.c --- gnu/usr.bin/perl/regcomp_invlist.c 14 May 2024 19:36:00 -0000 1.1.1.1 +++ gnu/usr.bin/perl/regcomp_invlist.c 22 Jan 2025 00:37:45 -0000 @@ -18,7 +18,7 @@ #include "unicode_constants.h" #include "regcomp_internal.h" - +#ifdef PERL_RE_BUILD_AUX void Perl_populate_bitmap_from_invlist(pTHX_ SV * invlist, const UV offset, const U8 * bitmap, const Size_t len) { @@ -70,6 +70,7 @@ Perl_populate_invlist_from_bitmap(pTHX_ } } } +#endif /* PERL_RE_BUILD_AUX */ /* This section of code defines the inversion list object and its methods. The * interfaces are highly subject to change, so as much as possible is static to Index: gnu/usr.bin/perl/regcomp_study.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/regcomp_study.c,v diff -u -p -a -u -p -r1.1.1.1 regcomp_study.c --- gnu/usr.bin/perl/regcomp_study.c 14 May 2024 19:36:29 -0000 1.1.1.1 +++ gnu/usr.bin/perl/regcomp_study.c 22 Jan 2025 00:37:45 -0000 @@ -906,102 +906,7 @@ S_ssc_clear_locale(regnode_ssc *ssc) ANYOF_FLAGS(ssc) &= ~ANYOF_LOCALE_FLAGS; } -bool -Perl_is_ssc_worth_it(const RExC_state_t * pRExC_state, const regnode_ssc * ssc) -{ - /* The synthetic start class is used to hopefully quickly winnow down - * places where a pattern could start a match in the target string. If it - * doesn't really narrow things down that much, there isn't much point to - * having the overhead of using it. This function uses some very crude - * heuristics to decide if to use the ssc or not. - * - * It returns TRUE if 'ssc' rules out more than half what it considers to - * be the "likely" possible matches, but of course it doesn't know what the - * actual things being matched are going to be; these are only guesses - * - * For /l matches, it assumes that the only likely matches are going to be - * in the 0-255 range, uniformly distributed, so half of that is 127 - * For /a and /d matches, it assumes that the likely matches will be just - * the ASCII range, so half of that is 63 - * For /u and there isn't anything matching above the Latin1 range, it - * assumes that that is the only range likely to be matched, and uses - * half that as the cut-off: 127. If anything matches above Latin1, - * it assumes that all of Unicode could match (uniformly), except for - * non-Unicode code points and things in the General Category "Other" - * (unassigned, private use, surrogates, controls and formats). This - * is a much large number. */ - - U32 count = 0; /* Running total of number of code points matched by - 'ssc' */ - UV start, end; /* Start and end points of current range in inversion - XXX outdated. UTF-8 locales are common, what about invert? list */ - const U32 max_code_points = (LOC) - ? 256 - : (( ! UNI_SEMANTICS - || invlist_highest(ssc->invlist) < 256) - ? 128 - : NON_OTHER_COUNT); - const U32 max_match = max_code_points / 2; - - PERL_ARGS_ASSERT_IS_SSC_WORTH_IT; - - invlist_iterinit(ssc->invlist); - while (invlist_iternext(ssc->invlist, &start, &end)) { - if (start >= max_code_points) { - break; - } - end = MIN(end, max_code_points - 1); - count += end - start + 1; - if (count >= max_match) { - invlist_iterfinish(ssc->invlist); - return FALSE; - } - } - return TRUE; -} - - -void -Perl_ssc_finalize(pTHX_ RExC_state_t *pRExC_state, regnode_ssc *ssc) -{ - /* The inversion list in the SSC is marked mortal; now we need a more - * permanent copy, which is stored the same way that is done in a regular - * ANYOF node, with the first NUM_ANYOF_CODE_POINTS code points in a bit - * map */ - - SV* invlist = invlist_clone(ssc->invlist, NULL); - - PERL_ARGS_ASSERT_SSC_FINALIZE; - - assert(is_ANYOF_SYNTHETIC(ssc)); - - /* The code in this file assumes that all but these flags aren't relevant - * to the SSC, except SSC_MATCHES_EMPTY_STRING, which should be cleared - * by the time we reach here */ - assert(! (ANYOF_FLAGS(ssc) - & ~( ANYOF_COMMON_FLAGS - |ANYOFD_NON_UTF8_MATCHES_ALL_NON_ASCII__shared - |ANYOF_HAS_EXTRA_RUNTIME_MATCHES))); - - populate_anyof_bitmap_from_invlist( (regnode *) ssc, &invlist); - - set_ANYOF_arg(pRExC_state, (regnode *) ssc, invlist, NULL, NULL); - SvREFCNT_dec(invlist); - - /* Make sure is clone-safe */ - ssc->invlist = NULL; - - if (ANYOF_POSIXL_SSC_TEST_ANY_SET(ssc)) { - ANYOF_FLAGS(ssc) |= ANYOF_MATCHES_POSIXL; - OP(ssc) = ANYOFPOSIXL; - } - else if (RExC_contains_locale) { - OP(ssc) = ANYOFL; - } - - assert(! (ANYOF_FLAGS(ssc) & ANYOF_LOCALE_FLAGS) || RExC_contains_locale); -} /* The below joins as many adjacent EXACTish nodes as possible into a single * one. The regop may be changed if the node(s) contain certain sequences that @@ -1159,9 +1064,9 @@ Perl_join_exact(pTHX_ RExC_state_t *pREx regnode *n = regnext(scan); U32 stringok = 1; regnode *next = REGNODE_AFTER_varies(scan); - U32 merged = 0; U32 stopnow = 0; #ifdef DEBUGGING + U32 merged = 0; regnode *stop = scan; DECLARE_AND_GET_RE_DEBUG_FLAGS; #else @@ -1309,7 +1214,9 @@ Perl_join_exact(pTHX_ RExC_state_t *pREx } DEBUG_PEEP("merg", n, depth, 0); +#ifdef DEBUGGING merged++; +#endif next = REGNODE_AFTER_varies(n); NEXT_OFF(scan) += NEXT_OFF(n); Index: gnu/usr.bin/perl/regcomp_trie.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/regcomp_trie.c,v diff -u -p -a -u -p -r1.1.1.1 regcomp_trie.c --- gnu/usr.bin/perl/regcomp_trie.c 14 May 2024 19:36:28 -0000 1.1.1.1 +++ gnu/usr.bin/perl/regcomp_trie.c 22 Jan 2025 00:37:45 -0000 @@ -517,21 +517,33 @@ is the recommended Unicode-aware way of : ( state==1 ? special : 0 ) \ ) -#define TRIE_BITMAP_SET_FOLDED(trie, uvc, folder) \ -STMT_START { \ - TRIE_BITMAP_SET(trie, uvc); \ - /* store the folded codepoint */ \ - if ( folder ) \ - TRIE_BITMAP_SET(trie, folder[(U8) uvc ]); \ - \ - if ( !UTF ) { \ - /* store first byte of utf8 representation of */ \ - /* variant codepoints */ \ - if (! UVCHR_IS_INVARIANT(uvc)) { \ - TRIE_BITMAP_SET(trie, UTF8_TWO_BYTE_HI(uvc)); \ - } \ - } \ -} STMT_END +/* Helper function for make_trie(): set a trie bit for both the character + * and its folded variant, and for the first byte of a variant codepoint, + * if any */ + +STATIC void +S_trie_bitmap_set_folded(pTHX_ RExC_state_t *pRExC_state, + reg_trie_data *trie, U8 ch, const U8 * folder) +{ + TRIE_BITMAP_SET(trie, ch); + /* store the folded codepoint */ + if ( folder ) + TRIE_BITMAP_SET(trie, folder[ch]); + + if ( !UTF ) { + /* store first byte of utf8 representation of */ + /* variant codepoints */ + if (! UVCHR_IS_INVARIANT(ch)) { + U8 hi = UTF8_TWO_BYTE_HI(ch); + /* Note that hi will be either 0xc2 or 0xc3 (apart from EBCDIC + * systems), and TRIE_BITMAP_SET() will do >>3 to get the byte + * offset within the bit table, which is constant, and + * Coverity complained about this (CID 488118). */ + TRIE_BITMAP_SET(trie, hi); + } + } +} + I32 Perl_make_trie(pTHX_ RExC_state_t *pRExC_state, regnode *startbranch, @@ -657,6 +669,14 @@ Perl_make_trie(pTHX_ RExC_state_t *pRExC STRLEN maxchars = 0; bool set_bit = trie->bitmap ? 1 : 0; /*store the first char in the bitmap?*/ + + /* wordlen is needed for the TRIE_READ_CHAR() macro, but we don't use its + value in this scope, we only modify it. clang 17 warns about this. + The later definitions of wordlen in this function do have their values + used. + */ + PERL_UNUSED_VAR(wordlen); + lastbranch = cur; if (OP(noper) == NOTHING) { @@ -777,7 +797,7 @@ Perl_make_trie(pTHX_ RExC_state_t *pRExC if ( set_bit ) { /* store the codepoint in the bitmap, and its folded * equivalent. */ - TRIE_BITMAP_SET_FOLDED(trie, uvc, folder); + S_trie_bitmap_set_folded(aTHX_ pRExC_state, trie, uvc, folder); set_bit = 0; /* We've done our bit :-) */ } } else { @@ -1400,14 +1420,14 @@ Perl_make_trie(pTHX_ RExC_state_t *pRExC SV ** const tmp = av_fetch_simple( revcharmap, first_ofs, 0); const U8 * const ch = (U8*)SvPV_nolen_const( *tmp ); - TRIE_BITMAP_SET_FOLDED(trie,*ch, folder); + S_trie_bitmap_set_folded(aTHX_ pRExC_state, trie, *ch, folder); DEBUG_OPTIMISE_r( Perl_re_printf( aTHX_ "%s", (char*)ch) ); } } /* store the current firstchar in the bitmap */ - TRIE_BITMAP_SET_FOLDED(trie,*ch, folder); + S_trie_bitmap_set_folded(aTHX_ pRExC_state, trie, *ch, folder); DEBUG_OPTIMISE_r(Perl_re_printf( aTHX_ "%s", ch)); } first_ofs = ofs; Index: gnu/usr.bin/perl/regen.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/regen.pl,v diff -u -p -a -u -p -r1.1.1.9 regen.pl --- gnu/usr.bin/perl/regen.pl 14 May 2024 19:36:26 -0000 1.1.1.9 +++ gnu/usr.bin/perl/regen.pl 22 Jan 2025 00:37:45 -0000 @@ -33,3 +33,4 @@ regcomp.pl scope_types.pl tidy_embed.pl warnings.pl +locale.pl Index: gnu/usr.bin/perl/regexec.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/regexec.c,v diff -u -p -a -u -p -r1.30 regexec.c --- gnu/usr.bin/perl/regexec.c 14 May 2024 19:38:54 -0000 1.30 +++ gnu/usr.bin/perl/regexec.c 22 Jan 2025 00:37:45 -0000 @@ -1934,13 +1934,16 @@ STMT_START { s++; \ } +#define LAST_REGTRY_SKIPPED_FORWARD(reginfo) (reginfo->cutpoint) + /* We keep track of where the next character should start after an occurrence * of the one we're looking for. Knowing that, we can see right away if the * next occurrence is adjacent to the previous. When 'doevery' is FALSE, we * don't accept the 2nd and succeeding adjacent occurrences */ #define FBC_CHECK_AND_TRY \ if ( ( doevery \ - || s != previous_occurrence_end) \ + || s != previous_occurrence_end \ + || LAST_REGTRY_SKIPPED_FORWARD(reginfo) ) \ && ( reginfo->intuit \ || (s <= reginfo->strend && regtry(reginfo, &s)))) \ { \ @@ -3545,6 +3548,10 @@ S_reg_set_capture_string(pTHX_ REGEXP * SSize_t max = strend - strbeg; SSize_t sublen; + /* NOTE: the following if block is not used or tested + * in standard builds. It is only used when PERL_SAWAMPERSAND is + * defined */ + if ( (flags & REXEC_COPY_SKIP_POST) && !(prog->extflags & RXf_PMf_KEEPCOPY) /* //p */ && !(PL_sawampersand & SAWAMPERSAND_RIGHT) @@ -3567,6 +3574,9 @@ S_reg_set_capture_string(pTHX_ REGEXP * assert(max >= 0 && max <= strend - strbeg); } + /* NOTE: the following if block is not used or tested + * in standard builds. It is only used when PERL_SAWAMPERSAND is + * defined */ if ( (flags & REXEC_COPY_SKIP_PRE) && !(prog->extflags & RXf_PMf_KEEPCOPY) /* //p */ && !(PL_sawampersand & SAWAMPERSAND_LEFT) @@ -3577,7 +3587,7 @@ S_reg_set_capture_string(pTHX_ REGEXP * * by a capture. Due to lookbehind, this may be to * the left of $&, so we have to scan all captures */ while (min && n <= RXp_LASTPAREN(prog)) { - I32 start = RXp_OFFS_START(prog,n); + SSize_t start = RXp_OFFS_START(prog,n); if ( start != -1 && start < min) { @@ -3585,11 +3595,11 @@ S_reg_set_capture_string(pTHX_ REGEXP * } n++; } - if ((PL_sawampersand & SAWAMPERSAND_RIGHT) - && min > RXp_OFFS_END(prog,0) - ) - min = RXp_OFFS_END(prog,0); - + if (PL_sawampersand & SAWAMPERSAND_RIGHT) { + SSize_t end = RXp_OFFS_END(prog,0); + if ( min > end ) + min = end; + } } assert(min >= 0 && min <= max && min <= strend - strbeg); @@ -4349,6 +4359,12 @@ Perl_regexec_flags(pTHX_ REGEXP * const /* - regtry - try match at specific point + + NOTE: *startpos may be modifed by regtry() to signal to the caller + that the next match should start at a specific position in the + string. The macro LAST_REGTRY_SKIPPED_FORWARD(reginfo) can be + used to detect when this has happened. + */ STATIC bool /* 0 failure, 1 success */ S_regtry(pTHX_ regmatch_info *reginfo, char **startposp) @@ -4421,7 +4437,8 @@ S_regtry(pTHX_ regmatch_info *reginfo, c */ #define REPORT_CODE_OFF 29 #define INDENT_CHARS(depth) ((int)(depth) % 20) -#ifdef DEBUGGING + +#ifdef PERL_RE_BUILD_DEBUG int Perl_re_exec_indentf(pTHX_ const char *fmt, U32 depth, ...) { @@ -5664,7 +5681,7 @@ S_isSB(pTHX_ SB_enum before, SB5. X (Extend | Format)* → X */ if (after == SB_Extend || after == SB_Format) { - /* Implied is that the these characters attach to everything + /* Implied is that these characters attach to everything * immediately prior to them except for those separator-type * characters. And the rules earlier have already handled the case * when one of those immediately precedes the extend char */ @@ -5913,7 +5930,7 @@ S_isWB(pTHX_ WB_enum previous, * should be set to WB_UNKNOWN. The other input parameters give the * boundaries and current position in the matching of the string. That * is, 'curpos' marks the position where the character whose wb value is - * 'after' begins. See http://www.unicode.org/reports/tr29/ */ + * 'after' begins. See https://www.unicode.org/reports/tr29/ */ U8 * before_pos = (U8 *) curpos; U8 * after_pos = (U8 *) curpos; @@ -11146,26 +11163,7 @@ S_reghop4(U8 *s, SSize_t off, const U8* { PERL_ARGS_ASSERT_REGHOP4; - if (off >= 0) { - while (off-- && s < rlim) { - /* XXX could check well-formedness here */ - s += UTF8SKIP(s); - } - } - else { - while (off++ && s > llim) { - s--; - if (UTF8_IS_CONTINUED(*s)) { - while (s > llim && UTF8_IS_CONTINUATION(*s)) - s--; - if (! UTF8_IS_START(*s)) { - Perl_croak_nocontext("Malformed UTF-8 character (fatal)"); - } - } - /* XXX could check well-formedness here */ - } - } - return s; + return utf8_hop_safe(s, off, llim, rlim); } /* like reghop3, but returns NULL on overrun, rather than returning last Index: gnu/usr.bin/perl/regexp.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/regexp.h,v diff -u -p -a -u -p -r1.19 regexp.h --- gnu/usr.bin/perl/regexp.h 14 May 2024 19:38:54 -0000 1.19 +++ gnu/usr.bin/perl/regexp.h 22 Jan 2025 00:37:45 -0000 @@ -130,8 +130,19 @@ struct reg_code_blocks { regexp's data array based on the data item's type. */ +/* NOTE: There is a copy of this struct in the documentation in perlreapi.pod + * if you make ANY changes please make sure they are ALSO made there. + */ typedef struct regexp { + /*---------------------------------------------------------------------- + * Fields required for compatibility with SV types + */ _XPV_HEAD; + + /*---------------------------------------------------------------------- + * Operational fields + */ + const struct regexp_engine* engine; /* what engine created this regexp? */ REGEXP *mother_re; /* what re is this a lightweight copy of? */ HV *paren_names; /* Optional hash of paren names */ @@ -149,7 +160,6 @@ typedef struct regexp { I32 *parno_to_logical_next; /* map every physical parno to the next physical with the same logical id */ - U32 extflags; /* Flags used both externally and internally */ SSize_t maxlen; /* maximum possible number of chars in string to match */ SSize_t minlen; /* minimum possible number of chars in string to match */ SSize_t minlenret; /* minimum possible number of chars in $& */ @@ -163,6 +173,8 @@ typedef struct regexp { void *pprivate; /* Data private to the regex engine which * created this object. */ + + U32 extflags; /* Flags used both externally and internally */ U32 intflags; /* Engine Specific Internal flags */ /*---------------------------------------------------------------------- @@ -170,10 +182,9 @@ typedef struct regexp { */ U32 lastparen; /* highest close paren matched ($+) */ + U32 lastcloseparen; /* last close paren matched ($^N) */ regexp_paren_pair *offs; /* Array of offsets for (@-) and (@+) */ char **recurse_locinput; /* used to detect infinite recursion, XXX: move to internal */ - U32 lastcloseparen; /* last close paren matched ($^N) */ - /*---------------------------------------------------------------------- */ @@ -192,8 +203,9 @@ typedef struct regexp { SSize_t suboffset; /* byte offset of subbeg from logical start of str */ SSize_t subcoffset; /* suboffset equiv, but in chars (for @-/@+) */ - /*---------------------------------------------------------------------- */ - + /*---------------------------------------------------------------------- + * More Operational fields + */ CV *qr_anoncv; /* the anon sub wrapped round qr/(?{..})/ */ } regexp; @@ -210,9 +222,51 @@ typedef struct regexp { #define RXp_OFFS_VALID(rx,n) \ (RXp_OFFSp(rx)[(n)].end != -1 && RXp_OFFSp(rx)[(n)].start != -1 ) + #define RX_OFFS_START(rx_sv,n) RXp_OFFS_START(ReANY(rx_sv),n) #define RX_OFFS_END(rx_sv,n) RXp_OFFS_END(ReANY(rx_sv),n) #define RX_OFFS_VALID(rx_sv,n) RXp_OFFS_VALID(ReANY(rx_sv),n) + +/* + +=for apidoc mh||RX_OFFSp|const REGEXP * rx_sv +Returns the RX_OFFS structure as a pointer. This should NOT be used +directly, and the structure it returns may change in future versions of +perl. Use one of the other RX_OFFS_xxx macros instead, which should be +stable as Perl evolves. The 'p' suffix on the macro is meant to indicate +both that the macro is "private" to the internals, and that it returns +a pointer. + +=for apidoc Amh||RX_OFFS_START|const REGEXP * rx_sv|U32 n +Returns the start offset of the C'th capture buffer, when +C is 0 it refers to the overall match as a whole. A value of +-1 is returned if the C'th capture buffer did not match. + +=for apidoc Amh||RXp_OFFS_START|const regexp * rx|U32 n +Same as RX_OFFS_START() but operates on a C instead of +an C. + +=for apidoc Amh||RX_OFFS_END|const REGEXP * rx_sv|U32 n +Returns the end offset of the C'th capture buffer, when C is 0 it +refers to the overall match as a whole. A value of +-1 is returned if the C'th capture buffer did not match. + +=for apidoc Amh||RXp_OFFS_END|const regexp * rx|U32 n +Same as RX_OFFS_END() but operates on a C instead of +an C. + +=for apidoc Amh||RX_OFFS_VALID|const REGEXP * rx_sv|U32 n +Returns true if the C'th offset buffer matched, false otherwise, when +C is 0 it refers to the overall match as a whole which should always +return true. + +=for apidoc Amh||RXp_OFFS_VALID|const regexp * rx|U32 n +Same as RX_OFFS_VLAID() but operates on a C instead of +an C. + +=cut + +*/ /* used for high speed searches */ typedef struct re_scream_pos_data_s Index: gnu/usr.bin/perl/run.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/run.c,v diff -u -p -a -u -p -r1.14 run.c --- gnu/usr.bin/perl/run.c 5 Feb 2017 00:31:53 -0000 1.14 +++ gnu/usr.bin/perl/run.c 22 Jan 2025 00:37:45 -0000 @@ -47,6 +47,123 @@ Perl_runops_standard(pTHX) return 0; } + +#ifdef PERL_RC_STACK + +/* this is a wrapper for all runops-style functions. It temporarily + * reifies the stack if necessary, then calls the real runops function + */ +int +Perl_runops_wrap(pTHX) +{ + /* runops loops assume a ref-counted stack. If we have been called via a + * wrapper (pp_wrap or xs_wrap) with the top half of the stack not + * reference-counted, or with a non-real stack, temporarily convert it + * to reference-counted. This is because the si_stack_nonrc_base + * mechanism only allows a single split in the stack, not multiple + * stripes. + * At the end, we revert the stack (or part thereof) to non-refcounted + * to keep whoever our caller is happy. + * + * If what we call croaks, catch it, revert, then rethrow. + */ + + I32 cut; /* the cut point between refcnted and non-refcnted */ + bool was_real = cBOOL(AvREAL(PL_curstack)); + I32 old_base = PL_curstackinfo->si_stack_nonrc_base; + + if (was_real && !old_base) { + PL_runops(aTHX); /* call the real loop */ + return 0; + } + + if (was_real) { + cut = old_base; + assert(PL_stack_base + cut <= PL_stack_sp + 1); + PL_curstackinfo->si_stack_nonrc_base = 0; + } + else { + assert(!old_base); + assert(!AvREIFY(PL_curstack)); + AvREAL_on(PL_curstack); + /* skip the PL_sv_undef guard at PL_stack_base[0] but still + * signal adjusting may be needed on return by setting to a + * non-zero value - even if stack is empty */ + cut = 1; + } + + if (cut) { + SV **svp = PL_stack_base + cut; + while (svp <= PL_stack_sp) { + SvREFCNT_inc_simple_void(*svp); + svp++; + } + } + + AV * old_curstack = PL_curstack; + + /* run the real loop while catching exceptions */ + dJMPENV; + int ret; + JMPENV_PUSH(ret); + switch (ret) { + case 0: /* normal return from JMPENV_PUSH */ + cur_env.je_mustcatch = cur_env.je_prev->je_mustcatch; + PL_runops(aTHX); /* call the real loop */ + + revert: + /* revert stack back its non-ref-counted state */ + assert(AvREAL(PL_curstack)); + + if (cut) { + /* undo the stack reification that took place at the beginning of + * this function */ + if (UNLIKELY(!was_real)) + AvREAL_off(PL_curstack); + + SSize_t n = PL_stack_sp - (PL_stack_base + cut) + 1; + if (n > 0) { + /* we need to decrement the refcount of every SV from cut + * upwards; but this may prematurely free them, so + * mortalise them instead */ + EXTEND_MORTAL(n); + for (SSize_t i = 0; i < n; i ++) { + SV* sv = PL_stack_base[cut + i]; + if (sv) + PL_tmps_stack[++PL_tmps_ix] = sv; + } + } + + I32 sp1 = PL_stack_sp - PL_stack_base + 1; + PL_curstackinfo->si_stack_nonrc_base = + old_base > sp1 ? sp1 : old_base; + } + break; + + case 3: /* exception trapped by eval - stack only partially unwound */ + + /* if the exception has already unwound to before the current + * stack, no need to fix it up */ + if (old_curstack == PL_curstack) + goto revert; + break; + + default: + break; + } + + JMPENV_POP; + + if (ret) { + JMPENV_JUMP(ret); /* re-throw the exception */ + NOT_REACHED; /* NOTREACHED */ + } + + return 0; +} + +#endif + /* * ex: set ts=8 sts=4 sw=4 et: */ Index: gnu/usr.bin/perl/scope.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/scope.c,v diff -u -p -a -u -p -r1.22 scope.c --- gnu/usr.bin/perl/scope.c 14 May 2024 19:38:54 -0000 1.22 +++ gnu/usr.bin/perl/scope.c 22 Jan 2025 00:37:45 -0000 @@ -47,16 +47,16 @@ Perl_stack_grow(pTHX_ SV **sp, SV **p, S 128; #endif /* If the total might wrap, panic instead. This is really testing - * that (current + n + extra < SSize_t_MAX), but done in a way that + * that (current + n + extra < Stack_off_t_MAX), but done in a way that * can't wrap */ - if (UNLIKELY( current > SSize_t_MAX - extra - || current + extra > SSize_t_MAX - n + if (UNLIKELY( current > Stack_off_t_MAX - extra + || current + extra > Stack_off_t_MAX - n )) /* diag_listed_as: Out of memory during %s extend */ Perl_croak(aTHX_ "Out of memory during stack extend"); av_extend(PL_curstack, current + n + extra); -#ifdef DEBUGGING +#ifdef PERL_USE_HWM PL_curstackinfo->si_stack_hwm = current + n + extra; #endif @@ -69,16 +69,31 @@ Perl_stack_grow(pTHX_ SV **sp, SV **p, S #define GROW(old) ((old) * 3 / 2) #endif +/* for backcomp */ PERL_SI * Perl_new_stackinfo(pTHX_ I32 stitems, I32 cxitems) { + return new_stackinfo_flags(stitems, cxitems, 0); +} + +/* current flag meanings: + * 1 make the new arg stack AvREAL + */ + +PERL_SI * +Perl_new_stackinfo_flags(pTHX_ I32 stitems, I32 cxitems, UV flags) +{ PERL_SI *si; Newx(si, 1, PERL_SI); si->si_stack = newAV(); - AvREAL_off(si->si_stack); + if (!(flags & 1)) + AvREAL_off(si->si_stack); av_extend(si->si_stack, stitems > 0 ? stitems-1 : 0); AvALLOC(si->si_stack)[0] = &PL_sv_undef; AvFILLp(si->si_stack) = 0; +#ifdef PERL_RC_STACK + si->si_stack_nonrc_base = 0; +#endif si->si_prev = 0; si->si_next = 0; si->si_cxmax = cxitems - 1; @@ -148,13 +163,13 @@ Perl_pop_scope(pTHX) LEAVE_SCOPE(oldsave); } -I32 * +Stack_off_t * Perl_markstack_grow(pTHX) { const I32 oldmax = PL_markstack_max - PL_markstack; const I32 newmax = GROW(oldmax); - Renew(PL_markstack, newmax, I32); + Renew(PL_markstack, newmax, Stack_off_t); PL_markstack_max = PL_markstack + newmax; PL_markstack_ptr = PL_markstack + oldmax; DEBUG_s(DEBUG_v(PerlIO_printf(Perl_debug_log, @@ -231,8 +246,12 @@ Perl_tmps_grow_p(pTHX_ SSize_t ix) { SSize_t extend_to = ix; #ifndef STRESS_REALLOC - if (ix - PL_tmps_max < 128) - extend_to += (PL_tmps_max < 512) ? 128 : 512; + SSize_t grow_size = PL_tmps_max < 512 ? 128 : PL_tmps_max / 2; + if (extend_to > SSize_t_MAX - grow_size - 1) + /* trigger memwrap message or fail allocation */ + extend_to = SSize_t_MAX-1; + else + extend_to += grow_size; #endif Renew(PL_tmps_stack, extend_to + 1, SV*); PL_tmps_max = extend_to + 1; @@ -1525,6 +1544,14 @@ Perl_leave_scope(pTHX_ I32 base) break; case SAVEt_STACK_POS: /* Position on Perl stack */ +#ifdef PERL_RC_STACK + /* DAPM Jan 2023. I don't think this save type is used any + * more, but if some XS code uses it, fail it for now, as + * it's not clear to me what perl should be doing to stack ref + * counts when arbitrarily resetting the stack pointer. + */ + assert(0); +#endif a0 = ap[0]; PL_stack_sp = PL_stack_base + a0.any_i32; break; @@ -1879,7 +1906,7 @@ Be aware that there is a signficant diff I and the I. If you are looking for a mechanism to trigger a function at the end of the B you should look at -C instead of this function. +L> instead of this function. =for apidoc mortal_svfunc_x @@ -1892,7 +1919,7 @@ Be aware that there is a signficant diff I and the I. If you are looking for a mechanism to trigger a function at the end of the B you should look at -C instead of this function. +L> instead of this function. =for apidoc magic_freedestruct Index: gnu/usr.bin/perl/scope.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/scope.h,v diff -u -p -a -u -p -r1.21 scope.h --- gnu/usr.bin/perl/scope.h 14 May 2024 19:38:54 -0000 1.21 +++ gnu/usr.bin/perl/scope.h 22 Jan 2025 00:37:45 -0000 @@ -256,13 +256,14 @@ scope has the given name. C must b /* =for apidoc_section $stack =for apidoc Am|SSize_t|SSNEW |Size_t size -=for apidoc_item | |SSNEWa |Size_t_size|Size_t align -=for apidoc_item | |SSNEWat|Size_t_size|type|Size_t align +=for apidoc_item | |SSNEWa |Size_t size|Size_t align +=for apidoc_item | |SSNEWat|Size_t size|type|Size_t align =for apidoc_item | |SSNEWt |Size_t size|type -These temporarily allocates data on the savestack, returning an SSize_t index into -the savestack, because a pointer would get broken if the savestack is moved on -reallocation. Use L> to convert the returned index into a pointer. +These each temporarily allocate data on the savestack, returning an SSize_t +index into the savestack, because a pointer would get broken if the savestack +is moved on reallocation. Use L> to convert the returned index into +a pointer. The forms differ in that plain C allocates C bytes; C and C allocate C objects, each of which is type Index: gnu/usr.bin/perl/sv.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/sv.c,v diff -u -p -a -u -p -r1.33 sv.c --- gnu/usr.bin/perl/sv.c 14 May 2024 19:38:54 -0000 1.33 +++ gnu/usr.bin/perl/sv.c 22 Jan 2025 00:37:45 -0000 @@ -375,7 +375,7 @@ S_sv_add_arena(pTHX_ char *const ptr, co /* visit(): call the named function for each non-free SV in the arenas * whose flags field matches the flags/mask args. */ -STATIC I32 +STATIC SSize_t S_visit(pTHX_ SVFUNC_t f, const U32 flags, const U32 mask) { SV* sva; @@ -587,15 +587,67 @@ SVs which are in complex self-referentia =cut */ -I32 +SSize_t Perl_sv_clean_all(pTHX) { - I32 cleaned; + SSize_t cleaned; PL_in_clean_all = TRUE; cleaned = visit(do_clean_all, 0,0); return cleaned; } + +#ifdef DEBUGGING + +/* Called by sv_mark_arenas() for each live SV: set SVf_BREAK */ + +static void +S_do_sv_mark_arenas(pTHX_ SV *const sv) +{ + sv->sv_flags |= SVf_BREAK; +} + +/* sv_mark_arenas(): for leak debugging: mark all live SVs with SVf_BREAK. + * Then later, use sv_sweep_arenas() to list any SVs not so marked. + */ + +void +Perl_sv_mark_arenas(pTHX) +{ + visit(S_do_sv_mark_arenas, 0, 0); +} + +/* Called by sv_sweep_arenas() for each live SV, to list any SVs without + * SVf_BREAK set */ + +static void +S_do_sv_sweep_arenas(pTHX_ SV *const sv) +{ + if (sv->sv_flags & SVf_BREAK) { + sv->sv_flags &= ~SVf_BREAK; + return; + } + PerlIO_printf(Perl_debug_log, "Unmarked SV: 0x%p: %s\n", + sv, SvPEEK(sv)); +} + + +/* sv_sweep_arenas(): for debugging: list all live SVs that don't have + * SVf_BREAK set, then turn off all SVf_BREAK flags. Typically used some + * time after sv_mark_arenas(), to find SVs which have been created since + * the marking but not yet freed (they may have leaked, or been stored in + * an array, or whatever). + */ + +void +Perl_sv_sweep_arenas(pTHX) +{ + visit(S_do_sv_sweep_arenas, 0, 0); +} + +#endif + + /* ARENASETS: a meta-arena implementation which separates arena-info into struct arena_set, which contains an array of struct @@ -2014,6 +2066,15 @@ S_sv_setnv(pTHX_ SV* sv, int numtype) } } +#ifndef NV_PRESERVES_UV +# define MAX_UV_PRESERVED_IN_NV (((UV)1 << NV_PRESERVES_UV_BITS) - 1) +# define MAX_IV_PRESERVED_IN_NV ((IV)MAX_UV_PRESERVED_IN_NV) +# define MIN_IV_PRESERVED_IN_NV (-MAX_IV_PRESERVED_IN_NV) +/* We presume that (IV)MAX_UV_PRESERVED_IN_NV and (-MAX_IV_PRESERVED_IN_NV) + above will not overflow if the condition below holds true: */ +STATIC_ASSERT_DECL(MAX_UV_PRESERVED_IN_NV <= (UV)IV_MAX); +#endif + STATIC bool S_sv_2iuv_common(pTHX_ SV *const sv) { @@ -2046,9 +2107,10 @@ S_sv_2iuv_common(pTHX_ SV *const sv) SvIV_set(sv, I_V(SvNVX(sv))); if (SvNVX(sv) == (NV) SvIVX(sv) #ifndef NV_PRESERVES_UV - && SvIVX(sv) != IV_MIN /* avoid negating IV_MIN below */ - && (((UV)1 << NV_PRESERVES_UV_BITS) > - (UV)(SvIVX(sv) > 0 ? SvIVX(sv) : -SvIVX(sv))) + /* Optimizing compilers might merge two comparisons below + into single comparison */ + && MIN_IV_PRESERVED_IN_NV <= SvIVX(sv) + && SvIVX(sv) <= MAX_IV_PRESERVED_IN_NV /* Don't flag it as "accurately an integer" if the number came from a (by definition imprecise) NV operation, and we're outside the range of NV integer precision */ @@ -3669,7 +3731,7 @@ Perl_sv_utf8_decode(pTHX_ SV *const sv) /* adjust pos to the start of a UTF8 char sequence */ MAGIC * mg = mg_find(sv, PERL_MAGIC_regex_global); if (mg) { - I32 pos = mg->mg_len; + SSize_t pos = mg->mg_len; if (pos > 0) { for (c = start + pos; c > start; c--) { if (UTF8_IS_START(*c)) @@ -4920,10 +4982,15 @@ Perl_sv_setsv_cow(pTHX_ SV *dsv, SV *ssv /* =for apidoc sv_setpv_bufsize -Sets the SV to be a string of cur bytes length, with at least -len bytes available. Ensures that there is a null byte at SvEND. +Sets the SV to be a string of C bytes length, with at least +C bytes available. Ensures that there is a null byte at C. + Returns a char * pointer to the SvPV buffer. +The caller must set the first C bytes of C before the first use of its +contents. This means that if C is zero, the SV is immediately fully +formed and ready to use, just like any other SV containing an empty string. + =cut */ @@ -4971,8 +5038,9 @@ first encountered C byte. In the forms that take a C argument, if it is NULL, the SV will become undefined. -The UTF-8 flag is not changed by these functions. A terminating NUL byte is -guaranteed in the result. +B + +A terminating NUL byte is guaranteed in the result. The C<_mg> forms handle 'set' magic; the other forms skip all magic. @@ -6400,17 +6468,17 @@ Perl_sv_kill_backrefs(pTHX_ SV *const sv } /* -=for apidoc sv_insert +=for apidoc sv_insert +=for apidoc_item sv_insert_flags -Inserts and/or replaces a string at the specified offset/length within the SV. -Similar to the Perl C function, with C bytes starting at -C replacing C bytes of the string in C starting at -C. Handles get magic. - -=for apidoc sv_insert_flags - -Same as C, but the extra C are passed to the -C that applies to C. +These insert and/or replace a string at the specified offset/length within the +SV. Similar to the Perl C function, with C bytes starting +at C replacing C bytes of the string in C starting at +C. They handle get magic. + +C is identical to plain C, but the extra C +are passed to the C operation that is internally applied to +C. =cut */ @@ -7033,6 +7101,12 @@ Perl_sv_clear(pTHX_ SV *const orig_sv) } if (--(SvREFCNT(sv))) continue; + if (SvIMMORTAL(sv)) { + /* make sure SvREFCNT(sv)==0 happens very seldom */ + SvREFCNT(sv) = SvREFCNT_IMMORTAL; + SvTEMP_off(sv); + continue; + } #ifdef DEBUGGING if (SvTEMP(sv)) { Perl_ck_warner_d(aTHX_ packWARN(WARN_DEBUGGING), @@ -7041,11 +7115,6 @@ Perl_sv_clear(pTHX_ SV *const orig_sv) continue; } #endif - if (SvIMMORTAL(sv)) { - /* make sure SvREFCNT(sv)==0 happens very seldom */ - SvREFCNT(sv) = SvREFCNT_IMMORTAL; - continue; - } break; } /* while 1 */ @@ -7228,6 +7297,12 @@ Perl_sv_free2(pTHX_ SV *const sv, const /* normal case */ SvREFCNT(sv) = 0; + if (SvIMMORTAL(sv)) { + /* make sure SvREFCNT(sv)==0 happens very seldom */ + SvREFCNT(sv) = SvREFCNT_IMMORTAL; + SvTEMP_off(sv); + return; + } #ifdef DEBUGGING if (SvTEMP(sv)) { Perl_ck_warner_d(aTHX_ packWARN(WARN_DEBUGGING), @@ -7236,11 +7311,6 @@ Perl_sv_free2(pTHX_ SV *const sv, const return; } #endif - if (SvIMMORTAL(sv)) { - /* make sure SvREFCNT(sv)==0 happens very seldom */ - SvREFCNT(sv) = SvREFCNT_IMMORTAL; - return; - } sv_clear(sv); if (! SvREFCNT(sv)) /* may have have been resurrected */ del_SV(sv); @@ -7424,24 +7494,20 @@ S_sv_pos_u2b_midway(const U8 *const star PERL_ARGS_ASSERT_SV_POS_U2B_MIDWAY; if (uoffset < 2 * backw) { - /* The assumption is that going forwards is twice the speed of going - forward (that's where the 2 * backw comes from). - (The real figure of course depends on the UTF-8 data.) */ + /* The assumption is that the average size of a character is 2 bytes, + * so going forwards is twice the speed of going backwards (that's + * where the 2 * backw comes from). (The real figure of course depends + * on the UTF-8 data.) */ const U8 *s = start; - while (s < send && uoffset--) - s += UTF8SKIP(s); + s = utf8_hop_forward(s, uoffset, send); assert (s <= send); if (s > send) s = send; return s - start; } - while (backw--) { - send--; - while (UTF8_IS_CONTINUATION(*send)) - send--; - } + send = utf8_hop_back(send, -backw, start); return send - start; } @@ -7836,10 +7902,7 @@ S_sv_pos_b2u_midway(pTHX_ const U8 *cons } while (end > target) { - end--; - while (UTF8_IS_CONTINUATION(*end)) { - end--; - } + end = utf8_hop_back(end, -1, target); endu--; } return endu; @@ -8000,23 +8063,20 @@ S_assert_uft8_cache_coherent(pTHX_ const } /* -=for apidoc sv_eq - -Returns a boolean indicating whether the strings in the two SVs are -identical. Is UTF-8 and S> aware, handles get magic, and will -coerce its args to strings if necessary. - -This function does not handle operator overloading. For a version that does, -see instead C. +=for apidoc sv_eq +=for apidoc_item sv_eq_flags -=for apidoc sv_eq_flags - -Returns a boolean indicating whether the strings in the two SVs are -identical. Is UTF-8 and S> aware and coerces its args to strings -if necessary. If the flags has the C bit set, it handles get-magic, too. +These each return a boolean indicating whether or not the strings in the two +SVs are equal. If S> is in effect, the comparison is +byte-by-byte; otherwise character-by-character. Each will coerce its args to +strings if necessary. + +They differ only in that C always processes get magic, while +C processes get magic only when the C parameter has the +C bit set. -This function does not handle operator overloading. For a version that does, -see instead C. +These functions do not handle operator overloading. For versions that do, +see instead C> or C>. =cut */ @@ -8286,7 +8346,7 @@ Perl_sv_cmp_flags(pTHX_ SV *const sv1, S * at the beginning of a character. But neither or both are * (or else earlier bytes would have been different). And * if we are in the middle of a character, the two - * characters are comprised of the same number of bytes + * characters have the same number of bytes * (because in this case the start bytes are the same, and * the start bytes encode the character's length). */ if (UTF8_IS_INVARIANT(*pv1)) @@ -10137,7 +10197,10 @@ Perl_sv_resetpvn(pTHX_ const char *s, ST sv = GvSV(gv); if (sv && !SvREADONLY(sv)) { SV_CHECK_THINKFIRST_COW_DROP(sv); - if (!isGV(sv)) SvOK_off(sv); + if (!isGV(sv)) { + SvOK_off(sv); + SvSETMAGIC(sv); + } } if (GvAV(gv)) { av_clear(GvAV(gv)); @@ -11016,6 +11079,8 @@ C and C) parameter, so are used in situations where the caller doesn't already have the thread context. +B + =cut */ @@ -11044,6 +11109,8 @@ C skips all magic. They are usually used via their frontends, C> and C>. +B + =cut */ @@ -11210,6 +11277,8 @@ Perl_sv_vcatpvf_mg(pTHX_ SV *const sv, c Works like C but copies the text into the SV instead of appending it. +B + Usually used via one of its frontends L> and L>. @@ -15087,7 +15156,10 @@ Perl_si_dup(pTHX_ PERL_SI *si, CLONE_PAR nsi->si_prev = si_dup(si->si_prev, param); nsi->si_next = si_dup(si->si_next, param); nsi->si_markoff = si->si_markoff; -#if defined DEBUGGING && !defined DEBUGGING_RE_ONLY +#ifdef PERL_RC_STACK + nsi->si_stack_nonrc_base = si->si_stack_nonrc_base; +#endif +#ifdef PERL_USE_HWM nsi->si_stack_hwm = 0; #endif @@ -16095,9 +16167,6 @@ perl_clone_using(PerlInterpreter *proto_ PL_numeric_underlying = true; PL_numeric_underlying_is_standard = true; -# if defined(USE_POSIX_2008_LOCALE) - PL_underlying_numeric_obj = NULL; -# endif #endif /* !USE_LOCALE_NUMERIC */ #if defined(USE_POSIX_2008_LOCALE) PL_scratch_locale_obj = NULL; @@ -16114,14 +16183,16 @@ perl_clone_using(PerlInterpreter *proto_ PL_wcrtomb_ps = proto_perl->Iwcrtomb_ps; #endif - PL_langinfo_buf = NULL; - PL_langinfo_bufsize = 0; + PL_langinfo_sv = newSVpvs(""); + PL_scratch_langinfo = newSVpvs(""); PL_setlocale_buf = NULL; PL_setlocale_bufsize = 0; - PL_stdize_locale_buf = NULL; - PL_stdize_locale_bufsize = 0; +#if defined(USE_LOCALE_THREADS) && ! defined(USE_THREAD_SAFE_LOCALE) + PL_less_dicey_locale_buf = NULL; + PL_less_dicey_locale_bufsize = 0; +#endif /* Unicode inversion lists */ @@ -16194,13 +16265,13 @@ perl_clone_using(PerlInterpreter *proto_ /* next PUSHMARK() sets *(PL_markstack_ptr+1) */ i = proto_perl->Imarkstack_max - proto_perl->Imarkstack; - Newx(PL_markstack, i, I32); + Newx(PL_markstack, i, Stack_off_t); PL_markstack_max = PL_markstack + (proto_perl->Imarkstack_max - proto_perl->Imarkstack); PL_markstack_ptr = PL_markstack + (proto_perl->Imarkstack_ptr - proto_perl->Imarkstack); Copy(proto_perl->Imarkstack, PL_markstack, - PL_markstack_ptr - PL_markstack + 1, I32); + PL_markstack_ptr - PL_markstack + 1, Stack_off_t); /* next push_scope()/ENTER sets PL_scopestack[PL_scopestack_ix] * NOTE: unlike the others! */ @@ -16275,12 +16346,14 @@ perl_clone_using(PerlInterpreter *proto_ HV* const stash = MUTABLE_HV(av_shift(param->stashes)); GV* const cloner = gv_fetchmethod_autoload(stash, "CLONE", 0); if (cloner && GvCV(cloner)) { - dSP; ENTER; SAVETMPS; - PUSHMARK(SP); - mXPUSHs(newSVhek(HvNAME_HEK(stash))); - PUTBACK; + PUSHMARK(PL_stack_sp); + rpp_extend(1); + SV *newsv = newSVhek(HvNAME_HEK(stash)); + *++PL_stack_sp = newsv; + if (!rpp_stack_is_rc()) + sv_2mortal(newsv); call_sv(MUTABLE_SV(GvCV(cloner)), G_DISCARD); FREETMPS; LEAVE; @@ -16738,6 +16811,9 @@ Perl_varname(pTHX_ const GV *const gv, c /* We know that name has no magic, so can use 0 instead of SV_GMAGIC */ Perl_sv_insert_flags(aTHX_ name, 0, 0, STR_WITH_LEN("within "), 0); } + else { + assert(subscript_type == FUV_SUBSCRIPT_NONE); + } return name; } @@ -17347,6 +17423,7 @@ S_find_uninit_var(pTHX_ const OP *const case OP_TIED: case OP_GETC: case OP_SYSREAD: + case OP_READLINE: case OP_SEND: case OP_IOCTL: case OP_SOCKET: @@ -17408,6 +17485,7 @@ S_find_uninit_var(pTHX_ const OP *const case OP_UNPACK: case OP_SYSOPEN: case OP_SYSSEEK: + case OP_SPLICE: /* scalar splice(@x, $i, 0) ==> undef */ match = 1; goto do_op; @@ -17428,6 +17506,51 @@ S_find_uninit_var(pTHX_ const OP *const return newSVpvs_flags("$.", SVs_TEMP); goto do_op; } + + case OP_LENGTH: + o = cUNOPx(obase)->op_first; + sv = find_uninit_var(o, uninit_sv, match, desc_p); + if (sv) { + Perl_sv_insert_flags(aTHX_ sv, 0, 0, STR_WITH_LEN("length("), 0); + sv_catpvs_nomg(sv, ")"); + } + return sv; + + case OP_SHIFT: + case OP_POP: + if (match) { + break; + } + if (!(obase->op_flags & OPf_KIDS)) { + sv = newSVpvn_flags("", 0, SVs_TEMP); + } + else { + o = cUNOPx(obase)->op_first; + if (o->op_type == OP_RV2AV) { + o2 = cUNOPx(o)->op_first; + if (o2->op_type != OP_GV) { + break; + } + gv = cGVOPx_gv(o2); + if (!gv) { + break; + } + } + else if (o->op_type == OP_PADAV) { + gv = NULL; + } + else { + break; + } + sv = varname(gv, '@', o->op_targ, NULL, 0, FUV_SUBSCRIPT_NONE); + } + if (sv) { + const char *name = OP_NAME(obase); + Perl_sv_insert_flags(aTHX_ sv, 0, 0, STR_WITH_LEN("("), 0); + Perl_sv_insert_flags(aTHX_ sv, 0, 0, name, strlen(name), 0); + sv_catpvs_nomg(sv, ")"); + } + return sv; case OP_POS: /* def-ness of rval pos() is independent of the def-ness of its arg */ Index: gnu/usr.bin/perl/sv.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/sv.h,v diff -u -p -a -u -p -r1.25 sv.h --- gnu/usr.bin/perl/sv.h 14 May 2024 19:38:54 -0000 1.25 +++ gnu/usr.bin/perl/sv.h 22 Jan 2025 00:37:45 -0000 @@ -2415,7 +2415,17 @@ that already have a PV buffer allocated, #ifdef DEBUGGING /* exercise the immortal resurrection code in sv_free2() */ -# define SvREFCNT_IMMORTAL 1000 +# ifdef PERL_RC_STACK + /* When the stack is ref-counted, the code tends to take a lot of + * short cuts with immortals, such as skipping the bump of the ref + * count of PL_sv_undef when pushing it on the stack. Exercise that + * this doesn't cause problems, especially on code which + * special-cases RC==1 etc. + */ +# define SvREFCNT_IMMORTAL 10 +# else +# define SvREFCNT_IMMORTAL 1000 +# endif #else # define SvREFCNT_IMMORTAL ((~(U32)0)/2) #endif Index: gnu/usr.bin/perl/sv_inline.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/sv_inline.h,v diff -u -p -a -u -p -r1.1.1.2 sv_inline.h --- gnu/usr.bin/perl/sv_inline.h 14 May 2024 19:36:28 -0000 1.1.1.2 +++ gnu/usr.bin/perl/sv_inline.h 22 Jan 2025 00:37:45 -0000 @@ -230,12 +230,25 @@ static const struct body_details bodies_ SVt_PVIV, FALSE, NONV, HASARENA, FIT_ARENA(0, sizeof(XPVIV) - STRUCT_OFFSET(XPV, xpv_cur)) }, +#if NVSIZE > 8 && PTRSIZE < 8 && MEM_ALIGNBYTES > 8 + /* NV may need strict 16 byte alignment. + + On 64-bit systems the NV ends up aligned despite the hack + avoiding allocation of xmg_stash and xmg_u, so only do this + for 32-bit systems. + */ + { sizeof(XPVNV), + sizeof(XPVNV), + 0, + SVt_PVNV, FALSE, HADNV, HASARENA, + FIT_ARENA(0, sizeof(XPVNV)) }, +#else { sizeof(XPVNV) - STRUCT_OFFSET(XPV, xpv_cur), copy_length(XPVNV, xnv_u) - STRUCT_OFFSET(XPV, xpv_cur), + STRUCT_OFFSET(XPV, xpv_cur), SVt_PVNV, FALSE, HADNV, HASARENA, FIT_ARENA(0, sizeof(XPVNV) - STRUCT_OFFSET(XPV, xpv_cur)) }, - +#endif { sizeof(XPVMG), copy_length(XPVMG, xnv_u), 0, SVt_PVMG, FALSE, HADNV, HASARENA, FIT_ARENA(0, sizeof(XPVMG)) }, @@ -567,6 +580,8 @@ Perl_SvPVXtrue(pTHX_ SV *sv) { PERL_ARGS_ASSERT_SVPVXTRUE; + PERL_UNUSED_CONTEXT; + if (! (XPV *) SvANY(sv)) { return false; } @@ -850,7 +865,7 @@ PERL_STATIC_INLINE UV Perl_SvUV_nomg(pTHX_ SV *sv) { PERL_ARGS_ASSERT_SVUV_NOMG; - if (SvIOK_nog(sv)) + if (SvUOK(sv)) return SvUVX(sv); return sv_2uv_flags(sv, 0); } @@ -859,7 +874,7 @@ PERL_STATIC_INLINE NV Perl_SvNV_nomg(pTHX_ SV *sv) { PERL_ARGS_ASSERT_SVNV_NOMG; - if (SvNOK_nog(sv)) + if (SvNOK(sv)) return SvNVX(sv); return sv_2nv_flags(sv, 0); } @@ -992,7 +1007,9 @@ Perl_sv_setpv_freshbuf(pTHX_ SV *const s assert(SvPVX(sv)); SvCUR_set(sv, 0); *(SvEND(sv))= '\0'; - (void)SvPOK_only_UTF8(sv); + (void)SvPOK_only_UTF8(sv); /* UTF-8 flag will be 0; This is used instead + of 'SvPOK_only' because the other sv_setpv + functions use it */ SvTAINT(sv); return SvPVX(sv); } Index: gnu/usr.bin/perl/toke.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/toke.c,v diff -u -p -a -u -p -r1.28 toke.c --- gnu/usr.bin/perl/toke.c 14 May 2024 19:38:54 -0000 1.28 +++ gnu/usr.bin/perl/toke.c 22 Jan 2025 00:37:45 -0000 @@ -482,7 +482,7 @@ static struct debug_tokens { DEBUG_TOKEN (NONE, NOAMP), DEBUG_TOKEN (NONE, NOTOP), DEBUG_TOKEN (IVAL, OROP), - DEBUG_TOKEN (NONE, OROR), + DEBUG_TOKEN (IVAL, OROR), DEBUG_TOKEN (IVAL, PERLY_AMPERSAND), DEBUG_TOKEN (IVAL, PERLY_BRACE_CLOSE), DEBUG_TOKEN (IVAL, PERLY_BRACE_OPEN), @@ -4054,9 +4054,13 @@ S_scan_const(pTHX_ char *start) } /* Add the (Unicode) code point to the output. */ - if (! d_is_utf8 || OFFUNI_IS_INVARIANT(uv)) { + if (OFFUNI_IS_INVARIANT(uv)) { *d++ = (char) LATIN1_TO_NATIVE(uv); } + else if (! d_is_utf8) { + *d++ = (char) LATIN1_TO_NATIVE(uv); + utf8_variant_count++; + } else { d = (char*) uvoffuni_to_utf8_flags((U8*)d, uv, (ckWARN(WARN_PORTABLE)) @@ -4464,7 +4468,7 @@ S_scan_const(pTHX_ char *start) * {4,5} (any digits around the comma) returns FALSE * if we're in a pattern and the first char is a [ * [] returns FALSE - * [SOMETHING] has a funky algorithm to decide whether it's a + * [SOMETHING] has a funky heuristic to decide whether it's a * character class or not. It has to deal with things like * /$foo[-3]/ and /$foo[$bar]/ as well as /$foo[$\d]+/ * anything else returns TRUE @@ -4477,135 +4481,258 @@ S_intuit_more(pTHX_ char *s, char *e) { PERL_ARGS_ASSERT_INTUIT_MORE; + /* This function has been mostly untouched for a long time, due to its, + * 'scariness', and lack of comments. khw has gone through and done some + * cleanup, while finding various instances of problematic behavior. + * Rather than change this base-level function immediately, khw has added + * commentary to those areas. */ + + /* If recursed within brackets, there is more to the expression */ if (PL_lex_brackets) return TRUE; - if (*s == '-' && s[1] == '>' && (s[2] == '[' || s[2] == '{')) - return TRUE; - if (*s == '-' && s[1] == '>' - && FEATURE_POSTDEREF_QQ_IS_ENABLED - && ( (s[2] == '$' && (s[3] == '*' || (s[3] == '#' && s[4] == '*'))) - ||(s[2] == '@' && memCHRs("*[{",s[3])) )) - return TRUE; - if (*s != '{' && *s != '[') + + /* If begins with '->' ... */ + if (s[0] == '-' && s[1] == '>') { + + /* '->[' and '->{' imply more to the expression */ + if (s[2] == '[' || s[2] == '{') { + return TRUE; + } + + /* Any post deref construct implies more to the expression */ + if ( FEATURE_POSTDEREF_QQ_IS_ENABLED + && ( (s[2] == '$' && ( s[3] == '*' + || (s[3] == '#' && s[4] == '*'))) + || (s[2] == '@' && memCHRs("*[{", s[3])) )) + { + return TRUE; + } + } + + if (s[0] != '{' && s[0] != '[') return FALSE; + + /* quit immediately from any errors from now on */ PL_parser->sub_no_recover = TRUE; + + /* Here is '{' or '['. Outside patterns, they're always subscripts */ if (!PL_lex_inpat) return TRUE; - /* In a pattern, so maybe we have {n,m}. */ - if (*s == '{') { + /* In a pattern, so maybe we have {n,m}, in which case, there isn't more to + * the expression. + * + * khw: This assumes that anything matching regcurly is a character class. + * The syntax of regcurly has been loosened since this function was + * written, and regcurly never required a comma, as in {0}. Probably it is + * ok as-is */ + if (s[0] == '{') { if (regcurly(s, e, NULL)) { return FALSE; } return TRUE; } - /* On the other hand, maybe we have a character class */ - + /* Here is '[': maybe we have a character class. Examine the guts */ s++; - if (*s == ']' || *s == '^') + + /* '^' implies a character class; An empty '[]' isn't legal, but it does + * mean there isn't more to come */ + if (s[0] == ']' || s[0] == '^') return FALSE; - else { - /* this is terrifying, and it works */ - int weight; - char seen[256]; - const char * const send = (char *) memchr(s, ']', e - s); - unsigned char un_char, last_un_char; - char tmpbuf[sizeof PL_tokenbuf * 4]; - if (!send) /* has to be an expression */ - return TRUE; - weight = 2; /* let's weigh the evidence */ + /* Find matching ']'. khw: This means any s[1] below is guaranteed to + * exist */ + const char * const send = (char *) memchr(s, ']', e - s); + if (! send) /* has to be an expression */ + return TRUE; - if (*s == '$') - weight -= 3; - else if (isDIGIT(*s)) { - if (s[1] != ']') { - if (isDIGIT(s[1]) && s[2] == ']') + /* If the construct consists entirely of one or two digits, call it a + * subscript. */ + if (isDIGIT(s[0]) && send - s <= 2 && (send - s == 1 || (isDIGIT(s[1])))) { + return TRUE; + } + + /* this is terrifying, and it mostly works. See GH #16478. + * + * khw: That ticket shows that the heuristics here get things wrong. That + * most of the weights are divisible by 5 indicates that not a lot of + * tuning was done, and that the values are fairly arbitrary. Especially + * problematic are when all characters in the construct are numeric. We + * have [89] always resolving to a subscript, though that could well be a + * character class that is related to finding non-octals. And [100] is a + * character class when it could well be a subscript. */ + + int weight; + + if (s[0] == '$') { /* First char is dollar; lean very slightly to it + being a subscript */ + weight = -1; + } + else { /* Otherwise, lean a little more towards it being a + character class. */ + weight = 2; + } + + /* Unsigned version of current character */ + unsigned char un_char = 0; + + /* Keep track of how many multiple occurrences of the same character there + * are */ + char seen[256]; + Zero(seen, 256, char); + + /* Examine each character in the construct */ + bool first_time = true; + for (; s < send; s++, first_time = false) { + unsigned char prev_un_char = un_char; + un_char = (unsigned char) s[0]; + switch (s[0]) { + case '@': + case '&': + case '$': + + /* Each additional occurrence of one of these three strongly + * indicates it is a subscript */ + weight -= seen[un_char] * 10; + + /* Following one of these characters, we look to see if there is an + * identifier already found in the program by that name. If so, + * strongly suspect this isn't a character class */ + if (isWORDCHAR_lazy_if_safe(s+1, PL_bufend, UTF)) { + int len; + char tmpbuf[sizeof PL_tokenbuf * 4]; + scan_ident(s, tmpbuf, sizeof tmpbuf, FALSE); + len = (int)strlen(tmpbuf); + if ( len > 1 + && gv_fetchpvn_flags(tmpbuf, + len, + UTF ? SVf_UTF8 : 0, + SVt_PV)) + weight -= 100; + else /* Not a multi-char identifier already known in the + program; is somewhat likely to be a subscript */ weight -= 10; } - else - weight -= 100; - } - Zero(seen,256,char); - un_char = 255; - for (; s < send; s++) { - last_un_char = un_char; - un_char = (unsigned char)*s; - switch (*s) { - case '@': - case '&': - case '$': - weight -= seen[un_char] * 10; - if (isWORDCHAR_lazy_if_safe(s+1, PL_bufend, UTF)) { - int len; - scan_ident(s, tmpbuf, sizeof tmpbuf, FALSE); - len = (int)strlen(tmpbuf); - if (len > 1 && gv_fetchpvn_flags(tmpbuf, len, - UTF ? SVf_UTF8 : 0, SVt_PV)) - weight -= 100; - else - weight -= 10; - } - else if (*s == '$' - && s[1] - && memCHRs("[#!%*<>()-=",s[1])) - { - if (/*{*/ memCHRs("])} =",s[2])) - weight -= 10; - else - weight -= 1; - } - break; - case '\\': - un_char = 254; - if (s[1]) { - if (memCHRs("wds]",s[1])) - weight += 100; - else if (seen[(U8)'\''] || seen[(U8)'"']) - weight += 1; - else if (memCHRs("rnftbxcav",s[1])) - weight += 40; - else if (isDIGIT(s[1])) { - weight += 40; - while (s[1] && isDIGIT(s[1])) - s++; - } - } + else if ( s[0] == '$' + && s[1] + && memCHRs("[#!%*<>()-=", s[1])) + { + /* Here we have what could be a punctuation variable. If the + * next character after it is a closing bracket, it makes it + * quite likely to be that, and hence a subscript. If it is + * something else, more mildly a subscript */ + if (/*{*/ memCHRs("])} =", s[2])) + weight -= 10; else - weight += 100; - break; - case '-': - if (s[1] == '\\') - weight += 50; - if (memCHRs("aA01! ",last_un_char)) - weight += 30; - if (memCHRs("zZ79~",s[1])) - weight += 30; - if (last_un_char == 255 && (isDIGIT(s[1]) || s[1] == '$')) - weight -= 5; /* cope with negative subscript */ - break; - default: - if (!isWORDCHAR(last_un_char) - && !(last_un_char == '$' || last_un_char == '@' - || last_un_char == '&') - && isALPHA(*s) && s[1] && isALPHA(s[1])) { - char *d = s; - while (isALPHA(*s)) + weight -= 1; + } + break; + + case '\\': + if (s[1]) { + if (memCHRs("wds]", s[1])) + weight += 100; /* \w \d \s => strongly charclass */ + /* khw: Why not \W \D \S \h \v, etc as well? */ + else if (seen[(U8)'\''] || seen[(U8)'"']) + weight += 1; /* \' => mildly charclass */ + else if (memCHRs("abcfnrtvx", s[1])) + weight += 40; /* \n, etc => charclass */ + /* khw: Why not \e etc as well? */ + else if (isDIGIT(s[1])) { + weight += 40; /* \123 => charclass */ + while (s[1] && isDIGIT(s[1])) s++; - if (keyword(d, s - d, 0)) - weight -= 150; } - if (un_char == last_un_char + 1) - weight += 5; - weight -= seen[un_char]; - break; } - seen[un_char]++; - } - if (weight >= 0) /* probably a character class */ - return FALSE; - } + else /* \ followed by NUL strongly indicates character class */ + weight += 100; + break; + + case '-': + /* If it is something like '-\', it is more likely to be a + * character class. + * + * khw: The rest of the conditionals in this 'case' really should + * be subject to an 'else' of this condition */ + if (s[1] == '\\') + weight += 50; + + /* If it is something like 'a-' or '0-', it is more likely to + * be a character class. '!' is the first ASCII graphic, so '!-' + * would be the start of a range of graphics. */ + if (! first_time && memCHRs("aA01! ", prev_un_char)) + weight += 30; + + /* If it is something like '-Z' or '-7' (for octal) or '-9' it + * is more likely to be a character class. '~' is the final ASCII + * graphic, so '-~' would be the end of a range of graphics. + * + * khw: Having [-z] really doesn't imply what the comments above + * indicate, so this should only be tested when '! first_time' */ + if (memCHRs("zZ79~", s[1])) + weight += 30; + + /* If it is something like -1 or -$foo, it is more likely to be a + * subscript. */ + if (first_time && (isDIGIT(s[1]) || s[1] == '$')) { + weight -= 5; /* cope with negative subscript */ + } + break; + + default: + if ( (first_time || ( ! isWORDCHAR(prev_un_char) + && prev_un_char != '$' + && prev_un_char != '@' + && prev_un_char != '&')) + && isALPHA(s[0]) + && isALPHA(s[1])) + { + /* Here it's \W (that isn't [$@&] ) followed immediately by two + * alphas in a row. Accumulate all the consecutive alphas */ + char *d = s; + while (isALPHA(s[0])) + s++; + + /* If those alphas spell a keyword, it's almost certainly not a + * character class */ + if (keyword(d, s - d, 0)) + weight -= 150; + + /* khw: Should those alphas be marked as seen? */ + } + + /* Consecutive chars like [...12...] and [...ab...] are presumed + * more likely to be character classes */ + if ( ! first_time + && ( NATIVE_TO_LATIN1(un_char) + == NATIVE_TO_LATIN1(prev_un_char) + 1)) + { + weight += 5; + } + + /* But repeating a character inside a character class does nothing, + * like [aba], so less likely that someone makes such a class, more + * likely that it is a subscript; the more repeats, the less + * likely. */ + weight -= seen[un_char]; + break; + } /* End of switch */ + + /* khw: 'seen' is declared as a char. This ++ can cause it to wrap. + * This gives different results with compilers for which a plain 'char' + * is actually unsigned, versus those where it is signed. I believe it + * is undefined behavior to wrap a 'signed'. I think it should be + * instead declared an unsigned int to make the chances of wrapping + * essentially zero. + * + * And I believe that extra backslashes are different from other + * repeated characters. */ + seen[un_char]++; + } /* End of loop through each character of the construct */ + + if (weight >= 0) /* probably a character class */ + return FALSE; return TRUE; } @@ -4919,7 +5046,32 @@ Perl_filter_read(pTHX_ int idx, SV *buf_ /* Return: <0:error, =0:eof, >0:not eof */ ENTER; save_scalar(PL_errgv); + + /* although this calls out to a random C function, there's a good + * chance that that function will call back into perl (e.g. using + * Filter::Util::Call). So downgrade the stack to + * non-reference-counted for backwards compatibility - i.e. do the + * equivalent of xs_wrap(), but this time we know there are no + * args to be passed or returned on the stack, simplifying it. + */ +#ifdef PERL_RC_STACK + assert(AvREAL(PL_curstack)); + I32 oldbase = PL_curstackinfo->si_stack_nonrc_base; + I32 oldsp = PL_stack_sp - PL_stack_base; + if (!oldbase) + PL_curstackinfo->si_stack_nonrc_base = oldsp + 1; +#endif + ret = (*funcp)(aTHX_ idx, buf_sv, correct_length); + +#ifdef PERL_RC_STACK + assert(oldsp == PL_stack_sp - PL_stack_base); + assert(AvREAL(PL_curstack)); + assert(PL_curstackinfo->si_stack_nonrc_base == + oldbase ? oldbase : oldsp + 1); + PL_curstackinfo->si_stack_nonrc_base = oldbase; +#endif + LEAVE; return ret; } @@ -5303,8 +5455,7 @@ yyl_dollar(pTHX_ char *s) } while (isSPACE(*t)); if (isIDFIRST_lazy_if_safe(t, PL_bufend, UTF)) { STRLEN len; - t = scan_word6(t, tmpbuf, sizeof tmpbuf, TRUE, - &len, TRUE); + t = scan_word(t, tmpbuf, sizeof tmpbuf, TRUE, &len); while (isSPACE(*t)) t++; if ( *t == ';' @@ -5947,6 +6098,16 @@ yyl_caret(pTHX_ char *s) { char *d = s; const bool bof = cBOOL(FEATURE_BITWISE_IS_ENABLED); + if (s[1] == '^') { + s += 2; + if (!PL_lex_allbrackets && PL_lex_fakeeof >= + (*s == '=' ? LEX_FAKEEOF_ASSIGN : LEX_FAKEEOF_LOGIC)) { + s -= 2; + TOKEN(0); + } + pl_yylval.ival = OP_XOR; + OPERATOR(OROR); + } if (bof && s[1] == '.') s++; if (!PL_lex_allbrackets && PL_lex_fakeeof >= @@ -6014,8 +6175,7 @@ yyl_colon(pTHX_ char *s) if (*d == '(') { d = scan_str(d,TRUE,TRUE,FALSE,NULL); if (!d) { - if (attrs) - op_free(attrs); + op_free(attrs); ASSUME(sv && SvREFCNT(sv) == 1); SvREFCNT_dec(sv); Perl_croak(aTHX_ "Unterminated attribute parameter in attribute list"); @@ -6063,8 +6223,7 @@ yyl_colon(pTHX_ char *s) ? Perl_form(aTHX_ "Invalid separator character " "%c%c%c in attribute list", q, *s, q) : "Unterminated attribute list" ) ); - if (attrs) - op_free(attrs); + op_free(attrs); OPERATOR(PERLY_COLON); } @@ -6072,8 +6231,7 @@ yyl_colon(pTHX_ char *s) if (PL_parser->sig_seen) { /* see comment about about sig_seen and parser error * handling */ - if (attrs) - op_free(attrs); + op_free(attrs); Perl_croak(aTHX_ "Subroutine attributes must come " "before the signature"); } @@ -6469,6 +6627,7 @@ yyl_verticalbar(pTHX_ char *s) s -= 2; TOKEN(0); } + pl_yylval.ival = OP_OR; AOPERATOR(OROR); } @@ -7029,9 +7188,7 @@ yyl_foreach(pTHX_ char *s) } if (UNLIKELY(paren_is_valid && *p == '(')) { - Perl_ck_warner_d(aTHX_ - packWARN(WARN_EXPERIMENTAL__FOR_LIST), - "for my (...) is experimental"); + ; /* fine - this is foreach my (list) */ } else if (UNLIKELY(*p != '$' && *p != '\\')) { /* "for myfoo (" will end up here, but with p pointing at the 'f' */ @@ -7791,19 +7948,18 @@ yyl_word_or_keyword(pTHX_ char *s, STRLE return yyl_just_a_word(aTHX_ s, len, orig_keyword, c); case KEY___FILE__: - FUN0OP( newSVOP(OP_CONST, 0, newSVpv(CopFILE(PL_curcop),0)) ); + FUN0OP(newSVOP(OP_CONST, OPpCONST_TOKEN_FILE<<8, + newSVpv(CopFILE(PL_curcop),0)) ); case KEY___LINE__: - FUN0OP( - newSVOP(OP_CONST, 0, - Perl_newSVpvf(aTHX_ "%" LINE_Tf, CopLINE(PL_curcop))) - ); + FUN0OP(newSVOP(OP_CONST, OPpCONST_TOKEN_LINE<<8, + Perl_newSVpvf(aTHX_ "%" LINE_Tf, CopLINE(PL_curcop)))); case KEY___PACKAGE__: - FUN0OP( - newSVOP(OP_CONST, 0, (PL_curstash - ? newSVhek(HvNAME_HEK(PL_curstash)) - : &PL_sv_undef)) + FUN0OP(newSVOP(OP_CONST, OPpCONST_TOKEN_PACKAGE<<8, + (PL_curstash + ? newSVhek(HvNAME_HEK(PL_curstash)) + : &PL_sv_undef)) ); case KEY___DATA__: @@ -7820,6 +7976,9 @@ yyl_word_or_keyword(pTHX_ char *s, STRLE ? newOP(OP_RUNCV, 0) : newSVOP(OP_RUNCV, 0, &PL_sv_undef)); + case KEY___CLASS__: + FUN0(OP_CLASSNAME); + case KEY_AUTOLOAD: case KEY_DESTROY: case KEY_BEGIN: @@ -7871,8 +8030,6 @@ yyl_word_or_keyword(pTHX_ char *s, STRLE FUN0(OP_BREAK); case KEY_catch: - Perl_ck_warner_d(aTHX_ - packWARN(WARN_EXPERIMENTAL__TRY), "try/catch is experimental"); PREBLOCK(KW_CATCH); case KEY_chop: @@ -8644,8 +8801,6 @@ yyl_word_or_keyword(pTHX_ char *s, STRLE case KEY_try: pl_yylval.ival = CopLINE(PL_curcop); - Perl_ck_warner_d(aTHX_ - packWARN(WARN_EXPERIMENTAL__TRY), "try/catch is experimental"); PREBLOCK(KW_TRY); case KEY_uc: @@ -9088,7 +9243,8 @@ yyl_try(pTHX_ char *s) } if (PL_minus_E) sv_catpvs(PL_linestr, - "use feature ':" STRINGIFY(PERL_REVISION) "." STRINGIFY(PERL_VERSION) "';"); + "use feature ':" STRINGIFY(PERL_REVISION) "." STRINGIFY(PERL_VERSION) "'; " + "use builtin ':" STRINGIFY(PERL_REVISION) "." STRINGIFY(PERL_VERSION) "';"); if (PL_minus_n || PL_minus_p) { sv_catpvs(PL_linestr, "LINE: while (<>) {"/*}*/); if (PL_minus_l) @@ -12698,10 +12854,6 @@ S_apply_builtin_cv_attribute(pTHX_ CV *c else if(memEQs(SvPVX(sv), len, "method")) CvNOWARN_AMBIGUOUS_on(cv); else if(memEQs(SvPVX(sv), len, "const")) { - Perl_ck_warner_d(aTHX_ - packWARN(WARN_EXPERIMENTAL__CONST_ATTR), - ":const is experimental" - ); CvANONCONST_on(cv); if (!CvANON(cv)) yyerror(":const is not permitted on named subroutines"); Index: gnu/usr.bin/perl/uconfig.h =================================================================== RCS file: gnu/usr.bin/perl/uconfig.h diff -N gnu/usr.bin/perl/uconfig.h --- gnu/usr.bin/perl/uconfig.h 14 May 2024 19:38:54 -0000 1.13 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,5387 +0,0 @@ -/* This file was produced by running the config_h.SH script, which - * gets its values from uconfig.sh, which is generally produced by - * running Configure. - * - * Feel free to modify any of this as the need arises. Note, however, - * that running config_h.SH again will wipe out any changes you've made. - * For a more permanent change edit uconfig.sh and rerun config_h.SH. - */ - -/* Package name : perl5 - * Source directory : . - * Configuration time: Thu Jan 1 00:00:00 GMT 1970 - * Configured by : root@localhost - * Target system : unknown - */ - -#ifndef _config_h_ -#define _config_h_ - -/* LOC_SED: - * This symbol holds the complete pathname to the sed program. - */ -#define LOC_SED "" /**/ - -/* HAS_ALARM: - * This symbol, if defined, indicates that the alarm routine is - * available. - */ -/*#define HAS_ALARM / **/ - -/* HAS_CBRT: - * This symbol, if defined, indicates that the cbrt() (cube root) - * function is available. - */ -/*#define HAS_CBRT / **/ - -/* HAS_CHOWN: - * This symbol, if defined, indicates that the chown routine is - * available. - */ -/*#define HAS_CHOWN / **/ - -/* HAS_CHROOT: - * This symbol, if defined, indicates that the chroot routine is - * available. - */ -/*#define HAS_CHROOT / **/ - -/* HAS_CHSIZE: - * This symbol, if defined, indicates that the chsize routine is available - * to truncate files. You might need a -lx to get this routine. - */ -/*#define HAS_CHSIZE / **/ - -/* HAS_CRYPT: - * This symbol, if defined, indicates that the crypt routine is available - * to encrypt passwords and the like. - */ -/*#define HAS_CRYPT / **/ - -/* HAS_CTERMID: - * This symbol, if defined, indicates that the ctermid routine is - * available to generate filename for terminal. - */ -/*#define HAS_CTERMID / **/ - -/* HAS_CUSERID: - * This symbol, if defined, indicates that the cuserid routine is - * available to get character login names. - */ -/*#define HAS_CUSERID / **/ - -/* HAS_DIFFTIME: - * This symbol, if defined, indicates that the difftime routine is - * available. - */ -/*#define HAS_DIFFTIME / **/ - -/* HAS_DLERROR: - * This symbol, if defined, indicates that the dlerror routine is - * available to return a string describing the last error that - * occurred from a call to dlopen(), dlclose() or dlsym(). - */ -/*#define HAS_DLERROR / **/ - -/* HAS_DUP2: - * This symbol, if defined, indicates that the dup2 routine is - * available to duplicate file descriptors. - */ -/*#define HAS_DUP2 / **/ - -/* HAS_FCHMOD: - * This symbol, if defined, indicates that the fchmod routine is available - * to change mode of opened files. If unavailable, use chmod(). - */ -/*#define HAS_FCHMOD / **/ - -/* HAS_FCHOWN: - * This symbol, if defined, indicates that the fchown routine is available - * to change ownership of opened files. If unavailable, use chown(). - */ -/*#define HAS_FCHOWN / **/ - -/* HAS_FCNTL: - * This symbol, if defined, indicates to the C program that - * the fcntl() function exists. - */ -/*#define HAS_FCNTL / **/ - -/* HAS_FGETPOS: - * This symbol, if defined, indicates that the fgetpos routine is - * available to get the file position indicator, similar to ftell(). - */ -/*#define HAS_FGETPOS / **/ - -/* HAS_FLOCK: - * This symbol, if defined, indicates that the flock routine is - * available to do file locking. - */ -/*#define HAS_FLOCK / **/ - -/* HAS_FORK: - * This symbol, if defined, indicates that the fork routine is - * available. - */ -#define HAS_FORK /**/ - -/* HAS_FSETPOS: - * This symbol, if defined, indicates that the fsetpos routine is - * available to set the file position indicator, similar to fseek(). - */ -/*#define HAS_FSETPOS / **/ - -/* HAS_GETTIMEOFDAY: - * This symbol, if defined, indicates that the gettimeofday() system - * call is available for a sub-second accuracy clock. Usually, the file - * needs to be included (see I_SYS_RESOURCE). - * The type "Timeval" should be used to refer to "struct timeval". - */ -/*#define HAS_GETTIMEOFDAY / **/ -#ifdef HAS_GETTIMEOFDAY -#define Timeval struct timeval /* Structure used by gettimeofday() */ -#endif - -/* HAS_GETGROUPS: - * This symbol, if defined, indicates that the getgroups() routine is - * available to get the list of process groups. If unavailable, multiple - * groups are probably not supported. - */ -/*#define HAS_GETGROUPS / **/ - -/* HAS_GETLOGIN: - * This symbol, if defined, indicates that the getlogin routine is - * available to get the login name. - */ -/*#define HAS_GETLOGIN / **/ - -/* HAS_GETPGID: - * This symbol, if defined, indicates to the C program that - * the getpgid(pid) function is available to get the - * process group id. - */ -/*#define HAS_GETPGID / **/ - -/* HAS_GETPGRP2: - * This symbol, if defined, indicates that the getpgrp2() (as in DG/UX) - * routine is available to get the current process group. - */ -/*#define HAS_GETPGRP2 / **/ - -/* HAS_GETPPID: - * This symbol, if defined, indicates that the getppid routine is - * available to get the parent process ID. - */ -/*#define HAS_GETPPID / **/ - -/* HAS_GETPRIORITY: - * This symbol, if defined, indicates that the getpriority routine is - * available to get a process's priority. - */ -/*#define HAS_GETPRIORITY / **/ - -/* HAS_INET_ATON: - * This symbol, if defined, indicates to the C program that the - * inet_aton() function is available to parse IP address "dotted-quad" - * strings. - */ -/*#define HAS_INET_ATON / **/ - -/* HAS_KILLPG: - * This symbol, if defined, indicates that the killpg routine is available - * to kill process groups. If unavailable, you probably should use kill - * with a negative process number. - */ -/*#define HAS_KILLPG / **/ - -/* HAS_LINK: - * This symbol, if defined, indicates that the link routine is - * available to create hard links. - */ -/*#define HAS_LINK / **/ - -/* HAS_LOCALECONV: - * This symbol, if defined, indicates that the localeconv routine is - * available for numeric and monetary formatting conventions. - */ -/*#define HAS_LOCALECONV / **/ - -/* HAS_LOCKF: - * This symbol, if defined, indicates that the lockf routine is - * available to do file locking. - */ -/*#define HAS_LOCKF / **/ - -/* HAS_LSTAT: - * This symbol, if defined, indicates that the lstat routine is - * available to do file stats on symbolic links. - */ -/*#define HAS_LSTAT / **/ - -/* HAS_MBLEN: - * This symbol, if defined, indicates that the mblen routine is available - * to find the number of bytes in a multibyte character. - */ -/*#define HAS_MBLEN / **/ - -/* HAS_MBSTOWCS: - * This symbol, if defined, indicates that the mbstowcs routine is - * available to convert a multibyte string into a wide character string. - */ -/*#define HAS_MBSTOWCS / **/ - -/* HAS_MBTOWC: - * This symbol, if defined, indicates that the mbtowc routine is available - * to convert a multibyte to a wide character. - */ -/*#define HAS_MBTOWC / **/ - -/* HAS_MKDIR: - * This symbol, if defined, indicates that the mkdir routine is available - * to create directories. Otherwise you should fork off a new process to - * exec /bin/mkdir. - */ -/*#define HAS_MKDIR / **/ - -/* HAS_MKFIFO: - * This symbol, if defined, indicates that the mkfifo routine is - * available to create FIFOs. Otherwise, mknod should be able to - * do it for you. However, if mkfifo is there, mknod might require - * super-user privileges which mkfifo will not. - */ -/*#define HAS_MKFIFO / **/ - -/* HAS_MKTIME: - * This symbol, if defined, indicates that the mktime routine is - * available. - */ -/*#define HAS_MKTIME / **/ - -/* HAS_MSG: - * This symbol, if defined, indicates that the entire msg*(2) library is - * supported (IPC mechanism based on message queues). - */ -/*#define HAS_MSG / **/ - -/* HAS_MSYNC: - * This symbol, if defined, indicates that the msync system call is - * available to synchronize a mapped file. - */ -/*#define HAS_MSYNC / **/ - -/* HAS_MUNMAP: - * This symbol, if defined, indicates that the munmap system call is - * available to unmap a region, usually mapped by mmap(). - */ -/*#define HAS_MUNMAP / **/ - -/* HAS_NICE: - * This symbol, if defined, indicates that the nice routine is - * available. - */ -/*#define HAS_NICE / **/ - -/* HAS_PATHCONF: - * This symbol, if defined, indicates that pathconf() is available - * to determine file-system related limits and options associated - * with a given filename. - */ -/* HAS_FPATHCONF: - * This symbol, if defined, indicates that pathconf() is available - * to determine file-system related limits and options associated - * with a given open file descriptor. - */ -/*#define HAS_PATHCONF / **/ -/*#define HAS_FPATHCONF / **/ - -/* HAS_PAUSE: - * This symbol, if defined, indicates that the pause routine is - * available to suspend a process until a signal is received. - */ -/*#define HAS_PAUSE / **/ - -/* HAS_PIPE: - * This symbol, if defined, indicates that the pipe routine is - * available to create an inter-process channel. - */ -/*#define HAS_PIPE / **/ - -/* HAS_POLL: - * This symbol, if defined, indicates that the poll routine is - * available to poll active file descriptors. Please check I_POLL and - * I_SYS_POLL to know which header should be included as well. - */ -/*#define HAS_POLL / **/ - -/* HAS_READDIR: - * This symbol, if defined, indicates that the readdir routine is - * available to read directory entries. You may have to include - * . See I_DIRENT. - */ -#define HAS_READDIR /**/ - -/* HAS_SEEKDIR: - * This symbol, if defined, indicates that the seekdir routine is - * available. You may have to include . See I_DIRENT. - */ -/*#define HAS_SEEKDIR / **/ - -/* HAS_TELLDIR: - * This symbol, if defined, indicates that the telldir routine is - * available. You may have to include . See I_DIRENT. - */ -/*#define HAS_TELLDIR / **/ - -/* HAS_REWINDDIR: - * This symbol, if defined, indicates that the rewinddir routine is - * available. You may have to include . See I_DIRENT. - */ -/*#define HAS_REWINDDIR / **/ - -/* HAS_READLINK: - * This symbol, if defined, indicates that the readlink routine is - * available to read the value of a symbolic link. - */ -/*#define HAS_READLINK / **/ - -/* HAS_REGCOMP: - * This symbol, if defined, indicates that the regcomp() routine is - * available to do some regular pattern matching (usually on POSIX.2 - * conforming systems). - */ -#define HAS_REGCOMP /* POSIX.2 */ - -/* HAS_RENAME: - * This symbol, if defined, indicates that the rename routine is available - * to rename files. Otherwise you should do the unlink(), link(), unlink() - * trick. - */ -#define HAS_RENAME /**/ - -/* HAS_RMDIR: - * This symbol, if defined, indicates that the rmdir routine is - * available to remove directories. Otherwise you should fork off a - * new process to exec /bin/rmdir. - */ -/*#define HAS_RMDIR / **/ - -/* HAS_SELECT: - * This symbol, if defined, indicates that the select routine is - * available to select active file descriptors. If the timeout field - * is used, may need to be included. - */ -/*#define HAS_SELECT / **/ - -/* HAS_SEM: - * This symbol, if defined, indicates that the entire sem*(2) library is - * supported. - */ -/*#define HAS_SEM / **/ - -/* HAS_SETEGID: - * This symbol, if defined, indicates that the setegid routine is available - * to change the effective gid of the current program. - */ -/*#define HAS_SETEGID / **/ - -/* HAS_SETEUID: - * This symbol, if defined, indicates that the seteuid routine is available - * to change the effective uid of the current program. - */ -/*#define HAS_SETEUID / **/ - -/* HAS_SETGROUPS: - * This symbol, if defined, indicates that the setgroups() routine is - * available to set the list of process groups. If unavailable, multiple - * groups are probably not supported. - */ -/*#define HAS_SETGROUPS / **/ - -/* HAS_SETLINEBUF: - * This symbol, if defined, indicates that the setlinebuf routine is - * available to change stderr or stdout from block-buffered or unbuffered - * to a line-buffered mode. - */ -/*#define HAS_SETLINEBUF / **/ - -/* HAS_SETPGID: - * This symbol, if defined, indicates that the setpgid(pid, gpid) - * routine is available to set process group ID. - */ -/*#define HAS_SETPGID / **/ - -/* HAS_SETPGRP2: - * This symbol, if defined, indicates that the setpgrp2() (as in DG/UX) - * routine is available to set the current process group. - */ -/*#define HAS_SETPGRP2 / **/ - -/* HAS_SETPRIORITY: - * This symbol, if defined, indicates that the setpriority routine is - * available to set a process's priority. - */ -/*#define HAS_SETPRIORITY / **/ - -/* HAS_SETREGID: - * This symbol, if defined, indicates that the setregid routine is - * available to change the real and effective gid of the current - * process. - */ -/* HAS_SETRESGID: - * This symbol, if defined, indicates that the setresgid routine is - * available to change the real, effective and saved gid of the current - * process. - */ -/*#define HAS_SETREGID / **/ -/*#define HAS_SETRESGID / **/ - -/* HAS_SETREUID: - * This symbol, if defined, indicates that the setreuid routine is - * available to change the real and effective uid of the current - * process. - */ -/* HAS_SETRESUID: - * This symbol, if defined, indicates that the setresuid routine is - * available to change the real, effective and saved uid of the current - * process. - */ -/*#define HAS_SETREUID / **/ -/*#define HAS_SETRESUID / **/ - -/* HAS_SETRGID: - * This symbol, if defined, indicates that the setrgid routine is available - * to change the real gid of the current program. - */ -/*#define HAS_SETRGID / **/ - -/* HAS_SETRUID: - * This symbol, if defined, indicates that the setruid routine is available - * to change the real uid of the current program. - */ -/*#define HAS_SETRUID / **/ - -/* HAS_SETSID: - * This symbol, if defined, indicates that the setsid routine is - * available to set the process group ID. - */ -/*#define HAS_SETSID / **/ - -/* HAS_STAT: - * This symbol, if defined, indicates that the stat routine is - * available to get file status. - */ -#define HAS_STAT /**/ - -/* HAS_STRCOLL: - * This symbol, if defined, indicates that the strcoll routine is - * available to compare strings using collating information. - */ -/*#define HAS_STRCOLL / **/ - -/* HAS_STRTOD: - * This symbol, if defined, indicates that the strtod routine is - * available to provide better numeric string conversion than atof(). - */ -/*#define HAS_STRTOD / **/ - -/* HAS_STRTOL: - * This symbol, if defined, indicates that the strtol routine is available - * to provide better numeric string conversion than atoi() and friends. - */ -#define HAS_STRTOL /**/ - -/* HAS_STRXFRM: - * This symbol, if defined, indicates that the strxfrm() routine is - * available to transform strings. - */ -/*#define HAS_STRXFRM / **/ - -/* HAS_SYMLINK: - * This symbol, if defined, indicates that the symlink routine is available - * to create symbolic links. - */ -/*#define HAS_SYMLINK / **/ - -/* HAS_SYSCALL: - * This symbol, if defined, indicates that the syscall routine is - * available to call arbitrary system calls. If undefined, that's tough. - */ -/*#define HAS_SYSCALL / **/ - -/* HAS_SYSCONF: - * This symbol, if defined, indicates that sysconf() is available - * to determine system related limits and options. - */ -/*#define HAS_SYSCONF / **/ - -/* HAS_SYSTEM: - * This symbol, if defined, indicates that the system routine is - * available to issue a shell command. - */ -/*#define HAS_SYSTEM / **/ - -/* HAS_TCGETPGRP: - * This symbol, if defined, indicates that the tcgetpgrp routine is - * available to get foreground process group ID. - */ -/*#define HAS_TCGETPGRP / **/ - -/* HAS_TCSETPGRP: - * This symbol, if defined, indicates that the tcsetpgrp routine is - * available to set foreground process group ID. - */ -/*#define HAS_TCSETPGRP / **/ - -/* HAS_TRUNCATE: - * This symbol, if defined, indicates that the truncate routine is - * available to truncate files. - */ -/*#define HAS_TRUNCATE / **/ - -/* HAS_TZNAME: - * This symbol, if defined, indicates that the tzname[] array is - * available to access timezone names. - */ -/*#define HAS_TZNAME / **/ - -/* HAS_UMASK: - * This symbol, if defined, indicates that the umask routine is - * available to set and get the value of the file creation mask. - */ -/*#define HAS_UMASK / **/ - -/* HAS_USLEEP: - * This symbol, if defined, indicates that the usleep routine is - * available to let the process sleep on a sub-second accuracy. - */ -/*#define HAS_USLEEP / **/ - -/* HAS_WAIT4: - * This symbol, if defined, indicates that wait4() exists. - */ -/*#define HAS_WAIT4 / **/ - -/* HAS_WAITPID: - * This symbol, if defined, indicates that the waitpid routine is - * available to wait for child process. - */ -/*#define HAS_WAITPID / **/ - -/* HAS_WCSTOMBS: - * This symbol, if defined, indicates that the wcstombs routine is - * available to convert wide character strings to multibyte strings. - */ -/*#define HAS_WCSTOMBS / **/ - -/* HAS_WCTOMB: - * This symbol, if defined, indicates that the wctomb routine is available - * to convert a wide character to a multibyte. - */ -/*#define HAS_WCTOMB / **/ - -/* Groups_t: - * This symbol holds the type used for the second argument to - * getgroups() and setgroups(). Usually, this is the same as - * gidtype (gid_t) , but sometimes it isn't. - * It can be int, ushort, gid_t, etc... - * It may be necessary to include to get any - * typedef'ed information. This is only required if you have - * getgroups() or setgroups().. - */ -#if defined(HAS_GETGROUPS) || defined(HAS_SETGROUPS) -#define Groups_t int /* Type for 2nd arg to [sg]etgroups() */ -#endif - -/* I_ARPA_INET: - * This symbol, if defined, indicates to the C program that it should - * include to get inet_addr and friends declarations. - */ -/*#define I_ARPA_INET / **/ - -/* I_DBM: - * This symbol, if defined, indicates that exists and should - * be included. - */ -/* I_RPCSVC_DBM: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_DBM / **/ -/*#define I_RPCSVC_DBM / **/ - -/* I_DLFCN: - * This symbol, if defined, indicates that exists and should - * be included. - */ -/*#define I_DLFCN / **/ - -/* I_FCNTL: - * This manifest constant tells the C program to include . - */ -/*#define I_FCNTL / **/ - -/* I_GDBM: - * This symbol, if defined, indicates that exists and should - * be included. - */ -/*#define I_GDBM / **/ - -/* I_LOCALE: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_LOCALE / **/ - -/* I_NETINET_IN: - * This symbol, if defined, indicates to the C program that it should - * include . Otherwise, you may try . - */ -/*#define I_NETINET_IN / **/ - -/* I_SYS_DIR: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_SYS_DIR / **/ - -/* I_SYS_FILE: - * This symbol, if defined, indicates to the C program that it should - * include to get definition of R_OK and friends. - */ -/*#define I_SYS_FILE / **/ - -/* I_SYS_IOCTL: - * This symbol, if defined, indicates that exists and should - * be included. Otherwise, include or . - */ -/* I_SYS_SOCKIO: - * This symbol, if defined, indicates the should be included - * to get socket ioctl options, like SIOCATMARK. - */ -/*#define I_SYS_IOCTL / **/ -/*#define I_SYS_SOCKIO / **/ - -/* I_SYS_NDIR: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_SYS_NDIR / **/ - -/* I_SYS_PARAM: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_SYS_PARAM / **/ - -/* I_SYS_POLL: - * This symbol, if defined, indicates that the program may include - * . When I_POLL is also defined, it's probably safest - * to only include . - */ -/*#define I_SYS_POLL / **/ - -/* I_SYS_RESOURCE: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_SYS_RESOURCE / **/ - -/* I_SYS_SELECT: - * This symbol, if defined, indicates to the C program that it should - * include in order to get definition of struct timeval. - */ -/*#define I_SYS_SELECT / **/ - -/* I_SYS_STAT: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -#define I_SYS_STAT /**/ - -/* I_SYS_TIMES: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_SYS_TIMES / **/ - -/* I_SYS_TYPES: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_SYS_TYPES / **/ - -/* I_SYS_UN: - * This symbol, if defined, indicates to the C program that it should - * include to get UNIX domain socket definitions. - */ -/*#define I_SYS_UN / **/ - -/* I_SYS_WAIT: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_SYS_WAIT / **/ - -/* I_UNISTD: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_UNISTD / **/ - -/* I_UTIME: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_UTIME / **/ - -/* I_VFORK: - * This symbol, if defined, indicates to the C program that it should - * include vfork.h. - */ -/*#define I_VFORK / **/ - -/* STDCHAR: - * This symbol is defined to be the type of char used in stdio.h. - * It has the values "unsigned char" or "char". - */ -#define STDCHAR char /**/ - -/* INTSIZE: - * This symbol contains the value of sizeof(int) so that the C - * preprocessor can make decisions based on it. - */ -/* LONGSIZE: - * This symbol contains the value of sizeof(long) so that the C - * preprocessor can make decisions based on it. - */ -/* SHORTSIZE: - * This symbol contains the value of sizeof(short) so that the C - * preprocessor can make decisions based on it. - */ -#define INTSIZE 4 /**/ -#define LONGSIZE 4 /**/ -#define SHORTSIZE 2 /**/ - -/* MULTIARCH: - * This symbol, if defined, signifies that the build - * process will produce some binary files that are going to be - * used in a cross-platform environment. This is the case for - * example with the NeXT "fat" binaries that contain executables - * for several CPUs. - */ -/*#define MULTIARCH / **/ - -/* HAS_QUAD: - * This symbol, if defined, tells that there's a 64-bit integer type, - * Quad_t, and its unsigned counterpart, Uquad_t. QUADKIND will be one - * of QUAD_IS_INT, QUAD_IS_LONG, QUAD_IS_LONG_LONG, QUAD_IS_INT64_T, - * or QUAD_IS___INT64. - */ -/*#define HAS_QUAD / **/ -#ifdef HAS_QUAD -# define Quad_t int64_t /**/ -# define Uquad_t uint64_t /**/ -# define QUADKIND 4 /**/ -# define QUAD_IS_INT 1 -# define QUAD_IS_LONG 2 -# define QUAD_IS_LONG_LONG 3 -# define QUAD_IS_INT64_T 4 -# define QUAD_IS___INT64 5 -#endif - -/* HAS_ACCESSX: - * This symbol, if defined, indicates that the accessx routine is - * available to do extended access checks. - */ -/*#define HAS_ACCESSX / **/ - -/* HAS_EACCESS: - * This symbol, if defined, indicates that the eaccess routine is - * available to do extended access checks. - */ -/*#define HAS_EACCESS / **/ - -/* I_SYS_ACCESS: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_SYS_ACCESS / **/ - -/* I_SYS_SECURITY: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_SYS_SECURITY / **/ - -/* MEM_ALIGNBYTES: - * This symbol contains the number of bytes required to align a - * double, or a long double when applicable. Usual values are 2, - * 4 and 8. The default is eight, for safety. For cross-compiling - * or multiarch support, Configure will set a minimum of 8. - */ -#define MEM_ALIGNBYTES 4 - -/* BYTEORDER: - * This symbol holds the hexadecimal constant defined in byteorder, - * in a UV, i.e. 0x1234 or 0x4321 or 0x12345678, etc... - * If the compiler supports cross-compiling or multiple-architecture - * binaries, use compiler-defined macros to - * determine the byte order. - */ -#if defined(MULTIARCH) -# ifdef __LITTLE_ENDIAN__ -# if LONGSIZE == 4 -# define BYTEORDER 0x1234 -# else -# if LONGSIZE == 8 -# define BYTEORDER 0x12345678 -# endif -# endif -# else -# ifdef __BIG_ENDIAN__ -# if LONGSIZE == 4 -# define BYTEORDER 0x4321 -# else -# if LONGSIZE == 8 -# define BYTEORDER 0x87654321 -# endif -# endif -# endif -# endif -#else -#define BYTEORDER 0x1234 /* large digits for MSB */ -#endif - -/* CHARBITS: - * This symbol contains the size of a char, so that the C preprocessor - * can make decisions based on it. - */ -#define CHARBITS 8 /**/ - -/* CASTI32: - * This symbol is defined if the C compiler can cast negative - * or large floating point numbers to 32-bit ints. - */ -/*#define CASTI32 / **/ - -/* CASTNEGFLOAT: - * This symbol is defined if the C compiler can cast negative - * numbers to unsigned longs, ints and shorts. - */ -/* CASTFLAGS: - * This symbol contains flags that say what difficulties the compiler - * has casting odd floating values to unsigned long: - * 0 = ok - * 1 = couldn't cast < 0 - * 2 = couldn't cast >= 0x80000000 - * 4 = couldn't cast in argument expression list - */ -/*#define CASTNEGFLOAT / **/ -#define CASTFLAGS 0 /**/ - -/* VOID_CLOSEDIR: - * This symbol, if defined, indicates that the closedir() routine - * does not return a value. - */ -/*#define VOID_CLOSEDIR / **/ - -/* HAS_FD_SET: - * This symbol, when defined, indicates presence of the fd_set typedef - * in - */ -/*#define HAS_FD_SET / **/ - -/* Gconvert: - * This preprocessor macro is defined to convert a floating point - * number to a string without a trailing decimal point. This - * emulates the behavior of sprintf("%g"), but is sometimes much more - * efficient. If gconvert() is not available, but gcvt() drops the - * trailing decimal point, then gcvt() is used. If all else fails, - * a macro using sprintf("%g") is used. Arguments for the Gconvert - * macro are: value, number of digits, whether trailing zeros should - * be retained, and the output buffer. - * The usual values are: - * d_Gconvert='gconvert((x),(n),(t),(b))' - * d_Gconvert='gcvt((x),(n),(b))' - * d_Gconvert='sprintf((b),"%.*g",(n),(x))' - * The last two assume trailing zeros should not be kept. - */ -#define Gconvert(x,n,t,b) sprintf((b),"%.*g",(n),(x)) - -/* HAS_GETPAGESIZE: - * This symbol, if defined, indicates that the getpagesize system call - * is available to get system page size, which is the granularity of - * many memory management calls. - */ -/*#define HAS_GETPAGESIZE / **/ - -/* HAS_GNULIBC: - * This symbol, if defined, indicates to the C program that - * the GNU C library is being used. A better check is to use - * the __GLIBC__ and __GLIBC_MINOR__ symbols supplied with glibc. - */ -/*#define HAS_GNULIBC / **/ -#if defined(HAS_GNULIBC) && !defined(_GNU_SOURCE) -# define _GNU_SOURCE -#endif - -/* HAS_ISASCII: - * This manifest constant lets the C program know that isascii - * is available. - */ -/*#define HAS_ISASCII / **/ - -/* HAS_LCHOWN: - * This symbol, if defined, indicates that the lchown routine is - * available to operate on a symbolic link (instead of following the - * link). - */ -/*#define HAS_LCHOWN / **/ - -/* HAS_OPEN3: - * This manifest constant lets the C program know that the three - * argument form of open(2) is available. - */ -/*#define HAS_OPEN3 / **/ - -/* HAS_SIGACTION: - * This symbol, if defined, indicates that Vr4's sigaction() routine - * is available. - */ -/*#define HAS_SIGACTION / **/ - -/* HAS_SIGINFO_SI_ERRNO: - * This symbol, if defined, indicates that siginfo_t has the - * si_errno member - */ -/* HAS_SIGINFO_SI_PID: - * This symbol, if defined, indicates that siginfo_t has the - * si_pid member - */ -/* HAS_SIGINFO_SI_UID: - * This symbol, if defined, indicates that siginfo_t has the - * si_uid member - */ -/* HAS_SIGINFO_SI_ADDR: - * This symbol, if defined, indicates that siginfo_t has the - * si_addr member - */ -/* HAS_SIGINFO_SI_STATUS: - * This symbol, if defined, indicates that siginfo_t has the - * si_status member - */ -/* HAS_SIGINFO_SI_BAND: - * This symbol, if defined, indicates that siginfo_t has the - * si_band member - */ -/* HAS_SIGINFO_SI_VALUE: - * This symbol, if defined, indicates that siginfo_t has the - * si_value member - */ -/*#define HAS_SIGINFO_SI_ERRNO / **/ -/*#define HAS_SIGINFO_SI_PID / **/ -/*#define HAS_SIGINFO_SI_UID / **/ -/*#define HAS_SIGINFO_SI_ADDR / **/ -/*#define HAS_SIGINFO_SI_STATUS / **/ -/*#define HAS_SIGINFO_SI_BAND / **/ -/*#define HAS_SIGINFO_SI_VALUE / **/ - -/* HAS_SIGSETJMP: - * This variable indicates to the C program that the sigsetjmp() - * routine is available to save the calling process's registers - * and stack environment for later use by siglongjmp(), and - * to optionally save the process's signal mask. See - * Sigjmp_buf, Sigsetjmp, and Siglongjmp. - */ -/* Sigjmp_buf: - * This is the buffer type to be used with Sigsetjmp and Siglongjmp. - */ -/* Sigsetjmp: - * This macro is used in the same way as sigsetjmp(), but will invoke - * traditional setjmp() if sigsetjmp isn't available. - * See HAS_SIGSETJMP. - */ -/* Siglongjmp: - * This macro is used in the same way as siglongjmp(), but will invoke - * traditional longjmp() if siglongjmp isn't available. - * See HAS_SIGSETJMP. - */ -/*#define HAS_SIGSETJMP / **/ -#ifdef HAS_SIGSETJMP -#define Sigjmp_buf sigjmp_buf -#define Sigsetjmp(buf,save_mask) sigsetjmp((buf),(save_mask)) -#define Siglongjmp(buf,retval) siglongjmp((buf),(retval)) -#else -#define Sigjmp_buf jmp_buf -#define Sigsetjmp(buf,save_mask) setjmp((buf)) -#define Siglongjmp(buf,retval) longjmp((buf),(retval)) -#endif - -/* HAS_STATIC_INLINE: - * This symbol, if defined, indicates that the C compiler supports - * C99-style static inline. That is, the function can't be called - * from another translation unit. - */ -/* PERL_STATIC_INLINE: - * This symbol gives the best-guess incantation to use for static - * inline functions. If HAS_STATIC_INLINE is defined, this will - * give C99-style inline. If HAS_STATIC_INLINE is not defined, - * this will give a plain 'static'. It will always be defined - * to something that gives static linkage. - * Possibilities include - * static inline (c99) - * static __inline__ (gcc -ansi) - * static __inline (MSVC) - * static _inline (older MSVC) - * static (c89 compilers) - */ -/*#define HAS_STATIC_INLINE / **/ -#define PERL_STATIC_INLINE static /**/ - -/* USE_STDIO_PTR: - * This symbol is defined if the _ptr and _cnt fields (or similar) - * of the stdio FILE structure can be used to access the stdio buffer - * for a file handle. If this is defined, then the FILE_ptr(fp) - * and FILE_cnt(fp) macros will also be defined and should be used - * to access these fields. - */ -/* FILE_ptr: - * This macro is used to access the _ptr field (or equivalent) of the - * FILE structure pointed to by its argument. This macro will always be - * defined if USE_STDIO_PTR is defined. - */ -/* STDIO_PTR_LVALUE: - * This symbol is defined if the FILE_ptr macro can be used as an - * lvalue. - */ -/* FILE_cnt: - * This macro is used to access the _cnt field (or equivalent) of the - * FILE structure pointed to by its argument. This macro will always be - * defined if USE_STDIO_PTR is defined. - */ -/* STDIO_CNT_LVALUE: - * This symbol is defined if the FILE_cnt macro can be used as an - * lvalue. - */ -/* STDIO_PTR_LVAL_SETS_CNT: - * This symbol is defined if using the FILE_ptr macro as an lvalue - * to increase the pointer by n has the side effect of decreasing the - * value of File_cnt(fp) by n. - */ -/* STDIO_PTR_LVAL_NOCHANGE_CNT: - * This symbol is defined if using the FILE_ptr macro as an lvalue - * to increase the pointer by n leaves File_cnt(fp) unchanged. - */ -/*#define USE_STDIO_PTR / **/ -#ifdef USE_STDIO_PTR -#define FILE_ptr(fp) ((fp)->_IO_read_ptr) -/*#define STDIO_PTR_LVALUE / **/ -#define FILE_cnt(fp) ((fp)->_IO_read_end - (fp)->_IO_read_ptr) -/*#define STDIO_CNT_LVALUE / **/ -/*#define STDIO_PTR_LVAL_SETS_CNT / **/ -/*#define STDIO_PTR_LVAL_NOCHANGE_CNT / **/ -#endif - -/* USE_STDIO_BASE: - * This symbol is defined if the _base field (or similar) of the - * stdio FILE structure can be used to access the stdio buffer for - * a file handle. If this is defined, then the FILE_base(fp) macro - * will also be defined and should be used to access this field. - * Also, the FILE_bufsiz(fp) macro will be defined and should be used - * to determine the number of bytes in the buffer. USE_STDIO_BASE - * will never be defined unless USE_STDIO_PTR is. - */ -/* FILE_base: - * This macro is used to access the _base field (or equivalent) of the - * FILE structure pointed to by its argument. This macro will always be - * defined if USE_STDIO_BASE is defined. - */ -/* FILE_bufsiz: - * This macro is used to determine the number of bytes in the I/O - * buffer pointed to by _base field (or equivalent) of the FILE - * structure pointed to its argument. This macro will always be defined - * if USE_STDIO_BASE is defined. - */ -/*#define USE_STDIO_BASE / **/ -#ifdef USE_STDIO_BASE -#define FILE_base(fp) ((fp)->_IO_read_base) -#define FILE_bufsiz(fp) ((fp)->_IO_read_end - (fp)->_IO_read_base) -#endif - -/* DOUBLESIZE: - * This symbol contains the size of a double, so that the C preprocessor - * can make decisions based on it. - */ -#define DOUBLESIZE 8 /**/ - -/* I_TIME: - * This symbol is always defined, and indicates to the C program that - * it should include . - */ -/* I_SYS_TIME: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/* I_SYS_TIME_KERNEL: - * This symbol, if defined, indicates to the C program that it should - * include with KERNEL defined. - */ -/* HAS_TM_TM_ZONE: - * This symbol, if defined, indicates to the C program that - * the struct tm has a tm_zone field. - */ -/* HAS_TM_TM_GMTOFF: - * This symbol, if defined, indicates to the C program that - * the struct tm has a tm_gmtoff field. - */ -#define I_TIME /**/ -/*#define I_SYS_TIME / **/ -/*#define I_SYS_TIME_KERNEL / **/ -/*#define HAS_TM_TM_ZONE / **/ -/*#define HAS_TM_TM_GMTOFF / **/ - -/* VAL_O_NONBLOCK: - * This symbol is to be used during open() or fcntl(F_SETFL) to turn on - * non-blocking I/O for the file descriptor. Note that there is no way - * back, i.e. you cannot turn it blocking again this way. If you wish to - * alternatively switch between blocking and non-blocking, use the - * ioctl(FIOSNBIO) call instead, but that is not supported by all devices. - */ -/* VAL_EAGAIN: - * This symbol holds the errno error code set by read() when no data was - * present on the non-blocking file descriptor. - */ -/* RD_NODATA: - * This symbol holds the return code from read() when no data is present - * on the non-blocking file descriptor. Be careful! If EOF_NONBLOCK is - * not defined, then you can't distinguish between no data and EOF by - * issuing a read(). You'll have to find another way to tell for sure! - */ -/* EOF_NONBLOCK: - * This symbol, if defined, indicates to the C program that a read() on - * a non-blocking file descriptor will return 0 on EOF, and not the value - * held in RD_NODATA (-1 usually, in that case!). - */ -#define VAL_O_NONBLOCK O_NONBLOCK -#define VAL_EAGAIN EAGAIN -#define RD_NODATA -1 -#undef EOF_NONBLOCK - -/* PTRSIZE: - * This symbol contains the size of a pointer, so that the C preprocessor - * can make decisions based on it. It will be sizeof(void *) if - * the compiler supports (void *); otherwise it will be - * sizeof(char *). - */ -#define PTRSIZE 4 /**/ - -/* Drand01: - * This macro is to be used to generate uniformly distributed - * random numbers over the range [0., 1.[. You may have to supply - * an 'extern double drand48();' in your program since SunOS 4.1.3 - * doesn't provide you with anything relevant in its headers. - * See HAS_DRAND48_PROTO. - */ -/* Rand_seed_t: - * This symbol defines the type of the argument of the - * random seed function. - */ -/* seedDrand01: - * This symbol defines the macro to be used in seeding the - * random number generator (see Drand01). - */ -/* RANDBITS: - * This symbol indicates how many bits are produced by the - * function used to generate normalized random numbers. - * Values include 15, 16, 31, and 48. - */ -#define Drand01() Perl_drand48() /**/ -#define Rand_seed_t U32 /**/ -#define seedDrand01(x) Perl_drand48_init((Rand_seed_t)x) /**/ -#define RANDBITS 48 /**/ - -/* SSize_t: - * This symbol holds the type used by functions that return - * a count of bytes or an error condition. It must be a signed type. - * It is usually ssize_t, but may be long or int, etc. - * It may be necessary to include or - * to get any typedef'ed information. - * We will pick a type such that sizeof(SSize_t) == sizeof(Size_t). - */ -#define SSize_t int /* signed count of bytes */ - -/* EBCDIC: - * This symbol, if defined, indicates that this system uses - * EBCDIC encoding. - */ -/*#define EBCDIC / **/ - -/* ARCHLIB: - * This variable, if defined, holds the name of the directory in - * which the user wants to put architecture-dependent public - * library files for perl5. It is most often a local directory - * such as /usr/local/lib. Programs using this variable must be - * prepared to deal with filename expansion. If ARCHLIB is the - * same as PRIVLIB, it is not defined, since presumably the - * program already searches PRIVLIB. - */ -/* ARCHLIB_EXP: - * This symbol contains the ~name expanded version of ARCHLIB, to be used - * in programs that are not prepared to deal with ~ expansion at run-time. - */ -/*#define ARCHLIB "/usr/local/lib/perl5/5.38/unknown" / **/ -/*#define ARCHLIB_EXP "/usr/local/lib/perl5/5.38/unknown" / **/ - -/* BIN: - * This symbol holds the path of the bin directory where the package will - * be installed. Program must be prepared to deal with ~name substitution. - */ -/* BIN_EXP: - * This symbol is the filename expanded version of the BIN symbol, for - * programs that do not want to deal with that at run-time. - */ -/* PERL_RELOCATABLE_INC: - * This symbol, if defined, indicates that we'd like to relocate entries - * in @INC at run time based on the location of the perl binary. - */ -#define BIN "/usr/local/bin" /**/ -#define BIN_EXP "/usr/local/bin" /**/ -#define PERL_RELOCATABLE_INC "undef" /**/ - -/* PERL_INC_VERSION_LIST: - * This variable specifies the list of subdirectories in over - * which perl.c:incpush() and lib/lib.pm will automatically - * search when adding directories to @INC, in a format suitable - * for a C initialization string. See the inc_version_list entry - * in Porting/Glossary for more details. - */ -/*#define PERL_INC_VERSION_LIST NULL / **/ - -/* INSTALL_USR_BIN_PERL: - * This symbol, if defined, indicates that Perl is to be installed - * also as /usr/bin/perl. - */ -/*#define INSTALL_USR_BIN_PERL / **/ - -/* PERL_OTHERLIBDIRS: - * This variable contains a colon-separated set of paths for the perl - * binary to search for additional library files or modules. - * These directories will be tacked to the end of @INC. - * Perl will automatically search below each path for version- - * and architecture-specific directories. See PERL_INC_VERSION_LIST - * for more details. - */ -/*#define PERL_OTHERLIBDIRS " " / **/ - -/* PRIVLIB: - * This symbol contains the name of the private library for this package. - * The library is private in the sense that it needn't be in anyone's - * execution path, but it should be accessible by the world. The program - * should be prepared to do ~ expansion. - */ -/* PRIVLIB_EXP: - * This symbol contains the ~name expanded version of PRIVLIB, to be used - * in programs that are not prepared to deal with ~ expansion at run-time. - */ -#define PRIVLIB "/usr/local/lib/perl5/5.38" /**/ -#define PRIVLIB_EXP "/usr/local/lib/perl5/5.38" /**/ - -/* SITEARCH: - * This symbol contains the name of the private library for this package. - * The library is private in the sense that it needn't be in anyone's - * execution path, but it should be accessible by the world. The program - * should be prepared to do ~ expansion. - * The standard distribution will put nothing in this directory. - * After perl has been installed, users may install their own local - * architecture-dependent modules in this directory with - * MakeMaker Makefile.PL - * or equivalent. See INSTALL for details. - */ -/* SITEARCH_EXP: - * This symbol contains the ~name expanded version of SITEARCH, to be used - * in programs that are not prepared to deal with ~ expansion at run-time. - */ -/*#define SITEARCH "/usr/local/lib/perl5/5.38/unknown" / **/ -/*#define SITEARCH_EXP "/usr/local/lib/perl5/5.38/unknown" / **/ - -/* SITELIB: - * This symbol contains the name of the private library for this package. - * The library is private in the sense that it needn't be in anyone's - * execution path, but it should be accessible by the world. The program - * should be prepared to do ~ expansion. - * The standard distribution will put nothing in this directory. - * After perl has been installed, users may install their own local - * architecture-independent modules in this directory with - * MakeMaker Makefile.PL - * or equivalent. See INSTALL for details. - */ -/* SITELIB_EXP: - * This symbol contains the ~name expanded version of SITELIB, to be used - * in programs that are not prepared to deal with ~ expansion at run-time. - */ -/* SITELIB_STEM: - * This define is SITELIB_EXP with any trailing version-specific component - * removed. The elements in inc_version_list (inc_version_list.U) can - * be tacked onto this variable to generate a list of directories to search. - */ -#define SITELIB "/usr/local/lib/perl5/5.38" /**/ -#define SITELIB_EXP "/usr/local/lib/perl5/5.38" /**/ -#define SITELIB_STEM "/usr/local/lib/perl5" /**/ - -/* PERL_VENDORARCH: - * If defined, this symbol contains the name of a private library. - * The library is private in the sense that it needn't be in anyone's - * execution path, but it should be accessible by the world. - * It may have a ~ on the front. - * The standard distribution will put nothing in this directory. - * Vendors who distribute perl may wish to place their own - * architecture-dependent modules and extensions in this directory with - * MakeMaker Makefile.PL INSTALLDIRS=vendor - * or equivalent. See INSTALL for details. - */ -/* PERL_VENDORARCH_EXP: - * This symbol contains the ~name expanded version of PERL_VENDORARCH, to be used - * in programs that are not prepared to deal with ~ expansion at run-time. - */ -/*#define PERL_VENDORARCH "" / **/ -/*#define PERL_VENDORARCH_EXP "" / **/ - -/* PERL_VENDORLIB_EXP: - * This symbol contains the ~name expanded version of VENDORLIB, to be used - * in programs that are not prepared to deal with ~ expansion at run-time. - */ -/* PERL_VENDORLIB_STEM: - * This define is PERL_VENDORLIB_EXP with any trailing version-specific component - * removed. The elements in inc_version_list (inc_version_list.U) can - * be tacked onto this variable to generate a list of directories to search. - */ -/*#define PERL_VENDORLIB_EXP "" / **/ -/*#define PERL_VENDORLIB_STEM "" / **/ - -/* OSNAME: - * This symbol contains the name of the operating system, as determined - * by Configure. You shouldn't rely on it too much; the specific - * feature tests from Configure are generally more reliable. - */ -/* OSVERS: - * This symbol contains the version of the operating system, as determined - * by Configure. You shouldn't rely on it too much; the specific - * feature tests from Configure are generally more reliable. - */ -#define OSNAME "unknown" /**/ -#define OSVERS "unknown" /**/ - -/* CAT2: - * This macro concatenates 2 tokens together. - */ -/* STRINGIFY: - * This macro surrounds its token with double quotes. - */ -#if 42 == 1 -#define CAT2(a,b) a/**/b -#define STRINGIFY(a) "a" -#endif -#if 42 == 42 -#define PeRl_CaTiFy(a, b) a ## b -#define PeRl_StGiFy(a) #a -#define CAT2(a,b) PeRl_CaTiFy(a,b) -#define StGiFy(a) PeRl_StGiFy(a) -#define STRINGIFY(a) PeRl_StGiFy(a) -#endif -#if 42 != 1 && 42 != 42 -#include "Bletch: How does this C preprocessor concatenate tokens?" -#endif - -/* CPPSTDIN: - * This symbol contains the first part of the string which will invoke - * the C preprocessor on the standard input and produce to standard - * output. Typical value of "cc -E" or "/lib/cpp", but it can also - * call a wrapper. See CPPRUN. - */ -/* CPPMINUS: - * This symbol contains the second part of the string which will invoke - * the C preprocessor on the standard input and produce to standard - * output. This symbol will have the value "-" if CPPSTDIN needs a minus - * to specify standard input, otherwise the value is "". - */ -/* CPPRUN: - * This symbol contains the string which will invoke a C preprocessor on - * the standard input and produce to standard output. It needs to end - * with CPPLAST, after all other preprocessor flags have been specified. - * The main difference with CPPSTDIN is that this program will never be a - * pointer to a shell wrapper, i.e. it will be empty if no preprocessor is - * available directly to the user. Note that it may well be different from - * the preprocessor used to compile the C program. - */ -/* CPPLAST: - * This symbol is intended to be used along with CPPRUN in the same manner - * symbol CPPMINUS is used with CPPSTDIN. It contains either "-" or "". - */ -#define CPPSTDIN "cc -E" -#define CPPMINUS "-" -#define CPPRUN "cc -E" -#define CPPLAST "-" - -/* HAS_ACCESS: - * This manifest constant lets the C program know that the access() - * system call is available to check for accessibility using real UID/GID. - * (always present on UNIX.) - */ -/*#define HAS_ACCESS / **/ - -/* HASATTRIBUTE_FORMAT: - * Can we handle GCC attribute for checking printf-style formats - */ -/* PRINTF_FORMAT_NULL_OK: - * Allows __printf__ format to be null when checking printf-style - */ -/* HASATTRIBUTE_MALLOC: - * Can we handle GCC attribute for malloc-style functions. - */ -/* HASATTRIBUTE_NONNULL: - * Can we handle GCC attribute for nonnull function parms. - */ -/* HASATTRIBUTE_NORETURN: - * Can we handle GCC attribute for functions that do not return - */ -/* HASATTRIBUTE_PURE: - * Can we handle GCC attribute for pure functions - */ -/* HASATTRIBUTE_UNUSED: - * Can we handle GCC attribute for unused variables and arguments - */ -/* HASATTRIBUTE_DEPRECATED: - * Can we handle GCC attribute for marking deprecated APIs - */ -/* HASATTRIBUTE_WARN_UNUSED_RESULT: - * Can we handle GCC attribute for warning on unused results - */ -/* HASATTRIBUTE_ALWAYS_INLINE: - * Can we handle GCC attribute for functions that should always be - * inlined. - */ -/* HASATTRIBUTE_VISIBILITY: - * Can we handle GCC attribute for functions that should have a - * different visibility. - */ -/*#define HASATTRIBUTE_DEPRECATED / **/ -/*#define HASATTRIBUTE_FORMAT / **/ -/*#define PRINTF_FORMAT_NULL_OK / **/ -/*#define HASATTRIBUTE_NORETURN / **/ -/*#define HASATTRIBUTE_MALLOC / **/ -/*#define HASATTRIBUTE_NONNULL / **/ -/*#define HASATTRIBUTE_PURE / **/ -/*#define HASATTRIBUTE_UNUSED / **/ -/*#define HASATTRIBUTE_WARN_UNUSED_RESULT / **/ -/*#define HASATTRIBUTE_ALWAYS_INLINE / **/ -/*#define HASATTRIBUTE_VISIBILITY / **/ - -/* HAS_BACKTRACE: - * This symbol, if defined, indicates that the backtrace() routine is - * available to get a stack trace. The header must be - * included to use this routine. - */ -/*#define HAS_BACKTRACE / **/ - -/* HAS_CSH: - * This symbol, if defined, indicates that the C-shell exists. - */ -/* CSH: - * This symbol, if defined, contains the full pathname of csh. - */ -/*#define HAS_CSH / **/ -#ifdef HAS_CSH -#define CSH "" /**/ -#endif - -/* HAS_DLADDR: - * This symbol, if defined, indicates that the dladdr() routine is - * available to query dynamic linker information for an address. - * The header must be included to use this routine. - */ -/*#define HAS_DLADDR / **/ - -/* SETUID_SCRIPTS_ARE_SECURE_NOW: - * This symbol, if defined, indicates that the bug that prevents - * setuid scripts from being secure is not present in this kernel. - */ -/* DOSUID: - * This symbol, if defined, indicates that the C program should - * check the script that it is executing for setuid/setgid bits, and - * attempt to emulate setuid/setgid on systems that have disabled - * setuid #! scripts because the kernel can't do it securely. - * It is up to the package designer to make sure that this emulation - * is done securely. Among other things, it should do an fstat on - * the script it just opened to make sure it really is a setuid/setgid - * script, it should make sure the arguments passed correspond exactly - * to the argument on the #! line, and it should not trust any - * subprocesses to which it must pass the filename rather than the - * file descriptor of the script to be executed. - */ -/*#define SETUID_SCRIPTS_ARE_SECURE_NOW / **/ -/*#define DOSUID / **/ - -/* HAS_ENDGRENT: - * This symbol, if defined, indicates that the getgrent routine is - * available for finalizing sequential access of the group database. - */ -/*#define HAS_ENDGRENT / **/ - -/* HAS_ENDHOSTENT: - * This symbol, if defined, indicates that the endhostent() routine is - * available to close whatever was being used for host queries. - */ -/*#define HAS_ENDHOSTENT / **/ - -/* HAS_ENDNETENT: - * This symbol, if defined, indicates that the endnetent() routine is - * available to close whatever was being used for network queries. - */ -/*#define HAS_ENDNETENT / **/ - -/* HAS_ENDPROTOENT: - * This symbol, if defined, indicates that the endprotoent() routine is - * available to close whatever was being used for protocol queries. - */ -/*#define HAS_ENDPROTOENT / **/ - -/* HAS_ENDPWENT: - * This symbol, if defined, indicates that the endpwent routine is - * available for finalizing sequential access of the passwd database. - */ -/*#define HAS_ENDPWENT / **/ - -/* HAS_ENDSERVENT: - * This symbol, if defined, indicates that the endservent() routine is - * available to close whatever was being used for service queries. - */ -/*#define HAS_ENDSERVENT / **/ - -/* FLEXFILENAMES: - * This symbol, if defined, indicates that the system supports filenames - * longer than 14 characters. - */ -/*#define FLEXFILENAMES / **/ - -/* HAS_GETGRENT: - * This symbol, if defined, indicates that the getgrent routine is - * available for sequential access of the group database. - */ -/*#define HAS_GETGRENT / **/ - -/* HAS_GETHOSTBYADDR: - * This symbol, if defined, indicates that the gethostbyaddr() routine is - * available to look up hosts by their IP addresses. - */ -/*#define HAS_GETHOSTBYADDR / **/ - -/* HAS_GETHOSTBYNAME: - * This symbol, if defined, indicates that the gethostbyname() routine is - * available to look up host names in some data base or other. - */ -/*#define HAS_GETHOSTBYNAME / **/ - -/* HAS_GETHOSTENT: - * This symbol, if defined, indicates that the gethostent() routine is - * available to look up host names in some data base or another. - */ -/*#define HAS_GETHOSTENT / **/ - -/* HAS_GETHOSTNAME: - * This symbol, if defined, indicates that the C program may use the - * gethostname() routine to derive the host name. See also HAS_UNAME - * and PHOSTNAME. - */ -/* HAS_UNAME: - * This symbol, if defined, indicates that the C program may use the - * uname() routine to derive the host name. See also HAS_GETHOSTNAME - * and PHOSTNAME. - */ -/* PHOSTNAME: - * This symbol, if defined, indicates the command to feed to the - * popen() routine to derive the host name. See also HAS_GETHOSTNAME - * and HAS_UNAME. Note that the command uses a fully qualified path, - * so that it is safe even if used by a process with super-user - * privileges. - */ -/* HAS_PHOSTNAME: - * This symbol, if defined, indicates that the C program may use the - * contents of PHOSTNAME as a command to feed to the popen() routine - * to derive the host name. - */ -/*#define HAS_GETHOSTNAME / **/ -/*#define HAS_UNAME / **/ -/*#define HAS_PHOSTNAME / **/ -#ifdef HAS_PHOSTNAME -#define PHOSTNAME "/bin/hostname" /* How to get the host name */ -#endif - -/* HAS_GETNETBYADDR: - * This symbol, if defined, indicates that the getnetbyaddr() routine is - * available to look up networks by their IP addresses. - */ -/*#define HAS_GETNETBYADDR / **/ - -/* HAS_GETNETBYNAME: - * This symbol, if defined, indicates that the getnetbyname() routine is - * available to look up networks by their names. - */ -/*#define HAS_GETNETBYNAME / **/ - -/* HAS_GETNETENT: - * This symbol, if defined, indicates that the getnetent() routine is - * available to look up network names in some data base or another. - */ -/*#define HAS_GETNETENT / **/ - -/* HAS_GETPROTOENT: - * This symbol, if defined, indicates that the getprotoent() routine is - * available to look up protocols in some data base or another. - */ -/*#define HAS_GETPROTOENT / **/ - -/* HAS_GETPGRP: - * This symbol, if defined, indicates that the getpgrp routine is - * available to get the current process group. - */ -/* USE_BSD_GETPGRP: - * This symbol, if defined, indicates that getpgrp needs one - * arguments whereas USG one needs none. - */ -/*#define HAS_GETPGRP / **/ -/*#define USE_BSD_GETPGRP / **/ - -/* HAS_GETPROTOBYNAME: - * This symbol, if defined, indicates that the getprotobyname() - * routine is available to look up protocols by their name. - */ -/* HAS_GETPROTOBYNUMBER: - * This symbol, if defined, indicates that the getprotobynumber() - * routine is available to look up protocols by their number. - */ -/*#define HAS_GETPROTOBYNAME / **/ -/*#define HAS_GETPROTOBYNUMBER / **/ - -/* HAS_GETPWENT: - * This symbol, if defined, indicates that the getpwent routine is - * available for sequential access of the passwd database. - * If this is not available, the older getpw() function may be available. - */ -/*#define HAS_GETPWENT / **/ - -/* HAS_GETSERVENT: - * This symbol, if defined, indicates that the getservent() routine is - * available to look up network services in some data base or another. - */ -/*#define HAS_GETSERVENT / **/ - -/* HAS_GETSERVBYNAME: - * This symbol, if defined, indicates that the getservbyname() - * routine is available to look up services by their name. - */ -/* HAS_GETSERVBYPORT: - * This symbol, if defined, indicates that the getservbyport() - * routine is available to look up services by their port. - */ -/*#define HAS_GETSERVBYNAME / **/ -/*#define HAS_GETSERVBYPORT / **/ - -/* HAS_HTONL: - * This symbol, if defined, indicates that the htonl() routine (and - * friends htons() ntohl() ntohs()) are available to do network - * order byte swapping. - */ -/* HAS_HTONS: - * This symbol, if defined, indicates that the htons() routine (and - * friends htonl() ntohl() ntohs()) are available to do network - * order byte swapping. - */ -/* HAS_NTOHL: - * This symbol, if defined, indicates that the ntohl() routine (and - * friends htonl() htons() ntohs()) are available to do network - * order byte swapping. - */ -/* HAS_NTOHS: - * This symbol, if defined, indicates that the ntohs() routine (and - * friends htonl() htons() ntohl()) are available to do network - * order byte swapping. - */ -/*#define HAS_HTONL / **/ -/*#define HAS_HTONS / **/ -/*#define HAS_NTOHL / **/ -/*#define HAS_NTOHS / **/ - -/* HAS_LONG_DOUBLE: - * This symbol will be defined if the C compiler supports long - * doubles. - */ -/* LONG_DOUBLESIZE: - * This symbol contains the size of a long double, so that the - * C preprocessor can make decisions based on it. It is only - * defined if the system supports long doubles. Note that this - * is sizeof(long double), which may include unused bytes. - */ -/* HAS_LDEXPL: - * This symbol, if defined, indicates that the ldexpl routine is - * available to shift a long double floating-point number - * by an integral power of 2. - */ -/* LONG_DOUBLEKIND: - * LONG_DOUBLEKIND will be one of - * LONG_DOUBLE_IS_DOUBLE - * LONG_DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN - * LONG_DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN - * LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN - * LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN - * LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE - * LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE - * LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE - * LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE - * LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LITTLE_ENDIAN - * LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BIG_ENDIAN - * LONG_DOUBLE_IS_VAX_H_FLOAT - * LONG_DOUBLE_IS_UNKNOWN_FORMAT - * It is only defined if the system supports long doubles. - */ -/* LONG_DOUBLE_STYLE_IEEE: - * This symbol, if defined, indicates that the long double - * is any of the IEEE 754 style long doubles: - * LONG_DOUBLE_STYLE_IEEE_STD, LONG_DOUBLE_STYLE_IEEE_EXTENDED, - * LONG_DOUBLE_STYLE_IEEE_DOUBLEDOUBLE. - */ -/* LONG_DOUBLE_STYLE_IEEE_DOUBLEDOUBLE: - * This symbol, if defined, indicates that the long double is - * the 128-bit double-double. - */ -/* LONG_DOUBLE_STYLE_IEEE_EXTENDED: - * This symbol, if defined, indicates that the long double is - * the 80-bit IEEE 754. Note that despite the 'extended' this - * is less than the 'std', since this is an extension of - * the double precision. - */ -/* LONG_DOUBLE_STYLE_IEEE_STD: - * This symbol, if defined, indicates that the long double is - * the 128-bit IEEE 754. - */ -/* LONG_DOUBLE_STYLE_VAX: - * This symbol, if defined, indicates that the long double is - * the 128-bit VAX format H. - */ -/*#define HAS_LDEXPL / **/ -/*#define HAS_LONG_DOUBLE / **/ -#ifdef HAS_LONG_DOUBLE -#define LONG_DOUBLESIZE 8 /**/ -#define LONG_DOUBLEKIND 0 /**/ -#define LONG_DOUBLE_IS_DOUBLE 0 -#define LONG_DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN 1 -#define LONG_DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN 2 -#define LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN 3 -#define LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN 4 -#define LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE 5 -#define LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE 6 -#define LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE 7 -#define LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE 8 -#define LONG_DOUBLE_IS_VAX_H_FLOAT 9 -#define LONG_DOUBLE_IS_UNKNOWN_FORMAT -1 -#define LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LITTLE_ENDIAN LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE /* back-compat */ -#define LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BIG_ENDIAN LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE /* back-compat */ -#undef LONG_DOUBLE_STYLE_IEEE -#undef LONG_DOUBLE_STYLE_IEEE_DOUBLEDOUBLE -#undef LONG_DOUBLE_STYLE_IEEE_EXTENDED -#undef LONG_DOUBLE_STYLE_IEEE_STD -#undef LONG_DOUBLE_STYLE_VAX -#endif - -/* HAS_LONG_LONG: - * This symbol will be defined if the C compiler supports long long. - */ -/* LONGLONGSIZE: - * This symbol contains the size of a long long, so that the - * C preprocessor can make decisions based on it. It is only - * defined if the system supports long long. - */ -/*#define HAS_LONG_LONG / **/ -#ifdef HAS_LONG_LONG -#define LONGLONGSIZE 8 /**/ -#endif - -/* HAS_MKSTEMP: - * This symbol, if defined, indicates that the mkstemp routine is - * available to exclusively create and open a uniquely named - * temporary file. - */ -/*#define HAS_MKSTEMP / **/ - -/* HAS_MMAP: - * This symbol, if defined, indicates that the mmap system call is - * available to map a file into memory. - */ -/* Mmap_t: - * This symbol holds the return type of the mmap() system call - * (and simultaneously the type of the first argument). - * Usually set to 'void *' or 'caddr_t'. - */ -/*#define HAS_MMAP / **/ -#define Mmap_t void * /**/ - -/* HAS_SETGRENT: - * This symbol, if defined, indicates that the setgrent routine is - * available for initializing sequential access of the group database. - */ -/*#define HAS_SETGRENT / **/ - -/* HAS_SETHOSTENT: - * This symbol, if defined, indicates that the sethostent() routine is - * available. - */ -/*#define HAS_SETHOSTENT / **/ - -/* HAS_SETNETENT: - * This symbol, if defined, indicates that the setnetent() routine is - * available. - */ -/*#define HAS_SETNETENT / **/ - -/* HAS_SETPROTOENT: - * This symbol, if defined, indicates that the setprotoent() routine is - * available. - */ -/*#define HAS_SETPROTOENT / **/ - -/* HAS_SETPGRP: - * This symbol, if defined, indicates that the setpgrp routine is - * available to set the current process group. - */ -/* USE_BSD_SETPGRP: - * This symbol, if defined, indicates that setpgrp needs two - * arguments whereas USG one needs none. See also HAS_SETPGID - * for a POSIX interface. - */ -/*#define HAS_SETPGRP / **/ -/*#define USE_BSD_SETPGRP / **/ - -/* HAS_SETPWENT: - * This symbol, if defined, indicates that the setpwent routine is - * available for initializing sequential access of the passwd database. - */ -/*#define HAS_SETPWENT / **/ - -/* HAS_SETSERVENT: - * This symbol, if defined, indicates that the setservent() routine is - * available. - */ -/*#define HAS_SETSERVENT / **/ - -/* HAS_SETVBUF: - * This symbol, if defined, indicates that the setvbuf routine is - * available to change buffering on an open stdio stream. - * to a line-buffered mode. - */ -/*#define HAS_SETVBUF / **/ - -/* HAS_SHM: - * This symbol, if defined, indicates that the entire shm*(2) library is - * supported. - */ -/*#define HAS_SHM / **/ - -/* Shmat_t: - * This symbol holds the return type of the shmat() system call. - * Usually set to 'void *' or 'char *'. - */ -/* HAS_SHMAT_PROTOTYPE: - * This symbol, if defined, indicates that the sys/shm.h includes - * a prototype for shmat(). Otherwise, it is up to the program to - * guess one. Shmat_t shmat(int, Shmat_t, int) is a good guess, - * but not always right so it should be emitted by the program only - * when HAS_SHMAT_PROTOTYPE is not defined to avoid conflicting defs. - */ -#define Shmat_t void * /**/ -/*#define HAS_SHMAT_PROTOTYPE / **/ - -/* HAS_SOCKET: - * This symbol, if defined, indicates that the BSD socket interface is - * supported. - */ -/* HAS_SOCKETPAIR: - * This symbol, if defined, indicates that the BSD socketpair() call is - * supported. - */ -/* HAS_SOCKADDR_SA_LEN: - * This symbol, if defined, indicates that the struct sockaddr - * structure has a member called sa_len, indicating the length of - * the structure. - */ -/* HAS_SOCKADDR_IN6: - * This symbol, if defined, indicates the availability of - * struct sockaddr_in6; - */ -/* HAS_SOCKADDR_STORAGE: - * This symbol, if defined, indicates the availability of - * struct sockaddr_storage; - */ -/* HAS_SIN6_SCOPE_ID: - * This symbol, if defined, indicates that the struct sockaddr_in6 - * structure has a member called sin6_scope_id. - */ -/* HAS_IP_MREQ: - * This symbol, if defined, indicates the availability of - * struct ip_mreq; - */ -/* HAS_IP_MREQ_SOURCE: - * This symbol, if defined, indicates the availability of - * struct ip_mreq_source; - */ -/* HAS_IPV6_MREQ: - * This symbol, if defined, indicates the availability of - * struct ipv6_mreq; - */ -/* HAS_IPV6_MREQ_SOURCE: - * This symbol, if defined, indicates the availability of - * struct ipv6_mreq_source; - */ -/*#define HAS_SOCKET / **/ -/*#define HAS_SOCKETPAIR / **/ -/*#define HAS_SOCKADDR_SA_LEN / **/ -/*#define HAS_SOCKADDR_IN6 / **/ -/*#define HAS_SOCKADDR_STORAGE / **/ -/*#define HAS_SIN6_SCOPE_ID / **/ -/*#define HAS_IP_MREQ / **/ -/*#define HAS_IP_MREQ_SOURCE / **/ -/*#define HAS_IPV6_MREQ / **/ -/*#define HAS_IPV6_MREQ_SOURCE / **/ - -/* USE_STAT_BLOCKS: - * This symbol is defined if this system has a stat structure declaring - * st_blksize and st_blocks. - */ -#ifndef USE_STAT_BLOCKS -/*#define USE_STAT_BLOCKS / **/ -#endif - -/* HAS_SYS_ERRLIST: - * This symbol, if defined, indicates that the sys_errlist array is - * available to translate error numbers to strings. The extern int - * sys_nerr gives the size of that table. - */ -/*#define HAS_SYS_ERRLIST / **/ - -/* HAS_STRTOUL: - * This symbol, if defined, indicates that the strtoul routine is - * available to provide conversion of strings to unsigned long. - */ -#define HAS_STRTOUL /**/ - -/* HAS_UNION_SEMUN: - * This symbol, if defined, indicates that the union semun is - * defined by including . If not, the user code - * probably needs to define it as: - * union semun { - * int val; - * struct semid_ds *buf; - * unsigned short *array; - * } - */ -/* USE_SEMCTL_SEMUN: - * This symbol, if defined, indicates that union semun is - * used for semctl IPC_STAT. - */ -/* USE_SEMCTL_SEMID_DS: - * This symbol, if defined, indicates that struct semid_ds * is - * used for semctl IPC_STAT. - */ -/*#define HAS_UNION_SEMUN / **/ -/*#define USE_SEMCTL_SEMUN / **/ -/*#define USE_SEMCTL_SEMID_DS / **/ - -/* HAS_VFORK: - * This symbol, if defined, indicates that vfork() exists. - */ -/*#define HAS_VFORK / **/ - -/* HAS_PSEUDOFORK: - * This symbol, if defined, indicates that an emulation of the - * fork routine is available. - */ -/*#define HAS_PSEUDOFORK / **/ - -/* Signal_t: - * This symbol's value is either "void" or "int", corresponding to the - * appropriate return type of a signal handler. Thus, you can declare - * a signal handler using "Signal_t (*handler)()", and define the - * handler using "Signal_t handler(sig)". - */ -#define Signal_t int /* Signal handler's return type */ - -/* I_DIRENT: - * This symbol, if defined, indicates to the C program that it should - * include . Using this symbol also triggers the definition - * of the Direntry_t define which ends up being 'struct dirent' or - * 'struct direct' depending on the availability of . - */ -/* DIRNAMLEN: - * This symbol, if defined, indicates to the C program that the length - * of directory entry names is provided by a d_namlen field. Otherwise - * you need to do strlen() on the d_name field. - */ -/* Direntry_t: - * This symbol is set to 'struct direct' or 'struct dirent' depending on - * whether dirent is available or not. You should use this pseudo type to - * portably declare your directory entries. - */ -#define I_DIRENT /**/ -/*#define DIRNAMLEN / **/ -#define Direntry_t struct dirent - -/* I_EXECINFO: - * This symbol, if defined, indicates to the C program that it should - * include for backtrace() support. - */ -/*#define I_EXECINFO / **/ - -/* I_GRP: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/* GRPASSWD: - * This symbol, if defined, indicates to the C program that struct group - * in contains gr_passwd. - */ -/*#define I_GRP / **/ -/*#define GRPASSWD / **/ - -/* I_NDBM: - * This symbol, if defined, indicates that exists and should - * be included. - */ -/* I_GDBMNDBM: - * This symbol, if defined, indicates that exists and should - * be included. This was the location of the ndbm.h compatibility file - * in RedHat 7.1. - */ -/* I_GDBM_NDBM: - * This symbol, if defined, indicates that exists and should - * be included. This is the location of the ndbm.h compatibility file - * in Debian 4.0. - */ -/* NDBM_H_USES_PROTOTYPES: - * This symbol, if defined, indicates that uses real ANSI C - * prototypes instead of K&R style function declarations without any - * parameter information. While ANSI C prototypes are supported in C++, - * K&R style function declarations will yield errors. - */ -/* GDBMNDBM_H_USES_PROTOTYPES: - * This symbol, if defined, indicates that uses real ANSI C - * prototypes instead of K&R style function declarations without any - * parameter information. While ANSI C prototypes are supported in C++, - * K&R style function declarations will yield errors. - */ -/* GDBM_NDBM_H_USES_PROTOTYPES: - * This symbol, if defined, indicates that uses real ANSI C - * prototypes instead of K&R style function declarations without any - * parameter information. While ANSI C prototypes are supported in C++, - * K&R style function declarations will yield errors. - */ -/*#define I_NDBM / **/ -/*#define I_GDBMNDBM / **/ -/*#define I_GDBM_NDBM / **/ -/*#define NDBM_H_USES_PROTOTYPES / **/ -/*#define GDBMNDBM_H_USES_PROTOTYPES / **/ -/*#define GDBM_NDBM_H_USES_PROTOTYPES / **/ - -/* I_NETDB: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_NETDB / **/ - -/* I_NET_ERRNO: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_NET_ERRNO / **/ - -/* I_PWD: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/* PWQUOTA: - * This symbol, if defined, indicates to the C program that struct passwd - * contains pw_quota. - */ -/* PWAGE: - * This symbol, if defined, indicates to the C program that struct passwd - * contains pw_age. - */ -/* PWCHANGE: - * This symbol, if defined, indicates to the C program that struct passwd - * contains pw_change. - */ -/* PWCLASS: - * This symbol, if defined, indicates to the C program that struct passwd - * contains pw_class. - */ -/* PWEXPIRE: - * This symbol, if defined, indicates to the C program that struct passwd - * contains pw_expire. - */ -/* PWCOMMENT: - * This symbol, if defined, indicates to the C program that struct passwd - * contains pw_comment. - */ -/* PWGECOS: - * This symbol, if defined, indicates to the C program that struct passwd - * contains pw_gecos. - */ -/* PWPASSWD: - * This symbol, if defined, indicates to the C program that struct passwd - * contains pw_passwd. - */ -/*#define I_PWD / **/ -/*#define PWQUOTA / **/ -/*#define PWAGE / **/ -/*#define PWCHANGE / **/ -/*#define PWCLASS / **/ -/*#define PWEXPIRE / **/ -/*#define PWCOMMENT / **/ -/*#define PWGECOS / **/ -/*#define PWPASSWD / **/ - -/* I_SYSUIO: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_SYSUIO / **/ - -/* I_TERMIO: - * This symbol, if defined, indicates that the program should include - * rather than . There are also differences in - * the ioctl() calls that depend on the value of this symbol. - */ -/* I_TERMIOS: - * This symbol, if defined, indicates that the program should include - * the POSIX termios.h rather than sgtty.h or termio.h. - * There are also differences in the ioctl() calls that depend on the - * value of this symbol. - */ -/* I_SGTTY: - * This symbol, if defined, indicates that the program should include - * rather than . There are also differences in - * the ioctl() calls that depend on the value of this symbol. - */ -/*#define I_TERMIO / **/ -/*#define I_TERMIOS / **/ -/*#define I_SGTTY / **/ - -/* Free_t: - * This variable contains the return type of free(). It is usually - * void, but occasionally int. - */ -/* Malloc_t: - * This symbol is the type of pointer returned by malloc and realloc. - */ -#define Malloc_t void * /**/ -#define Free_t void /**/ - -/* PERL_MALLOC_WRAP: - * This symbol, if defined, indicates that we'd like malloc wrap checks. - */ -/*#define PERL_MALLOC_WRAP / **/ - -/* MYMALLOC: - * This symbol, if defined, indicates that we're using our own malloc. - */ -/*#define MYMALLOC / **/ - -/* SH_PATH: - * This symbol contains the full pathname to the shell used on this - * on this system to execute Bourne shell scripts. Usually, this will be - * /bin/sh, though it's possible that some systems will have /bin/ksh, - * /bin/pdksh, /bin/ash, /bin/bash, or even something such as - * D:/bin/sh.exe. - */ -#define SH_PATH "/bin/sh" /**/ - -/* SIG_NAME: - * This symbol contains a list of signal names in order of - * signal number. This is intended - * to be used as a static array initialization, like this: - * char *sig_name[] = { SIG_NAME }; - * The signals in the list are separated with commas, and each signal - * is surrounded by double quotes. There is no leading SIG in the signal - * name, i.e. SIGQUIT is known as "QUIT". - * Gaps in the signal numbers (up to NSIG) are filled in with NUMnn, - * etc., where nn is the actual signal number (e.g. NUM37). - * The signal number for sig_name[i] is stored in sig_num[i]. - * The last element is 0 to terminate the list with a NULL. This - * corresponds to the 0 at the end of the sig_name_init list. - * Note that this variable is initialized from the sig_name_init, - * not from sig_name (which is unused). - */ -/* SIG_NUM: - * This symbol contains a list of signal numbers, in the same order as the - * SIG_NAME list. It is suitable for static array initialization, as in: - * int sig_num[] = { SIG_NUM }; - * The signals in the list are separated with commas, and the indices - * within that list and the SIG_NAME list match, so it's easy to compute - * the signal name from a number or vice versa at the price of a small - * dynamic linear lookup. - * Duplicates are allowed, but are moved to the end of the list. - * The signal number corresponding to sig_name[i] is sig_number[i]. - * if (i < NSIG) then sig_number[i] == i. - * The last element is 0, corresponding to the 0 at the end of - * the sig_name_init list. - * Note that this variable is initialized from the sig_num_init, - * not from sig_num (which is unused). - */ -/* SIG_SIZE: - * This variable contains the number of elements of the SIG_NAME - * and SIG_NUM arrays, excluding the final NULL entry. - */ -#define SIG_NAME 0 /**/ -#define SIG_NUM 0 /**/ -#define SIG_SIZE 1 /**/ - -/* USE_CROSS_COMPILE: - * This symbol, if defined, indicates that Perl is being cross-compiled. - */ -/* PERL_TARGETARCH: - * This symbol, if defined, indicates the target architecture - * Perl has been cross-compiled to. Undefined if not a cross-compile. - */ -#ifndef USE_CROSS_COMPILE -/*#define USE_CROSS_COMPILE / **/ -#define PERL_TARGETARCH "" /**/ -#endif - -/* PERL_USE_DEVEL: - * This symbol, if defined, indicates that Perl was configured with - * -Dusedevel, to enable development features. This should not be - * done for production builds. - */ -/*#define PERL_USE_DEVEL / **/ - -/* HAS_ATOLF: - * This symbol, if defined, indicates that the atolf routine is - * available to convert strings into long doubles. - */ -/*#define HAS_ATOLF / **/ - -/* HAS_ATOLL: - * This symbol, if defined, indicates that the atoll routine is - * available to convert strings into long longs. - */ -/*#define HAS_ATOLL / **/ - -/* HAS__FWALK: - * This symbol, if defined, indicates that the _fwalk system call is - * available to apply a function to all the file handles. - */ -/*#define HAS__FWALK / **/ - -/* HAS_ACCEPT4: - * This symbol, if defined, indicates that the accept4 routine is - * available to accept socket connections. - */ -/*#define HAS_ACCEPT4 / **/ - -/* HAS_ACOSH: - * This symbol, if defined, indicates that the acosh routine is - * available to do the inverse hyperbolic cosine function. - */ -/*#define HAS_ACOSH / **/ - -/* HAS_AINTL: - * This symbol, if defined, indicates that the aintl routine is - * available. If copysignl is also present we can emulate modfl. - */ -/*#define HAS_AINTL / **/ - -/* HAS_ASINH: - * This symbol, if defined, indicates that the asinh routine is - * available to do the inverse hyperbolic sine function. - */ -/*#define HAS_ASINH / **/ - -/* HAS_ATANH: - * This symbol, if defined, indicates that the atanh routine is - * available to do the inverse hyperbolic tangent function. - */ -/*#define HAS_ATANH / **/ - -/* HAS_NON_INT_BITFIELDS: - * This symbol, if defined, indicates that the C compiler accepts, without - * error or warning, struct bitfields that are declared with sizes other - * than plain 'int'; for example 'unsigned char' is accepted. - */ -#define HAS_NON_INT_BITFIELDS /**/ - -/* HAS_BUILTIN_CHOOSE_EXPR: - * Can we handle GCC builtin for compile-time ternary-like expressions - */ -/* HAS_BUILTIN_EXPECT: - * Can we handle GCC builtin for telling that certain values are more - * likely - */ -/*#define HAS_BUILTIN_EXPECT / **/ -/*#define HAS_BUILTIN_CHOOSE_EXPR / **/ - -/* HAS_BUILTIN_ADD_OVERFLOW: - * This symbol, if defined, indicates that the compiler supports - * __builtin_add_overflow for adding integers with overflow checks. - */ -/* HAS_BUILTIN_SUB_OVERFLOW: - * This symbol, if defined, indicates that the compiler supports - * __builtin_sub_overflow for subtracting integers with overflow checks. - */ -/* HAS_BUILTIN_MUL_OVERFLOW: - * This symbol, if defined, indicates that the compiler supports - * __builtin_mul_overflow for multiplying integers with overflow checks. - */ -/*#define HAS_BUILTIN_ADD_OVERFLOW / **/ -/*#define HAS_BUILTIN_SUB_OVERFLOW / **/ -/*#define HAS_BUILTIN_MUL_OVERFLOW / **/ - -/* HAS_C99_VARIADIC_MACROS: - * If defined, the compiler supports C99 variadic macros. - */ -/*#define HAS_C99_VARIADIC_MACROS / **/ - -/* HAS_CLASS: - * This symbol, if defined, indicates that the class routine is - * available to classify doubles. Available for example in AIX. - * The returned values are defined in and are: - * - * FP_PLUS_NORM Positive normalized, nonzero - * FP_MINUS_NORM Negative normalized, nonzero - * FP_PLUS_DENORM Positive denormalized, nonzero - * FP_MINUS_DENORM Negative denormalized, nonzero - * FP_PLUS_ZERO +0.0 - * FP_MINUS_ZERO -0.0 - * FP_PLUS_INF +INF - * FP_MINUS_INF -INF - * FP_NANS Signaling Not a Number (NaNS) - * FP_NANQ Quiet Not a Number (NaNQ) - */ -/*#define HAS_CLASS / **/ - -/* HAS_CLEARENV: - * This symbol, if defined, indicates that the clearenv () routine is - * available for use. - */ -/*#define HAS_CLEARENV / **/ - -/* HAS_STRUCT_CMSGHDR: - * This symbol, if defined, indicates that the struct cmsghdr - * is supported. - */ -/*#define HAS_STRUCT_CMSGHDR / **/ - -/* HAS_COPYSIGN: - * This symbol, if defined, indicates that the copysign routine is - * available to do the copysign function. - */ -/*#define HAS_COPYSIGN / **/ - -/* HAS_COPYSIGNL: - * This symbol, if defined, indicates that the copysignl routine is - * available. If aintl is also present we can emulate modfl. - */ -/*#define HAS_COPYSIGNL / **/ - -/* USE_CPLUSPLUS: - * This symbol, if defined, indicates that a C++ compiler was - * used to compiled Perl and will be used to compile extensions. - */ -/*#define USE_CPLUSPLUS / **/ - -/* HAS_DBMINIT_PROTO: - * This symbol, if defined, indicates that the system provides - * a prototype for the dbminit() function. Otherwise, it is up - * to the program to supply one. A good guess is - * extern int dbminit(char *); - */ -/*#define HAS_DBMINIT_PROTO / **/ - -/* HAS_DIR_DD_FD: - * This symbol, if defined, indicates that the DIR* dirstream - * structure contains a member variable named dd_fd. - */ -/*#define HAS_DIR_DD_FD / **/ - -/* HAS_DIRFD: - * This manifest constant lets the C program know that dirfd - * is available. - */ -/*#define HAS_DIRFD / **/ - -/* DLSYM_NEEDS_UNDERSCORE: - * This symbol, if defined, indicates that we need to prepend an - * underscore to the symbol name before calling dlsym(). This only - * makes sense if you *have* dlsym, which we will presume is the - * case if you're using dl_dlopen.xs. - */ -/*#define DLSYM_NEEDS_UNDERSCORE / **/ - -/* HAS_DUP3: - * This symbol, if defined, indicates that the dup3 routine is - * available to duplicate file descriptors. - */ -/*#define HAS_DUP3 / **/ - -/* HAS_ERF: - * This symbol, if defined, indicates that the erf routine is - * available to do the error function. - */ -/*#define HAS_ERF / **/ - -/* HAS_ERFC: - * This symbol, if defined, indicates that the erfc routine is - * available to do the complementary error function. - */ -/*#define HAS_ERFC / **/ - -/* HAS_EXP2: - * This symbol, if defined, indicates that the exp2 routine is - * available to do the 2**x function. - */ -/*#define HAS_EXP2 / **/ - -/* HAS_EXPM1: - * This symbol, if defined, indicates that the expm1 routine is - * available to do the exp(x) - 1 when x is near 1 function. - */ -/*#define HAS_EXPM1 / **/ - -/* HAS_FAST_STDIO: - * This symbol, if defined, indicates that the "fast stdio" - * is available to manipulate the stdio buffers directly. - */ -/*#define HAS_FAST_STDIO / **/ - -/* HAS_FCHDIR: - * This symbol, if defined, indicates that the fchdir routine is - * available to change directory using a file descriptor. - */ -/*#define HAS_FCHDIR / **/ - -/* FCNTL_CAN_LOCK: - * This symbol, if defined, indicates that fcntl() can be used - * for file locking. Normally on Unix systems this is defined. - * It may be undefined on VMS. - */ -/*#define FCNTL_CAN_LOCK / **/ - -/* HAS_FDCLOSE: - * This symbol, if defined, indicates that the fdclose routine is - * available to free a FILE structure without closing the underlying - * file descriptor. This function appeared in FreeBSD 10.2. - */ -/*#define HAS_FDCLOSE / **/ - -/* HAS_FDIM: - * This symbol, if defined, indicates that the fdim routine is - * available to do the positive difference function. - */ -/*#define HAS_FDIM / **/ - -/* HAS_FEGETROUND: - * This symbol, if defined, indicates that the fegetround routine is - * available to return the macro corresponding to the current rounding - * mode. - */ -/*#define HAS_FEGETROUND / **/ - -/* HAS_FFS: - * This symbol, if defined, indicates that the ffs routine is available - * to find the first bit set in its argument. If it's not available, - * roll your own. - */ -/* HAS_FFSL: - * This symbol, if defined, indicates that the ffsl routine is available - * to find the first bit set in its argument. If it's not available, - * roll your own. - */ -/*#define HAS_FFS / **/ -/*#define HAS_FFSL / **/ - -/* HAS_FINITE: - * This symbol, if defined, indicates that the finite routine is - * available to check whether a double is finite (non-infinity non-NaN). - */ -/*#define HAS_FINITE / **/ - -/* HAS_FINITEL: - * This symbol, if defined, indicates that the finitel routine is - * available to check whether a long double is finite - * (non-infinity non-NaN). - */ -/*#define HAS_FINITEL / **/ - -/* HAS_FLOCK_PROTO: - * This symbol, if defined, indicates that the system provides - * a prototype for the flock() function. Otherwise, it is up - * to the program to supply one. A good guess is - * extern int flock(int, int); - */ -/*#define HAS_FLOCK_PROTO / **/ - -/* HAS_FMA: - * This symbol, if defined, indicates that the fma routine is - * available to do the multiply-add function. - */ -/*#define HAS_FMA / **/ - -/* HAS_FMAX: - * This symbol, if defined, indicates that the fmax routine is - * available to do the maximum function. - */ -/*#define HAS_FMAX / **/ - -/* HAS_FMIN: - * This symbol, if defined, indicates that the fmin routine is - * available to do the minimum function. - */ -/*#define HAS_FMIN / **/ - -/* HAS_FP_CLASS: - * This symbol, if defined, indicates that the fp_class routine is - * available to classify doubles. Available for example in Digital UNIX. - * The returned values are defined in and are: - * - * FP_SNAN Signaling NaN (Not-a-Number) - * FP_QNAN Quiet NaN (Not-a-Number) - * FP_POS_INF +infinity - * FP_NEG_INF -infinity - * FP_POS_NORM Positive normalized - * FP_NEG_NORM Negative normalized - * FP_POS_DENORM Positive denormalized - * FP_NEG_DENORM Negative denormalized - * FP_POS_ZERO +0.0 (positive zero) - * FP_NEG_ZERO -0.0 (negative zero) - */ -/*#define HAS_FP_CLASS / **/ - -/* HAS_FP_CLASSL: - * This symbol, if defined, indicates that the fp_classl routine is - * available to classify long doubles. Available for example in - * Digital UNIX. See for possible values HAS_FP_CLASS. - */ -/*#define HAS_FP_CLASSL / **/ - -/* HAS_FPCLASS: - * This symbol, if defined, indicates that the fpclass routine is - * available to classify doubles. Available for example in Solaris/SVR4. - * The returned values are defined in and are: - * - * FP_SNAN signaling NaN - * FP_QNAN quiet NaN - * FP_NINF negative infinity - * FP_PINF positive infinity - * FP_NDENORM negative denormalized non-zero - * FP_PDENORM positive denormalized non-zero - * FP_NZERO negative zero - * FP_PZERO positive zero - * FP_NNORM negative normalized non-zero - * FP_PNORM positive normalized non-zero - */ -/*#define HAS_FPCLASS / **/ - -/* HAS_FPCLASSIFY: - * This symbol, if defined, indicates that the fpclassify routine is - * available to classify doubles. Available for example in HP-UX. - * The returned values are defined in and are - * - * FP_NORMAL Normalized - * FP_ZERO Zero - * FP_INFINITE Infinity - * FP_SUBNORMAL Denormalized - * FP_NAN NaN - * - */ -/* HAS_FP_CLASSIFY: - * This symbol, if defined, indicates that the fp_classify routine is - * available to classify doubles. The values are defined in - * - * FP_NORMAL Normalized - * FP_ZERO Zero - * FP_INFINITE Infinity - * FP_SUBNORMAL Denormalized - * FP_NAN NaN - * - */ -/*#define HAS_FPCLASSIFY / **/ -/*#define HAS_FP_CLASSIFY / **/ - -/* HAS_FPCLASSL: - * This symbol, if defined, indicates that the fpclassl routine is - * available to classify long doubles. Available for example in IRIX. - * The returned values are defined in and are: - * - * FP_SNAN signaling NaN - * FP_QNAN quiet NaN - * FP_NINF negative infinity - * FP_PINF positive infinity - * FP_NDENORM negative denormalized non-zero - * FP_PDENORM positive denormalized non-zero - * FP_NZERO negative zero - * FP_PZERO positive zero - * FP_NNORM negative normalized non-zero - * FP_PNORM positive normalized non-zero - */ -/*#define HAS_FPCLASSL / **/ - -/* HAS_FPGETROUND: - * This symbol, if defined, indicates that the fpgetround routine is - * available to get the floating point rounding mode. - */ -/*#define HAS_FPGETROUND / **/ - -/* HAS_FPOS64_T: - * This symbol will be defined if the C compiler supports fpos64_t. - */ -/*#define HAS_FPOS64_T / **/ - -/* HAS_FREXPL: - * This symbol, if defined, indicates that the frexpl routine is - * available to break a long double floating-point number into - * a normalized fraction and an integral power of 2. - */ -/*#define HAS_FREXPL / **/ - -/* HAS_STRUCT_FS_DATA: - * This symbol, if defined, indicates that the struct fs_data - * to do statfs() is supported. - */ -/*#define HAS_STRUCT_FS_DATA / **/ - -/* HAS_FCHMODAT: - * This symbol is defined if the fchmodat() routine is available. - */ -/* HAS_LINKAT: - * This symbol is defined if the linkat() routine is available. - */ -/* HAS_OPENAT: - * This symbol is defined if the openat() routine is available. - */ -/* HAS_RENAMEAT: - * This symbol is defined if the renameat() routine is available. - */ -/* HAS_UNLINKAT: - * This symbol is defined if the unlinkat() routine is available. - */ -/*#define HAS_FCHMODAT / **/ -/*#define HAS_LINKAT / **/ -/*#define HAS_OPENAT / **/ -/*#define HAS_RENAMEAT / **/ -/*#define HAS_UNLINKAT / **/ - -/* HAS_FSEEKO: - * This symbol, if defined, indicates that the fseeko routine is - * available to fseek beyond 32 bits (useful for ILP32 hosts). - */ -/*#define HAS_FSEEKO / **/ - -/* HAS_FSTATFS: - * This symbol, if defined, indicates that the fstatfs routine is - * available to stat filesystems by file descriptors. - */ -/*#define HAS_FSTATFS / **/ - -/* HAS_FSYNC: - * This symbol, if defined, indicates that the fsync routine is - * available to write a file's modified data and attributes to - * permanent storage. - */ -/*#define HAS_FSYNC / **/ - -/* HAS_FTELLO: - * This symbol, if defined, indicates that the ftello routine is - * available to ftell beyond 32 bits (useful for ILP32 hosts). - */ -/*#define HAS_FTELLO / **/ - -/* HAS_FUTIMES: - * This symbol, if defined, indicates that the futimes routine is - * available to change file descriptor time stamps with struct timevals. - */ -/*#define HAS_FUTIMES / **/ - -/* HAS_GAI_STRERROR: - * This symbol, if defined, indicates that the gai_strerror routine - * is available to translate error codes returned by getaddrinfo() - * into human readable strings. - */ -/*#define HAS_GAI_STRERROR / **/ - -/* HAS_GETADDRINFO: - * This symbol, if defined, indicates that the getaddrinfo() function - * is available for use. - */ -/*#define HAS_GETADDRINFO / **/ - -/* HAS_GETCWD: - * This symbol, if defined, indicates that the getcwd routine is - * available to get the current working directory. - */ -/*#define HAS_GETCWD / **/ - -/* HAS_GETESPWNAM: - * This symbol, if defined, indicates that the getespwnam system call is - * available to retrieve enhanced (shadow) password entries by name. - */ -/*#define HAS_GETESPWNAM / **/ - -/* HAS_GETFSSTAT: - * This symbol, if defined, indicates that the getfsstat routine is - * available to stat filesystems in bulk. - */ -/*#define HAS_GETFSSTAT / **/ - -/* HAS_GETITIMER: - * This symbol, if defined, indicates that the getitimer routine is - * available to return interval timers. - */ -/*#define HAS_GETITIMER / **/ - -/* HAS_GETMNT: - * This symbol, if defined, indicates that the getmnt routine is - * available to get filesystem mount info by filename. - */ -/*#define HAS_GETMNT / **/ - -/* HAS_GETMNTENT: - * This symbol, if defined, indicates that the getmntent routine is - * available to iterate through mounted file systems to get their info. - */ -/*#define HAS_GETMNTENT / **/ - -/* HAS_GETNAMEINFO: - * This symbol, if defined, indicates that the getnameinfo() function - * is available for use. - */ -/*#define HAS_GETNAMEINFO / **/ - -/* HAS_GETPRPWNAM: - * This symbol, if defined, indicates that the getprpwnam system call is - * available to retrieve protected (shadow) password entries by name. - */ -/*#define HAS_GETPRPWNAM / **/ - -/* HAS_GETSPNAM: - * This symbol, if defined, indicates that the getspnam system call is - * available to retrieve SysV shadow password entries by name. - */ -/*#define HAS_GETSPNAM / **/ - -/* HAS_HASMNTOPT: - * This symbol, if defined, indicates that the hasmntopt routine is - * available to query the mount options of file systems. - */ -/*#define HAS_HASMNTOPT / **/ - -/* HAS_HYPOT: - * This symbol, if defined, indicates that the hypot routine is - * available to do the hypotenuse function. - */ -/*#define HAS_HYPOT / **/ - -/* HAS_ILOGB: - * This symbol, if defined, indicates that the ilogb routine is - * available to get integer exponent of a floating-point value. - */ -/*#define HAS_ILOGB / **/ - -/* HAS_ILOGBL: - * This symbol, if defined, indicates that the ilogbl routine is - * available. If scalbnl is also present we can emulate frexpl. - */ -/*#define HAS_ILOGBL / **/ - -/* HAS_INETNTOP: - * This symbol, if defined, indicates that the inet_ntop() function - * is available to parse IPv4 and IPv6 strings. - */ -/*#define HAS_INETNTOP / **/ - -/* HAS_INETPTON: - * This symbol, if defined, indicates that the inet_pton() function - * is available to parse IPv4 and IPv6 strings. - */ -/*#define HAS_INETPTON / **/ - -/* HAS_INT64_T: - * This symbol will defined if the C compiler supports int64_t. - * Usually the needs to be included, but sometimes - * is enough. - */ -/*#define HAS_INT64_T / **/ - -/* HAS_ISBLANK: - * This manifest constant lets the C program know that isblank - * is available. - */ -/*#define HAS_ISBLANK / **/ - -/* HAS_ISFINITE: - * This symbol, if defined, indicates that the isfinite routine is - * available to check whether a double is finite (non-infinity non-NaN). - */ -/*#define HAS_ISFINITE / **/ - -/* HAS_ISFINITEL: - * This symbol, if defined, indicates that the isfinitel routine is - * available to check whether a long double is finite. - * (non-infinity non-NaN). - */ -/*#define HAS_ISFINITEL / **/ - -/* HAS_ISINF: - * This symbol, if defined, indicates that the isinf routine is - * available to check whether a double is an infinity. - */ -/*#define HAS_ISINF / **/ - -/* HAS_ISINFL: - * This symbol, if defined, indicates that the isinfl routine is - * available to check whether a long double is an infinity. - */ -/*#define HAS_ISINFL / **/ - -/* HAS_ISLESS: - * This symbol, if defined, indicates that the isless routine is - * available to do the isless function. - */ -/*#define HAS_ISLESS / **/ - -/* HAS_ISNAN: - * This symbol, if defined, indicates that the isnan routine is - * available to check whether a double is a NaN. - */ -/*#define HAS_ISNAN / **/ - -/* HAS_ISNANL: - * This symbol, if defined, indicates that the isnanl routine is - * available to check whether a long double is a NaN. - */ -/*#define HAS_ISNANL / **/ - -/* HAS_ISNORMAL: - * This symbol, if defined, indicates that the isnormal routine is - * available to check whether a double is normal (non-zero normalized). - */ -/*#define HAS_ISNORMAL / **/ - -/* HAS_J0: - * This symbol, if defined, indicates to the C program that the - * j0() function is available for Bessel functions of the first - * kind of the order zero, for doubles. - */ -/* HAS_J0L: - * This symbol, if defined, indicates to the C program that the - * j0l() function is available for Bessel functions of the first - * kind of the order zero, for long doubles. - */ -/*#define HAS_J0 / **/ -/*#define HAS_J0L / **/ - -/* HAS_LC_MONETARY_2008: - * This symbol, if defined, indicates that the localeconv routine is - * available and has the additional members added in POSIX 1003.1-2008. - */ -/*#define HAS_LC_MONETARY_2008 / **/ - -/* HAS_LDBL_DIG: - * This symbol, if defined, indicates that this system's - * or defines the symbol LDBL_DIG, which is the number - * of significant digits in a long double precision number. Unlike - * for DBL_DIG, there's no good guess for LDBL_DIG if it is undefined. - */ -/*#define HAS_LDBL_DIG / * */ - -/* HAS_LGAMMA: - * This symbol, if defined, indicates that the lgamma routine is - * available to do the log gamma function. See also HAS_TGAMMA and - * HAS_LGAMMA_R. - */ -/*#define HAS_LGAMMA / **/ - -/* HAS_LGAMMA_R: - * This symbol, if defined, indicates that the lgamma_r routine is - * available to do the log gamma function without using the global - * signgam variable. - */ -/*#define HAS_LGAMMA_R / **/ - -/* LIBM_LIB_VERSION: - * This symbol, if defined, indicates that libm exports _LIB_VERSION - * and that math.h defines the enum to manipulate it. - */ -/*#define LIBM_LIB_VERSION / **/ - -/* HAS_LLRINT: - * This symbol, if defined, indicates that the llrint routine is - * available to return the long long value closest to a double - * (according to the current rounding mode). - */ -/*#define HAS_LLRINT / **/ - -/* HAS_LLRINTL: - * This symbol, if defined, indicates that the llrintl routine is - * available to return the long long value closest to a long double - * (according to the current rounding mode). - */ -/*#define HAS_LLRINTL / **/ - -/* HAS_LLROUND: - * This symbol, if defined, indicates that the llround routine is - * available to return the nearest long long value. - */ -/*#define HAS_LLROUND / **/ - -/* HAS_LLROUNDL: - * This symbol, if defined, indicates that the llroundl routine is - * available to return the nearest long long value away from zero of - * the long double argument value. - */ -/*#define HAS_LLROUNDL / **/ - -/* HAS_LOG1P: - * This symbol, if defined, indicates that the log1p routine is - * available to do the logarithm of 1 plus argument function. - */ -/*#define HAS_LOG1P / **/ - -/* HAS_LOG2: - * This symbol, if defined, indicates that the log2 routine is - * available to do the log2 function. - */ -/*#define HAS_LOG2 / **/ - -/* HAS_LOGB: - * This symbol, if defined, indicates that the logb routine is - * available to do the logb function. - */ -/*#define HAS_LOGB / **/ - -/* HAS_LRINT: - * This symbol, if defined, indicates that the lrint routine is - * available to return the integral value closest to a double - * (according to the current rounding mode). - */ -/*#define HAS_LRINT / **/ - -/* HAS_LRINTL: - * This symbol, if defined, indicates that the lrintl routine is - * available to return the integral value closest to a long double - * (according to the current rounding mode). - */ -/*#define HAS_LRINTL / **/ - -/* HAS_LROUND: - * This symbol, if defined, indicates that the lround routine is - * available to return the nearest integral value. - */ -/*#define HAS_LROUND / **/ - -/* HAS_LROUNDL: - * This symbol, if defined, indicates that the lroundl routine is - * available to return the nearest integral value away from zero of - * the long double argument value. - */ -/*#define HAS_LROUNDL / **/ - -/* HAS_MADVISE: - * This symbol, if defined, indicates that the madvise system call is - * available to map a file into memory. - */ -/*#define HAS_MADVISE / **/ - -/* HAS_MALLOC_SIZE: - * This symbol, if defined, indicates that the malloc_size - * routine is available for use. - */ -/*#define HAS_MALLOC_SIZE / **/ - -/* HAS_MALLOC_GOOD_SIZE: - * This symbol, if defined, indicates that the malloc_good_size - * routine is available for use. - */ -/*#define HAS_MALLOC_GOOD_SIZE / **/ - -/* HAS_MEMMEM: - * This symbol, if defined, indicates that the memmem routine is - * available to return a pointer to the start of the first occurrence - * of a substring in a memory area (or NULL if not found). - * In glibc, memmem is a GNU extension. The function is visible in - * libc, but the prototype is only visible if _GNU_SOURCE is #defined. - * Thus we only define this if both the prototype and symbol are found. - */ -/*#define HAS_MEMMEM / **/ - -/* HAS_MEMRCHR: - * This symbol, if defined, indicates that the memrchr routine is - * available to return a pointer to the last occurrence of a byte in - * a memory area (or NULL if not found). - */ -/*#define HAS_MEMRCHR / **/ - -/* HAS_MKDTEMP: - * This symbol, if defined, indicates that the mkdtemp routine is - * available to exclusively create a uniquely named temporary directory. - */ -/*#define HAS_MKDTEMP / **/ - -/* HAS_MKOSTEMP: - * This symbol, if defined, indicates that the mkostemp routine is - * available to exclusively create and open a uniquely named (with a - * suffix) temporary file. - */ -/*#define HAS_MKOSTEMP / **/ - -/* HAS_MKSTEMPS: - * This symbol, if defined, indicates that the mkstemps routine is - * available to exclusively create and open a uniquely named - * (with a suffix) temporary file. - */ -/*#define HAS_MKSTEMPS / **/ - -/* HAS_MODFL: - * This symbol, if defined, indicates that the modfl routine is - * available to split a long double x into a fractional part f and - * an integer part i such that |f| < 1.0 and (f + i) = x. - */ -/* HAS_MODFL_PROTO: - * This symbol, if defined, indicates that the system provides - * a prototype for the modfl() function. Otherwise, it is up - * to the program to supply one. - */ -/*#define HAS_MODFL / **/ -/*#define HAS_MODFL_PROTO / **/ - -/* HAS_MPROTECT: - * This symbol, if defined, indicates that the mprotect system call is - * available to modify the access protection of a memory mapped file. - */ -/*#define HAS_MPROTECT / **/ - -/* HAS_STRUCT_MSGHDR: - * This symbol, if defined, indicates that the struct msghdr - * is supported. - */ -/*#define HAS_STRUCT_MSGHDR / **/ - -/* HAS_NAN: - * This symbol, if defined, indicates that the nan routine is - * available to generate NaN. - */ -/*#define HAS_NAN / **/ - -/* HAS_NANOSLEEP: - * This symbol, if defined, indicates that the nanosleep - * system call is available to sleep with 1E-9 sec accuracy. - */ -/*#define HAS_NANOSLEEP / **/ - -/* HAS_NEARBYINT: - * This symbol, if defined, indicates that the nearbyint routine is - * available to return the integral value closest to (according to - * the current rounding mode) to x. - */ -/*#define HAS_NEARBYINT / **/ - -/* HAS_NEWLOCALE: - * This symbol, if defined, indicates that the newlocale routine is - * available to return a new locale object or modify an existing - * locale object. - */ -/* HAS_FREELOCALE: - * This symbol, if defined, indicates that the freelocale routine is - * available to deallocates the resources associated with a locale object. - */ -/* HAS_USELOCALE: - * This symbol, if defined, indicates that the uselocale routine is - * available to set the current locale for the calling thread. - */ -/* HAS_DUPLOCALE: - * This symbol, if defined, indicates that the duplocale routine is - * available to duplicate a locale object. - */ -/* HAS_QUERYLOCALE: - * This symbol, if defined, indicates that the querylocale routine is - * available to return the name of the locale for a category mask. - */ -/* I_XLOCALE: - * This symbol, if defined, indicates to the C program that the - * header xlocale.h is available. See also NEED_XLOCALE_H - */ -/* NEED_XLOCALE_H: - * This symbol, if defined, indicates that the C program should - * include to get newlocale() and its friends. - */ -/*#define HAS_NEWLOCALE / **/ -/*#define HAS_FREELOCALE / **/ -/*#define HAS_USELOCALE / **/ -/*#define HAS_DUPLOCALE / **/ -/*#define HAS_QUERYLOCALE / **/ -/*#define NEED_XLOCALE_H / **/ -/*#define I_XLOCALE / **/ - -/* HAS_NEXTAFTER: - * This symbol, if defined, indicates that the nextafter routine is - * available to return the next machine representable double from - * x in direction y. - */ -/*#define HAS_NEXTAFTER / **/ - -/* HAS_NEXTTOWARD: - * This symbol, if defined, indicates that the nexttoward routine is - * available to return the next machine representable long double from - * x in direction y. - */ -/*#define HAS_NEXTTOWARD / **/ - -/* HAS_NL_LANGINFO: - * This symbol, if defined, indicates that the nl_langinfo routine is - * available to return local data. You will also need - * and therefore I_LANGINFO. - */ -/*#define HAS_NL_LANGINFO / **/ - -/* HAS_OFF64_T: - * This symbol will be defined if the C compiler supports off64_t. - */ -/*#define HAS_OFF64_T / **/ - -/* HAS_PIPE2: - * This symbol, if defined, indicates that the pipe2 routine is - * available to create an inter-process channel. - */ -/*#define HAS_PIPE2 / **/ - -/* HAS_PRCTL: - * This symbol, if defined, indicates that the prctl routine is - * available to set process title. - * Note that there are at least two prctl variants: Linux and Irix. - * While they are somewhat similar, they are incompatible. - */ -/* HAS_PRCTL_SET_NAME: - * This symbol, if defined, indicates that the prctl routine is - * available to set process title and supports PR_SET_NAME. - */ -/*#define HAS_PRCTL / **/ -/*#define HAS_PRCTL_SET_NAME / **/ - -/* HAS_PROCSELFEXE: - * This symbol is defined if PROCSELFEXE_PATH is a symlink - * to the absolute pathname of the executing program. - */ -/* PROCSELFEXE_PATH: - * If HAS_PROCSELFEXE is defined this symbol is the filename - * of the symbolic link pointing to the absolute pathname of - * the executing program. - */ -/*#define HAS_PROCSELFEXE / **/ -#if defined(HAS_PROCSELFEXE) && !defined(PROCSELFEXE_PATH) -#define PROCSELFEXE_PATH /**/ -#endif - -/* HAS_PTHREAD_ATTR_SETSCOPE: - * This symbol, if defined, indicates that the pthread_attr_setscope - * system call is available to set the contention scope attribute of - * a thread attribute object. - */ -/*#define HAS_PTHREAD_ATTR_SETSCOPE / **/ - -/* HAS_PTRDIFF_T: - * This symbol will be defined if the C compiler supports ptrdiff_t. - */ -#define HAS_PTRDIFF_T /**/ - -/* HAS_READV: - * This symbol, if defined, indicates that the readv routine is - * available to do gather reads. You will also need - * and there I_SYSUIO. - */ -/*#define HAS_READV / **/ - -/* HAS_RECVMSG: - * This symbol, if defined, indicates that the recvmsg routine is - * available to send structured socket messages. - */ -/*#define HAS_RECVMSG / **/ - -/* HAS_REMAINDER: - * This symbol, if defined, indicates that the remainder routine is - * available to return the floating-point remainder. - */ -/*#define HAS_REMAINDER / **/ - -/* HAS_REMQUO: - * This symbol, if defined, indicates that the remquo routine is - * available to return the remainder and part of quotient. - */ -/*#define HAS_REMQUO / **/ - -/* HAS_RINT: - * This symbol, if defined, indicates that the rint routine is - * available to return the nearest integral value to x as double - * using the current rounding mode. - */ -/*#define HAS_RINT / **/ - -/* HAS_ROUND: - * This symbol, if defined, indicates that the round routine is - * available to round to nearest integer, away from zero. - */ -/*#define HAS_ROUND / **/ - -/* HAS_SBRK_PROTO: - * This symbol, if defined, indicates that the system provides - * a prototype for the sbrk() function. Otherwise, it is up - * to the program to supply one. Good guesses are - * extern void* sbrk(int); - * extern void* sbrk(size_t); - */ -/*#define HAS_SBRK_PROTO / **/ - -/* HAS_SCALBN: - * This symbol, if defined, indicates that the scalbn routine is - * available to multiply floating-point number by integral power - * of radix. - */ -/*#define HAS_SCALBN / **/ - -/* HAS_SCALBNL: - * This symbol, if defined, indicates that the scalbnl routine is - * available. If ilogbl is also present we can emulate frexpl. - */ -/*#define HAS_SCALBNL / **/ - -/* HAS_SENDMSG: - * This symbol, if defined, indicates that the sendmsg routine is - * available to send structured socket messages. - */ -/*#define HAS_SENDMSG / **/ - -/* HAS_SETENV: - * This symbol, if defined, indicates that the setenv routine is - * available for use. - */ -/*#define HAS_SETENV / **/ - -/* HAS_SETITIMER: - * This symbol, if defined, indicates that the setitimer routine is - * available to set interval timers. - */ -/*#define HAS_SETITIMER / **/ - -/* HAS_SETLOCALE: - * This symbol, if defined, indicates that the setlocale routine is - * available to handle locale-specific ctype implementations. - */ -/* SETLOCALE_ACCEPTS_ANY_LOCALE_NAME: - * This symbol, if defined, indicates that the setlocale routine is - * available and it accepts any input locale name as valid. - */ -/*#define HAS_SETLOCALE / **/ -/*#define SETLOCALE_ACCEPTS_ANY_LOCALE_NAME / **/ - -/* HAS_SETPROCTITLE: - * This symbol, if defined, indicates that the setproctitle routine is - * available to set process title. - */ -/*#define HAS_SETPROCTITLE / **/ - -/* HAS_SIGNBIT: - * This symbol, if defined, indicates that the signbit routine is - * available to check if the given number has the sign bit set. - * This should include correct testing of -0.0. This will only be set - * if the signbit() routine is safe to use with the NV type used internally - * in perl. Users should call Perl_signbit(), which will be #defined to - * the system's signbit() function or macro if this symbol is defined. - */ -/*#define HAS_SIGNBIT / **/ - -/* HAS_SIGPROCMASK: - * This symbol, if defined, indicates that the sigprocmask - * system call is available to examine or change the signal mask - * of the calling process. - */ -/*#define HAS_SIGPROCMASK / **/ - -/* USE_SITECUSTOMIZE: - * This symbol, if defined, indicates that sitecustomize should - * be used. - */ -#ifndef USE_SITECUSTOMIZE -/*#define USE_SITECUSTOMIZE / **/ -#endif - -/* HAS_SNPRINTF: - * This symbol, if defined, indicates that the snprintf () library - * function is available for use. - */ -/* HAS_VSNPRINTF: - * This symbol, if defined, indicates that the vsnprintf () library - * function is available for use. - */ -/*#define HAS_SNPRINTF / **/ -/*#define HAS_VSNPRINTF / **/ - -/* HAS_SOCKATMARK: - * This symbol, if defined, indicates that the sockatmark routine is - * available to test whether a socket is at the out-of-band mark. - */ -/*#define HAS_SOCKATMARK / **/ - -/* HAS_SOCKATMARK_PROTO: - * This symbol, if defined, indicates that the system provides - * a prototype for the sockatmark() function. Otherwise, it is up - * to the program to supply one. A good guess is - * extern int sockatmark(int); - */ -/*#define HAS_SOCKATMARK_PROTO / **/ - -/* HAS_SOCKS5_INIT: - * This symbol, if defined, indicates that the socks5_init routine is - * available to initialize SOCKS 5. - */ -/*#define HAS_SOCKS5_INIT / **/ - -/* HAS_SQRTL: - * This symbol, if defined, indicates that the sqrtl routine is - * available to do long double square roots. - */ -/*#define HAS_SQRTL / **/ - -/* HAS_SETRESGID_PROTO: - * This symbol, if defined, indicates that the system provides - * a prototype for the setresgid() function. Otherwise, it is up - * to the program to supply one. Good guesses are - * extern int setresgid(uid_t ruid, uid_t euid, uid_t suid); - */ -/*#define HAS_SETRESGID_PROTO / **/ - -/* HAS_SETRESUID_PROTO: - * This symbol, if defined, indicates that the system provides - * a prototype for the setresuid() function. Otherwise, it is up - * to the program to supply one. Good guesses are - * extern int setresuid(uid_t ruid, uid_t euid, uid_t suid); - */ -/*#define HAS_SETRESUID_PROTO / **/ - -/* HAS_STRUCT_STATFS_F_FLAGS: - * This symbol, if defined, indicates that the struct statfs - * does have the f_flags member containing the mount flags of - * the filesystem containing the file. - * This kind of struct statfs is coming from (BSD 4.3), - * not from (SYSV). Older BSDs (like Ultrix) do not - * have statfs() and struct statfs, they have ustat() and getmnt() - * with struct ustat and struct fs_data. - */ -/*#define HAS_STRUCT_STATFS_F_FLAGS / **/ - -/* HAS_STRUCT_STATFS: - * This symbol, if defined, indicates that the struct statfs - * to do statfs() is supported. - */ -/*#define HAS_STRUCT_STATFS / **/ - -/* HAS_FSTATVFS: - * This symbol, if defined, indicates that the fstatvfs routine is - * available to stat filesystems by file descriptors. - */ -/*#define HAS_FSTATVFS / **/ - -/* HAS_STRERROR_L: - * This symbol, if defined, indicates that the strerror_l routine is - * available to return the error message for a given errno value in - * a particular locale (identified by a locale_t object). - */ -/*#define HAS_STRERROR_L / **/ - -/* HAS_STRFTIME: - * This symbol, if defined, indicates that the strftime routine is - * available to do time formatting. - */ -/*#define HAS_STRFTIME / **/ - -/* HAS_STRLCAT: - * This symbol, if defined, indicates that the strlcat () routine is - * available to do string concatenation. - */ -/*#define HAS_STRLCAT / **/ - -/* HAS_STRLCPY: - * This symbol, if defined, indicates that the strlcpy () routine is - * available to do string copying. - */ -/*#define HAS_STRLCPY / **/ - -/* HAS_STRNLEN: - * This symbol, if defined, indicates that the strnlen () routine is - * available to check the length of a string up to a maximum. - */ -/*#define HAS_STRNLEN / **/ - -/* HAS_STRTOLD: - * This symbol, if defined, indicates that the strtold routine is - * available to convert strings to long doubles. - */ -/*#define HAS_STRTOLD / **/ - -/* HAS_STRTOLL: - * This symbol, if defined, indicates that the strtoll routine is - * available to convert strings to long longs. - */ -/*#define HAS_STRTOLL / **/ - -/* HAS_STRTOQ: - * This symbol, if defined, indicates that the strtoq routine is - * available to convert strings to long longs (quads). - */ -/*#define HAS_STRTOQ / **/ - -/* HAS_STRTOULL: - * This symbol, if defined, indicates that the strtoull routine is - * available to convert strings to unsigned long longs. - */ -/*#define HAS_STRTOULL / **/ - -/* HAS_STRTOUQ: - * This symbol, if defined, indicates that the strtouq routine is - * available to convert strings to unsigned long longs (quads). - */ -/*#define HAS_STRTOUQ / **/ - -/* HAS_STRXFRM_L: - * This symbol, if defined, indicates that the strxfrm_l() routine is - * available to transform strings. - */ -/*#define HAS_STRXFRM_L / **/ - -/* HAS_SYSCALL_PROTO: - * This symbol, if defined, indicates that the system provides - * a prototype for the syscall() function. Otherwise, it is up - * to the program to supply one. Good guesses are - * extern int syscall(int, ...); - * extern int syscall(long, ...); - */ -/*#define HAS_SYSCALL_PROTO / **/ - -/* HAS_TELLDIR_PROTO: - * This symbol, if defined, indicates that the system provides - * a prototype for the telldir() function. Otherwise, it is up - * to the program to supply one. A good guess is - * extern long telldir(DIR*); - */ -/*#define HAS_TELLDIR_PROTO / **/ - -/* HAS_TGAMMA: - * This symbol, if defined, indicates that the tgamma routine is - * available to do the gamma function. See also HAS_LGAMMA. - */ -/*#define HAS_TGAMMA / **/ - -/* HAS_CTIME64: - * This symbol, if defined, indicates that the ctime64 () routine is - * available to do the 64bit variant of ctime () - */ -/* HAS_LOCALTIME64: - * This symbol, if defined, indicates that the localtime64 () routine is - * available to do the 64bit variant of localtime () - */ -/* HAS_GMTIME64: - * This symbol, if defined, indicates that the gmtime64 () routine is - * available to do the 64bit variant of gmtime () - */ -/* HAS_MKTIME64: - * This symbol, if defined, indicates that the mktime64 () routine is - * available to do the 64bit variant of mktime () - */ -/* HAS_DIFFTIME64: - * This symbol, if defined, indicates that the difftime64 () routine is - * available to do the 64bit variant of difftime () - */ -/* HAS_ASCTIME64: - * This symbol, if defined, indicates that the asctime64 () routine is - * available to do the 64bit variant of asctime () - */ -/*#define HAS_CTIME64 / **/ -/*#define HAS_LOCALTIME64 / **/ -/*#define HAS_GMTIME64 / **/ -/*#define HAS_MKTIME64 / **/ -/*#define HAS_DIFFTIME64 / **/ -/*#define HAS_ASCTIME64 / **/ - -/* HAS_TIMEGM: - * This symbol, if defined, indicates that the timegm routine is - * available to do the opposite of gmtime () - */ -/*#define HAS_TIMEGM / **/ - -/* HAS_TOWLOWER: - * This symbol, if defined, indicates that the towlower () routine is - * available to do case conversion. - */ -/*#define HAS_TOWLOWER / **/ - -/* HAS_TOWUPPER: - * This symbol, if defined, indicates that the towupper () routine is - * available to do case conversion. - */ -/*#define HAS_TOWUPPER / **/ - -/* HAS_TRUNC: - * This symbol, if defined, indicates that the trunc routine is - * available to round doubles towards zero. - */ -/*#define HAS_TRUNC / **/ - -/* HAS_TRUNCL: - * This symbol, if defined, indicates that the truncl routine is - * available. If copysignl is also present we can emulate modfl. - */ -/*#define HAS_TRUNCL / **/ - -/* U32_ALIGNMENT_REQUIRED: - * This symbol, if defined, indicates that you must access - * character data through U32-aligned pointers. - */ -#ifndef U32_ALIGNMENT_REQUIRED -#define U32_ALIGNMENT_REQUIRED /**/ -#endif - -/* HAS_UALARM: - * This symbol, if defined, indicates that the ualarm routine is - * available to do alarms with microsecond granularity. - */ -/*#define HAS_UALARM / **/ - -/* HAS_UNORDERED: - * This symbol, if defined, indicates that the unordered routine is - * available to check whether two doubles are unordered - * (effectively: whether either of them is NaN) - */ -/*#define HAS_UNORDERED / **/ - -/* HAS_UNSETENV: - * This symbol, if defined, indicates that the unsetenv () routine is - * available for use. - */ -/*#define HAS_UNSETENV / **/ - -/* HAS_USLEEP_PROTO: - * This symbol, if defined, indicates that the system provides - * a prototype for the usleep() function. Otherwise, it is up - * to the program to supply one. A good guess is - * extern int usleep(useconds_t); - */ -/*#define HAS_USLEEP_PROTO / **/ - -/* HAS_USTAT: - * This symbol, if defined, indicates that the ustat system call is - * available to query file system statistics by dev_t. - */ -/*#define HAS_USTAT / **/ - -/* HAS_WCSCMP: - * This symbol, if defined, indicates that the wcscmp routine is - * available to compare two wide character strings. - */ -/*#define HAS_WCSCMP / **/ - -/* HAS_WCSXFRM: - * This symbol, if defined, indicates that the wcsxfrm routine is - * available to transform a wide character string for wcscmp(). - */ -/*#define HAS_WCSXFRM / **/ - -/* HAS_WRITEV: - * This symbol, if defined, indicates that the writev routine is - * available to do scatter writes. - */ -/*#define HAS_WRITEV / **/ - -/* DEFAULT_INC_EXCLUDES_DOT: - * This symbol, if defined, removes the legacy default behavior of - * including '.' at the end of @INC. - */ -/*#define DEFAULT_INC_EXCLUDES_DOT / **/ - -/* USE_DYNAMIC_LOADING: - * This symbol, if defined, indicates that dynamic loading of - * some sort is available. - */ -/*#define USE_DYNAMIC_LOADING / **/ - -/* FFLUSH_NULL: - * This symbol, if defined, tells that fflush(NULL) correctly - * flushes all pending stdio output without side effects. In - * particular, on some platforms calling fflush(NULL) *still* - * corrupts STDIN if it is a pipe. - */ -/* FFLUSH_ALL: - * This symbol, if defined, tells that to flush - * all pending stdio output one must loop through all - * the stdio file handles stored in an array and fflush them. - * Note that if fflushNULL is defined, fflushall will not - * even be probed for and will be left undefined. - */ -/*#define FFLUSH_NULL / **/ -/*#define FFLUSH_ALL / **/ - -/* I_BFD: - * This symbol, if defined, indicates that exists and - * can be included. - */ -/*#define I_BFD / **/ - -/* I_CRYPT: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_CRYPT / **/ - -/* DB_Prefix_t: - * This symbol contains the type of the prefix structure element - * in the header file. In older versions of DB, it was - * int, while in newer ones it is u_int32_t. - */ -/* DB_Hash_t: - * This symbol contains the type of the prefix structure element - * in the header file. In older versions of DB, it was - * int, while in newer ones it is size_t. - */ -/* DB_VERSION_MAJOR_CFG: - * This symbol, if defined, defines the major version number of - * Berkeley DB found in the header when Perl was configured. - */ -/* DB_VERSION_MINOR_CFG: - * This symbol, if defined, defines the minor version number of - * Berkeley DB found in the header when Perl was configured. - * For DB version 1 this is always 0. - */ -/* DB_VERSION_PATCH_CFG: - * This symbol, if defined, defines the patch version number of - * Berkeley DB found in the header when Perl was configured. - * For DB version 1 this is always 0. - */ -#define DB_Hash_t u_int32_t /**/ -#define DB_Prefix_t size_t /**/ -#define DB_VERSION_MAJOR_CFG 0 /**/ -#define DB_VERSION_MINOR_CFG 0 /**/ -#define DB_VERSION_PATCH_CFG 0 /**/ - -/* I_FENV: - * This symbol, if defined, indicates to the C program that it should - * include to get the floating point environment definitions. - */ -/*#define I_FENV / **/ - -/* I_FP: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_FP / **/ - -/* I_FP_CLASS: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_FP_CLASS / **/ - -/* I_IEEEFP: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_IEEEFP / **/ - -/* I_INTTYPES: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_INTTYPES / **/ - -/* I_LANGINFO: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_LANGINFO / **/ - -/* I_LIBUTIL: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_LIBUTIL / **/ - -/* I_MALLOCMALLOC: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_MALLOCMALLOC / **/ - -/* I_MNTENT: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_MNTENT / **/ - -/* I_NETINET_TCP: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_NETINET_TCP / **/ - -/* I_POLL: - * This symbol, if defined, indicates that exists and - * should be included. (see also HAS_POLL) - */ -/*#define I_POLL / **/ - -/* I_PROT: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_PROT / **/ - -/* I_QUADMATH: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_QUADMATH / **/ - -/* I_SHADOW: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_SHADOW / **/ - -/* I_SOCKS: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_SOCKS / **/ - -/* I_STDBOOL: - * This symbol, if defined, indicates that exists and - * can be included. - */ -/*#define I_STDBOOL / **/ - -/* I_STDINT: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_STDINT / **/ - -/* I_SUNMATH: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_SUNMATH / **/ - -/* I_SYSLOG: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_SYSLOG / **/ - -/* I_SYSMODE: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_SYSMODE / **/ - -/* I_SYS_MOUNT: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_SYS_MOUNT / **/ - -/* I_SYS_STATFS: - * This symbol, if defined, indicates that exists. - */ -/*#define I_SYS_STATFS / **/ - -/* I_SYS_STATVFS: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_SYS_STATVFS / **/ - -/* I_SYS_SYSCALL: - * This symbol, if defined, indicates that exists. - */ -/*#define I_SYS_SYSCALL / **/ - -/* I_SYSUTSNAME: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_SYSUTSNAME / **/ - -/* I_SYS_VFS: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_SYS_VFS / **/ - -/* I_USTAT: - * This symbol, if defined, indicates that exists and - * should be included. - */ -/*#define I_USTAT / **/ - -/* I_WCHAR: - * This symbol, if defined, indicates to the C program that - * is available for inclusion - */ -/*#define I_WCHAR / **/ - -/* I_WCTYPE: - * This symbol, if defined, indicates that exists. - */ -/*#define I_WCTYPE / **/ - -/* DOUBLEINFBYTES: - * This symbol, if defined, is a comma-separated list of - * hexadecimal bytes for the double precision infinity. - */ -/* DOUBLENANBYTES: - * This symbol, if defined, is a comma-separated list of - * hexadecimal bytes (0xHH) for the double precision not-a-number. - */ -/* LONGDBLINFBYTES: - * This symbol, if defined, is a comma-separated list of - * hexadecimal bytes for the long double precision infinity. - */ -/* LONGDBLNANBYTES: - * This symbol, if defined, is a comma-separated list of - * hexadecimal bytes (0xHH) for the long double precision not-a-number. - */ -#define DOUBLEINFBYTES 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f /**/ -#define DOUBLENANBYTES 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x7f /**/ -#define LONGDBLINFBYTES 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /**/ -#define LONGDBLNANBYTES 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /**/ - -/* PERL_PRIfldbl: - * This symbol, if defined, contains the string used by stdio to - * format long doubles (format 'f') for output. - */ -/* PERL_PRIgldbl: - * This symbol, if defined, contains the string used by stdio to - * format long doubles (format 'g') for output. - */ -/* PERL_PRIeldbl: - * This symbol, if defined, contains the string used by stdio to - * format long doubles (format 'e') for output. - */ -/* PERL_SCNfldbl: - * This symbol, if defined, contains the string used by stdio to - * format long doubles (format 'f') for input. - */ -/* DOUBLEKIND: - * DOUBLEKIND will be one of - * DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN - * DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN - * DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN - * DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN - * DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN - * DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN - * DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE - * DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE - * DOUBLE_IS_VAX_F_FLOAT - * DOUBLE_IS_VAX_D_FLOAT - * DOUBLE_IS_VAX_G_FLOAT - * DOUBLE_IS_IBM_SINGLE_32_BIT - * DOUBLE_IS_IBM_DOUBLE_64_BIT - * DOUBLE_IS_CRAY_SINGLE_64_BIT - * DOUBLE_IS_UNKNOWN_FORMAT - */ -/* DOUBLE_HAS_INF: - * This symbol, if defined, indicates that the double has - * the infinity. - */ -/* DOUBLE_HAS_NAN: - * This symbol, if defined, indicates that the double has - * the not-a-number. - */ -/* DOUBLE_HAS_NEGATIVE_ZERO: - * This symbol, if defined, indicates that the double has - * the negative_zero. - */ -/* DOUBLE_HAS_SUBNORMALS: - * This symbol, if defined, indicates that the double has - * the subnormals (denormals). - */ -/* DOUBLE_STYLE_CRAY: - * This symbol, if defined, indicates that the double is - * the 64-bit CRAY mainframe format. - */ -/* DOUBLE_STYLE_IBM: - * This symbol, if defined, indicates that the double is - * the 64-bit IBM mainframe format. - */ -/* DOUBLE_STYLE_IEEE: - * This symbol, if defined, indicates that the double is - * the 64-bit IEEE 754. - */ -/* DOUBLE_STYLE_VAX: - * This symbol, if defined, indicates that the double is - * the 64-bit VAX format D or G. - */ -#define DOUBLEKIND 3 /**/ -#define DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN 1 -#define DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN 2 -#define DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN 3 -#define DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN 4 -#define DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN 5 -#define DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN 6 -#define DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE 7 -#define DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE 8 -#define DOUBLE_IS_VAX_F_FLOAT 9 -#define DOUBLE_IS_VAX_D_FLOAT 10 -#define DOUBLE_IS_VAX_G_FLOAT 11 -#define DOUBLE_IS_IBM_SINGLE_32_BIT 12 -#define DOUBLE_IS_IBM_DOUBLE_64_BIT 13 -#define DOUBLE_IS_CRAY_SINGLE_64_BIT 14 -#define DOUBLE_IS_UNKNOWN_FORMAT -1 -/*#define PERL_PRIfldbl "llf" / **/ -/*#define PERL_PRIgldbl "llg" / **/ -/*#define PERL_PRIeldbl "lle" / **/ -/*#define PERL_SCNfldbl "llf" / **/ -#define DOUBLE_HAS_INF -#define DOUBLE_HAS_NAN -#define DOUBLE_HAS_NEGATIVE_ZERO -#define DOUBLE_HAS_SUBNORMALS -#undef DOUBLE_STYLE_CRAY -#undef DOUBLE_STYLE_IBM -#define DOUBLE_STYLE_IEEE -#undef DOUBLE_STYLE_VAX - -/* DOUBLEMANTBITS: - * This symbol, if defined, tells how many mantissa bits - * there are in double precision floating point format. - * Note that this is usually DBL_MANT_DIG minus one, since - * with the standard IEEE 754 formats DBL_MANT_DIG includes - * the implicit bit, which doesn't really exist. - */ -/* LONGDBLMANTBITS: - * This symbol, if defined, tells how many mantissa bits - * there are in long double precision floating point format. - * Note that this can be LDBL_MANT_DIG minus one, - * since LDBL_MANT_DIG can include the IEEE 754 implicit bit. - * The common x86-style 80-bit long double does not have - * an implicit bit. - */ -/* NVMANTBITS: - * This symbol, if defined, tells how many mantissa bits - * (not including implicit bit) there are in a Perl NV. - * This depends on which floating point type was chosen. - */ -#define DOUBLEMANTBITS 52 -#define LONGDBLMANTBITS 64 -#define NVMANTBITS 52 - -/* NEED_VA_COPY: - * This symbol, if defined, indicates that the system stores - * the variable argument list datatype, va_list, in a format - * that cannot be copied by simple assignment, so that some - * other means must be used when copying is required. - * As such systems vary in their provision (or non-provision) - * of copying mechanisms, handy.h defines a platform- - * independent macro, Perl_va_copy(src, dst), to do the job. - */ -#define NEED_VA_COPY /**/ - -/* I32df: - * This symbol defines the format string used for printing a Perl I32 - * as a signed decimal integer. - */ -/* U32uf: - * This symbol defines the format string used for printing a Perl U32 - * as an unsigned decimal integer. - */ -/* U32of: - * This symbol defines the format string used for printing a Perl U32 - * as an unsigned octal integer. - */ -/* U32xf: - * This symbol defines the format string used for printing a Perl U32 - * as an unsigned hexadecimal integer in lowercase abcdef. - */ -/* U32Xf: - * This symbol defines the format string used for printing a Perl U32 - * as an unsigned hexadecimal integer in uppercase ABCDEF. - */ -#define I32df "ld" /**/ -#define U32of "lo" /**/ -#define U32uf "lu" /**/ -#define U32xf "lx" /**/ -#define U32Xf "lX" /**/ - -/* IVTYPE: - * This symbol defines the C type used for Perl's IV. - */ -/* UVTYPE: - * This symbol defines the C type used for Perl's UV. - */ -/* I8TYPE: - * This symbol defines the C type used for Perl's I8. - */ -/* U8TYPE: - * This symbol defines the C type used for Perl's U8. - */ -/* I16TYPE: - * This symbol defines the C type used for Perl's I16. - */ -/* U16TYPE: - * This symbol defines the C type used for Perl's U16. - */ -/* I32TYPE: - * This symbol defines the C type used for Perl's I32. - */ -/* U32TYPE: - * This symbol defines the C type used for Perl's U32. - */ -/* I64TYPE: - * This symbol defines the C type used for Perl's I64. - */ -/* U64TYPE: - * This symbol defines the C type used for Perl's U64. - */ -/* NVTYPE: - * This symbol defines the C type used for Perl's NV. - */ -/* IVSIZE: - * This symbol contains the sizeof(IV). - */ -/* UVSIZE: - * This symbol contains the sizeof(UV). - */ -/* I8SIZE: - * This symbol contains the sizeof(I8). - */ -/* U8SIZE: - * This symbol contains the sizeof(U8). - */ -/* I16SIZE: - * This symbol contains the sizeof(I16). - */ -/* U16SIZE: - * This symbol contains the sizeof(U16). - */ -/* I32SIZE: - * This symbol contains the sizeof(I32). - */ -/* U32SIZE: - * This symbol contains the sizeof(U32). - */ -/* I64SIZE: - * This symbol contains the sizeof(I64). - */ -/* U64SIZE: - * This symbol contains the sizeof(U64). - */ -/* NVSIZE: - * This symbol contains the sizeof(NV). - * Note that some floating point formats have unused bytes. - * The most notable example is the x86* 80-bit extended precision - * which comes in byte sizes of 12 and 16 (for 32 and 64 bit - * platforms, respectively), but which only uses 10 bytes. - * Perl compiled with -Duselongdouble on x86* is like this. - */ -/* NV_PRESERVES_UV: - * This symbol, if defined, indicates that a variable of type NVTYPE - * can preserve all the bits of a variable of type UVTYPE. - */ -/* NV_PRESERVES_UV_BITS: - * This symbol contains the number of bits a variable of type NVTYPE - * can preserve of a variable of type UVTYPE. - */ -/* NV_OVERFLOWS_INTEGERS_AT: - * This symbol gives the largest integer value that NVs can hold. This - * value + 1.0 cannot be stored accurately. It is expressed as constant - * floating point expression to reduce the chance of decimal/binary - * conversion issues. If it can not be determined, the value 0 is given. - */ -/* NV_ZERO_IS_ALLBITS_ZERO: - * This symbol, if defined, indicates that a variable of type NVTYPE - * stores 0.0 in memory as all bits zero. - */ -#define IVTYPE long /**/ -#define UVTYPE unsigned long /**/ -#define I8TYPE signed char /**/ -#define U8TYPE unsigned char /**/ -#define I16TYPE short /**/ -#define U16TYPE unsigned short /**/ -#define I32TYPE long /**/ -#define U32TYPE unsigned long /**/ -#ifdef HAS_QUAD -#define I64TYPE int64_t /**/ -#define U64TYPE uint64_t /**/ -#endif -#define NVTYPE double /**/ -#define IVSIZE 4 /**/ -#define UVSIZE 4 /**/ -#define I8SIZE 1 /**/ -#define U8SIZE 1 /**/ -#define I16SIZE 2 /**/ -#define U16SIZE 2 /**/ -#define I32SIZE 4 /**/ -#define U32SIZE 4 /**/ -#ifdef HAS_QUAD -#define I64SIZE 8 /**/ -#define U64SIZE 8 /**/ -#endif -#define NVSIZE 8 /**/ -#undef NV_PRESERVES_UV -#define NV_PRESERVES_UV_BITS 0 -#define NV_OVERFLOWS_INTEGERS_AT (256.0*256.0*256.0*256.0*256.0*256.0*2.0*2.0*2.0*2.0*2.0) -#undef NV_ZERO_IS_ALLBITS_ZERO -#if UVSIZE == 8 -# ifdef BYTEORDER -# if BYTEORDER == 0x1234 -# undef BYTEORDER -# define BYTEORDER 0x12345678 -# else -# if BYTEORDER == 0x4321 -# undef BYTEORDER -# define BYTEORDER 0x87654321 -# endif -# endif -# endif -#endif - -/* IVdf: - * This symbol defines the format string used for printing a Perl IV - * as a signed decimal integer. - */ -/* UVuf: - * This symbol defines the format string used for printing a Perl UV - * as an unsigned decimal integer. - */ -/* UVof: - * This symbol defines the format string used for printing a Perl UV - * as an unsigned octal integer. - */ -/* UVxf: - * This symbol defines the format string used for printing a Perl UV - * as an unsigned hexadecimal integer in lowercase abcdef. - */ -/* UVXf: - * This symbol defines the format string used for printing a Perl UV - * as an unsigned hexadecimal integer in uppercase ABCDEF. - */ -/* NVef: - * This symbol defines the format string used for printing a Perl NV - * using %e-ish floating point format. - */ -/* NVff: - * This symbol defines the format string used for printing a Perl NV - * using %f-ish floating point format. - */ -/* NVgf: - * This symbol defines the format string used for printing a Perl NV - * using %g-ish floating point format. - */ -#define IVdf "ld" /**/ -#define UVuf "lu" /**/ -#define UVof "lo" /**/ -#define UVxf "lx" /**/ -#define UVXf "lX" /**/ -#define NVef "e" /**/ -#define NVff "f" /**/ -#define NVgf "g" /**/ - -/* SELECT_MIN_BITS: - * This symbol holds the minimum number of bits operated by select. - * That is, if you do select(n, ...), how many bits at least will be - * cleared in the masks if some activity is detected. Usually this - * is either n or 32*ceil(n/32), especially many little-endians do - * the latter. This is only useful if you have select(), naturally. - */ -#define SELECT_MIN_BITS 32 /**/ - -/* ST_DEV_SIZE: - * This variable contains the size of struct stat's st_dev in bytes. - */ -/* ST_DEV_SIGN: - * This symbol holds the signedness of struct stat's st_dev. - * 1 for unsigned, -1 for signed. - */ -#define ST_DEV_SIGN 1 /* st_dev sign */ -#define ST_DEV_SIZE 4 /* st_dev size */ - -/* ST_INO_SIZE: - * This variable contains the size of struct stat's st_ino in bytes. - */ -/* ST_INO_SIGN: - * This symbol holds the signedness of struct stat's st_ino. - * 1 for unsigned, -1 for signed. - */ -#define ST_INO_SIGN 1 /* st_ino sign */ -#define ST_INO_SIZE 4 /* st_ino size */ - -/* STARTPERL: - * This variable contains the string to put in front of a perl - * script to make sure (one hopes) that it runs with perl and not - * some shell. - */ -#define STARTPERL "#!perl" /**/ - -/* HAS_STDIO_STREAM_ARRAY: - * This symbol, if defined, tells that there is an array - * holding the stdio streams. - */ -/* STDIO_STREAM_ARRAY: - * This symbol tells the name of the array holding the stdio streams. - * Usual values include _iob, __iob, and __sF. - */ -/*#define HAS_STDIO_STREAM_ARRAY / **/ -#ifdef HAS_STDIO_STREAM_ARRAY -#define STDIO_STREAM_ARRAY -#endif - -/* GMTIME_MAX: - * This symbol contains the maximum value for the time_t offset that - * the system function gmtime () accepts, and defaults to 0 - */ -/* GMTIME_MIN: - * This symbol contains the minimum value for the time_t offset that - * the system function gmtime () accepts, and defaults to 0 - */ -/* LOCALTIME_MAX: - * This symbol contains the maximum value for the time_t offset that - * the system function localtime () accepts, and defaults to 0 - */ -/* LOCALTIME_MIN: - * This symbol contains the minimum value for the time_t offset that - * the system function localtime () accepts, and defaults to 0 - */ -#define GMTIME_MAX 2147483647 /**/ -#define GMTIME_MIN 0 /**/ -#define LOCALTIME_MAX 2147483647 /**/ -#define LOCALTIME_MIN 0 /**/ - -/* USE_64_BIT_INT: - * This symbol, if defined, indicates that 64-bit integers should - * be used when available. If not defined, the native integers - * will be employed (be they 32 or 64 bits). The minimal possible - * 64-bitness is used, just enough to get 64-bit integers into Perl. - * This may mean using for example "long longs", while your memory - * may still be limited to 2 gigabytes. - */ -/* USE_64_BIT_ALL: - * This symbol, if defined, indicates that 64-bit integers should - * be used when available. If not defined, the native integers - * will be used (be they 32 or 64 bits). The maximal possible - * 64-bitness is employed: LP64 or ILP64, meaning that you will - * be able to use more than 2 gigabytes of memory. This mode is - * even more binary incompatible than USE_64_BIT_INT. You may not - * be able to run the resulting executable in a 32-bit CPU at all or - * you may need at least to reboot your OS to 64-bit mode. - */ -#ifndef USE_64_BIT_INT -/*#define USE_64_BIT_INT / **/ -#endif -#ifndef USE_64_BIT_ALL -/*#define USE_64_BIT_ALL / **/ -#endif - -/* USE_C_BACKTRACE: - * This symbol, if defined, indicates that Perl should - * be built with support for backtrace. - */ -/*#define USE_C_BACKTRACE / **/ - -/* USE_STRICT_BY_DEFAULT: - * This symbol, if defined, enables additional defaults. - * At this time it only enables implicit strict by default. - */ -/*#define USE_STRICT_BY_DEFAULT / * use strict by default */ - -/* USE_DTRACE: - * This symbol, if defined, indicates that Perl should - * be built with support for DTrace. - */ -/*#define USE_DTRACE / **/ - -/* USE_FAST_STDIO: - * This symbol, if defined, indicates that Perl should - * be built to use 'fast stdio'. - * Defaults to define in Perls 5.8 and earlier, to undef later. - */ -#ifndef USE_FAST_STDIO -/*#define USE_FAST_STDIO / **/ -#endif - -/* USE_KERN_PROC_PATHNAME: - * This symbol, if defined, indicates that we can use sysctl with - * KERN_PROC_PATHNAME to get a full path for the executable, and hence - * convert $^X to an absolute path. - */ -/*#define USE_KERN_PROC_PATHNAME / **/ - -/* USE_LARGE_FILES: - * This symbol, if defined, indicates that large file support - * should be used when available. - */ -#ifndef USE_LARGE_FILES -/*#define USE_LARGE_FILES / **/ -#endif - -/* USE_LONG_DOUBLE: - * This symbol, if defined, indicates that long doubles should - * be used when available. - */ -#ifndef USE_LONG_DOUBLE -/*#define USE_LONG_DOUBLE / **/ -#endif - -/* USE_MORE_BITS: - * This symbol, if defined, indicates that 64-bit interfaces and - * long doubles should be used when available. - */ -#ifndef USE_MORE_BITS -/*#define USE_MORE_BITS / **/ -#endif - -/* MULTIPLICITY: - * This symbol, if defined, indicates that Perl should - * be built to use multiplicity. - */ -#ifndef MULTIPLICITY -/*#define MULTIPLICITY / **/ -#endif - -/* USE_NSGETEXECUTABLEPATH: - * This symbol, if defined, indicates that we can use _NSGetExecutablePath - * and realpath to get a full path for the executable, and hence convert - * $^X to an absolute path. - */ -/*#define USE_NSGETEXECUTABLEPATH / **/ - -/* USE_PERLIO: - * This symbol, if defined, indicates that the PerlIO abstraction should - * be used throughout. If not defined, stdio should be - * used in a fully backward compatible manner. - */ -#ifndef USE_PERLIO -/*#define USE_PERLIO / **/ -#endif - -/* USE_QUADMATH: - * This symbol, if defined, indicates that the quadmath library should - * be used when available. - */ -#ifndef USE_QUADMATH -/*#define USE_QUADMATH / **/ -#endif - -/* USE_SOCKS: - * This symbol, if defined, indicates that Perl should - * be built to use socks. - */ -#ifndef USE_SOCKS -/*#define USE_SOCKS / **/ -#endif - -/* HAS_DRAND48_PROTO: - * This symbol, if defined, indicates that the system provides - * a prototype for the drand48() function. Otherwise, it is up - * to the program to supply one. A good guess is - * extern double drand48(void); - */ -/*#define HAS_DRAND48_PROTO / **/ - -/* HAS_GETHOST_PROTOS: - * This symbol, if defined, indicates that includes - * prototypes for gethostent(), gethostbyname(), and - * gethostbyaddr(). Otherwise, it is up to the program to guess - * them. See netdbtype.U for probing for various Netdb_xxx_t types. - */ -/*#define HAS_GETHOST_PROTOS / **/ - -/* HAS_GETNET_PROTOS: - * This symbol, if defined, indicates that includes - * prototypes for getnetent(), getnetbyname(), and - * getnetbyaddr(). Otherwise, it is up to the program to guess - * them. See netdbtype.U for probing for various Netdb_xxx_t types. - */ -/*#define HAS_GETNET_PROTOS / **/ - -/* HAS_GETPROTO_PROTOS: - * This symbol, if defined, indicates that includes - * prototypes for getprotoent(), getprotobyname(), and - * getprotobyaddr(). Otherwise, it is up to the program to guess - * them. See netdbtype.U for probing for various Netdb_xxx_t types. - */ -/*#define HAS_GETPROTO_PROTOS / **/ - -/* HAS_GETSERV_PROTOS: - * This symbol, if defined, indicates that includes - * prototypes for getservent(), getservbyname(), and - * getservbyaddr(). Otherwise, it is up to the program to guess - * them. See netdbtype.U for probing for various Netdb_xxx_t types. - */ -/*#define HAS_GETSERV_PROTOS / **/ - -/* HAS_LSEEK_PROTO: - * This symbol, if defined, indicates that the system provides - * a prototype for the lseek() function. Otherwise, it is up - * to the program to supply one. A good guess is - * extern off_t lseek(int, off_t, int); - */ -/*#define HAS_LSEEK_PROTO / **/ - -/* Netdb_host_t: - * This symbol holds the type used for the 1st argument - * to gethostbyaddr(). - */ -/* Netdb_hlen_t: - * This symbol holds the type used for the 2nd argument - * to gethostbyaddr(). - */ -/* Netdb_name_t: - * This symbol holds the type used for the argument to - * gethostbyname(). - */ -/* Netdb_net_t: - * This symbol holds the type used for the 1st argument to - * getnetbyaddr(). - */ -#define Netdb_host_t const char * /**/ -#define Netdb_hlen_t int /**/ -#define Netdb_name_t const char * /**/ -#define Netdb_net_t unsigned long /**/ - -/* Select_fd_set_t: - * This symbol holds the type used for the 2nd, 3rd, and 4th - * arguments to select. Usually, this is 'fd_set *', if HAS_FD_SET - * is defined, and 'int *' otherwise. This is only useful if you - * have select(), of course. - */ -#define Select_fd_set_t int /**/ - -/* Sock_size_t: - * This symbol holds the type used for the size argument of - * various socket calls (just the base type, not the pointer-to). - */ -#define Sock_size_t int /**/ - -/* ARCHNAME: - * This symbol holds a string representing the architecture name. - * It may be used to construct an architecture-dependant pathname - * where library files may be held under a private library, for - * instance. - */ -#define ARCHNAME "unknown" /**/ - -/* HAS_ASCTIME_R: - * This symbol, if defined, indicates that the asctime_r routine - * is available to asctime re-entrantly. - */ -/* ASCTIME_R_PROTO: - * This symbol encodes the prototype of asctime_r. - * It is zero if d_asctime_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_asctime_r - * is defined. - */ -/*#define HAS_ASCTIME_R / **/ -#define ASCTIME_R_PROTO 0 /**/ - -/* HAS_CRYPT_R: - * This symbol, if defined, indicates that the crypt_r routine - * is available to crypt re-entrantly. - */ -/* CRYPT_R_PROTO: - * This symbol encodes the prototype of crypt_r. - * It is zero if d_crypt_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_crypt_r - * is defined. - */ -/*#define HAS_CRYPT_R / **/ -#define CRYPT_R_PROTO 0 /**/ - -/* HAS_CTERMID_R: - * This symbol, if defined, indicates that the ctermid_r routine - * is available to ctermid re-entrantly. - */ -/* CTERMID_R_PROTO: - * This symbol encodes the prototype of ctermid_r. - * It is zero if d_ctermid_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_ctermid_r - * is defined. - */ -/*#define HAS_CTERMID_R / **/ -#define CTERMID_R_PROTO 0 /**/ - -/* HAS_CTIME_R: - * This symbol, if defined, indicates that the ctime_r routine - * is available to ctime re-entrantly. - */ -/* CTIME_R_PROTO: - * This symbol encodes the prototype of ctime_r. - * It is zero if d_ctime_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_ctime_r - * is defined. - */ -/*#define HAS_CTIME_R / **/ -#define CTIME_R_PROTO 0 /**/ - -/* HAS_DRAND48_R: - * This symbol, if defined, indicates that the drand48_r routine - * is available to drand48 re-entrantly. - */ -/* DRAND48_R_PROTO: - * This symbol encodes the prototype of drand48_r. - * It is zero if d_drand48_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_drand48_r - * is defined. - */ -/*#define HAS_DRAND48_R / **/ -#define DRAND48_R_PROTO 0 /**/ - -/* HAS_ENDGRENT_R: - * This symbol, if defined, indicates that the endgrent_r routine - * is available to endgrent re-entrantly. - */ -/* ENDGRENT_R_PROTO: - * This symbol encodes the prototype of endgrent_r. - * It is zero if d_endgrent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_endgrent_r - * is defined. - */ -/*#define HAS_ENDGRENT_R / **/ -#define ENDGRENT_R_PROTO 0 /**/ - -/* HAS_ENDHOSTENT_R: - * This symbol, if defined, indicates that the endhostent_r routine - * is available to endhostent re-entrantly. - */ -/* ENDHOSTENT_R_PROTO: - * This symbol encodes the prototype of endhostent_r. - * It is zero if d_endhostent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_endhostent_r - * is defined. - */ -/*#define HAS_ENDHOSTENT_R / **/ -#define ENDHOSTENT_R_PROTO 0 /**/ - -/* HAS_ENDNETENT_R: - * This symbol, if defined, indicates that the endnetent_r routine - * is available to endnetent re-entrantly. - */ -/* ENDNETENT_R_PROTO: - * This symbol encodes the prototype of endnetent_r. - * It is zero if d_endnetent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_endnetent_r - * is defined. - */ -/*#define HAS_ENDNETENT_R / **/ -#define ENDNETENT_R_PROTO 0 /**/ - -/* HAS_ENDPROTOENT_R: - * This symbol, if defined, indicates that the endprotoent_r routine - * is available to endprotoent re-entrantly. - */ -/* ENDPROTOENT_R_PROTO: - * This symbol encodes the prototype of endprotoent_r. - * It is zero if d_endprotoent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_endprotoent_r - * is defined. - */ -/*#define HAS_ENDPROTOENT_R / **/ -#define ENDPROTOENT_R_PROTO 0 /**/ - -/* HAS_ENDPWENT_R: - * This symbol, if defined, indicates that the endpwent_r routine - * is available to endpwent re-entrantly. - */ -/* ENDPWENT_R_PROTO: - * This symbol encodes the prototype of endpwent_r. - * It is zero if d_endpwent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_endpwent_r - * is defined. - */ -/*#define HAS_ENDPWENT_R / **/ -#define ENDPWENT_R_PROTO 0 /**/ - -/* HAS_ENDSERVENT_R: - * This symbol, if defined, indicates that the endservent_r routine - * is available to endservent re-entrantly. - */ -/* ENDSERVENT_R_PROTO: - * This symbol encodes the prototype of endservent_r. - * It is zero if d_endservent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_endservent_r - * is defined. - */ -/*#define HAS_ENDSERVENT_R / **/ -#define ENDSERVENT_R_PROTO 0 /**/ - -/* GETENV_PRESERVES_OTHER_THREAD: - * This symbol, if defined, indicates that the getenv system call doesn't - * zap the static buffer of getenv() in a different thread. - * - * The typical getenv() implementation will return a pointer to the proper - * position in **environ. But some may instead copy them to a static - * buffer in getenv(). If there is a per-thread instance of that buffer, - * or the return points to **environ, then a many-reader/1-writer mutex - * will work; otherwise an exclusive locking mutex is required to prevent - * races. - */ -#define GETENV_PRESERVES_OTHER_THREAD /**/ - -/* HAS_GETGRENT_R: - * This symbol, if defined, indicates that the getgrent_r routine - * is available to getgrent re-entrantly. - */ -/* GETGRENT_R_PROTO: - * This symbol encodes the prototype of getgrent_r. - * It is zero if d_getgrent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getgrent_r - * is defined. - */ -/*#define HAS_GETGRENT_R / **/ -#define GETGRENT_R_PROTO 0 /**/ - -/* HAS_GETGRGID_R: - * This symbol, if defined, indicates that the getgrgid_r routine - * is available to getgrgid re-entrantly. - */ -/* GETGRGID_R_PROTO: - * This symbol encodes the prototype of getgrgid_r. - * It is zero if d_getgrgid_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getgrgid_r - * is defined. - */ -/*#define HAS_GETGRGID_R / **/ -#define GETGRGID_R_PROTO 0 /**/ - -/* HAS_GETGRNAM_R: - * This symbol, if defined, indicates that the getgrnam_r routine - * is available to getgrnam re-entrantly. - */ -/* GETGRNAM_R_PROTO: - * This symbol encodes the prototype of getgrnam_r. - * It is zero if d_getgrnam_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getgrnam_r - * is defined. - */ -/*#define HAS_GETGRNAM_R / **/ -#define GETGRNAM_R_PROTO 0 /**/ - -/* HAS_GETHOSTBYADDR_R: - * This symbol, if defined, indicates that the gethostbyaddr_r routine - * is available to gethostbyaddr re-entrantly. - */ -/* GETHOSTBYADDR_R_PROTO: - * This symbol encodes the prototype of gethostbyaddr_r. - * It is zero if d_gethostbyaddr_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_gethostbyaddr_r - * is defined. - */ -/*#define HAS_GETHOSTBYADDR_R / **/ -#define GETHOSTBYADDR_R_PROTO 0 /**/ - -/* HAS_GETHOSTBYNAME_R: - * This symbol, if defined, indicates that the gethostbyname_r routine - * is available to gethostbyname re-entrantly. - */ -/* GETHOSTBYNAME_R_PROTO: - * This symbol encodes the prototype of gethostbyname_r. - * It is zero if d_gethostbyname_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_gethostbyname_r - * is defined. - */ -/*#define HAS_GETHOSTBYNAME_R / **/ -#define GETHOSTBYNAME_R_PROTO 0 /**/ - -/* HAS_GETHOSTENT_R: - * This symbol, if defined, indicates that the gethostent_r routine - * is available to gethostent re-entrantly. - */ -/* GETHOSTENT_R_PROTO: - * This symbol encodes the prototype of gethostent_r. - * It is zero if d_gethostent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_gethostent_r - * is defined. - */ -/*#define HAS_GETHOSTENT_R / **/ -#define GETHOSTENT_R_PROTO 0 /**/ - -/* HAS_GETLOGIN_R: - * This symbol, if defined, indicates that the getlogin_r routine - * is available to getlogin re-entrantly. - */ -/* GETLOGIN_R_PROTO: - * This symbol encodes the prototype of getlogin_r. - * It is zero if d_getlogin_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getlogin_r - * is defined. - */ -/*#define HAS_GETLOGIN_R / **/ -#define GETLOGIN_R_PROTO 0 /**/ - -/* HAS_GETNETBYADDR_R: - * This symbol, if defined, indicates that the getnetbyaddr_r routine - * is available to getnetbyaddr re-entrantly. - */ -/* GETNETBYADDR_R_PROTO: - * This symbol encodes the prototype of getnetbyaddr_r. - * It is zero if d_getnetbyaddr_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getnetbyaddr_r - * is defined. - */ -/*#define HAS_GETNETBYADDR_R / **/ -#define GETNETBYADDR_R_PROTO 0 /**/ - -/* HAS_GETNETBYNAME_R: - * This symbol, if defined, indicates that the getnetbyname_r routine - * is available to getnetbyname re-entrantly. - */ -/* GETNETBYNAME_R_PROTO: - * This symbol encodes the prototype of getnetbyname_r. - * It is zero if d_getnetbyname_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getnetbyname_r - * is defined. - */ -/*#define HAS_GETNETBYNAME_R / **/ -#define GETNETBYNAME_R_PROTO 0 /**/ - -/* HAS_GETNETENT_R: - * This symbol, if defined, indicates that the getnetent_r routine - * is available to getnetent re-entrantly. - */ -/* GETNETENT_R_PROTO: - * This symbol encodes the prototype of getnetent_r. - * It is zero if d_getnetent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getnetent_r - * is defined. - */ -/*#define HAS_GETNETENT_R / **/ -#define GETNETENT_R_PROTO 0 /**/ - -/* HAS_GETPROTOBYNAME_R: - * This symbol, if defined, indicates that the getprotobyname_r routine - * is available to getprotobyname re-entrantly. - */ -/* GETPROTOBYNAME_R_PROTO: - * This symbol encodes the prototype of getprotobyname_r. - * It is zero if d_getprotobyname_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getprotobyname_r - * is defined. - */ -/*#define HAS_GETPROTOBYNAME_R / **/ -#define GETPROTOBYNAME_R_PROTO 0 /**/ - -/* HAS_GETPROTOBYNUMBER_R: - * This symbol, if defined, indicates that the getprotobynumber_r routine - * is available to getprotobynumber re-entrantly. - */ -/* GETPROTOBYNUMBER_R_PROTO: - * This symbol encodes the prototype of getprotobynumber_r. - * It is zero if d_getprotobynumber_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getprotobynumber_r - * is defined. - */ -/*#define HAS_GETPROTOBYNUMBER_R / **/ -#define GETPROTOBYNUMBER_R_PROTO 0 /**/ - -/* HAS_GETPROTOENT_R: - * This symbol, if defined, indicates that the getprotoent_r routine - * is available to getprotoent re-entrantly. - */ -/* GETPROTOENT_R_PROTO: - * This symbol encodes the prototype of getprotoent_r. - * It is zero if d_getprotoent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getprotoent_r - * is defined. - */ -/*#define HAS_GETPROTOENT_R / **/ -#define GETPROTOENT_R_PROTO 0 /**/ - -/* HAS_GETPWENT_R: - * This symbol, if defined, indicates that the getpwent_r routine - * is available to getpwent re-entrantly. - */ -/* GETPWENT_R_PROTO: - * This symbol encodes the prototype of getpwent_r. - * It is zero if d_getpwent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getpwent_r - * is defined. - */ -/*#define HAS_GETPWENT_R / **/ -#define GETPWENT_R_PROTO 0 /**/ - -/* HAS_GETPWNAM_R: - * This symbol, if defined, indicates that the getpwnam_r routine - * is available to getpwnam re-entrantly. - */ -/* GETPWNAM_R_PROTO: - * This symbol encodes the prototype of getpwnam_r. - * It is zero if d_getpwnam_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getpwnam_r - * is defined. - */ -/*#define HAS_GETPWNAM_R / **/ -#define GETPWNAM_R_PROTO 0 /**/ - -/* HAS_GETPWUID_R: - * This symbol, if defined, indicates that the getpwuid_r routine - * is available to getpwuid re-entrantly. - */ -/* GETPWUID_R_PROTO: - * This symbol encodes the prototype of getpwuid_r. - * It is zero if d_getpwuid_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getpwuid_r - * is defined. - */ -/*#define HAS_GETPWUID_R / **/ -#define GETPWUID_R_PROTO 0 /**/ - -/* HAS_GETSERVBYNAME_R: - * This symbol, if defined, indicates that the getservbyname_r routine - * is available to getservbyname re-entrantly. - */ -/* GETSERVBYNAME_R_PROTO: - * This symbol encodes the prototype of getservbyname_r. - * It is zero if d_getservbyname_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getservbyname_r - * is defined. - */ -/*#define HAS_GETSERVBYNAME_R / **/ -#define GETSERVBYNAME_R_PROTO 0 /**/ - -/* HAS_GETSERVBYPORT_R: - * This symbol, if defined, indicates that the getservbyport_r routine - * is available to getservbyport re-entrantly. - */ -/* GETSERVBYPORT_R_PROTO: - * This symbol encodes the prototype of getservbyport_r. - * It is zero if d_getservbyport_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getservbyport_r - * is defined. - */ -/*#define HAS_GETSERVBYPORT_R / **/ -#define GETSERVBYPORT_R_PROTO 0 /**/ - -/* HAS_GETSERVENT_R: - * This symbol, if defined, indicates that the getservent_r routine - * is available to getservent re-entrantly. - */ -/* GETSERVENT_R_PROTO: - * This symbol encodes the prototype of getservent_r. - * It is zero if d_getservent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getservent_r - * is defined. - */ -/*#define HAS_GETSERVENT_R / **/ -#define GETSERVENT_R_PROTO 0 /**/ - -/* HAS_GETSPNAM_R: - * This symbol, if defined, indicates that the getspnam_r routine - * is available to getspnam re-entrantly. - */ -/* GETSPNAM_R_PROTO: - * This symbol encodes the prototype of getspnam_r. - * It is zero if d_getspnam_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_getspnam_r - * is defined. - */ -/*#define HAS_GETSPNAM_R / **/ -#define GETSPNAM_R_PROTO 0 /**/ - -/* HAS_GMTIME_R: - * This symbol, if defined, indicates that the gmtime_r routine - * is available to gmtime re-entrantly. - */ -/* GMTIME_R_PROTO: - * This symbol encodes the prototype of gmtime_r. - * It is zero if d_gmtime_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_gmtime_r - * is defined. - */ -/*#define HAS_GMTIME_R / **/ -#define GMTIME_R_PROTO 0 /**/ - -/* HAS_LOCALECONV_L: - * This symbol, if defined, indicates that the localeconv_l routine is - * available to query certain information about a locale. - */ -/*#define HAS_LOCALECONV_L / **/ - -/* HAS_LOCALTIME_R: - * This symbol, if defined, indicates that the localtime_r routine - * is available to localtime re-entrantly. - */ -/* LOCALTIME_R_NEEDS_TZSET: - * Many libc's localtime_r implementations do not call tzset, - * making them differ from localtime(), and making timezone - * changes using $ENV{TZ} without explicitly calling tzset - * impossible. This symbol makes us call tzset before localtime_r - */ -/*#define LOCALTIME_R_NEEDS_TZSET / **/ -#ifdef LOCALTIME_R_NEEDS_TZSET -#define L_R_TZSET tzset(), -#else -#define L_R_TZSET -#endif - -/* L_R_TZSET: - * If localtime_r() needs tzset, it is defined in this define - */ -/* LOCALTIME_R_PROTO: - * This symbol encodes the prototype of localtime_r. - * It is zero if d_localtime_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_localtime_r - * is defined. - */ -/*#define HAS_LOCALTIME_R / **/ -#define LOCALTIME_R_PROTO 0 /**/ - -/* HAS_MBRLEN: - * This symbol, if defined, indicates that the mbrlen routine is - * available to get the length of multi-byte character strings. - */ -/*#define HAS_MBRLEN / **/ - -/* HAS_MBRTOWC: - * This symbol, if defined, indicates that the mbrtowc routine is - * available to convert a multi-byte character into a wide character. - */ -/*#define HAS_MBRTOWC / **/ - -/* HAS_NL_LANGINFO_L: - * This symbol, when defined, indicates presence of the nl_langinfo_l() - * function - */ -/* HAS_THREAD_SAFE_NL_LANGINFO_L: - * This symbol, when defined, indicates presence of the nl_langinfo_l() - * function, and that it is thread-safe. - */ -/*#define HAS_NL_LANGINFO_L / **/ -/*#define HAS_THREAD_SAFE_NL_LANGINFO_L / **/ - -/* OLD_PTHREAD_CREATE_JOINABLE: - * This symbol, if defined, indicates how to create pthread - * in joinable (aka undetached) state. NOTE: not defined - * if pthread.h already has defined PTHREAD_CREATE_JOINABLE - * (the new version of the constant). - * If defined, known values are PTHREAD_CREATE_UNDETACHED - * and __UNDETACHED. - */ -/*#define OLD_PTHREAD_CREATE_JOINABLE / **/ - -/* HAS_PTHREAD_ATFORK: - * This symbol, if defined, indicates that the pthread_atfork routine - * is available to setup fork handlers. - */ -/*#define HAS_PTHREAD_ATFORK / **/ - -/* HAS_PTHREAD_YIELD: - * This symbol, if defined, indicates that the pthread_yield - * routine is available to yield the execution of the current - * thread. sched_yield is preferable to pthread_yield. - */ -/* SCHED_YIELD: - * This symbol defines the way to yield the execution of - * the current thread. Known ways are sched_yield, - * pthread_yield, and pthread_yield with NULL. - */ -/* HAS_SCHED_YIELD: - * This symbol, if defined, indicates that the sched_yield - * routine is available to yield the execution of the current - * thread. sched_yield is preferable to pthread_yield. - */ -/*#define HAS_PTHREAD_YIELD / **/ -#define SCHED_YIELD sched_yield() /**/ -/*#define HAS_SCHED_YIELD / **/ - -/* HAS_RANDOM_R: - * This symbol, if defined, indicates that the random_r routine - * is available to random re-entrantly. - */ -/* RANDOM_R_PROTO: - * This symbol encodes the prototype of random_r. - * It is zero if d_random_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_random_r - * is defined. - */ -/*#define HAS_RANDOM_R / **/ -#define RANDOM_R_PROTO 0 /**/ - -/* HAS_READDIR64_R: - * This symbol, if defined, indicates that the readdir64_r routine - * is available to readdir64 re-entrantly. - */ -/* READDIR64_R_PROTO: - * This symbol encodes the prototype of readdir64_r. - * It is zero if d_readdir64_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_readdir64_r - * is defined. - */ -/*#define HAS_READDIR64_R / **/ -#define READDIR64_R_PROTO 0 /**/ - -/* HAS_READDIR_R: - * This symbol, if defined, indicates that the readdir_r routine - * is available to readdir re-entrantly. - */ -/* READDIR_R_PROTO: - * This symbol encodes the prototype of readdir_r. - * It is zero if d_readdir_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_readdir_r - * is defined. - */ -/*#define HAS_READDIR_R / **/ -#define READDIR_R_PROTO 0 /**/ - -/* HAS_SETGRENT_R: - * This symbol, if defined, indicates that the setgrent_r routine - * is available to setgrent re-entrantly. - */ -/* SETGRENT_R_PROTO: - * This symbol encodes the prototype of setgrent_r. - * It is zero if d_setgrent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_setgrent_r - * is defined. - */ -/*#define HAS_SETGRENT_R / **/ -#define SETGRENT_R_PROTO 0 /**/ - -/* HAS_SETHOSTENT_R: - * This symbol, if defined, indicates that the sethostent_r routine - * is available to sethostent re-entrantly. - */ -/* SETHOSTENT_R_PROTO: - * This symbol encodes the prototype of sethostent_r. - * It is zero if d_sethostent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_sethostent_r - * is defined. - */ -/*#define HAS_SETHOSTENT_R / **/ -#define SETHOSTENT_R_PROTO 0 /**/ - -/* HAS_SETLOCALE_R: - * This symbol, if defined, indicates that the setlocale_r routine - * is available to setlocale re-entrantly. - */ -/* SETLOCALE_R_PROTO: - * This symbol encodes the prototype of setlocale_r. - * It is zero if d_setlocale_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_setlocale_r - * is defined. - */ -/*#define HAS_SETLOCALE_R / **/ -#define SETLOCALE_R_PROTO 0 /**/ - -/* HAS_SETNETENT_R: - * This symbol, if defined, indicates that the setnetent_r routine - * is available to setnetent re-entrantly. - */ -/* SETNETENT_R_PROTO: - * This symbol encodes the prototype of setnetent_r. - * It is zero if d_setnetent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_setnetent_r - * is defined. - */ -/*#define HAS_SETNETENT_R / **/ -#define SETNETENT_R_PROTO 0 /**/ - -/* HAS_SETPROTOENT_R: - * This symbol, if defined, indicates that the setprotoent_r routine - * is available to setprotoent re-entrantly. - */ -/* SETPROTOENT_R_PROTO: - * This symbol encodes the prototype of setprotoent_r. - * It is zero if d_setprotoent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_setprotoent_r - * is defined. - */ -/*#define HAS_SETPROTOENT_R / **/ -#define SETPROTOENT_R_PROTO 0 /**/ - -/* HAS_SETPWENT_R: - * This symbol, if defined, indicates that the setpwent_r routine - * is available to setpwent re-entrantly. - */ -/* SETPWENT_R_PROTO: - * This symbol encodes the prototype of setpwent_r. - * It is zero if d_setpwent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_setpwent_r - * is defined. - */ -/*#define HAS_SETPWENT_R / **/ -#define SETPWENT_R_PROTO 0 /**/ - -/* HAS_SETSERVENT_R: - * This symbol, if defined, indicates that the setservent_r routine - * is available to setservent re-entrantly. - */ -/* SETSERVENT_R_PROTO: - * This symbol encodes the prototype of setservent_r. - * It is zero if d_setservent_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_setservent_r - * is defined. - */ -/*#define HAS_SETSERVENT_R / **/ -#define SETSERVENT_R_PROTO 0 /**/ - -/* HAS_SRAND48_R: - * This symbol, if defined, indicates that the srand48_r routine - * is available to srand48 re-entrantly. - */ -/* SRAND48_R_PROTO: - * This symbol encodes the prototype of srand48_r. - * It is zero if d_srand48_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_srand48_r - * is defined. - */ -/*#define HAS_SRAND48_R / **/ -#define SRAND48_R_PROTO 0 /**/ - -/* HAS_SRANDOM_R: - * This symbol, if defined, indicates that the srandom_r routine - * is available to srandom re-entrantly. - */ -/* SRANDOM_R_PROTO: - * This symbol encodes the prototype of srandom_r. - * It is zero if d_srandom_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_srandom_r - * is defined. - */ -/*#define HAS_SRANDOM_R / **/ -#define SRANDOM_R_PROTO 0 /**/ - -/* HAS_STRERROR_R: - * This symbol, if defined, indicates that the strerror_r routine - * is available to strerror re-entrantly. - */ -/* STRERROR_R_PROTO: - * This symbol encodes the prototype of strerror_r. - * It is zero if d_strerror_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_strerror_r - * is defined. - */ -/*#define HAS_STRERROR_R / **/ -#define STRERROR_R_PROTO 0 /**/ - -/* HAS_STRTOD_L: - * This symbol, if defined, indicates that the strtod_l routine is - * available to convert strings to long doubles. - */ -/*#define HAS_STRTOD_L / **/ - -/* HAS_STRTOLD_L: - * This symbol, if defined, indicates that the strtold_l routine is - * available to convert strings to long doubles. - */ -/*#define HAS_STRTOLD_L / **/ - -/* PERL_THREAD_LOCAL: - * This symbol, if defined, gives a linkage specification for thread-local - * storage. For example, for a C11 compiler this will be _Thread_local. - * Beware, some compilers are sensitive to the C language standard they are - * told to parse. For example, suncc defaults to C11, so our probe will - * report that _Thread_local can be used. However, if the -std=c99 is later - * added to the compiler flags, then _Thread_local will become a syntax - * error. Hence it is important for these flags to be consistent between - * probing and use. - */ -/*#define PERL_THREAD_LOCAL / **/ - -/* HAS_TMPNAM_R: - * This symbol, if defined, indicates that the tmpnam_r routine - * is available to tmpnam re-entrantly. - */ -/* TMPNAM_R_PROTO: - * This symbol encodes the prototype of tmpnam_r. - * It is zero if d_tmpnam_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_tmpnam_r - * is defined. - */ -/*#define HAS_TMPNAM_R / **/ -#define TMPNAM_R_PROTO 0 /**/ - -/* HAS_TTYNAME_R: - * This symbol, if defined, indicates that the ttyname_r routine - * is available to ttyname re-entrantly. - */ -/* TTYNAME_R_PROTO: - * This symbol encodes the prototype of ttyname_r. - * It is zero if d_ttyname_r is undef, and one of the - * REENTRANT_PROTO_T_ABC macros of reentr.h if d_ttyname_r - * is defined. - */ -/*#define HAS_TTYNAME_R / **/ -#define TTYNAME_R_PROTO 0 /**/ - -/* HAS_WCRTOMB: - * This symbol, if defined, indicates that the wcrtomb routine is - * available to convert a wide character into a multi-byte character. - */ -/*#define HAS_WCRTOMB / **/ - -/* I_MACH_CTHREADS: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_MACH_CTHREADS / **/ - -/* I_PTHREAD: - * This symbol, if defined, indicates to the C program that it should - * include . - */ -/*#define I_PTHREAD / **/ - -/* USE_ITHREADS: - * This symbol, if defined, indicates that Perl should be built to - * use the interpreter-based threading implementation. - */ -/* USE_THREADS: - * This symbol, if defined, indicates that Perl should - * be built to use threads. At present, it is a synonym for - * and USE_ITHREADS, but eventually the source ought to be - * changed to use this to mean _any_ threading implementation. - */ -/* OLD_PTHREADS_API: - * This symbol, if defined, indicates that Perl should - * be built to use the old draft POSIX threads API. - */ -/* USE_REENTRANT_API: - * This symbol, if defined, indicates that Perl should - * try to use the various _r versions of library functions. - * This is extremely experimental. - */ -/*#define USE_ITHREADS / **/ -/*#define USE_THREADS / **/ -/*#define OLD_PTHREADS_API / **/ -/*#define USE_REENTRANT_API / **/ - -/* HAS_TIME: - * This symbol, if defined, indicates that the time() routine exists. - */ -/* Time_t: - * This symbol holds the type returned by time(). It can be long, - * or time_t on BSD sites (in which case should be - * included). - */ -#define HAS_TIME /**/ -#define Time_t time_t /* Time type */ - -/* HAS_TIMES: - * This symbol, if defined, indicates that the times() routine exists. - * Note that this became obsolete on some systems (SUNOS), which now - * use getrusage(). It may be necessary to include . - */ -/*#define HAS_TIMES / **/ - -/* Fpos_t: - * This symbol holds the type used to declare file positions in libc. - * It can be fpos_t, long, uint, etc... It may be necessary to include - * to get any typedef'ed information. - */ -#define Fpos_t int /* File position type */ - -/* Gid_t_f: - * This symbol defines the format string used for printing a Gid_t. - */ -#define Gid_t_f "lu" /**/ - -/* Gid_t_sign: - * This symbol holds the signedness of a Gid_t. - * 1 for unsigned, -1 for signed. - */ -#define Gid_t_sign 1 /* GID sign */ - -/* Gid_t_size: - * This symbol holds the size of a Gid_t in bytes. - */ -#define Gid_t_size 4 /* GID size */ - -/* Gid_t: - * This symbol holds the return type of getgid() and the type of - * argument to setrgid() and related functions. Typically, - * it is the type of group ids in the kernel. It can be int, ushort, - * gid_t, etc... It may be necessary to include to get - * any typedef'ed information. - */ -#define Gid_t int /* Type for getgid(), etc... */ - -/* Off_t: - * This symbol holds the type used to declare offsets in the kernel. - * It can be int, long, off_t, etc... It may be necessary to include - * to get any typedef'ed information. - */ -/* LSEEKSIZE: - * This symbol holds the number of bytes used by the Off_t. - */ -/* Off_t_size: - * This symbol holds the number of bytes used by the Off_t. - */ -#define Off_t int /* type */ -#define LSEEKSIZE 4 /* size */ -#define Off_t_size 4 /* size */ - -/* Mode_t: - * This symbol holds the type used to declare file modes - * for systems calls. It is usually mode_t, but may be - * int or unsigned short. It may be necessary to include - * to get any typedef'ed information. - */ -#define Mode_t int /* file mode parameter for system calls */ - -/* Pid_t: - * This symbol holds the type used to declare process ids in the kernel. - * It can be int, uint, pid_t, etc... It may be necessary to include - * to get any typedef'ed information. - */ -#define Pid_t int /* PID type */ - -/* Size_t_size: - * This symbol holds the size of a Size_t in bytes. - */ -#define Size_t_size 4 /**/ - -/* Size_t: - * This symbol holds the type used to declare length parameters - * for string functions. It is usually size_t, but may be - * unsigned long, int, etc. It may be necessary to include - * to get any typedef'ed information. - */ -#define Size_t size_t /* length parameter for string functions */ - -/* Uid_t_f: - * This symbol defines the format string used for printing a Uid_t. - */ -#define Uid_t_f "lu" /**/ - -/* Uid_t_sign: - * This symbol holds the signedness of a Uid_t. - * 1 for unsigned, -1 for signed. - */ -#define Uid_t_sign 1 /* UID sign */ - -/* Uid_t_size: - * This symbol holds the size of a Uid_t in bytes. - */ -#define Uid_t_size 4 /* UID size */ - -/* Uid_t: - * This symbol holds the type used to declare user ids in the kernel. - * It can be int, ushort, uid_t, etc... It may be necessary to include - * to get any typedef'ed information. - */ -#define Uid_t int /* UID type */ - -#endif - -/* Generated from: - * e17a83ff6ae98071d846d4a001f6ce1a669df08c357fe153c2370adc4910135e config_h.SH - * 8d785207fec43bbad5118a8125e625d1cc654455994f09a76c1625b2ae2ae2d0 uconfig.sh - * ex: set ro ft=c: */ Index: gnu/usr.bin/perl/uconfig.sh =================================================================== RCS file: gnu/usr.bin/perl/uconfig.sh diff -N gnu/usr.bin/perl/uconfig.sh --- gnu/usr.bin/perl/uconfig.sh 14 May 2024 19:38:54 -0000 1.13 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,938 +0,0 @@ -#!/bin/sh -Author='' -_a='.a' -_o='.o' -afs='false' -afsroot='/afs' -alignbytes='4' -aphostname='/bin/hostname' -archlib='/usr/local/lib/perl5/5.38/unknown' -archlibexp='/usr/local/lib/perl5/5.38/unknown' -archname='unknown' -asctime_r_proto='0' -bin='/usr/local/bin' -binexp='/usr/local/bin' -bootstrap_charset='undef' -byteorder='1234' -castflags='0' -cf_by='root@localhost' -cf_time='Thu Jan 1 00:00:00 GMT 1970' -charbits='8' -clocktype='clock_t' -cpp_stuff='42' -cpplast='-' -cppminus='-' -cpprun='cc -E' -cppstdin='cc -E' -crypt_r_proto='0' -ctermid_r_proto='0' -ctime_r_proto='0' -d_Gconvert='sprintf((b),"%.*g",(n),(x))' -d_PRIEUldbl='undef' -d_PRIFUldbl='undef' -d_PRIGUldbl='undef' -d_PRIXU64='undef' -d_PRId64='undef' -d_PRIeldbl='undef' -d_PRIfldbl='undef' -d_PRIgldbl='undef' -d_PRIi64='undef' -d_PRIo64='undef' -d_PRIu64='undef' -d_PRIx64='undef' -d_SCNfldbl='undef' -d__fwalk='undef' -d_accept4='undef' -d_access='undef' -d_accessx='undef' -d_acosh='undef' -d_aintl='undef' -d_alarm='undef' -d_archlib='undef' -d_asctime64='undef' -d_asctime_r='undef' -d_asinh='undef' -d_atanh='undef' -d_atolf='undef' -d_atoll='undef' -d_attribute_always_inline='undef' -d_attribute_deprecated='undef' -d_attribute_format='undef' -d_attribute_malloc='undef' -d_attribute_nonnull='undef' -d_attribute_noreturn='undef' -d_attribute_pure='undef' -d_attribute_unused='undef' -d_attribute_visibility='undef' -d_attribute_warn_unused_result='undef' -d_backtrace='undef' -d_bsd='undef' -d_bsdgetpgrp='undef' -d_bsdsetpgrp='undef' -d_builtin_add_overflow='undef' -d_builtin_choose_expr='undef' -d_builtin_expect='undef' -d_builtin_mul_overflow='undef' -d_builtin_sub_overflow='undef' -d_c99_variadic_macros='undef' -d_casti32='undef' -d_castneg='undef' -d_cbrt='undef' -d_chown='undef' -d_chroot='undef' -d_chsize='undef' -d_class='undef' -d_clearenv='undef' -d_closedir='define' -d_cmsghdr_s='undef' -d_copysign='undef' -d_copysignl='undef' -d_cplusplus='undef' -d_crypt='undef' -d_crypt_r='undef' -d_csh='undef' -d_ctermid='undef' -d_ctermid_r='undef' -d_ctime64='undef' -d_ctime_r='undef' -d_cuserid='undef' -d_dbl_dig='undef' -d_dbminitproto='undef' -d_difftime64='undef' -d_difftime='undef' -d_dir_dd_fd='undef' -d_dirfd='undef' -d_dirnamlen='undef' -d_dladdr='undef' -d_dlerror='undef' -d_dlopen='undef' -d_dlsymun='undef' -d_dosuid='undef' -d_double_has_inf='define' -d_double_has_nan='define' -d_double_has_negative_zero='define' -d_double_has_subnormals='define' -d_double_style_cray='undef' -d_double_style_ibm='undef' -d_double_style_ieee='define' -d_double_style_vax='undef' -d_drand48_r='undef' -d_drand48proto='undef' -d_dup2='undef' -d_dup3='undef' -d_duplocale='undef' -d_eaccess='undef' -d_endgrent='undef' -d_endgrent_r='undef' -d_endhent='undef' -d_endhostent_r='undef' -d_endnent='undef' -d_endnetent_r='undef' -d_endpent='undef' -d_endprotoent_r='undef' -d_endpwent='undef' -d_endpwent_r='undef' -d_endsent='undef' -d_endservent_r='undef' -d_eofnblk='undef' -d_erf='undef' -d_erfc='undef' -d_eunice='undef' -d_exp2='undef' -d_expm1='undef' -d_faststdio='undef' -d_fchdir='undef' -d_fchmod='undef' -d_fchmodat='undef' -d_fchown='undef' -d_fcntl='undef' -d_fcntl_can_lock='undef' -d_fd_macros='undef' -d_fd_set='undef' -d_fdclose='undef' -d_fdim='undef' -d_fds_bits='undef' -d_fegetround='undef' -d_ffs='undef' -d_ffsl='undef' -d_fgetpos='undef' -d_finite='undef' -d_finitel='undef' -d_flexfnam='undef' -d_flock='undef' -d_flockproto='undef' -d_fma='undef' -d_fmax='undef' -d_fmin='undef' -d_fork='define' -d_fp_class='undef' -d_fp_classify='undef' -d_fp_classl='undef' -d_fpathconf='undef' -d_fpclass='undef' -d_fpclassify='undef' -d_fpclassl='undef' -d_fpgetround='undef' -d_fpos64_t='undef' -d_freelocale='undef' -d_frexpl='undef' -d_fs_data_s='undef' -d_fseeko='undef' -d_fsetpos='undef' -d_fstatfs='undef' -d_fstatvfs='undef' -d_fsync='undef' -d_ftello='undef' -d_ftime='undef' -d_futimes='undef' -d_gai_strerror='undef' -d_gdbm_ndbm_h_uses_prototypes='undef' -d_gdbmndbm_h_uses_prototypes='undef' -d_getaddrinfo='undef' -d_getcwd='undef' -d_getenv_preserves_other_thread='define' -d_getespwnam='undef' -d_getfsstat='undef' -d_getgrent='undef' -d_getgrent_r='undef' -d_getgrgid_r='undef' -d_getgrnam_r='undef' -d_getgrps='undef' -d_gethbyaddr='undef' -d_gethbyname='undef' -d_gethent='undef' -d_gethname='undef' -d_gethostbyaddr_r='undef' -d_gethostbyname_r='undef' -d_gethostent_r='undef' -d_gethostprotos='undef' -d_getitimer='undef' -d_getlogin='undef' -d_getlogin_r='undef' -d_getmnt='undef' -d_getmntent='undef' -d_getnameinfo='undef' -d_getnbyaddr='undef' -d_getnbyname='undef' -d_getnent='undef' -d_getnetbyaddr_r='undef' -d_getnetbyname_r='undef' -d_getnetent_r='undef' -d_getnetprotos='undef' -d_getpagsz='undef' -d_getpbyname='undef' -d_getpbynumber='undef' -d_getpent='undef' -d_getpgid='undef' -d_getpgrp2='undef' -d_getpgrp='undef' -d_getppid='undef' -d_getprior='undef' -d_getprotobyname_r='undef' -d_getprotobynumber_r='undef' -d_getprotoent_r='undef' -d_getprotoprotos='undef' -d_getprpwnam='undef' -d_getpwent='undef' -d_getpwent_r='undef' -d_getpwnam_r='undef' -d_getpwuid_r='undef' -d_getsbyname='undef' -d_getsbyport='undef' -d_getsent='undef' -d_getservbyname_r='undef' -d_getservbyport_r='undef' -d_getservent_r='undef' -d_getservprotos='undef' -d_getspent='undef' -d_getspnam='undef' -d_getspnam_r='undef' -d_gettimeod='undef' -d_gmtime64='undef' -d_gmtime_r='undef' -d_gnulibc='undef' -d_grpasswd='undef' -d_hasmntopt='undef' -d_htonl='undef' -d_hypot='undef' -d_ilogb='undef' -d_ilogbl='undef' -d_inc_version_list='undef' -d_index='undef' -d_inetaton='undef' -d_inetntop='undef' -d_inetpton='undef' -d_int64_t='undef' -d_ip_mreq='undef' -d_ip_mreq_source='undef' -d_ipv6_mreq='undef' -d_ipv6_mreq_source='undef' -d_isascii='undef' -d_isblank='undef' -d_isfinite='undef' -d_isfinitel='undef' -d_isinf='undef' -d_isinfl='undef' -d_isless='undef' -d_isnan='undef' -d_isnanl='undef' -d_isnormal='undef' -d_j0='undef' -d_j0l='undef' -d_killpg='undef' -d_lc_monetary_2008='undef' -d_lchown='undef' -d_ldbl_dig='undef' -d_ldexpl='undef' -d_lgamma='undef' -d_lgamma_r='undef' -d_libm_lib_version='undef' -d_link='undef' -d_linkat='undef' -d_llrint='undef' -d_llrintl='undef' -d_llround='undef' -d_llroundl='undef' -d_localeconv_l='undef' -d_localtime64='undef' -d_localtime_r='undef' -d_localtime_r_needs_tzset='undef' -d_locconv='undef' -d_lockf='undef' -d_log1p='undef' -d_log2='undef' -d_logb='undef' -d_long_double_style_ieee='undef' -d_long_double_style_ieee_doubledouble='undef' -d_long_double_style_ieee_extended='undef' -d_long_double_style_ieee_std='undef' -d_long_double_style_vax='undef' -d_longdbl='undef' -d_longlong='undef' -d_lrint='undef' -d_lrintl='undef' -d_lround='undef' -d_lroundl='undef' -d_lseekproto='undef' -d_lstat='undef' -d_madvise='undef' -d_malloc_good_size='undef' -d_malloc_size='undef' -d_mblen='undef' -d_mbrlen='undef' -d_mbrtowc='undef' -d_mbstowcs='undef' -d_mbtowc='undef' -d_memmem='undef' -d_memrchr='undef' -d_mkdir='undef' -d_mkdtemp='undef' -d_mkfifo='undef' -d_mkostemp='undef' -d_mkstemp='undef' -d_mkstemps='undef' -d_mktime64='undef' -d_mktime='undef' -d_mmap='undef' -d_modfl='undef' -d_modfl_pow32_bug='undef' -d_modflproto='undef' -d_mprotect='undef' -d_msg='undef' -d_msg_ctrunc='undef' -d_msg_dontroute='undef' -d_msg_oob='undef' -d_msg_peek='undef' -d_msg_proxy='undef' -d_msgctl='undef' -d_msgget='undef' -d_msghdr_s='undef' -d_msgrcv='undef' -d_msgsnd='undef' -d_msync='undef' -d_munmap='undef' -d_mymalloc='undef' -d_nan='undef' -d_nanosleep='undef' -d_ndbm_h_uses_prototypes='undef' -d_nearbyint='undef' -d_newlocale='undef' -d_nextafter='undef' -d_nexttoward='undef' -d_nice='undef' -d_nl_langinfo='undef' -d_nl_langinfo_l='undef' -d_non_int_bitfields='define' -d_nv_preserves_uv='undef' -d_nv_zero_is_allbits_zero='undef' -d_off64_t='undef' -d_old_pthread_create_joinable='undef' -d_oldpthreads='undef' -d_oldsock='undef' -d_open3='undef' -d_openat='undef' -d_pathconf='undef' -d_pause='undef' -d_perl_otherlibdirs='undef' -d_phostname='undef' -d_pipe2='undef' -d_pipe='undef' -d_poll='undef' -d_portable='undef' -d_prctl='undef' -d_prctl_set_name='undef' -d_printf_format_null='undef' -d_procselfexe='undef' -d_pseudofork='undef' -d_pthread_atfork='undef' -d_pthread_attr_setscope='undef' -d_pthread_yield='undef' -d_ptrdiff_t='define' -d_pwage='undef' -d_pwchange='undef' -d_pwclass='undef' -d_pwcomment='undef' -d_pwexpire='undef' -d_pwgecos='undef' -d_pwpasswd='undef' -d_pwquota='undef' -d_qgcvt='undef' -d_quad='undef' -d_querylocale='undef' -d_random_r='undef' -d_readdir64_r='undef' -d_readdir='define' -d_readdir_r='undef' -d_readlink='undef' -d_readv='undef' -d_recvmsg='undef' -d_regcomp='define' -d_remainder='undef' -d_remquo='undef' -d_rename='define' -d_renameat='undef' -d_rewinddir='undef' -d_rint='undef' -d_rmdir='undef' -d_round='undef' -d_sbrkproto='undef' -d_scalbn='undef' -d_scalbnl='undef' -d_sched_yield='undef' -d_scm_rights='undef' -d_seekdir='undef' -d_select='undef' -d_sem='undef' -d_semctl='undef' -d_semctl_semid_ds='undef' -d_semctl_semun='undef' -d_semget='undef' -d_semop='undef' -d_sendmsg='undef' -d_setegid='undef' -d_setenv='undef' -d_seteuid='undef' -d_setgrent='undef' -d_setgrent_r='undef' -d_setgrps='undef' -d_sethent='undef' -d_sethostent_r='undef' -d_setitimer='undef' -d_setlinebuf='undef' -d_setlocale='undef' -d_setlocale_accepts_any_locale_name='undef' -d_setlocale_r='undef' -d_setnent='undef' -d_setnetent_r='undef' -d_setpent='undef' -d_setpgid='undef' -d_setpgrp2='undef' -d_setpgrp='undef' -d_setprior='undef' -d_setproctitle='undef' -d_setprotoent_r='undef' -d_setpwent='undef' -d_setpwent_r='undef' -d_setregid='undef' -d_setresgid='undef' -d_setresuid='undef' -d_setreuid='undef' -d_setrgid='undef' -d_setruid='undef' -d_setsent='undef' -d_setservent_r='undef' -d_setsid='undef' -d_setvbuf='undef' -d_shm='undef' -d_shmat='undef' -d_shmatprototype='undef' -d_shmctl='undef' -d_shmdt='undef' -d_shmget='undef' -d_sigaction='undef' -d_siginfo_si_addr='undef' -d_siginfo_si_band='undef' -d_siginfo_si_errno='undef' -d_siginfo_si_pid='undef' -d_siginfo_si_status='undef' -d_siginfo_si_uid='undef' -d_siginfo_si_value='undef' -d_signbit='undef' -d_sigprocmask='undef' -d_sigsetjmp='undef' -d_sin6_scope_id='undef' -d_sitearch='undef' -d_snprintf='undef' -d_sockaddr_in6='undef' -d_sockaddr_sa_len='undef' -d_sockaddr_storage='undef' -d_sockatmark='undef' -d_sockatmarkproto='undef' -d_socket='undef' -d_socklen_t='undef' -d_sockpair='undef' -d_socks5_init='undef' -d_sqrtl='undef' -d_srand48_r='undef' -d_srandom_r='undef' -d_sresgproto='undef' -d_sresuproto='undef' -d_stat='define' -d_statblks='undef' -d_statfs_f_flags='undef' -d_statfs_s='undef' -d_static_inline='undef' -d_statvfs='undef' -d_stdio_cnt_lval='undef' -d_stdio_ptr_lval='undef' -d_stdio_ptr_lval_nochange_cnt='undef' -d_stdio_ptr_lval_sets_cnt='undef' -d_stdio_stream_array='undef' -d_stdiobase='undef' -d_stdstdio='undef' -d_strcoll='undef' -d_strerror_l='undef' -d_strerror_r='undef' -d_strftime='undef' -d_strlcat='undef' -d_strlcpy='undef' -d_strnlen='undef' -d_strtod='undef' -d_strtod_l='undef' -d_strtol='define' -d_strtold='undef' -d_strtold_l='undef' -d_strtoll='undef' -d_strtoq='undef' -d_strtoul='define' -d_strtoull='undef' -d_strtouq='undef' -d_strxfrm='undef' -d_strxfrm_l='undef' -d_suidsafe='undef' -d_symlink='undef' -d_syscall='undef' -d_syscallproto='undef' -d_sysconf='undef' -d_sysernlst='' -d_syserrlst='undef' -d_system='undef' -d_tcgetpgrp='undef' -d_tcsetpgrp='undef' -d_telldir='undef' -d_telldirproto='undef' -d_tgamma='undef' -d_thread_local='undef' -d_thread_safe_nl_langinfo_l='undef' -d_time='define' -d_timegm='undef' -d_times='undef' -d_tm_tm_gmtoff='undef' -d_tm_tm_zone='undef' -d_tmpnam_r='undef' -d_towlower='undef' -d_towupper='undef' -d_trunc='undef' -d_truncate='undef' -d_truncl='undef' -d_ttyname_r='undef' -d_tzname='undef' -d_u32align='define' -d_ualarm='undef' -d_umask='undef' -d_uname='undef' -d_union_semun='undef' -d_unlinkat='undef' -d_unordered='undef' -d_unsetenv='undef' -d_uselocale='undef' -d_usleep='undef' -d_usleepproto='undef' -d_ustat='undef' -d_vendorarch='undef' -d_vendorbin='undef' -d_vendorlib='undef' -d_vfork='undef' -d_void_closedir='undef' -d_voidsig='undef' -d_voidtty='' -d_vsnprintf='undef' -d_wait4='undef' -d_waitpid='undef' -d_wcrtomb='undef' -d_wcscmp='undef' -d_wcstombs='undef' -d_wcsxfrm='undef' -d_wctomb='undef' -d_writev='undef' -d_xenix='undef' -db_hashtype='u_int32_t' -db_prefixtype='size_t' -db_version_major='0' -db_version_minor='0' -db_version_patch='0' -default_inc_excludes_dot='undef' -direntrytype='struct dirent' -doubleinfbytes='0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f' -doublekind='3' -doublemantbits='52' -doublenanbytes='0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x7f' -doublesize='8' -drand01="Perl_drand48()" -drand48_r_proto='0' -dtrace='' -eagain='EAGAIN' -ebcdic='undef' -endgrent_r_proto='0' -endhostent_r_proto='0' -endnetent_r_proto='0' -endprotoent_r_proto='0' -endpwent_r_proto='0' -endservent_r_proto='0' -fflushNULL='undef' -fflushall='undef' -firstmakefile='makefile' -fpossize='4' -fpostype=int -freetype=void -full_csh='' -full_sed='' -getgrent_r_proto='0' -getgrgid_r_proto='0' -getgrnam_r_proto='0' -gethostbyaddr_r_proto='0' -gethostbyname_r_proto='0' -gethostent_r_proto='0' -getlogin_r_proto='0' -getnetbyaddr_r_proto='0' -getnetbyname_r_proto='0' -getnetent_r_proto='0' -getprotobyname_r_proto='0' -getprotobynumber_r_proto='0' -getprotoent_r_proto='0' -getpwent_r_proto='0' -getpwnam_r_proto='0' -getpwuid_r_proto='0' -getservbyname_r_proto='0' -getservbyport_r_proto='0' -getservent_r_proto='0' -getspnam_r_proto='0' -gidformat='"lu"' -gidsign='1' -gidsize='4' -gidtype=int -gmtime_r_proto='0' -groupstype=int -h_fcntl='false' -h_sysfile='true' -i16size='2' -i16type='short' -i32dformat='"ld"' -i32size='4' -i32type='long' -i64size='8' -i64type='int64_t' -i8size='1' -i8type='signed char' -i_arpainet='undef' -i_bfd='undef' -i_bsdioctl='' -i_crypt='undef' -i_db='undef' -i_dbm='undef' -i_dirent='define' -i_dlfcn='undef' -i_execinfo='undef' -i_fcntl='undef' -i_fenv='undef' -i_fp='undef' -i_fp_class='undef' -i_gdbm='undef' -i_gdbm_ndbm='undef' -i_gdbmndbm='undef' -i_grp='undef' -i_ieeefp='undef' -i_inttypes='undef' -i_langinfo='undef' -i_libutil='undef' -i_locale='undef' -i_machcthr='undef' -i_malloc='undef' -i_mallocmalloc='undef' -i_mntent='undef' -i_ndbm='undef' -i_netdb='undef' -i_neterrno='undef' -i_netinettcp='undef' -i_niin='undef' -i_poll='undef' -i_prot='undef' -i_pthread='undef' -i_pwd='undef' -i_quadmath='undef' -i_rpcsvcdbm='undef' -i_sgtty='undef' -i_shadow='undef' -i_socks='undef' -i_stdbool='undef' -i_stdint='undef' -i_stdlib='define' -i_sunmath='undef' -i_sysaccess='undef' -i_sysdir='undef' -i_sysfile='undef' -i_sysfilio='undef' -i_sysin='undef' -i_sysioctl='undef' -i_syslog='undef' -i_sysmman='undef' -i_sysmode='undef' -i_sysmount='undef' -i_sysndir='undef' -i_sysparam='undef' -i_syspoll='undef' -i_sysresrc='undef' -i_syssecrt='undef' -i_sysselct='undef' -i_syssockio='undef' -i_sysstat='define' -i_sysstatfs='undef' -i_sysstatvfs='undef' -i_syssyscall='undef' -i_systime='undef' -i_systimek='undef' -i_systimes='undef' -i_systypes='undef' -i_sysuio='undef' -i_sysun='undef' -i_sysutsname='undef' -i_sysvfs='undef' -i_syswait='undef' -i_termio='undef' -i_termios='undef' -i_time='define' -i_unistd='undef' -i_ustat='undef' -i_utime='undef' -i_vfork='undef' -i_wchar='undef' -i_wctype='undef' -i_xlocale='undef' -ignore_versioned_solibs='y' -inc_version_list_init='NULL' -installstyle='lib/perl5' -installusrbinperl='undef' -intsize='4' -ivdformat='"ld"' -ivsize='4' -ivtype='long' -ld_can_script='define' -lib_ext='.a' -localtime_r_proto='0' -longdblinfbytes='0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00' -longdblkind=0 -longdblmantbits='64' -longdblnanbytes='0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00' -longdblsize=8 -longlongsize=8 -longsize='4' -lseeksize=4 -lseektype=int -malloctype='int*' -malloctype='void *' -mmaptype='void *' -modetype='mode_t' -modetype=int -multiarch='undef' -myarchname='unknown' -myuname='unknown' -need_va_copy='define' -netdb_hlen_type='int' -netdb_host_type='const char *' -netdb_name_type='const char *' -netdb_net_type='unsigned long' -nroff='nroff' -nv_overflows_integers_at='256.0*256.0*256.0*256.0*256.0*256.0*2.0*2.0*2.0*2.0*2.0' -nv_preserves_uv_bits='0' -nveformat='"e"' -nvfformat='"f"' -nvgformat='"g"' -nvmantbits='52' -nvsize='8' -nvtype='double' -o_nonblock='O_NONBLOCK' -obj_ext='.o' -old_pthread_create_joinable='' -optimize='' -orderlib='false' -osname='unknown' -osvers='unknown' -otherlibdirs=' ' -package='perl5' -perl_static_inline='static' -perl_thread_local='' -phostname='hostname' -pidtype=int -privlib='/usr/local/lib/perl5/5.38' -privlibexp='/usr/local/lib/perl5/5.38' -procselfexe='' -prototype='undef' -ptrsize='4' -quadkind='4' -quadtype='int64_t' -randbits='48' -randfunc='Perl_drand48' -random_r_proto='0' -randseedtype='U32' -rd_nodata='-1' -readdir64_r_proto='0' -readdir_r_proto='0' -sGMTIME_max='2147483647' -sGMTIME_min='0' -sLOCALTIME_max='2147483647' -sLOCALTIME_min='0' -sPRIEUldbl='"llE"' -sPRIFUldbl='"llF"' -sPRIGUldbl='"llG"' -sPRIXU64='"LX"' -sPRId64='"Ld"' -sPRIeldbl='"lle"' -sPRIfldbl='"llf"' -sPRIgldbl='"llg"' -sPRIi64='"Li"' -sPRIo64='"Lo"' -sPRIu64='"Lu"' -sPRIx64='"Lx"' -sSCNfldbl='"llf"' -sched_yield='sched_yield()' -scriptdir='/usr/local/bin' -scriptdirexp='/usr/local/bin' -seedfunc='Perl_drand48_init' -selectminbits='32' -selecttype=int -setgrent_r_proto='0' -sethostent_r_proto='0' -setlocale_r_proto='0' -setnetent_r_proto='0' -setprotoent_r_proto='0' -setpwent_r_proto='0' -setservent_r_proto='0' -sh='/bin/sh' -shmattype='void *' -shortsize='2' -sig_name_init='0' -sig_num_init='0' -sig_size='1' -signal_t=int -sitearch='/usr/local/lib/perl5/5.38/unknown' -sitearchexp='/usr/local/lib/perl5/5.38/unknown' -sitelib='/usr/local/lib/perl5/5.38' -sitelib_stem='/usr/local/lib/perl5' -sitelibexp='/usr/local/lib/perl5/5.38' -sizesize=4 -sizetype='size_t' -socksizetype='int' -srand48_r_proto='0' -srandom_r_proto='0' -src='.' -ssizetype=int -st_dev_sign='1' -st_dev_size='4' -st_ino_sign='1' -st_ino_size='4' -startperl='#!perl' -stdchar=char -stdio_base='((fp)->_IO_read_base)' -stdio_bufsiz='((fp)->_IO_read_end - (fp)->_IO_read_base)' -stdio_cnt='((fp)->_IO_read_end - (fp)->_IO_read_ptr)' -stdio_filbuf='' -stdio_ptr='((fp)->_IO_read_ptr)' -stdio_stream_array='' -strerror_r_proto='0' -targetarch='' -targetsh='/bin/sh' -timetype=time_t -tmpnam_r_proto='0' -touch='touch' -ttyname_r_proto='0' -u16size='2' -u16type='unsigned short' -u32XUformat='"lX"' -u32oformat='"lo"' -u32size='4' -u32type='unsigned long' -u32uformat='"lu"' -u32xformat='"lx"' -u64size='8' -u64type='uint64_t' -u8size='1' -u8type='unsigned char' -uidformat='"lu"' -uidsign='1' -uidsize='4' -uidtype=int -uquadtype='uint64_t' -use64bitall='undef' -use64bitint='undef' -usecbacktrace='undef' -usecrosscompile='undef' -usedefaultstrict='undef' -usedevel='undef' -usedl='undef' -usedtrace='undef' -usefaststdio='undef' -useithreads='undef' -usekernprocpathname='undef' -uselargefiles='undef' -uselongdouble='undef' -usemallocwrap='undef' -usemorebits='undef' -usemultiplicity='undef' -usemymalloc='n' -usenm='false' -usensgetexecutablepath='undef' -useopcode='true' -useperlio='undef' -useposix='true' -usequadmath='undef' -usereentrant='undef' -userelocatableinc='undef' -useshrplib='false' -usesitecustomize='undef' -usesocks='undef' -usethreads='undef' -usevendorprefix='undef' -usevfork='false' -uvXUformat='"lX"' -uvoformat='"lo"' -uvsize='4' -uvtype='unsigned long' -uvuformat='"lu"' -uvxformat='"lx"' -vendorarch='' -vendorarchexp='' -vendorlib_stem='' -vendorlibexp='' -versiononly='undef' -xlocale_needed='undef' -zip='' Index: gnu/usr.bin/perl/uconfig64.sh =================================================================== RCS file: gnu/usr.bin/perl/uconfig64.sh diff -N gnu/usr.bin/perl/uconfig64.sh --- gnu/usr.bin/perl/uconfig64.sh 14 May 2024 19:38:54 -0000 1.13 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,938 +0,0 @@ -#!/bin/sh -Author='' -_a='.a' -_o='.o' -afs='false' -afsroot='/afs' -alignbytes='8' -aphostname='/bin/hostname' -archlib='/usr/local/lib/perl5/5.38/unknown' -archlibexp='/usr/local/lib/perl5/5.38/unknown' -archname='unknown64' -asctime_r_proto='0' -bin='/usr/local/bin' -binexp='/usr/local/bin' -bootstrap_charset='undef' -byteorder='12345678' -castflags='0' -cf_by='root@localhost' -cf_time='Thu Jan 1 00:00:00 GMT 1970' -charbits='8' -clocktype='clock_t' -cpp_stuff='42' -cpplast='-' -cppminus='-' -cpprun='cc -E' -cppstdin='cc -E' -crypt_r_proto='0' -ctermid_r_proto='0' -ctime_r_proto='0' -d_Gconvert='sprintf((b),"%.*g",(n),(x))' -d_PRIEUldbl='undef' -d_PRIFUldbl='undef' -d_PRIGUldbl='undef' -d_PRIXU64='define' -d_PRId64='define' -d_PRIeldbl='undef' -d_PRIfldbl='undef' -d_PRIgldbl='undef' -d_PRIi64='define' -d_PRIo64='define' -d_PRIu64='define' -d_PRIx64='define' -d_SCNfldbl='define' -d__fwalk='undef' -d_accept4='undef' -d_access='undef' -d_accessx='undef' -d_acosh='undef' -d_aintl='undef' -d_alarm='undef' -d_archlib='undef' -d_asctime64='undef' -d_asctime_r='undef' -d_asinh='undef' -d_atanh='undef' -d_atolf='undef' -d_atoll='undef' -d_attribute_always_inline='undef' -d_attribute_deprecated='undef' -d_attribute_format='undef' -d_attribute_malloc='undef' -d_attribute_nonnull='undef' -d_attribute_noreturn='undef' -d_attribute_pure='undef' -d_attribute_unused='undef' -d_attribute_visibility='undef' -d_attribute_warn_unused_result='undef' -d_backtrace='undef' -d_bsd='undef' -d_bsdgetpgrp='undef' -d_bsdsetpgrp='undef' -d_builtin_add_overflow='undef' -d_builtin_choose_expr='undef' -d_builtin_expect='undef' -d_builtin_mul_overflow='undef' -d_builtin_sub_overflow='undef' -d_c99_variadic_macros='undef' -d_casti32='undef' -d_castneg='undef' -d_cbrt='undef' -d_chown='undef' -d_chroot='undef' -d_chsize='undef' -d_class='undef' -d_clearenv='undef' -d_closedir='define' -d_cmsghdr_s='undef' -d_copysign='undef' -d_copysignl='undef' -d_cplusplus='undef' -d_crypt='undef' -d_crypt_r='undef' -d_csh='undef' -d_ctermid='undef' -d_ctermid_r='undef' -d_ctime64='undef' -d_ctime_r='undef' -d_cuserid='undef' -d_dbl_dig='undef' -d_dbminitproto='undef' -d_difftime64='undef' -d_difftime='undef' -d_dir_dd_fd='undef' -d_dirfd='undef' -d_dirnamlen='undef' -d_dladdr='undef' -d_dlerror='undef' -d_dlopen='undef' -d_dlsymun='undef' -d_dosuid='undef' -d_double_has_inf='define' -d_double_has_nan='define' -d_double_has_negative_zero='define' -d_double_has_subnormals='define' -d_double_style_cray='undef' -d_double_style_ibm='undef' -d_double_style_ieee='define' -d_double_style_vax='undef' -d_drand48_r='undef' -d_drand48proto='undef' -d_dup2='undef' -d_dup3='undef' -d_duplocale='undef' -d_eaccess='undef' -d_endgrent='undef' -d_endgrent_r='undef' -d_endhent='undef' -d_endhostent_r='undef' -d_endnent='undef' -d_endnetent_r='undef' -d_endpent='undef' -d_endprotoent_r='undef' -d_endpwent='undef' -d_endpwent_r='undef' -d_endsent='undef' -d_endservent_r='undef' -d_eofnblk='undef' -d_erf='undef' -d_erfc='undef' -d_eunice='undef' -d_exp2='undef' -d_expm1='undef' -d_faststdio='undef' -d_fchdir='undef' -d_fchmod='undef' -d_fchmodat='undef' -d_fchown='undef' -d_fcntl='undef' -d_fcntl_can_lock='undef' -d_fd_macros='undef' -d_fd_set='undef' -d_fdclose='undef' -d_fdim='undef' -d_fds_bits='undef' -d_fegetround='undef' -d_ffs='undef' -d_ffsl='undef' -d_fgetpos='undef' -d_finite='undef' -d_finitel='undef' -d_flexfnam='undef' -d_flock='undef' -d_flockproto='undef' -d_fma='undef' -d_fmax='undef' -d_fmin='undef' -d_fork='define' -d_fp_class='undef' -d_fp_classify='undef' -d_fp_classl='undef' -d_fpathconf='undef' -d_fpclass='undef' -d_fpclassify='undef' -d_fpclassl='undef' -d_fpgetround='undef' -d_fpos64_t='undef' -d_freelocale='undef' -d_frexpl='undef' -d_fs_data_s='undef' -d_fseeko='undef' -d_fsetpos='undef' -d_fstatfs='undef' -d_fstatvfs='undef' -d_fsync='undef' -d_ftello='undef' -d_ftime='undef' -d_futimes='undef' -d_gai_strerror='undef' -d_gdbm_ndbm_h_uses_prototypes='undef' -d_gdbmndbm_h_uses_prototypes='undef' -d_getaddrinfo='undef' -d_getcwd='undef' -d_getenv_preserves_other_thread='define' -d_getespwnam='undef' -d_getfsstat='undef' -d_getgrent='undef' -d_getgrent_r='undef' -d_getgrgid_r='undef' -d_getgrnam_r='undef' -d_getgrps='undef' -d_gethbyaddr='undef' -d_gethbyname='undef' -d_gethent='undef' -d_gethname='undef' -d_gethostbyaddr_r='undef' -d_gethostbyname_r='undef' -d_gethostent_r='undef' -d_gethostprotos='undef' -d_getitimer='undef' -d_getlogin='undef' -d_getlogin_r='undef' -d_getmnt='undef' -d_getmntent='undef' -d_getnameinfo='undef' -d_getnbyaddr='undef' -d_getnbyname='undef' -d_getnent='undef' -d_getnetbyaddr_r='undef' -d_getnetbyname_r='undef' -d_getnetent_r='undef' -d_getnetprotos='undef' -d_getpagsz='undef' -d_getpbyname='undef' -d_getpbynumber='undef' -d_getpent='undef' -d_getpgid='undef' -d_getpgrp2='undef' -d_getpgrp='undef' -d_getppid='undef' -d_getprior='undef' -d_getprotobyname_r='undef' -d_getprotobynumber_r='undef' -d_getprotoent_r='undef' -d_getprotoprotos='undef' -d_getprpwnam='undef' -d_getpwent='undef' -d_getpwent_r='undef' -d_getpwnam_r='undef' -d_getpwuid_r='undef' -d_getsbyname='undef' -d_getsbyport='undef' -d_getsent='undef' -d_getservbyname_r='undef' -d_getservbyport_r='undef' -d_getservent_r='undef' -d_getservprotos='undef' -d_getspent='undef' -d_getspnam='undef' -d_getspnam_r='undef' -d_gettimeod='undef' -d_gmtime64='undef' -d_gmtime_r='undef' -d_gnulibc='undef' -d_grpasswd='undef' -d_hasmntopt='undef' -d_htonl='undef' -d_hypot='undef' -d_ilogb='undef' -d_ilogbl='undef' -d_inc_version_list='undef' -d_index='undef' -d_inetaton='undef' -d_inetntop='undef' -d_inetpton='undef' -d_int64_t='undef' -d_ip_mreq='undef' -d_ip_mreq_source='undef' -d_ipv6_mreq='undef' -d_ipv6_mreq_source='undef' -d_isascii='undef' -d_isblank='undef' -d_isfinite='undef' -d_isfinitel='undef' -d_isinf='undef' -d_isinfl='undef' -d_isless='undef' -d_isnan='undef' -d_isnanl='undef' -d_isnormal='undef' -d_j0='undef' -d_j0l='undef' -d_killpg='undef' -d_lc_monetary_2008='undef' -d_lchown='undef' -d_ldbl_dig='undef' -d_ldexpl='undef' -d_lgamma='undef' -d_lgamma_r='undef' -d_libm_lib_version='undef' -d_link='undef' -d_linkat='undef' -d_llrint='undef' -d_llrintl='undef' -d_llround='undef' -d_llroundl='undef' -d_localeconv_l='undef' -d_localtime64='undef' -d_localtime_r='undef' -d_localtime_r_needs_tzset='undef' -d_locconv='undef' -d_lockf='undef' -d_log1p='undef' -d_log2='undef' -d_logb='undef' -d_long_double_style_ieee='undef' -d_long_double_style_ieee_doubledouble='undef' -d_long_double_style_ieee_extended='undef' -d_long_double_style_ieee_std='undef' -d_long_double_style_vax='undef' -d_longdbl='undef' -d_longlong='undef' -d_lrint='undef' -d_lrintl='undef' -d_lround='undef' -d_lroundl='undef' -d_lseekproto='undef' -d_lstat='undef' -d_madvise='undef' -d_malloc_good_size='undef' -d_malloc_size='undef' -d_mblen='undef' -d_mbrlen='undef' -d_mbrtowc='undef' -d_mbstowcs='undef' -d_mbtowc='undef' -d_memmem='undef' -d_memrchr='undef' -d_mkdir='undef' -d_mkdtemp='undef' -d_mkfifo='undef' -d_mkostemp='undef' -d_mkstemp='undef' -d_mkstemps='undef' -d_mktime64='undef' -d_mktime='undef' -d_mmap='undef' -d_modfl='undef' -d_modfl_pow32_bug='undef' -d_modflproto='undef' -d_mprotect='undef' -d_msg='undef' -d_msg_ctrunc='undef' -d_msg_dontroute='undef' -d_msg_oob='undef' -d_msg_peek='undef' -d_msg_proxy='undef' -d_msgctl='undef' -d_msgget='undef' -d_msghdr_s='undef' -d_msgrcv='undef' -d_msgsnd='undef' -d_msync='undef' -d_munmap='undef' -d_mymalloc='undef' -d_nan='undef' -d_nanosleep='undef' -d_ndbm_h_uses_prototypes='undef' -d_nearbyint='undef' -d_newlocale='undef' -d_nextafter='undef' -d_nexttoward='undef' -d_nice='undef' -d_nl_langinfo='undef' -d_nl_langinfo_l='undef' -d_non_int_bitfields='define' -d_nv_preserves_uv='undef' -d_nv_zero_is_allbits_zero='undef' -d_off64_t='undef' -d_old_pthread_create_joinable='undef' -d_oldpthreads='undef' -d_oldsock='undef' -d_open3='undef' -d_openat='undef' -d_pathconf='undef' -d_pause='undef' -d_perl_otherlibdirs='undef' -d_phostname='undef' -d_pipe2='undef' -d_pipe='undef' -d_poll='undef' -d_portable='undef' -d_prctl='undef' -d_prctl_set_name='undef' -d_printf_format_null='undef' -d_procselfexe='undef' -d_pseudofork='undef' -d_pthread_atfork='undef' -d_pthread_attr_setscope='undef' -d_pthread_yield='undef' -d_ptrdiff_t='define' -d_pwage='undef' -d_pwchange='undef' -d_pwclass='undef' -d_pwcomment='undef' -d_pwexpire='undef' -d_pwgecos='undef' -d_pwpasswd='undef' -d_pwquota='undef' -d_qgcvt='undef' -d_quad='define' -d_querylocale='undef' -d_random_r='undef' -d_readdir64_r='undef' -d_readdir='define' -d_readdir_r='undef' -d_readlink='undef' -d_readv='undef' -d_recvmsg='undef' -d_regcomp='undef' -d_remainder='undef' -d_remquo='undef' -d_rename='define' -d_renameat='undef' -d_rewinddir='undef' -d_rint='undef' -d_rmdir='undef' -d_round='undef' -d_sbrkproto='undef' -d_scalbn='undef' -d_scalbnl='undef' -d_sched_yield='undef' -d_scm_rights='undef' -d_seekdir='undef' -d_select='undef' -d_sem='undef' -d_semctl='undef' -d_semctl_semid_ds='undef' -d_semctl_semun='undef' -d_semget='undef' -d_semop='undef' -d_sendmsg='undef' -d_setegid='undef' -d_setenv='undef' -d_seteuid='undef' -d_setgrent='undef' -d_setgrent_r='undef' -d_setgrps='undef' -d_sethent='undef' -d_sethostent_r='undef' -d_setitimer='undef' -d_setlinebuf='undef' -d_setlocale='undef' -d_setlocale_accepts_any_locale_name='undef' -d_setlocale_r='undef' -d_setnent='undef' -d_setnetent_r='undef' -d_setpent='undef' -d_setpgid='undef' -d_setpgrp2='undef' -d_setpgrp='undef' -d_setprior='undef' -d_setproctitle='undef' -d_setprotoent_r='undef' -d_setpwent='undef' -d_setpwent_r='undef' -d_setregid='undef' -d_setresgid='undef' -d_setresuid='undef' -d_setreuid='undef' -d_setrgid='undef' -d_setruid='undef' -d_setsent='undef' -d_setservent_r='undef' -d_setsid='undef' -d_setvbuf='undef' -d_shm='undef' -d_shmat='undef' -d_shmatprototype='undef' -d_shmctl='undef' -d_shmdt='undef' -d_shmget='undef' -d_sigaction='undef' -d_siginfo_si_addr='undef' -d_siginfo_si_band='undef' -d_siginfo_si_errno='undef' -d_siginfo_si_pid='undef' -d_siginfo_si_status='undef' -d_siginfo_si_uid='undef' -d_siginfo_si_value='undef' -d_signbit='undef' -d_sigprocmask='undef' -d_sigsetjmp='undef' -d_sin6_scope_id='undef' -d_sitearch='undef' -d_snprintf='undef' -d_sockaddr_in6='undef' -d_sockaddr_sa_len='undef' -d_sockaddr_storage='undef' -d_sockatmark='undef' -d_sockatmarkproto='undef' -d_socket='undef' -d_socklen_t='undef' -d_sockpair='undef' -d_socks5_init='undef' -d_sqrtl='undef' -d_srand48_r='undef' -d_srandom_r='undef' -d_sresgproto='undef' -d_sresuproto='undef' -d_stat='define' -d_statblks='undef' -d_statfs_f_flags='undef' -d_statfs_s='undef' -d_static_inline='undef' -d_statvfs='undef' -d_stdio_cnt_lval='undef' -d_stdio_ptr_lval='undef' -d_stdio_ptr_lval_nochange_cnt='undef' -d_stdio_ptr_lval_sets_cnt='undef' -d_stdio_stream_array='undef' -d_stdiobase='undef' -d_stdstdio='undef' -d_strcoll='undef' -d_strerror_l='undef' -d_strerror_r='undef' -d_strftime='undef' -d_strlcat='undef' -d_strlcpy='undef' -d_strnlen='undef' -d_strtod='undef' -d_strtod_l='undef' -d_strtol='define' -d_strtold='undef' -d_strtold_l='undef' -d_strtoll='undef' -d_strtoq='undef' -d_strtoul='define' -d_strtoull='undef' -d_strtouq='undef' -d_strxfrm='undef' -d_strxfrm_l='undef' -d_suidsafe='undef' -d_symlink='undef' -d_syscall='undef' -d_syscallproto='undef' -d_sysconf='undef' -d_sysernlst='' -d_syserrlst='undef' -d_system='undef' -d_tcgetpgrp='undef' -d_tcsetpgrp='undef' -d_telldir='undef' -d_telldirproto='undef' -d_tgamma='undef' -d_thread_local='undef' -d_thread_safe_nl_langinfo_l='undef' -d_time='define' -d_timegm='undef' -d_times='undef' -d_tm_tm_gmtoff='undef' -d_tm_tm_zone='undef' -d_tmpnam_r='undef' -d_towlower='undef' -d_towupper='undef' -d_trunc='undef' -d_truncate='undef' -d_truncl='undef' -d_ttyname_r='undef' -d_tzname='undef' -d_u32align='define' -d_ualarm='undef' -d_umask='undef' -d_uname='undef' -d_union_semun='undef' -d_unlinkat='undef' -d_unordered='undef' -d_unsetenv='undef' -d_uselocale='undef' -d_usleep='undef' -d_usleepproto='undef' -d_ustat='undef' -d_vendorarch='undef' -d_vendorbin='undef' -d_vendorlib='undef' -d_vfork='undef' -d_void_closedir='undef' -d_voidsig='undef' -d_voidtty='' -d_vsnprintf='undef' -d_wait4='undef' -d_waitpid='undef' -d_wcrtomb='undef' -d_wcscmp='undef' -d_wcstombs='undef' -d_wcsxfrm='undef' -d_wctomb='undef' -d_writev='undef' -d_xenix='undef' -db_hashtype='u_int32_t' -db_prefixtype='size_t' -db_version_major='0' -db_version_minor='0' -db_version_patch='0' -default_inc_excludes_dot='undef' -direntrytype='struct dirent' -doubleinfbytes='0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f' -doublekind='3' -doublemantbits='52' -doublenanbytes='0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x7f' -doublesize='8' -drand01="((rand() & 0x7FFF) / (double) ((unsigned long)1 << 15))" -drand48_r_proto='0' -dtrace='' -eagain='EAGAIN' -ebcdic='undef' -endgrent_r_proto='0' -endhostent_r_proto='0' -endnetent_r_proto='0' -endprotoent_r_proto='0' -endpwent_r_proto='0' -endservent_r_proto='0' -fflushNULL='undef' -fflushall='undef' -firstmakefile='makefile' -fpossize='4' -fpostype=int -freetype=void -full_csh='' -full_sed='' -getgrent_r_proto='0' -getgrgid_r_proto='0' -getgrnam_r_proto='0' -gethostbyaddr_r_proto='0' -gethostbyname_r_proto='0' -gethostent_r_proto='0' -getlogin_r_proto='0' -getnetbyaddr_r_proto='0' -getnetbyname_r_proto='0' -getnetent_r_proto='0' -getprotobyname_r_proto='0' -getprotobynumber_r_proto='0' -getprotoent_r_proto='0' -getpwent_r_proto='0' -getpwnam_r_proto='0' -getpwuid_r_proto='0' -getservbyname_r_proto='0' -getservbyport_r_proto='0' -getservent_r_proto='0' -getspnam_r_proto='0' -gidformat='"u"' -gidsign='1' -gidsize='4' -gidtype=int -gmtime_r_proto='0' -groupstype=int -h_fcntl='false' -h_sysfile='true' -i16size='2' -i16type='short' -i32dformat='"d"' -i32size='4' -i32type='int' -i64size='8' -i64type='long' -i8size='1' -i8type='signed char' -i_arpainet='undef' -i_bfd='undef' -i_bsdioctl='' -i_crypt='undef' -i_db='undef' -i_dbm='undef' -i_dirent='define' -i_dlfcn='undef' -i_execinfo='undef' -i_fcntl='undef' -i_fenv='undef' -i_fp='undef' -i_fp_class='undef' -i_gdbm='undef' -i_gdbm_ndbm='undef' -i_gdbmndbm='undef' -i_grp='undef' -i_ieeefp='undef' -i_inttypes='undef' -i_langinfo='undef' -i_libutil='undef' -i_locale='undef' -i_machcthr='undef' -i_malloc='undef' -i_mallocmalloc='undef' -i_mntent='undef' -i_ndbm='undef' -i_netdb='undef' -i_neterrno='undef' -i_netinettcp='undef' -i_niin='undef' -i_poll='undef' -i_prot='undef' -i_pthread='undef' -i_pwd='undef' -i_quadmath='undef' -i_rpcsvcdbm='undef' -i_sgtty='undef' -i_shadow='undef' -i_socks='undef' -i_stdbool='undef' -i_stdint='undef' -i_stdlib='define' -i_sunmath='undef' -i_sysaccess='undef' -i_sysdir='undef' -i_sysfile='undef' -i_sysfilio='undef' -i_sysin='undef' -i_sysioctl='undef' -i_syslog='undef' -i_sysmman='undef' -i_sysmode='undef' -i_sysmount='undef' -i_sysndir='undef' -i_sysparam='undef' -i_syspoll='undef' -i_sysresrc='undef' -i_syssecrt='undef' -i_sysselct='undef' -i_syssockio='undef' -i_sysstat='define' -i_sysstatfs='undef' -i_sysstatvfs='undef' -i_syssyscall='undef' -i_systime='undef' -i_systimek='undef' -i_systimes='undef' -i_systypes='undef' -i_sysuio='undef' -i_sysun='undef' -i_sysutsname='undef' -i_sysvfs='undef' -i_syswait='undef' -i_termio='undef' -i_termios='undef' -i_time='define' -i_unistd='undef' -i_ustat='undef' -i_utime='undef' -i_vfork='undef' -i_wchar='undef' -i_wctype='undef' -i_xlocale='undef' -ignore_versioned_solibs='y' -inc_version_list_init='NULL' -installstyle='lib/perl5' -installusrbinperl='undef' -intsize='4' -ivdformat='"ld"' -ivsize='8' -ivtype='long' -lib_ext='.a' -localtime_r_proto='0' -longdblinfbytes='0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00' -longdblkind=0 -longdblmantbits='64' -longdblnanbytes='0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00' -longdblsize=8 -longlongsize=8 -longsize='8' -lseeksize=8 -lseektype=long -mad='undef' -malloctype='int*' -malloctype='void *' -mmaptype='void *' -modetype='mode_t' -modetype=int -multiarch='undef' -myarchname='unknown64' -myuname='unknown' -need_va_copy='define' -netdb_hlen_type='int' -netdb_host_type='const char *' -netdb_name_type='const char *' -netdb_net_type='unsigned long' -nroff='nroff' -nv_overflows_integers_at='256.0*256.0*256.0*256.0*256.0*256.0*2.0*2.0*2.0*2.0*2.0' -nv_preserves_uv_bits='0' -nveformat='"e"' -nvfformat='"f"' -nvgformat='"g"' -nvmantbits='52' -nvsize='8' -nvtype='double' -o_nonblock='O_NONBLOCK' -obj_ext='.o' -old_pthread_create_joinable='' -optimize='' -orderlib='false' -osname='unknown' -osvers='unknown' -otherlibdirs=' ' -package='perl5' -perl_static_inline='static' -perl_thread_local='' -phostname='hostname' -pidtype=int -privlib='/usr/local/lib/perl5/5.38' -privlibexp='/usr/local/lib/perl5/5.38' -procselfexe='' -prototype='undef' -ptrsize='8' -quadkind='2' -quadtype='long' -randbits='48' -randfunc='drand48' -random_r_proto='0' -randseedtype='int' -rd_nodata='-1' -readdir64_r_proto='0' -readdir_r_proto='0' -sGMTIME_max='2147483647' -sGMTIME_min='0' -sLOCALTIME_max='2147483647' -sLOCALTIME_min='0' -sPRIEUldbl='"llE"' -sPRIFUldbl='"llF"' -sPRIGUldbl='"llG"' -sPRIXU64='"lX"' -sPRId64='"ld"' -sPRIeldbl='"lle"' -sPRIfldbl='"llf"' -sPRIgldbl='"llg"' -sPRIi64='"li"' -sPRIo64='"lo"' -sPRIu64='"lu"' -sPRIx64='"lx"' -sSCNfldbl='"llf"' -sched_yield='sched_yield()' -scriptdir='/usr/local/bin' -scriptdirexp='/usr/local/bin' -seedfunc='srand' -selectminbits='64' -selecttype=int -setgrent_r_proto='0' -sethostent_r_proto='0' -setlocale_r_proto='0' -setnetent_r_proto='0' -setprotoent_r_proto='0' -setpwent_r_proto='0' -setservent_r_proto='0' -sh='/bin/sh' -shmattype='void *' -shortsize='2' -sig_name_init='0' -sig_num_init='0' -sig_size='1' -signal_t=int -sitearch='/usr/local/lib/perl5/5.38/unknown' -sitearchexp='/usr/local/lib/perl5/5.38/unknown' -sitelib='/usr/local/lib/perl5/5.38' -sitelib_stem='/usr/local/lib/perl5' -sitelibexp='/usr/local/lib/perl5/5.38' -sizesize=4 -sizetype='size_t' -socksizetype='int' -srand48_r_proto='0' -srandom_r_proto='0' -src='.' -ssizetype=long -st_dev_sign='1' -st_dev_size='4' -st_ino_sign='1' -st_ino_size='8' -startperl='#!perl' -stdchar=char -stdio_base='((fp)->_IO_read_base)' -stdio_bufsiz='((fp)->_IO_read_end - (fp)->_IO_read_base)' -stdio_cnt='((fp)->_IO_read_end - (fp)->_IO_read_ptr)' -stdio_filbuf='' -stdio_ptr='((fp)->_IO_read_ptr)' -stdio_stream_array='' -strerror_r_proto='0' -targetarch='' -targetsh='/bin/sh' -timetype=time_t -tmpnam_r_proto='0' -touch='touch' -ttyname_r_proto='0' -u16size='2' -u16type='unsigned short' -u32XUformat='"X"' -u32oformat='"o"' -u32size='4' -u32type='unsigned int' -u32uformat='"u"' -u32xformat='"x"' -u64size='8' -u64type='unsigned long' -u8size='1' -u8type='unsigned char' -uidformat='"u"' -uidsign='1' -uidsize='4' -uidtype=int -uquadtype='unsigned long' -use64bitall='define' -use64bitint='define' -usecbacktrace='undef' -usecrosscompile='undef' -usedefaultstrict='undef' -usedevel='undef' -usedl='undef' -usedtrace='undef' -usefaststdio='undef' -useithreads='undef' -usekernprocpathname='undef' -uselargefiles='undef' -uselongdouble='undef' -usemallocwrap='undef' -usemorebits='undef' -usemultiplicity='undef' -usemymalloc='n' -usenm='false' -usensgetexecutablepath='undef' -useopcode='true' -useperlio='undef' -useposix='true' -usequadmath='undef' -usereentrant='undef' -userelocatableinc='undef' -useshrplib='false' -usesitecustomize='undef' -usesocks='undef' -usethreads='undef' -usevendorprefix='undef' -usevfork='false' -uvXUformat='"lX"' -uvoformat='"lo"' -uvsize='8' -uvtype='unsigned long' -uvuformat='"lu"' -uvxformat='"lx"' -vendorarch='' -vendorarchexp='' -vendorlib_stem='' -vendorlibexp='' -versiononly='undef' -xlocale_needed='undef' -zip='' Index: gnu/usr.bin/perl/uni_keywords.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/uni_keywords.h,v diff -u -p -a -u -p -r1.1.1.5 uni_keywords.h --- gnu/usr.bin/perl/uni_keywords.h 14 May 2024 19:36:01 -0000 1.1.1.5 +++ gnu/usr.bin/perl/uni_keywords.h 22 Jan 2025 00:37:45 -0000 @@ -10,7 +10,7 @@ #define MPH_VALt I16 /* -generator script: ./regen/mk_invlists.pl +generator script: regen/mk_invlists.pl split strategy: squeeze srand: 1785235451 rows: 7498 @@ -7756,7 +7756,7 @@ match_uniprop( const unsigned char * con * 3f4f32ed2a577344a508114527e721d7a8b633d32f38945d47fe0c743650c585 lib/unicore/extracted/DLineBreak.txt * 710abf2d581ac9c57f244c0834f9d9969d9781e0396adccd330eaae658ac7d6b lib/unicore/extracted/DNumType.txt * 6bd30f385f3baf3ab5d5308c111a81de87bea5f494ba0ba69e8ab45263b8c34d lib/unicore/extracted/DNumValues.txt - * f7265069b38ba9a0675a18600e241b1ec6fc8c55fd806fe4c13bc5d8cb0dc508 lib/unicore/mktables + * 8968a5ee00063fa31ff15474b95ccb6b9c228e3ebad6c20bc77f4225187e2023 lib/unicore/mktables * 55d90fdc3f902e5c0b16b3378f9eaa36e970a1c09723c33de7d47d0370044012 lib/unicore/version * 0a6b5ab33bb1026531f816efe81aea1a8ffcd34a27cbea37dd6a70a63d73c844 regen/charset_translations.pl * c7ff8e0d207d3538c7feb4a1a152b159e5e902d20293b303569ea8323e84633e regen/mk_PL_charclass.pl Index: gnu/usr.bin/perl/unicode_constants.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/unicode_constants.h,v diff -u -p -a -u -p -r1.7 unicode_constants.h --- gnu/usr.bin/perl/unicode_constants.h 14 May 2024 19:38:54 -0000 1.7 +++ gnu/usr.bin/perl/unicode_constants.h 22 Jan 2025 00:37:45 -0000 @@ -16,10 +16,12 @@ * * The macros that have the suffix "_UTF8" may have further suffixes, as * follows: - * "_FIRST_BYTE" if the value is just the first byte of the UTF-8 - * representation; the value will be a numeric constant. - * "_TAIL" if instead it represents all but the first byte. This, and - * with no additional suffix are both string constants */ + * "_FIRST_BYTE" if the value is just the first byte of the UTF-8 + * representation; the value will be a numeric constant. + * "_FIRST_BYTEs" same, but the first byte is represented as a literal + * string + * "_TAIL" if instead it represents all but the first byte. This, + * and with no additional suffix are both string constants */ /* =for apidoc_section $unicode @@ -88,18 +90,22 @@ bytes. # define LATIN_SMALL_LETTER_Y_WITH_DIAERESIS_NATIVE 0xFF /* U+00FF */ # define MICRO_SIGN_NATIVE 0xB5 /* U+00B5 */ # define MICRO_SIGN_UTF8 "\xC2\xB5" /* U+00B5 */ +# define ARABIC_DECIMAL_SEPARATOR_UTF8 "\xD9\xAB" /* U+066B */ +# define ARABIC_DECIMAL_SEPARATOR_UTF8_FIRST_BYTE 0xD9 /* U+066B */ +# define ARABIC_DECIMAL_SEPARATOR_UTF8_TAIL "\xAB" /* U+066B */ +# define ARABIC_DECIMAL_SEPARATOR_UTF8_FIRST_BYTE_s "\xD9" /* U+066B */ # ifdef PERL_IN_TOKE_C /* Paired characters for quote-like operators, in UTF-8 */ -# define EXTRA_OPENING_UTF8_BRACKETS "\x28\x3C\x5B\x7B\xC2\xAB\xC2\xBB\xDC\x86\xE0\xBC\xBA\xE0\xBC\xBC\xE1\x9A\x9B\xE2\x80\x98\xE2\x80\x99\xE2\x80\x9C\xE2\x80\x9D\xE2\x80\xB5\xE2\x80\xB6\xE2\x80\xB7\xE2\x80\xB9\xE2\x80\xBA\xE2\x81\x85\xE2\x81\x8D\xE2\x81\xBD\xE2\x82\x8D\xE2\x86\x92\xE2\x86\x9B\xE2\x86\x9D\xE2\x86\xA0\xE2\x86\xA3\xE2\x86\xA6\xE2\x86\xAA\xE2\x86\xAC\xE2\x86\xB1\xE2\x86\xB3\xE2\x87\x80\xE2\x87\x81\xE2\x87\x89\xE2\x87\x8F\xE2\x87\x92\xE2\x87\x9B\xE2\x87\x9D\xE2\x87\xA2\xE2\x87\xA5\xE2\x87\xA8\xE2\x87\xB4\xE2\x87\xB6\xE2\x87\xB8\xE2\x87\xBB\xE2\x87\xBE\xE2\x88\x88\xE2\x88\x89\xE2\x88\x8A\xE2\x89\xA4\xE2\x89\xA6\xE2\x89\xA8\xE2\x89\xAA\xE2\x89\xAE\xE2\x89\xB0\xE2\x89\xB2\xE2\x89\xB4\xE2\x89\xBA\xE2\x89\xBC\xE2\x89\xBE\xE2\x8A\x80\xE2\x8A\x82\xE2\x8A\x84\xE2\x8A\x86\xE2\x8A\x88\xE2\x8A\x8A\xE2\x8A\xA3\xE2\x8A\xA6\xE2\x8A\xA8\xE2\x8A\xA9\xE2\x8A\xB0\xE2\x8B\x90\xE2\x8B\x96\xE2\x8B\x98\xE2\x8B\x9C\xE2\x8B\x9E\xE2\x8B\xA0\xE2\x8B\xA6\xE2\x8B\xA8\xE2\x8B\xB2\xE2\x8B\xB3\xE2\x8B\xB4\xE2\x8B\xB6\xE2\x8B\xB7\xE2\x8C\x88\xE2\x8C\x8A\xE2\x8C\xA6\xE2\x8C\xA9\xE2\x8D\x88\xE2\x8F\xA9\xE2\x8F\xAD\xE2\x98\x9B\xE2\x98\x9E\xE2\x9A\x9E\xE2\x9D\xA8\xE2\x9D\xAA\xE2\x9D\xAC\xE2\x9D\xAE\xE2\x9D\xB0\xE2\x9D\xB2\xE2\x9D\xB4\xE2\x9F\x83\xE2\x9F\x85\xE2\x9F\x88\xE2\x9F\x9E\xE2\x9F\xA6\xE2\x9F\xA8\xE2\x9F\xAA\xE2\x9F\xAC\xE2\x9F\xAE\xE2\x9F\xB4\xE2\x9F\xB6\xE2\x9F\xB9\xE2\x9F\xBC\xE2\x9F\xBE\xE2\x9F\xBF\xE2\xA4\x80\xE2\xA4\x81\xE2\xA4\x83\xE2\xA4\x85\xE2\xA4\x87\xE2\xA4\x8D\xE2\xA4\x8F\xE2\xA4\x90\xE2\xA4\x91\xE2\xA4\x94\xE2\xA4\x95\xE2\xA4\x96\xE2\xA4\x97\xE2\xA4\x98\xE2\xA4\x9A\xE2\xA4\x9C\xE2\xA4\x9E\xE2\xA4\xA0\xE2\xA4\xB3\xE2\xA4\xB7\xE2\xA5\x85\xE2\xA5\x87\xE2\xA5\x93\xE2\xA5\x97\xE2\xA5\x9B\xE2\xA5\x9F\xE2\xA5\xA4\xE2\xA5\xAC\xE2\xA5\xAD\xE2\xA5\xB1\xE2\xA5\xB2\xE2\xA5\xB4\xE2\xA5\xB5\xE2\xA5\xB9\xE2\xA6\x83\xE2\xA6\x85\xE2\xA6\x87\xE2\xA6\x89\xE2\xA6\x8B\xE2\xA6\x8D\xE2\xA6\x8F\xE2\xA6\x91\xE2\xA6\x93\xE2\xA6\x95\xE2\xA6\x97\xE2\xA6\xA8\xE2\xA6\xAA\xE2\xA6\xB3\xE2\xA7\x80\xE2\xA7\x98\xE2\xA7\x9A\xE2\xA7\xBC\xE2\xA9\xB9\xE2\xA9\xBB\xE2\xA9\xBD\xE2\xA9\xBF\xE2\xAA\x81\xE2\xAA\x83\xE2\xAA\x85\xE2\xAA\x87\xE2\xAA\x89\xE2\xAA\x8D\xE2\xAA\x95\xE2\xAA\x97\xE2\xAA\x99\xE2\xAA\x9B\xE2\xAA\x9D\xE2\xAA\x9F\xE2\xAA\xA1\xE2\xAA\xA6\xE2\xAA\xA8\xE2\xAA\xAA\xE2\xAA\xAC\xE2\xAA\xAF\xE2\xAA\xB1\xE2\xAA\xB3\xE2\xAA\xB5\xE2\xAA\xB7\xE2\xAA\xB9\xE2\xAA\xBB\xE2\xAA\xBD\xE2\xAA\xBF\xE2\xAB\x81\xE2\xAB\x83\xE2\xAB\x85\xE2\xAB\x87\xE2\xAB\x89\xE2\xAB\x8B\xE2\xAB\x8F\xE2\xAB\x91\xE2\xAB\x95\xE2\xAB\xA5\xE2\xAB\xB7\xE2\xAB\xB9\xE2\xAD\x86\xE2\xAD\x87\xE2\xAD\x88\xE2\xAD\x8C\xE2\xAD\xA2\xE2\xAD\xAC\xE2\xAD\xB2\xE2\xAD\xBC\xE2\xAE\x86\xE2\xAE\x8A\xE2\xAE\x95\xE2\xAE\x9A\xE2\xAE\x9E\xE2\xAE\xA1\xE2\xAE\xA3\xE2\xAE\xA9\xE2\xAE\xAB\xE2\xAE\xB1\xE2\xAE\xB3\xE2\xAF\xAE\xE2\xB8\x82\xE2\xB8\x83\xE2\xB8\x84\xE2\xB8\x85\xE2\xB8\x89\xE2\xB8\x8A\xE2\xB8\x8C\xE2\xB8\x8D\xE2\xB8\x91\xE2\xB8\x9C\xE2\xB8\x9D\xE2\xB8\xA0\xE2\xB8\xA1\xE2\xB8\xA2\xE2\xB8\xA4\xE2\xB8\xA6\xE2\xB8\xA8\xE2\xB8\xB6\xE2\xB9\x82\xE2\xB9\x95\xE2\xB9\x97\xE2\xB9\x99\xE2\xB9\x9B\xE3\x80\x88\xE3\x80\x8A\xE3\x80\x8C\xE3\x80\x8E\xE3\x80\x90\xE3\x80\x94\xE3\x80\x96\xE3\x80\x98\xE3\x80\x9A\xE3\x80\x9D\xEA\xA7\x81\xEF\xB4\xBE\xEF\xB9\x99\xEF\xB9\x9B\xEF\xB9\x9D\xEF\xB9\xA4\xEF\xBC\x88\xEF\xBC\x9C\xEF\xBC\xBB\xEF\xBD\x9B\xEF\xBD\x9F\xEF\xBD\xA2\xEF\xBF\xAB\xF0\x9D\x84\x83\xF0\x9D\x84\x86\xF0\x9F\x91\x89\xF0\x9F\x94\x88\xF0\x9F\x94\x89\xF0\x9F\x94\x8A\xF0\x9F\x95\xBB\xF0\x9F\x96\x99\xF0\x9F\x96\x9B\xF0\x9F\x96\x9D\xF0\x9F\x97\xA6\xF0\x9F\xA0\x82\xF0\x9F\xA0\x86\xF0\x9F\xA0\x8A\xF0\x9F\xA0\x92\xF0\x9F\xA0\x96\xF0\x9F\xA0\x9A\xF0\x9F\xA0\x9E\xF0\x9F\xA0\xA2\xF0\x9F\xA0\xA6\xF0\x9F\xA0\xAA\xF0\x9F\xA0\xAE\xF0\x9F\xA0\xB2\xF0\x9F\xA0\xB6\xF0\x9F\xA0\xBA\xF0\x9F\xA0\xBE\xF0\x9F\xA1\x82\xF0\x9F\xA1\x86\xF0\x9F\xA1\x92\xF0\x9F\xA1\xA2\xF0\x9F\xA1\xAA\xF0\x9F\xA1\xB2\xF0\x9F\xA1\xBA\xF0\x9F\xA2\x82\xF0\x9F\xA2\x92\xF0\x9F\xA2\x96\xF0\x9F\xA2\x9A\xF0\x9F\xA2\xA1\xF0\x9F\xA2\xA3\xF0\x9F\xA2\xA5\xF0\x9F\xA2\xA7\xF0\x9F\xA2\xA9\xF0\x9F\xA2\xAB" -# define EXTRA_CLOSING_UTF8_BRACKETS "\x29\x3E\x5D\x7D\xC2\xBB\xC2\xAB\xDC\x87\xE0\xBC\xBB\xE0\xBC\xBD\xE1\x9A\x9C\xE2\x80\x99\xE2\x80\x98\xE2\x80\x9D\xE2\x80\x9C\xE2\x80\xB2\xE2\x80\xB3\xE2\x80\xB4\xE2\x80\xBA\xE2\x80\xB9\xE2\x81\x86\xE2\x81\x8C\xE2\x81\xBE\xE2\x82\x8E\xE2\x86\x90\xE2\x86\x9A\xE2\x86\x9C\xE2\x86\x9E\xE2\x86\xA2\xE2\x86\xA4\xE2\x86\xA9\xE2\x86\xAB\xE2\x86\xB0\xE2\x86\xB2\xE2\x86\xBC\xE2\x86\xBD\xE2\x87\x87\xE2\x87\x8D\xE2\x87\x90\xE2\x87\x9A\xE2\x87\x9C\xE2\x87\xA0\xE2\x87\xA4\xE2\x87\xA6\xE2\xAC\xB0\xE2\xAC\xB1\xE2\x87\xB7\xE2\x87\xBA\xE2\x87\xBD\xE2\x88\x8B\xE2\x88\x8C\xE2\x88\x8D\xE2\x89\xA5\xE2\x89\xA7\xE2\x89\xA9\xE2\x89\xAB\xE2\x89\xAF\xE2\x89\xB1\xE2\x89\xB3\xE2\x89\xB5\xE2\x89\xBB\xE2\x89\xBD\xE2\x89\xBF\xE2\x8A\x81\xE2\x8A\x83\xE2\x8A\x85\xE2\x8A\x87\xE2\x8A\x89\xE2\x8A\x8B\xE2\x8A\xA2\xE2\xAB\x9E\xE2\xAB\xA4\xE2\xAB\xA3\xE2\x8A\xB1\xE2\x8B\x91\xE2\x8B\x97\xE2\x8B\x99\xE2\x8B\x9D\xE2\x8B\x9F\xE2\x8B\xA1\xE2\x8B\xA7\xE2\x8B\xA9\xE2\x8B\xBA\xE2\x8B\xBB\xE2\x8B\xBC\xE2\x8B\xBD\xE2\x8B\xBE\xE2\x8C\x89\xE2\x8C\x8B\xE2\x8C\xAB\xE2\x8C\xAA\xE2\x8D\x87\xE2\x8F\xAA\xE2\x8F\xAE\xE2\x98\x9A\xE2\x98\x9C\xE2\x9A\x9F\xE2\x9D\xA9\xE2\x9D\xAB\xE2\x9D\xAD\xE2\x9D\xAF\xE2\x9D\xB1\xE2\x9D\xB3\xE2\x9D\xB5\xE2\x9F\x84\xE2\x9F\x86\xE2\x9F\x89\xE2\x9F\x9D\xE2\x9F\xA7\xE2\x9F\xA9\xE2\x9F\xAB\xE2\x9F\xAD\xE2\x9F\xAF\xE2\xAC\xB2\xE2\x9F\xB5\xE2\x9F\xB8\xE2\x9F\xBB\xE2\x9F\xBD\xE2\xAC\xB3\xE2\xAC\xB4\xE2\xAC\xB5\xE2\xA4\x82\xE2\xAC\xB6\xE2\xA4\x86\xE2\xA4\x8C\xE2\xA4\x8E\xE2\xAC\xB7\xE2\xAC\xB8\xE2\xAC\xB9\xE2\xAC\xBA\xE2\xAC\xBB\xE2\xAC\xBC\xE2\xAC\xBD\xE2\xA4\x99\xE2\xA4\x9B\xE2\xA4\x9D\xE2\xA4\x9F\xE2\xAC\xBF\xE2\xA4\xB6\xE2\xA5\x86\xE2\xAC\xBE\xE2\xA5\x92\xE2\xA5\x96\xE2\xA5\x9A\xE2\xA5\x9E\xE2\xA5\xA2\xE2\xA5\xAA\xE2\xA5\xAB\xE2\xAD\x80\xE2\xAD\x81\xE2\xAD\x8B\xE2\xAD\x82\xE2\xA5\xBB\xE2\xA6\x84\xE2\xA6\x86\xE2\xA6\x88\xE2\xA6\x8A\xE2\xA6\x8C\xE2\xA6\x90\xE2\xA6\x8E\xE2\xA6\x92\xE2\xA6\x94\xE2\xA6\x96\xE2\xA6\x98\xE2\xA6\xA9\xE2\xA6\xAB\xE2\xA6\xB4\xE2\xA7\x81\xE2\xA7\x99\xE2\xA7\x9B\xE2\xA7\xBD\xE2\xA9\xBA\xE2\xA9\xBC\xE2\xA9\xBE\xE2\xAA\x80\xE2\xAA\x82\xE2\xAA\x84\xE2\xAA\x86\xE2\xAA\x88\xE2\xAA\x8A\xE2\xAA\x8E\xE2\xAA\x96\xE2\xAA\x98\xE2\xAA\x9A\xE2\xAA\x9C\xE2\xAA\x9E\xE2\xAA\xA0\xE2\xAA\xA2\xE2\xAA\xA7\xE2\xAA\xA9\xE2\xAA\xAB\xE2\xAA\xAD\xE2\xAA\xB0\xE2\xAA\xB2\xE2\xAA\xB4\xE2\xAA\xB6\xE2\xAA\xB8\xE2\xAA\xBA\xE2\xAA\xBC\xE2\xAA\xBE\xE2\xAB\x80\xE2\xAB\x82\xE2\xAB\x84\xE2\xAB\x86\xE2\xAB\x88\xE2\xAB\x8A\xE2\xAB\x8C\xE2\xAB\x90\xE2\xAB\x92\xE2\xAB\x96\xE2\x8A\xAB\xE2\xAB\xB8\xE2\xAB\xBA\xE2\xAD\x85\xE2\xAD\x89\xE2\xAD\x8A\xE2\xA5\xB3\xE2\xAD\xA0\xE2\xAD\xAA\xE2\xAD\xB0\xE2\xAD\xBA\xE2\xAE\x84\xE2\xAE\x88\xE2\xAC\x85\xE2\xAE\x98\xE2\xAE\x9C\xE2\xAE\xA0\xE2\xAE\xA2\xE2\xAE\xA8\xE2\xAE\xAA\xE2\xAE\xB0\xE2\xAE\xB2\xE2\xAF\xAC\xE2\xB8\x83\xE2\xB8\x82\xE2\xB8\x85\xE2\xB8\x84\xE2\xB8\x8A\xE2\xB8\x89\xE2\xB8\x8D\xE2\xB8\x8C\xE2\xB8\x90\xE2\xB8\x9D\xE2\xB8\x9C\xE2\xB8\xA1\xE2\xB8\xA0\xE2\xB8\xA3\xE2\xB8\xA5\xE2\xB8\xA7\xE2\xB8\xA9\xE2\xB8\xB7\xE2\x80\x9E\xE2\xB9\x96\xE2\xB9\x98\xE2\xB9\x9A\xE2\xB9\x9C\xE3\x80\x89\xE3\x80\x8B\xE3\x80\x8D\xE3\x80\x8F\xE3\x80\x91\xE3\x80\x95\xE3\x80\x97\xE3\x80\x99\xE3\x80\x9B\xE3\x80\x9E\xEA\xA7\x82\xEF\xB4\xBF\xEF\xB9\x9A\xEF\xB9\x9C\xEF\xB9\x9E\xEF\xB9\xA5\xEF\xBC\x89\xEF\xBC\x9E\xEF\xBC\xBD\xEF\xBD\x9D\xEF\xBD\xA0\xEF\xBD\xA3\xEF\xBF\xA9\xF0\x9D\x84\x82\xF0\x9D\x84\x87\xF0\x9F\x91\x88\xF0\x9F\x95\xA8\xF0\x9F\x95\xA9\xF0\x9F\x95\xAA\xF0\x9F\x95\xBD\xF0\x9F\x96\x98\xF0\x9F\x96\x9A\xF0\x9F\x96\x9C\xF0\x9F\x97\xA7\xF0\x9F\xA0\x80\xF0\x9F\xA0\x84\xF0\x9F\xA0\x88\xF0\x9F\xA0\x90\xF0\x9F\xA0\x94\xF0\x9F\xA0\x98\xF0\x9F\xA0\x9C\xF0\x9F\xA0\xA0\xF0\x9F\xA0\xA4\xF0\x9F\xA0\xA8\xF0\x9F\xA0\xAC\xF0\x9F\xA0\xB0\xF0\x9F\xA0\xB4\xF0\x9F\xA0\xB8\xF0\x9F\xA0\xBC\xF0\x9F\xA1\x80\xF0\x9F\xA1\x84\xF0\x9F\xA1\x90\xF0\x9F\xA1\xA0\xF0\x9F\xA1\xA8\xF0\x9F\xA1\xB0\xF0\x9F\xA1\xB8\xF0\x9F\xA2\x80\xF0\x9F\xA2\x90\xF0\x9F\xA2\x94\xF0\x9F\xA2\x98\xF0\x9F\xA2\xA0\xF0\x9F\xA2\xA2\xF0\x9F\xA2\xA6\xF0\x9F\xA2\xA4\xF0\x9F\xA2\xA8\xF0\x9F\xA2\xAA" +# define EXTRA_OPENING_UTF8_BRACKETS "\x28\x3C\x5B\x7B\xC2\xAB\xC2\xBB\xE0\xBC\xBA\xE0\xBC\xBC\xE1\x9A\x9B\xE2\x80\x98\xE2\x80\x99\xE2\x80\x9C\xE2\x80\x9D\xE2\x80\xB5\xE2\x80\xB6\xE2\x80\xB7\xE2\x80\xB9\xE2\x80\xBA\xE2\x81\x85\xE2\x81\x8D\xE2\x81\xBD\xE2\x82\x8D\xE2\x86\x92\xE2\x86\x9B\xE2\x86\x9D\xE2\x86\xA0\xE2\x86\xA3\xE2\x86\xA6\xE2\x86\xAA\xE2\x86\xAC\xE2\x86\xB1\xE2\x86\xB3\xE2\x87\x80\xE2\x87\x81\xE2\x87\x89\xE2\x87\x8F\xE2\x87\x92\xE2\x87\x9B\xE2\x87\x9D\xE2\x87\xA2\xE2\x87\xA5\xE2\x87\xA8\xE2\x87\xB4\xE2\x87\xB6\xE2\x87\xB8\xE2\x87\xBB\xE2\x87\xBE\xE2\x88\x88\xE2\x88\x89\xE2\x88\x8A\xE2\x89\xA4\xE2\x89\xA6\xE2\x89\xA8\xE2\x89\xAA\xE2\x89\xAE\xE2\x89\xB0\xE2\x89\xB2\xE2\x89\xB4\xE2\x89\xBA\xE2\x89\xBC\xE2\x89\xBE\xE2\x8A\x80\xE2\x8A\x82\xE2\x8A\x84\xE2\x8A\x86\xE2\x8A\x88\xE2\x8A\x8A\xE2\x8A\xA3\xE2\x8A\xA6\xE2\x8A\xA8\xE2\x8A\xA9\xE2\x8A\xB0\xE2\x8B\x90\xE2\x8B\x96\xE2\x8B\x98\xE2\x8B\x9C\xE2\x8B\x9E\xE2\x8B\xA0\xE2\x8B\xA6\xE2\x8B\xA8\xE2\x8B\xB2\xE2\x8B\xB3\xE2\x8B\xB4\xE2\x8B\xB6\xE2\x8B\xB7\xE2\x8C\x88\xE2\x8C\x8A\xE2\x8C\xA6\xE2\x8C\xA9\xE2\x8D\x88\xE2\x8F\xA9\xE2\x8F\xAD\xE2\x98\x9B\xE2\x98\x9E\xE2\x9A\x9E\xE2\x9D\xA8\xE2\x9D\xAA\xE2\x9D\xAC\xE2\x9D\xAE\xE2\x9D\xB0\xE2\x9D\xB2\xE2\x9D\xB4\xE2\x9F\x83\xE2\x9F\x85\xE2\x9F\x88\xE2\x9F\x9E\xE2\x9F\xA6\xE2\x9F\xA8\xE2\x9F\xAA\xE2\x9F\xAC\xE2\x9F\xAE\xE2\x9F\xB4\xE2\x9F\xB6\xE2\x9F\xB9\xE2\x9F\xBC\xE2\x9F\xBE\xE2\x9F\xBF\xE2\xA4\x80\xE2\xA4\x81\xE2\xA4\x83\xE2\xA4\x85\xE2\xA4\x87\xE2\xA4\x8D\xE2\xA4\x8F\xE2\xA4\x90\xE2\xA4\x91\xE2\xA4\x94\xE2\xA4\x95\xE2\xA4\x96\xE2\xA4\x97\xE2\xA4\x98\xE2\xA4\x9A\xE2\xA4\x9C\xE2\xA4\x9E\xE2\xA4\xA0\xE2\xA4\xB3\xE2\xA4\xB7\xE2\xA5\x85\xE2\xA5\x87\xE2\xA5\x93\xE2\xA5\x97\xE2\xA5\x9B\xE2\xA5\x9F\xE2\xA5\xA4\xE2\xA5\xAC\xE2\xA5\xAD\xE2\xA5\xB1\xE2\xA5\xB2\xE2\xA5\xB4\xE2\xA5\xB5\xE2\xA5\xB9\xE2\xA6\x83\xE2\xA6\x85\xE2\xA6\x87\xE2\xA6\x89\xE2\xA6\x8B\xE2\xA6\x8D\xE2\xA6\x8F\xE2\xA6\x91\xE2\xA6\x93\xE2\xA6\x95\xE2\xA6\x97\xE2\xA6\xA8\xE2\xA6\xAA\xE2\xA6\xB3\xE2\xA7\x80\xE2\xA7\x98\xE2\xA7\x9A\xE2\xA7\xBC\xE2\xA9\xB9\xE2\xA9\xBB\xE2\xA9\xBD\xE2\xA9\xBF\xE2\xAA\x81\xE2\xAA\x83\xE2\xAA\x85\xE2\xAA\x87\xE2\xAA\x89\xE2\xAA\x8D\xE2\xAA\x95\xE2\xAA\x97\xE2\xAA\x99\xE2\xAA\x9B\xE2\xAA\x9D\xE2\xAA\x9F\xE2\xAA\xA1\xE2\xAA\xA6\xE2\xAA\xA8\xE2\xAA\xAA\xE2\xAA\xAC\xE2\xAA\xAF\xE2\xAA\xB1\xE2\xAA\xB3\xE2\xAA\xB5\xE2\xAA\xB7\xE2\xAA\xB9\xE2\xAA\xBB\xE2\xAA\xBD\xE2\xAA\xBF\xE2\xAB\x81\xE2\xAB\x83\xE2\xAB\x85\xE2\xAB\x87\xE2\xAB\x89\xE2\xAB\x8B\xE2\xAB\x8F\xE2\xAB\x91\xE2\xAB\x95\xE2\xAB\xA5\xE2\xAB\xB7\xE2\xAB\xB9\xE2\xAD\x86\xE2\xAD\x87\xE2\xAD\x88\xE2\xAD\x8C\xE2\xAD\xA2\xE2\xAD\xAC\xE2\xAD\xB2\xE2\xAD\xBC\xE2\xAE\x86\xE2\xAE\x8A\xE2\xAE\x95\xE2\xAE\x9A\xE2\xAE\x9E\xE2\xAE\xA1\xE2\xAE\xA3\xE2\xAE\xA9\xE2\xAE\xAB\xE2\xAE\xB1\xE2\xAE\xB3\xE2\xAF\xAE\xE2\xB8\x82\xE2\xB8\x83\xE2\xB8\x84\xE2\xB8\x85\xE2\xB8\x89\xE2\xB8\x8A\xE2\xB8\x8C\xE2\xB8\x8D\xE2\xB8\x91\xE2\xB8\x9C\xE2\xB8\x9D\xE2\xB8\xA0\xE2\xB8\xA1\xE2\xB8\xA2\xE2\xB8\xA4\xE2\xB8\xA6\xE2\xB8\xA8\xE2\xB8\xB6\xE2\xB9\x82\xE2\xB9\x95\xE2\xB9\x97\xE2\xB9\x99\xE2\xB9\x9B\xE3\x80\x88\xE3\x80\x8A\xE3\x80\x8C\xE3\x80\x8E\xE3\x80\x90\xE3\x80\x94\xE3\x80\x96\xE3\x80\x98\xE3\x80\x9A\xE3\x80\x9D\xEA\xA7\x81\xEF\xB4\xBE\xEF\xB9\x99\xEF\xB9\x9B\xEF\xB9\x9D\xEF\xB9\xA4\xEF\xBC\x88\xEF\xBC\x9C\xEF\xBC\xBB\xEF\xBD\x9B\xEF\xBD\x9F\xEF\xBD\xA2\xEF\xBF\xAB\xF0\x9D\x84\x83\xF0\x9D\x84\x86\xF0\x9F\x91\x89\xF0\x9F\x94\x88\xF0\x9F\x94\x89\xF0\x9F\x94\x8A\xF0\x9F\x95\xBB\xF0\x9F\x96\x99\xF0\x9F\x96\x9B\xF0\x9F\x96\x9D\xF0\x9F\x97\xA6\xF0\x9F\xA0\x82\xF0\x9F\xA0\x86\xF0\x9F\xA0\x8A\xF0\x9F\xA0\x92\xF0\x9F\xA0\x96\xF0\x9F\xA0\x9A\xF0\x9F\xA0\x9E\xF0\x9F\xA0\xA2\xF0\x9F\xA0\xA6\xF0\x9F\xA0\xAA\xF0\x9F\xA0\xAE\xF0\x9F\xA0\xB2\xF0\x9F\xA0\xB6\xF0\x9F\xA0\xBA\xF0\x9F\xA0\xBE\xF0\x9F\xA1\x82\xF0\x9F\xA1\x86\xF0\x9F\xA1\x92\xF0\x9F\xA1\xA2\xF0\x9F\xA1\xAA\xF0\x9F\xA1\xB2\xF0\x9F\xA1\xBA\xF0\x9F\xA2\x82\xF0\x9F\xA2\x92\xF0\x9F\xA2\x96\xF0\x9F\xA2\x9A\xF0\x9F\xA2\xA1\xF0\x9F\xA2\xA3\xF0\x9F\xA2\xA5\xF0\x9F\xA2\xA7\xF0\x9F\xA2\xA9\xF0\x9F\xA2\xAB" +# define EXTRA_CLOSING_UTF8_BRACKETS "\x29\x3E\x5D\x7D\xC2\xBB\xC2\xAB\xE0\xBC\xBB\xE0\xBC\xBD\xE1\x9A\x9C\xE2\x80\x99\xE2\x80\x98\xE2\x80\x9D\xE2\x80\x9C\xE2\x80\xB2\xE2\x80\xB3\xE2\x80\xB4\xE2\x80\xBA\xE2\x80\xB9\xE2\x81\x86\xE2\x81\x8C\xE2\x81\xBE\xE2\x82\x8E\xE2\x86\x90\xE2\x86\x9A\xE2\x86\x9C\xE2\x86\x9E\xE2\x86\xA2\xE2\x86\xA4\xE2\x86\xA9\xE2\x86\xAB\xE2\x86\xB0\xE2\x86\xB2\xE2\x86\xBC\xE2\x86\xBD\xE2\x87\x87\xE2\x87\x8D\xE2\x87\x90\xE2\x87\x9A\xE2\x87\x9C\xE2\x87\xA0\xE2\x87\xA4\xE2\x87\xA6\xE2\xAC\xB0\xE2\xAC\xB1\xE2\x87\xB7\xE2\x87\xBA\xE2\x87\xBD\xE2\x88\x8B\xE2\x88\x8C\xE2\x88\x8D\xE2\x89\xA5\xE2\x89\xA7\xE2\x89\xA9\xE2\x89\xAB\xE2\x89\xAF\xE2\x89\xB1\xE2\x89\xB3\xE2\x89\xB5\xE2\x89\xBB\xE2\x89\xBD\xE2\x89\xBF\xE2\x8A\x81\xE2\x8A\x83\xE2\x8A\x85\xE2\x8A\x87\xE2\x8A\x89\xE2\x8A\x8B\xE2\x8A\xA2\xE2\xAB\x9E\xE2\xAB\xA4\xE2\xAB\xA3\xE2\x8A\xB1\xE2\x8B\x91\xE2\x8B\x97\xE2\x8B\x99\xE2\x8B\x9D\xE2\x8B\x9F\xE2\x8B\xA1\xE2\x8B\xA7\xE2\x8B\xA9\xE2\x8B\xBA\xE2\x8B\xBB\xE2\x8B\xBC\xE2\x8B\xBD\xE2\x8B\xBE\xE2\x8C\x89\xE2\x8C\x8B\xE2\x8C\xAB\xE2\x8C\xAA\xE2\x8D\x87\xE2\x8F\xAA\xE2\x8F\xAE\xE2\x98\x9A\xE2\x98\x9C\xE2\x9A\x9F\xE2\x9D\xA9\xE2\x9D\xAB\xE2\x9D\xAD\xE2\x9D\xAF\xE2\x9D\xB1\xE2\x9D\xB3\xE2\x9D\xB5\xE2\x9F\x84\xE2\x9F\x86\xE2\x9F\x89\xE2\x9F\x9D\xE2\x9F\xA7\xE2\x9F\xA9\xE2\x9F\xAB\xE2\x9F\xAD\xE2\x9F\xAF\xE2\xAC\xB2\xE2\x9F\xB5\xE2\x9F\xB8\xE2\x9F\xBB\xE2\x9F\xBD\xE2\xAC\xB3\xE2\xAC\xB4\xE2\xAC\xB5\xE2\xA4\x82\xE2\xAC\xB6\xE2\xA4\x86\xE2\xA4\x8C\xE2\xA4\x8E\xE2\xAC\xB7\xE2\xAC\xB8\xE2\xAC\xB9\xE2\xAC\xBA\xE2\xAC\xBB\xE2\xAC\xBC\xE2\xAC\xBD\xE2\xA4\x99\xE2\xA4\x9B\xE2\xA4\x9D\xE2\xA4\x9F\xE2\xAC\xBF\xE2\xA4\xB6\xE2\xA5\x86\xE2\xAC\xBE\xE2\xA5\x92\xE2\xA5\x96\xE2\xA5\x9A\xE2\xA5\x9E\xE2\xA5\xA2\xE2\xA5\xAA\xE2\xA5\xAB\xE2\xAD\x80\xE2\xAD\x81\xE2\xAD\x8B\xE2\xAD\x82\xE2\xA5\xBB\xE2\xA6\x84\xE2\xA6\x86\xE2\xA6\x88\xE2\xA6\x8A\xE2\xA6\x8C\xE2\xA6\x90\xE2\xA6\x8E\xE2\xA6\x92\xE2\xA6\x94\xE2\xA6\x96\xE2\xA6\x98\xE2\xA6\xA9\xE2\xA6\xAB\xE2\xA6\xB4\xE2\xA7\x81\xE2\xA7\x99\xE2\xA7\x9B\xE2\xA7\xBD\xE2\xA9\xBA\xE2\xA9\xBC\xE2\xA9\xBE\xE2\xAA\x80\xE2\xAA\x82\xE2\xAA\x84\xE2\xAA\x86\xE2\xAA\x88\xE2\xAA\x8A\xE2\xAA\x8E\xE2\xAA\x96\xE2\xAA\x98\xE2\xAA\x9A\xE2\xAA\x9C\xE2\xAA\x9E\xE2\xAA\xA0\xE2\xAA\xA2\xE2\xAA\xA7\xE2\xAA\xA9\xE2\xAA\xAB\xE2\xAA\xAD\xE2\xAA\xB0\xE2\xAA\xB2\xE2\xAA\xB4\xE2\xAA\xB6\xE2\xAA\xB8\xE2\xAA\xBA\xE2\xAA\xBC\xE2\xAA\xBE\xE2\xAB\x80\xE2\xAB\x82\xE2\xAB\x84\xE2\xAB\x86\xE2\xAB\x88\xE2\xAB\x8A\xE2\xAB\x8C\xE2\xAB\x90\xE2\xAB\x92\xE2\xAB\x96\xE2\x8A\xAB\xE2\xAB\xB8\xE2\xAB\xBA\xE2\xAD\x85\xE2\xAD\x89\xE2\xAD\x8A\xE2\xA5\xB3\xE2\xAD\xA0\xE2\xAD\xAA\xE2\xAD\xB0\xE2\xAD\xBA\xE2\xAE\x84\xE2\xAE\x88\xE2\xAC\x85\xE2\xAE\x98\xE2\xAE\x9C\xE2\xAE\xA0\xE2\xAE\xA2\xE2\xAE\xA8\xE2\xAE\xAA\xE2\xAE\xB0\xE2\xAE\xB2\xE2\xAF\xAC\xE2\xB8\x83\xE2\xB8\x82\xE2\xB8\x85\xE2\xB8\x84\xE2\xB8\x8A\xE2\xB8\x89\xE2\xB8\x8D\xE2\xB8\x8C\xE2\xB8\x90\xE2\xB8\x9D\xE2\xB8\x9C\xE2\xB8\xA1\xE2\xB8\xA0\xE2\xB8\xA3\xE2\xB8\xA5\xE2\xB8\xA7\xE2\xB8\xA9\xE2\xB8\xB7\xE2\x80\x9E\xE2\xB9\x96\xE2\xB9\x98\xE2\xB9\x9A\xE2\xB9\x9C\xE3\x80\x89\xE3\x80\x8B\xE3\x80\x8D\xE3\x80\x8F\xE3\x80\x91\xE3\x80\x95\xE3\x80\x97\xE3\x80\x99\xE3\x80\x9B\xE3\x80\x9E\xEA\xA7\x82\xEF\xB4\xBF\xEF\xB9\x9A\xEF\xB9\x9C\xEF\xB9\x9E\xEF\xB9\xA5\xEF\xBC\x89\xEF\xBC\x9E\xEF\xBC\xBD\xEF\xBD\x9D\xEF\xBD\xA0\xEF\xBD\xA3\xEF\xBF\xA9\xF0\x9D\x84\x82\xF0\x9D\x84\x87\xF0\x9F\x91\x88\xF0\x9F\x95\xA8\xF0\x9F\x95\xA9\xF0\x9F\x95\xAA\xF0\x9F\x95\xBD\xF0\x9F\x96\x98\xF0\x9F\x96\x9A\xF0\x9F\x96\x9C\xF0\x9F\x97\xA7\xF0\x9F\xA0\x80\xF0\x9F\xA0\x84\xF0\x9F\xA0\x88\xF0\x9F\xA0\x90\xF0\x9F\xA0\x94\xF0\x9F\xA0\x98\xF0\x9F\xA0\x9C\xF0\x9F\xA0\xA0\xF0\x9F\xA0\xA4\xF0\x9F\xA0\xA8\xF0\x9F\xA0\xAC\xF0\x9F\xA0\xB0\xF0\x9F\xA0\xB4\xF0\x9F\xA0\xB8\xF0\x9F\xA0\xBC\xF0\x9F\xA1\x80\xF0\x9F\xA1\x84\xF0\x9F\xA1\x90\xF0\x9F\xA1\xA0\xF0\x9F\xA1\xA8\xF0\x9F\xA1\xB0\xF0\x9F\xA1\xB8\xF0\x9F\xA2\x80\xF0\x9F\xA2\x90\xF0\x9F\xA2\x94\xF0\x9F\xA2\x98\xF0\x9F\xA2\xA0\xF0\x9F\xA2\xA2\xF0\x9F\xA2\xA6\xF0\x9F\xA2\xA4\xF0\x9F\xA2\xA8\xF0\x9F\xA2\xAA" /* And not in UTF-8 */ # define EXTRA_OPENING_NON_UTF8_BRACKETS "\x28\x3C\x5B\x7B\xAB\xBB" # define EXTRA_CLOSING_NON_UTF8_BRACKETS "\x29\x3E\x5D\x7D\xBB\xAB" /* And what's deprecated */ -# define DEPRECATED_OPENING_UTF8_BRACKETS "\xC2\xAB\xC2\xBB\xC2\xBB\xDC\x86\xDC\x87\xE0\xBC\xBA\xE0\xBC\xBB\xE0\xBC\xBC\xE0\xBC\xBD\xE1\x9A\x9B\xE1\x9A\x9C\xE2\x80\x98\xE2\x80\x99\xE2\x80\x99\xE2\x80\x9C\xE2\x80\x9D\xE2\x80\x9D\xE2\x80\xB5\xE2\x80\xB2\xE2\x80\xB6\xE2\x80\xB3\xE2\x80\xB7\xE2\x80\xB4\xE2\x80\xB9\xE2\x80\xBA\xE2\x80\xBA\xE2\x81\x85\xE2\x81\x86\xE2\x81\x8D\xE2\x81\x8C\xE2\x81\xBD\xE2\x81\xBE\xE2\x82\x8D\xE2\x82\x8E\xE2\x86\x92\xE2\x86\x90\xE2\x86\x9B\xE2\x86\x9A\xE2\x86\x9D\xE2\x86\x9C\xE2\x86\xA0\xE2\x86\x9E\xE2\x86\xA3\xE2\x86\xA2\xE2\x86\xA6\xE2\x86\xA4\xE2\x86\xAA\xE2\x86\xA9\xE2\x86\xAC\xE2\x86\xAB\xE2\x86\xB1\xE2\x86\xB0\xE2\x86\xB3\xE2\x86\xB2\xE2\x87\x80\xE2\x86\xBC\xE2\x87\x81\xE2\x86\xBD\xE2\x87\x89\xE2\x87\x87\xE2\x87\x8F\xE2\x87\x8D\xE2\x87\x92\xE2\x87\x90\xE2\x87\x9B\xE2\x87\x9A\xE2\x87\x9D\xE2\x87\x9C\xE2\x87\xA2\xE2\x87\xA0\xE2\x87\xA5\xE2\x87\xA4\xE2\x87\xA8\xE2\x87\xA6\xE2\x87\xB4\xE2\xAC\xB0\xE2\x87\xB6\xE2\xAC\xB1\xE2\x87\xB8\xE2\x87\xB7\xE2\x87\xBB\xE2\x87\xBA\xE2\x87\xBE\xE2\x87\xBD\xE2\x88\x88\xE2\x88\x8B\xE2\x88\x89\xE2\x88\x8C\xE2\x88\x8A\xE2\x88\x8D\xE2\x89\xA4\xE2\x89\xA5\xE2\x89\xA6\xE2\x89\xA7\xE2\x89\xA8\xE2\x89\xA9\xE2\x89\xAA\xE2\x89\xAB\xE2\x89\xAE\xE2\x89\xAF\xE2\x89\xB0\xE2\x89\xB1\xE2\x89\xB2\xE2\x89\xB3\xE2\x89\xB4\xE2\x89\xB5\xE2\x89\xBA\xE2\x89\xBB\xE2\x89\xBC\xE2\x89\xBD\xE2\x89\xBE\xE2\x89\xBF\xE2\x8A\x80\xE2\x8A\x81\xE2\x8A\x82\xE2\x8A\x83\xE2\x8A\x84\xE2\x8A\x85\xE2\x8A\x86\xE2\x8A\x87\xE2\x8A\x88\xE2\x8A\x89\xE2\x8A\x8A\xE2\x8A\x8B\xE2\x8A\xA3\xE2\x8A\xA2\xE2\x8A\xA6\xE2\xAB\x9E\xE2\x8A\xA8\xE2\xAB\xA4\xE2\x8A\xA9\xE2\xAB\xA3\xE2\x8A\xB0\xE2\x8A\xB1\xE2\x8B\x90\xE2\x8B\x91\xE2\x8B\x96\xE2\x8B\x97\xE2\x8B\x98\xE2\x8B\x99\xE2\x8B\x9C\xE2\x8B\x9D\xE2\x8B\x9E\xE2\x8B\x9F\xE2\x8B\xA0\xE2\x8B\xA1\xE2\x8B\xA6\xE2\x8B\xA7\xE2\x8B\xA8\xE2\x8B\xA9\xE2\x8B\xB2\xE2\x8B\xBA\xE2\x8B\xB3\xE2\x8B\xBB\xE2\x8B\xB4\xE2\x8B\xBC\xE2\x8B\xB6\xE2\x8B\xBD\xE2\x8B\xB7\xE2\x8B\xBE\xE2\x8C\x88\xE2\x8C\x89\xE2\x8C\x8A\xE2\x8C\x8B\xE2\x8C\xA6\xE2\x8C\xAB\xE2\x8C\xA9\xE2\x8C\xAA\xE2\x8D\x88\xE2\x8D\x87\xE2\x8F\xA9\xE2\x8F\xAA\xE2\x8F\xAD\xE2\x8F\xAE\xE2\x98\x9B\xE2\x98\x9A\xE2\x98\x9E\xE2\x98\x9C\xE2\x9A\x9E\xE2\x9A\x9F\xE2\x9D\xA8\xE2\x9D\xA9\xE2\x9D\xAA\xE2\x9D\xAB\xE2\x9D\xAC\xE2\x9D\xAD\xE2\x9D\xAE\xE2\x9D\xAF\xE2\x9D\xB0\xE2\x9D\xB1\xE2\x9D\xB2\xE2\x9D\xB3\xE2\x9D\xB4\xE2\x9D\xB5\xE2\x9F\x83\xE2\x9F\x84\xE2\x9F\x85\xE2\x9F\x86\xE2\x9F\x88\xE2\x9F\x89\xE2\x9F\x9E\xE2\x9F\x9D\xE2\x9F\xA6\xE2\x9F\xA7\xE2\x9F\xA8\xE2\x9F\xA9\xE2\x9F\xAA\xE2\x9F\xAB\xE2\x9F\xAC\xE2\x9F\xAD\xE2\x9F\xAE\xE2\x9F\xAF\xE2\x9F\xB4\xE2\xAC\xB2\xE2\x9F\xB6\xE2\x9F\xB5\xE2\x9F\xB9\xE2\x9F\xB8\xE2\x9F\xBC\xE2\x9F\xBB\xE2\x9F\xBE\xE2\x9F\xBD\xE2\x9F\xBF\xE2\xAC\xB3\xE2\xA4\x80\xE2\xAC\xB4\xE2\xA4\x81\xE2\xAC\xB5\xE2\xA4\x83\xE2\xA4\x82\xE2\xA4\x85\xE2\xAC\xB6\xE2\xA4\x87\xE2\xA4\x86\xE2\xA4\x8D\xE2\xA4\x8C\xE2\xA4\x8F\xE2\xA4\x8E\xE2\xA4\x90\xE2\xAC\xB7\xE2\xA4\x91\xE2\xAC\xB8\xE2\xA4\x94\xE2\xAC\xB9\xE2\xA4\x95\xE2\xAC\xBA\xE2\xA4\x96\xE2\xAC\xBB\xE2\xA4\x97\xE2\xAC\xBC\xE2\xA4\x98\xE2\xAC\xBD\xE2\xA4\x9A\xE2\xA4\x99\xE2\xA4\x9C\xE2\xA4\x9B\xE2\xA4\x9E\xE2\xA4\x9D\xE2\xA4\xA0\xE2\xA4\x9F\xE2\xA4\xB3\xE2\xAC\xBF\xE2\xA4\xB7\xE2\xA4\xB6\xE2\xA5\x85\xE2\xA5\x86\xE2\xA5\x87\xE2\xAC\xBE\xE2\xA5\x93\xE2\xA5\x92\xE2\xA5\x97\xE2\xA5\x96\xE2\xA5\x9B\xE2\xA5\x9A\xE2\xA5\x9F\xE2\xA5\x9E\xE2\xA5\xA4\xE2\xA5\xA2\xE2\xA5\xAC\xE2\xA5\xAA\xE2\xA5\xAD\xE2\xA5\xAB\xE2\xA5\xB1\xE2\xAD\x80\xE2\xA5\xB2\xE2\xAD\x81\xE2\xA5\xB4\xE2\xAD\x8B\xE2\xA5\xB5\xE2\xAD\x82\xE2\xA5\xB9\xE2\xA5\xBB\xE2\xA6\x83\xE2\xA6\x84\xE2\xA6\x85\xE2\xA6\x86\xE2\xA6\x87\xE2\xA6\x88\xE2\xA6\x89\xE2\xA6\x8A\xE2\xA6\x8B\xE2\xA6\x8C\xE2\xA6\x8D\xE2\xA6\x90\xE2\xA6\x8F\xE2\xA6\x8E\xE2\xA6\x91\xE2\xA6\x92\xE2\xA6\x93\xE2\xA6\x94\xE2\xA6\x95\xE2\xA6\x96\xE2\xA6\x97\xE2\xA6\x98\xE2\xA6\xA8\xE2\xA6\xA9\xE2\xA6\xAA\xE2\xA6\xAB\xE2\xA6\xB3\xE2\xA6\xB4\xE2\xA7\x80\xE2\xA7\x81\xE2\xA7\x98\xE2\xA7\x99\xE2\xA7\x9A\xE2\xA7\x9B\xE2\xA7\xBC\xE2\xA7\xBD\xE2\xA9\xB9\xE2\xA9\xBA\xE2\xA9\xBB\xE2\xA9\xBC\xE2\xA9\xBD\xE2\xA9\xBE\xE2\xA9\xBF\xE2\xAA\x80\xE2\xAA\x81\xE2\xAA\x82\xE2\xAA\x83\xE2\xAA\x84\xE2\xAA\x85\xE2\xAA\x86\xE2\xAA\x87\xE2\xAA\x88\xE2\xAA\x89\xE2\xAA\x8A\xE2\xAA\x8D\xE2\xAA\x8E\xE2\xAA\x95\xE2\xAA\x96\xE2\xAA\x97\xE2\xAA\x98\xE2\xAA\x99\xE2\xAA\x9A\xE2\xAA\x9B\xE2\xAA\x9C\xE2\xAA\x9D\xE2\xAA\x9E\xE2\xAA\x9F\xE2\xAA\xA0\xE2\xAA\xA1\xE2\xAA\xA2\xE2\xAA\xA6\xE2\xAA\xA7\xE2\xAA\xA8\xE2\xAA\xA9\xE2\xAA\xAA\xE2\xAA\xAB\xE2\xAA\xAC\xE2\xAA\xAD\xE2\xAA\xAF\xE2\xAA\xB0\xE2\xAA\xB1\xE2\xAA\xB2\xE2\xAA\xB3\xE2\xAA\xB4\xE2\xAA\xB5\xE2\xAA\xB6\xE2\xAA\xB7\xE2\xAA\xB8\xE2\xAA\xB9\xE2\xAA\xBA\xE2\xAA\xBB\xE2\xAA\xBC\xE2\xAA\xBD\xE2\xAA\xBE\xE2\xAA\xBF\xE2\xAB\x80\xE2\xAB\x81\xE2\xAB\x82\xE2\xAB\x83\xE2\xAB\x84\xE2\xAB\x85\xE2\xAB\x86\xE2\xAB\x87\xE2\xAB\x88\xE2\xAB\x89\xE2\xAB\x8A\xE2\xAB\x8B\xE2\xAB\x8C\xE2\xAB\x8F\xE2\xAB\x90\xE2\xAB\x91\xE2\xAB\x92\xE2\xAB\x95\xE2\xAB\x96\xE2\xAB\xA5\xE2\x8A\xAB\xE2\xAB\xB7\xE2\xAB\xB8\xE2\xAB\xB9\xE2\xAB\xBA\xE2\xAD\x86\xE2\xAD\x85\xE2\xAD\x87\xE2\xAD\x89\xE2\xAD\x88\xE2\xAD\x8A\xE2\xAD\x8C\xE2\xA5\xB3\xE2\xAD\xA2\xE2\xAD\xA0\xE2\xAD\xAC\xE2\xAD\xAA\xE2\xAD\xB2\xE2\xAD\xB0\xE2\xAD\xBC\xE2\xAD\xBA\xE2\xAE\x86\xE2\xAE\x84\xE2\xAE\x8A\xE2\xAE\x88\xE2\xAE\x95\xE2\xAC\x85\xE2\xAE\x9A\xE2\xAE\x98\xE2\xAE\x9E\xE2\xAE\x9C\xE2\xAE\xA1\xE2\xAE\xA0\xE2\xAE\xA3\xE2\xAE\xA2\xE2\xAE\xA9\xE2\xAE\xA8\xE2\xAE\xAB\xE2\xAE\xAA\xE2\xAE\xB1\xE2\xAE\xB0\xE2\xAE\xB3\xE2\xAE\xB2\xE2\xAF\xAE\xE2\xAF\xAC\xE2\xB8\x82\xE2\xB8\x83\xE2\xB8\x83\xE2\xB8\x84\xE2\xB8\x85\xE2\xB8\x85\xE2\xB8\x89\xE2\xB8\x8A\xE2\xB8\x8A\xE2\xB8\x8C\xE2\xB8\x8D\xE2\xB8\x8D\xE2\xB8\x91\xE2\xB8\x90\xE2\xB8\x9C\xE2\xB8\x9D\xE2\xB8\x9D\xE2\xB8\xA0\xE2\xB8\xA1\xE2\xB8\xA1\xE2\xB8\xA2\xE2\xB8\xA3\xE2\xB8\xA4\xE2\xB8\xA5\xE2\xB8\xA6\xE2\xB8\xA7\xE2\xB8\xA8\xE2\xB8\xA9\xE2\xB8\xB6\xE2\xB8\xB7\xE2\xB9\x82\xE2\x80\x9E\xE2\xB9\x95\xE2\xB9\x96\xE2\xB9\x97\xE2\xB9\x98\xE2\xB9\x99\xE2\xB9\x9A\xE2\xB9\x9B\xE2\xB9\x9C\xE3\x80\x88\xE3\x80\x89\xE3\x80\x8A\xE3\x80\x8B\xE3\x80\x8C\xE3\x80\x8D\xE3\x80\x8E\xE3\x80\x8F\xE3\x80\x90\xE3\x80\x91\xE3\x80\x94\xE3\x80\x95\xE3\x80\x96\xE3\x80\x97\xE3\x80\x98\xE3\x80\x99\xE3\x80\x9A\xE3\x80\x9B\xE3\x80\x9D\xE3\x80\x9E\xEA\xA7\x81\xEA\xA7\x82\xEF\xB4\xBE\xEF\xB4\xBF\xEF\xB9\x99\xEF\xB9\x9A\xEF\xB9\x9B\xEF\xB9\x9C\xEF\xB9\x9D\xEF\xB9\x9E\xEF\xB9\xA4\xEF\xB9\xA5\xEF\xBC\x88\xEF\xBC\x89\xEF\xBC\x9C\xEF\xBC\x9E\xEF\xBC\xBB\xEF\xBC\xBD\xEF\xBD\x9B\xEF\xBD\x9D\xEF\xBD\x9F\xEF\xBD\xA0\xEF\xBD\xA2\xEF\xBD\xA3\xEF\xBF\xAB\xEF\xBF\xA9\xF0\x9D\x84\x83\xF0\x9D\x84\x82\xF0\x9D\x84\x86\xF0\x9D\x84\x87\xF0\x9F\x91\x89\xF0\x9F\x91\x88\xF0\x9F\x94\x88\xF0\x9F\x95\xA8\xF0\x9F\x94\x89\xF0\x9F\x95\xA9\xF0\x9F\x94\x8A\xF0\x9F\x95\xAA\xF0\x9F\x95\xBB\xF0\x9F\x95\xBD\xF0\x9F\x96\x99\xF0\x9F\x96\x98\xF0\x9F\x96\x9B\xF0\x9F\x96\x9A\xF0\x9F\x96\x9D\xF0\x9F\x96\x9C\xF0\x9F\x97\xA6\xF0\x9F\x97\xA7\xF0\x9F\xA0\x82\xF0\x9F\xA0\x80\xF0\x9F\xA0\x86\xF0\x9F\xA0\x84\xF0\x9F\xA0\x8A\xF0\x9F\xA0\x88\xF0\x9F\xA0\x92\xF0\x9F\xA0\x90\xF0\x9F\xA0\x96\xF0\x9F\xA0\x94\xF0\x9F\xA0\x9A\xF0\x9F\xA0\x98\xF0\x9F\xA0\x9E\xF0\x9F\xA0\x9C\xF0\x9F\xA0\xA2\xF0\x9F\xA0\xA0\xF0\x9F\xA0\xA6\xF0\x9F\xA0\xA4\xF0\x9F\xA0\xAA\xF0\x9F\xA0\xA8\xF0\x9F\xA0\xAE\xF0\x9F\xA0\xAC\xF0\x9F\xA0\xB2\xF0\x9F\xA0\xB0\xF0\x9F\xA0\xB6\xF0\x9F\xA0\xB4\xF0\x9F\xA0\xBA\xF0\x9F\xA0\xB8\xF0\x9F\xA0\xBE\xF0\x9F\xA0\xBC\xF0\x9F\xA1\x82\xF0\x9F\xA1\x80\xF0\x9F\xA1\x86\xF0\x9F\xA1\x84\xF0\x9F\xA1\x92\xF0\x9F\xA1\x90\xF0\x9F\xA1\xA2\xF0\x9F\xA1\xA0\xF0\x9F\xA1\xAA\xF0\x9F\xA1\xA8\xF0\x9F\xA1\xB2\xF0\x9F\xA1\xB0\xF0\x9F\xA1\xBA\xF0\x9F\xA1\xB8\xF0\x9F\xA2\x82\xF0\x9F\xA2\x80\xF0\x9F\xA2\x92\xF0\x9F\xA2\x90\xF0\x9F\xA2\x96\xF0\x9F\xA2\x94\xF0\x9F\xA2\x9A\xF0\x9F\xA2\x98\xF0\x9F\xA2\xA1\xF0\x9F\xA2\xA0\xF0\x9F\xA2\xA3\xF0\x9F\xA2\xA2\xF0\x9F\xA2\xA5\xF0\x9F\xA2\xA6\xF0\x9F\xA2\xA7\xF0\x9F\xA2\xA4\xF0\x9F\xA2\xA9\xF0\x9F\xA2\xA8\xF0\x9F\xA2\xAB\xF0\x9F\xA2\xAA" +# define DEPRECATED_OPENING_UTF8_BRACKETS "\xC2\xAB\xC2\xBB\xC2\xBB\xE0\xBC\xBA\xE0\xBC\xBB\xE0\xBC\xBC\xE0\xBC\xBD\xE1\x9A\x9B\xE1\x9A\x9C\xE2\x80\x98\xE2\x80\x99\xE2\x80\x99\xE2\x80\x9C\xE2\x80\x9D\xE2\x80\x9D\xE2\x80\xB5\xE2\x80\xB2\xE2\x80\xB6\xE2\x80\xB3\xE2\x80\xB7\xE2\x80\xB4\xE2\x80\xB9\xE2\x80\xBA\xE2\x80\xBA\xE2\x81\x85\xE2\x81\x86\xE2\x81\x8D\xE2\x81\x8C\xE2\x81\xBD\xE2\x81\xBE\xE2\x82\x8D\xE2\x82\x8E\xE2\x86\x92\xE2\x86\x90\xE2\x86\x9B\xE2\x86\x9A\xE2\x86\x9D\xE2\x86\x9C\xE2\x86\xA0\xE2\x86\x9E\xE2\x86\xA3\xE2\x86\xA2\xE2\x86\xA6\xE2\x86\xA4\xE2\x86\xAA\xE2\x86\xA9\xE2\x86\xAC\xE2\x86\xAB\xE2\x86\xB1\xE2\x86\xB0\xE2\x86\xB3\xE2\x86\xB2\xE2\x87\x80\xE2\x86\xBC\xE2\x87\x81\xE2\x86\xBD\xE2\x87\x89\xE2\x87\x87\xE2\x87\x8F\xE2\x87\x8D\xE2\x87\x92\xE2\x87\x90\xE2\x87\x9B\xE2\x87\x9A\xE2\x87\x9D\xE2\x87\x9C\xE2\x87\xA2\xE2\x87\xA0\xE2\x87\xA5\xE2\x87\xA4\xE2\x87\xA8\xE2\x87\xA6\xE2\x87\xB4\xE2\xAC\xB0\xE2\x87\xB6\xE2\xAC\xB1\xE2\x87\xB8\xE2\x87\xB7\xE2\x87\xBB\xE2\x87\xBA\xE2\x87\xBE\xE2\x87\xBD\xE2\x88\x88\xE2\x88\x8B\xE2\x88\x89\xE2\x88\x8C\xE2\x88\x8A\xE2\x88\x8D\xE2\x89\xA4\xE2\x89\xA5\xE2\x89\xA6\xE2\x89\xA7\xE2\x89\xA8\xE2\x89\xA9\xE2\x89\xAA\xE2\x89\xAB\xE2\x89\xAE\xE2\x89\xAF\xE2\x89\xB0\xE2\x89\xB1\xE2\x89\xB2\xE2\x89\xB3\xE2\x89\xB4\xE2\x89\xB5\xE2\x89\xBA\xE2\x89\xBB\xE2\x89\xBC\xE2\x89\xBD\xE2\x89\xBE\xE2\x89\xBF\xE2\x8A\x80\xE2\x8A\x81\xE2\x8A\x82\xE2\x8A\x83\xE2\x8A\x84\xE2\x8A\x85\xE2\x8A\x86\xE2\x8A\x87\xE2\x8A\x88\xE2\x8A\x89\xE2\x8A\x8A\xE2\x8A\x8B\xE2\x8A\xA3\xE2\x8A\xA2\xE2\x8A\xA6\xE2\xAB\x9E\xE2\x8A\xA8\xE2\xAB\xA4\xE2\x8A\xA9\xE2\xAB\xA3\xE2\x8A\xB0\xE2\x8A\xB1\xE2\x8B\x90\xE2\x8B\x91\xE2\x8B\x96\xE2\x8B\x97\xE2\x8B\x98\xE2\x8B\x99\xE2\x8B\x9C\xE2\x8B\x9D\xE2\x8B\x9E\xE2\x8B\x9F\xE2\x8B\xA0\xE2\x8B\xA1\xE2\x8B\xA6\xE2\x8B\xA7\xE2\x8B\xA8\xE2\x8B\xA9\xE2\x8B\xB2\xE2\x8B\xBA\xE2\x8B\xB3\xE2\x8B\xBB\xE2\x8B\xB4\xE2\x8B\xBC\xE2\x8B\xB6\xE2\x8B\xBD\xE2\x8B\xB7\xE2\x8B\xBE\xE2\x8C\x88\xE2\x8C\x89\xE2\x8C\x8A\xE2\x8C\x8B\xE2\x8C\xA6\xE2\x8C\xAB\xE2\x8C\xA9\xE2\x8C\xAA\xE2\x8D\x88\xE2\x8D\x87\xE2\x8F\xA9\xE2\x8F\xAA\xE2\x8F\xAD\xE2\x8F\xAE\xE2\x98\x9B\xE2\x98\x9A\xE2\x98\x9E\xE2\x98\x9C\xE2\x9A\x9E\xE2\x9A\x9F\xE2\x9D\xA8\xE2\x9D\xA9\xE2\x9D\xAA\xE2\x9D\xAB\xE2\x9D\xAC\xE2\x9D\xAD\xE2\x9D\xAE\xE2\x9D\xAF\xE2\x9D\xB0\xE2\x9D\xB1\xE2\x9D\xB2\xE2\x9D\xB3\xE2\x9D\xB4\xE2\x9D\xB5\xE2\x9F\x83\xE2\x9F\x84\xE2\x9F\x85\xE2\x9F\x86\xE2\x9F\x88\xE2\x9F\x89\xE2\x9F\x9E\xE2\x9F\x9D\xE2\x9F\xA6\xE2\x9F\xA7\xE2\x9F\xA8\xE2\x9F\xA9\xE2\x9F\xAA\xE2\x9F\xAB\xE2\x9F\xAC\xE2\x9F\xAD\xE2\x9F\xAE\xE2\x9F\xAF\xE2\x9F\xB4\xE2\xAC\xB2\xE2\x9F\xB6\xE2\x9F\xB5\xE2\x9F\xB9\xE2\x9F\xB8\xE2\x9F\xBC\xE2\x9F\xBB\xE2\x9F\xBE\xE2\x9F\xBD\xE2\x9F\xBF\xE2\xAC\xB3\xE2\xA4\x80\xE2\xAC\xB4\xE2\xA4\x81\xE2\xAC\xB5\xE2\xA4\x83\xE2\xA4\x82\xE2\xA4\x85\xE2\xAC\xB6\xE2\xA4\x87\xE2\xA4\x86\xE2\xA4\x8D\xE2\xA4\x8C\xE2\xA4\x8F\xE2\xA4\x8E\xE2\xA4\x90\xE2\xAC\xB7\xE2\xA4\x91\xE2\xAC\xB8\xE2\xA4\x94\xE2\xAC\xB9\xE2\xA4\x95\xE2\xAC\xBA\xE2\xA4\x96\xE2\xAC\xBB\xE2\xA4\x97\xE2\xAC\xBC\xE2\xA4\x98\xE2\xAC\xBD\xE2\xA4\x9A\xE2\xA4\x99\xE2\xA4\x9C\xE2\xA4\x9B\xE2\xA4\x9E\xE2\xA4\x9D\xE2\xA4\xA0\xE2\xA4\x9F\xE2\xA4\xB3\xE2\xAC\xBF\xE2\xA4\xB7\xE2\xA4\xB6\xE2\xA5\x85\xE2\xA5\x86\xE2\xA5\x87\xE2\xAC\xBE\xE2\xA5\x93\xE2\xA5\x92\xE2\xA5\x97\xE2\xA5\x96\xE2\xA5\x9B\xE2\xA5\x9A\xE2\xA5\x9F\xE2\xA5\x9E\xE2\xA5\xA4\xE2\xA5\xA2\xE2\xA5\xAC\xE2\xA5\xAA\xE2\xA5\xAD\xE2\xA5\xAB\xE2\xA5\xB1\xE2\xAD\x80\xE2\xA5\xB2\xE2\xAD\x81\xE2\xA5\xB4\xE2\xAD\x8B\xE2\xA5\xB5\xE2\xAD\x82\xE2\xA5\xB9\xE2\xA5\xBB\xE2\xA6\x83\xE2\xA6\x84\xE2\xA6\x85\xE2\xA6\x86\xE2\xA6\x87\xE2\xA6\x88\xE2\xA6\x89\xE2\xA6\x8A\xE2\xA6\x8B\xE2\xA6\x8C\xE2\xA6\x8D\xE2\xA6\x90\xE2\xA6\x8F\xE2\xA6\x8E\xE2\xA6\x91\xE2\xA6\x92\xE2\xA6\x93\xE2\xA6\x94\xE2\xA6\x95\xE2\xA6\x96\xE2\xA6\x97\xE2\xA6\x98\xE2\xA6\xA8\xE2\xA6\xA9\xE2\xA6\xAA\xE2\xA6\xAB\xE2\xA6\xB3\xE2\xA6\xB4\xE2\xA7\x80\xE2\xA7\x81\xE2\xA7\x98\xE2\xA7\x99\xE2\xA7\x9A\xE2\xA7\x9B\xE2\xA7\xBC\xE2\xA7\xBD\xE2\xA9\xB9\xE2\xA9\xBA\xE2\xA9\xBB\xE2\xA9\xBC\xE2\xA9\xBD\xE2\xA9\xBE\xE2\xA9\xBF\xE2\xAA\x80\xE2\xAA\x81\xE2\xAA\x82\xE2\xAA\x83\xE2\xAA\x84\xE2\xAA\x85\xE2\xAA\x86\xE2\xAA\x87\xE2\xAA\x88\xE2\xAA\x89\xE2\xAA\x8A\xE2\xAA\x8D\xE2\xAA\x8E\xE2\xAA\x95\xE2\xAA\x96\xE2\xAA\x97\xE2\xAA\x98\xE2\xAA\x99\xE2\xAA\x9A\xE2\xAA\x9B\xE2\xAA\x9C\xE2\xAA\x9D\xE2\xAA\x9E\xE2\xAA\x9F\xE2\xAA\xA0\xE2\xAA\xA1\xE2\xAA\xA2\xE2\xAA\xA6\xE2\xAA\xA7\xE2\xAA\xA8\xE2\xAA\xA9\xE2\xAA\xAA\xE2\xAA\xAB\xE2\xAA\xAC\xE2\xAA\xAD\xE2\xAA\xAF\xE2\xAA\xB0\xE2\xAA\xB1\xE2\xAA\xB2\xE2\xAA\xB3\xE2\xAA\xB4\xE2\xAA\xB5\xE2\xAA\xB6\xE2\xAA\xB7\xE2\xAA\xB8\xE2\xAA\xB9\xE2\xAA\xBA\xE2\xAA\xBB\xE2\xAA\xBC\xE2\xAA\xBD\xE2\xAA\xBE\xE2\xAA\xBF\xE2\xAB\x80\xE2\xAB\x81\xE2\xAB\x82\xE2\xAB\x83\xE2\xAB\x84\xE2\xAB\x85\xE2\xAB\x86\xE2\xAB\x87\xE2\xAB\x88\xE2\xAB\x89\xE2\xAB\x8A\xE2\xAB\x8B\xE2\xAB\x8C\xE2\xAB\x8F\xE2\xAB\x90\xE2\xAB\x91\xE2\xAB\x92\xE2\xAB\x95\xE2\xAB\x96\xE2\xAB\xA5\xE2\x8A\xAB\xE2\xAB\xB7\xE2\xAB\xB8\xE2\xAB\xB9\xE2\xAB\xBA\xE2\xAD\x86\xE2\xAD\x85\xE2\xAD\x87\xE2\xAD\x89\xE2\xAD\x88\xE2\xAD\x8A\xE2\xAD\x8C\xE2\xA5\xB3\xE2\xAD\xA2\xE2\xAD\xA0\xE2\xAD\xAC\xE2\xAD\xAA\xE2\xAD\xB2\xE2\xAD\xB0\xE2\xAD\xBC\xE2\xAD\xBA\xE2\xAE\x86\xE2\xAE\x84\xE2\xAE\x8A\xE2\xAE\x88\xE2\xAE\x95\xE2\xAC\x85\xE2\xAE\x9A\xE2\xAE\x98\xE2\xAE\x9E\xE2\xAE\x9C\xE2\xAE\xA1\xE2\xAE\xA0\xE2\xAE\xA3\xE2\xAE\xA2\xE2\xAE\xA9\xE2\xAE\xA8\xE2\xAE\xAB\xE2\xAE\xAA\xE2\xAE\xB1\xE2\xAE\xB0\xE2\xAE\xB3\xE2\xAE\xB2\xE2\xAF\xAE\xE2\xAF\xAC\xE2\xB8\x82\xE2\xB8\x83\xE2\xB8\x83\xE2\xB8\x84\xE2\xB8\x85\xE2\xB8\x85\xE2\xB8\x89\xE2\xB8\x8A\xE2\xB8\x8A\xE2\xB8\x8C\xE2\xB8\x8D\xE2\xB8\x8D\xE2\xB8\x91\xE2\xB8\x90\xE2\xB8\x9C\xE2\xB8\x9D\xE2\xB8\x9D\xE2\xB8\xA0\xE2\xB8\xA1\xE2\xB8\xA1\xE2\xB8\xA2\xE2\xB8\xA3\xE2\xB8\xA4\xE2\xB8\xA5\xE2\xB8\xA6\xE2\xB8\xA7\xE2\xB8\xA8\xE2\xB8\xA9\xE2\xB8\xB6\xE2\xB8\xB7\xE2\xB9\x82\xE2\x80\x9E\xE2\xB9\x95\xE2\xB9\x96\xE2\xB9\x97\xE2\xB9\x98\xE2\xB9\x99\xE2\xB9\x9A\xE2\xB9\x9B\xE2\xB9\x9C\xE3\x80\x88\xE3\x80\x89\xE3\x80\x8A\xE3\x80\x8B\xE3\x80\x8C\xE3\x80\x8D\xE3\x80\x8E\xE3\x80\x8F\xE3\x80\x90\xE3\x80\x91\xE3\x80\x94\xE3\x80\x95\xE3\x80\x96\xE3\x80\x97\xE3\x80\x98\xE3\x80\x99\xE3\x80\x9A\xE3\x80\x9B\xE3\x80\x9D\xE3\x80\x9E\xEA\xA7\x81\xEA\xA7\x82\xEF\xB4\xBE\xEF\xB4\xBF\xEF\xB9\x99\xEF\xB9\x9A\xEF\xB9\x9B\xEF\xB9\x9C\xEF\xB9\x9D\xEF\xB9\x9E\xEF\xB9\xA4\xEF\xB9\xA5\xEF\xBC\x88\xEF\xBC\x89\xEF\xBC\x9C\xEF\xBC\x9E\xEF\xBC\xBB\xEF\xBC\xBD\xEF\xBD\x9B\xEF\xBD\x9D\xEF\xBD\x9F\xEF\xBD\xA0\xEF\xBD\xA2\xEF\xBD\xA3\xEF\xBF\xAB\xEF\xBF\xA9\xF0\x9D\x84\x83\xF0\x9D\x84\x82\xF0\x9D\x84\x86\xF0\x9D\x84\x87\xF0\x9F\x91\x89\xF0\x9F\x91\x88\xF0\x9F\x94\x88\xF0\x9F\x95\xA8\xF0\x9F\x94\x89\xF0\x9F\x95\xA9\xF0\x9F\x94\x8A\xF0\x9F\x95\xAA\xF0\x9F\x95\xBB\xF0\x9F\x95\xBD\xF0\x9F\x96\x99\xF0\x9F\x96\x98\xF0\x9F\x96\x9B\xF0\x9F\x96\x9A\xF0\x9F\x96\x9D\xF0\x9F\x96\x9C\xF0\x9F\x97\xA6\xF0\x9F\x97\xA7\xF0\x9F\xA0\x82\xF0\x9F\xA0\x80\xF0\x9F\xA0\x86\xF0\x9F\xA0\x84\xF0\x9F\xA0\x8A\xF0\x9F\xA0\x88\xF0\x9F\xA0\x92\xF0\x9F\xA0\x90\xF0\x9F\xA0\x96\xF0\x9F\xA0\x94\xF0\x9F\xA0\x9A\xF0\x9F\xA0\x98\xF0\x9F\xA0\x9E\xF0\x9F\xA0\x9C\xF0\x9F\xA0\xA2\xF0\x9F\xA0\xA0\xF0\x9F\xA0\xA6\xF0\x9F\xA0\xA4\xF0\x9F\xA0\xAA\xF0\x9F\xA0\xA8\xF0\x9F\xA0\xAE\xF0\x9F\xA0\xAC\xF0\x9F\xA0\xB2\xF0\x9F\xA0\xB0\xF0\x9F\xA0\xB6\xF0\x9F\xA0\xB4\xF0\x9F\xA0\xBA\xF0\x9F\xA0\xB8\xF0\x9F\xA0\xBE\xF0\x9F\xA0\xBC\xF0\x9F\xA1\x82\xF0\x9F\xA1\x80\xF0\x9F\xA1\x86\xF0\x9F\xA1\x84\xF0\x9F\xA1\x92\xF0\x9F\xA1\x90\xF0\x9F\xA1\xA2\xF0\x9F\xA1\xA0\xF0\x9F\xA1\xAA\xF0\x9F\xA1\xA8\xF0\x9F\xA1\xB2\xF0\x9F\xA1\xB0\xF0\x9F\xA1\xBA\xF0\x9F\xA1\xB8\xF0\x9F\xA2\x82\xF0\x9F\xA2\x80\xF0\x9F\xA2\x92\xF0\x9F\xA2\x90\xF0\x9F\xA2\x96\xF0\x9F\xA2\x94\xF0\x9F\xA2\x9A\xF0\x9F\xA2\x98\xF0\x9F\xA2\xA1\xF0\x9F\xA2\xA0\xF0\x9F\xA2\xA3\xF0\x9F\xA2\xA2\xF0\x9F\xA2\xA5\xF0\x9F\xA2\xA6\xF0\x9F\xA2\xA7\xF0\x9F\xA2\xA4\xF0\x9F\xA2\xA9\xF0\x9F\xA2\xA8\xF0\x9F\xA2\xAB\xF0\x9F\xA2\xAA" # define DEPRECATED_OPENING_NON_UTF8_BRACKETS "\xAB\xBB" # endif @@ -149,18 +155,22 @@ bytes. # define LATIN_SMALL_LETTER_Y_WITH_DIAERESIS_NATIVE 0xDF /* U+00FF */ # define MICRO_SIGN_NATIVE 0xA0 /* U+00B5 */ # define MICRO_SIGN_UTF8 "\x80\x64" /* U+00B5 */ +# define ARABIC_DECIMAL_SEPARATOR_UTF8 "\xB8\x62\x52" /* U+066B */ +# define ARABIC_DECIMAL_SEPARATOR_UTF8_FIRST_BYTE 0xB8 /* U+066B */ +# define ARABIC_DECIMAL_SEPARATOR_UTF8_TAIL "\x62\x52" /* U+066B */ +# define ARABIC_DECIMAL_SEPARATOR_UTF8_FIRST_BYTE_s "\xB8" /* U+066B */ # ifdef PERL_IN_TOKE_C /* Paired characters for quote-like operators, in UTF-8 */ -# define EXTRA_OPENING_UTF8_BRACKETS "\x4D\x4C\xAD\xC0\x80\x52\x80\x6A\xB8\x67\x47\xBA\x68\x69\xBA\x68\x70\xBC\x63\x6A\xCA\x41\x67\xCA\x41\x68\xCA\x41\x70\xCA\x41\x71\xCA\x42\x64\xCA\x42\x65\xCA\x42\x66\xCA\x42\x68\xCA\x42\x69\xCA\x43\x46\xCA\x43\x54\xCA\x44\x71\xCA\x45\x54\xCA\x53\x59\xCA\x53\x6A\xCA\x53\x71\xCA\x54\x41\xCA\x54\x44\xCA\x54\x47\xCA\x54\x51\xCA\x54\x53\xCA\x54\x58\xCA\x54\x62\xCA\x55\x41\xCA\x55\x42\xCA\x55\x4A\xCA\x55\x56\xCA\x55\x59\xCA\x55\x6A\xCA\x55\x71\xCA\x56\x43\xCA\x56\x46\xCA\x56\x49\xCA\x56\x63\xCA\x56\x65\xCA\x56\x67\xCA\x56\x6A\xCA\x56\x72\xCA\x57\x49\xCA\x57\x4A\xCA\x57\x51\xCA\x62\x45\xCA\x62\x47\xCA\x62\x49\xCA\x62\x51\xCA\x62\x55\xCA\x62\x57\xCA\x62\x59\xCA\x62\x63\xCA\x62\x69\xCA\x62\x70\xCA\x62\x72\xCA\x63\x41\xCA\x63\x43\xCA\x63\x45\xCA\x63\x47\xCA\x63\x49\xCA\x63\x51\xCA\x64\x44\xCA\x64\x47\xCA\x64\x49\xCA\x64\x4A\xCA\x64\x57\xCA\x65\x57\xCA\x65\x65\xCA\x65\x67\xCA\x65\x70\xCA\x65\x72\xCA\x66\x41\xCA\x66\x47\xCA\x66\x49\xCA\x66\x59\xCA\x66\x62\xCA\x66\x63\xCA\x66\x65\xCA\x66\x66\xCA\x67\x49\xCA\x67\x51\xCA\x68\x47\xCA\x68\x4A\xCA\x69\x49\xCA\x73\x4A\xCA\x73\x54\xCB\x57\x6A\xCB\x57\x72\xCB\x63\x72\xCB\x6A\x49\xCB\x6A\x51\xCB\x6A\x53\xCB\x6A\x55\xCB\x6A\x57\xCB\x6A\x59\xCB\x6A\x63\xCB\x72\x44\xCB\x72\x46\xCB\x72\x49\xCB\x72\x72\xCB\x73\x47\xCB\x73\x49\xCB\x73\x51\xCB\x73\x53\xCB\x73\x55\xCB\x73\x63\xCB\x73\x65\xCB\x73\x68\xCB\x73\x70\xCB\x73\x72\xCB\x73\x73\xCC\x49\x41\xCC\x49\x42\xCC\x49\x44\xCC\x49\x46\xCC\x49\x48\xCC\x49\x54\xCC\x49\x56\xCC\x49\x57\xCC\x49\x58\xCC\x49\x63\xCC\x49\x64\xCC\x49\x65\xCC\x49\x66\xCC\x49\x67\xCC\x49\x69\xCC\x49\x70\xCC\x49\x72\xCC\x4A\x41\xCC\x4A\x62\xCC\x4A\x66\xCC\x51\x46\xCC\x51\x48\xCC\x51\x62\xCC\x51\x66\xCC\x51\x6A\xCC\x51\x73\xCC\x52\x45\xCC\x52\x53\xCC\x52\x54\xCC\x52\x58\xCC\x52\x59\xCC\x52\x63\xCC\x52\x64\xCC\x52\x68\xCC\x53\x44\xCC\x53\x46\xCC\x53\x48\xCC\x53\x4A\xCC\x53\x52\xCC\x53\x54\xCC\x53\x56\xCC\x53\x58\xCC\x53\x62\xCC\x53\x64\xCC\x53\x66\xCC\x54\x49\xCC\x54\x51\xCC\x54\x62\xCC\x55\x41\xCC\x55\x67\xCC\x55\x69\xCC\x56\x70\xCC\x62\x68\xCC\x62\x6A\xCC\x62\x71\xCC\x62\x73\xCC\x63\x42\xCC\x63\x44\xCC\x63\x46\xCC\x63\x48\xCC\x63\x4A\xCC\x63\x54\xCC\x63\x64\xCC\x63\x66\xCC\x63\x68\xCC\x63\x6A\xCC\x63\x71\xCC\x63\x73\xCC\x64\x42\xCC\x64\x47\xCC\x64\x49\xCC\x64\x51\xCC\x64\x53\xCC\x64\x56\xCC\x64\x58\xCC\x64\x62\xCC\x64\x64\xCC\x64\x66\xCC\x64\x68\xCC\x64\x6A\xCC\x64\x71\xCC\x64\x73\xCC\x65\x42\xCC\x65\x44\xCC\x65\x46\xCC\x65\x48\xCC\x65\x4A\xCC\x65\x52\xCC\x65\x56\xCC\x65\x58\xCC\x65\x64\xCC\x66\x46\xCC\x66\x66\xCC\x66\x68\xCC\x69\x47\xCC\x69\x48\xCC\x69\x49\xCC\x69\x53\xCC\x6A\x43\xCC\x6A\x53\xCC\x6A\x59\xCC\x6A\x70\xCC\x70\x47\xCC\x70\x51\xCC\x70\x64\xCC\x70\x69\xCC\x70\x72\xCC\x71\x42\xCC\x71\x44\xCC\x71\x4A\xCC\x71\x52\xCC\x71\x58\xCC\x71\x62\xCC\x73\x55\xCD\x57\x43\xCD\x57\x44\xCD\x57\x45\xCD\x57\x46\xCD\x57\x4A\xCD\x57\x51\xCD\x57\x53\xCD\x57\x54\xCD\x57\x58\xCD\x57\x70\xCD\x57\x71\xCD\x58\x41\xCD\x58\x42\xCD\x58\x43\xCD\x58\x45\xCD\x58\x47\xCD\x58\x49\xCD\x58\x65\xCD\x59\x43\xCD\x59\x64\xCD\x59\x66\xCD\x59\x68\xCD\x59\x6A\xCE\x41\x49\xCE\x41\x51\xCE\x41\x53\xCE\x41\x55\xCE\x41\x57\xCE\x41\x63\xCE\x41\x65\xCE\x41\x67\xCE\x41\x69\xCE\x41\x71\xDD\x51\x55\x42\xDD\x73\x4A\x72\xDD\x73\x59\x68\xDD\x73\x59\x6A\xDD\x73\x59\x71\xDD\x73\x62\x45\xDD\x73\x67\x49\xDD\x73\x67\x70\xDD\x73\x68\x6A\xDD\x73\x69\x6A\xDD\x73\x69\x73\xDD\x73\x6A\x43\xDD\x73\x73\x52\xDF\x63\x49\x44\xDF\x63\x49\x47\xDF\x71\x43\x4A\xDF\x71\x49\x49\xDF\x71\x49\x4A\xDF\x71\x49\x51\xDF\x71\x52\x6A\xDF\x71\x53\x68\xDF\x71\x53\x6A\xDF\x71\x53\x71\xDF\x71\x56\x47\xDF\x72\x41\x43\xDF\x72\x41\x47\xDF\x72\x41\x51\xDF\x72\x41\x59\xDF\x72\x41\x65\xDF\x72\x41\x69\xDF\x72\x41\x72\xDF\x72\x42\x43\xDF\x72\x42\x47\xDF\x72\x42\x51\xDF\x72\x42\x55\xDF\x72\x42\x59\xDF\x72\x42\x65\xDF\x72\x42\x69\xDF\x72\x42\x72\xDF\x72\x43\x43\xDF\x72\x43\x47\xDF\x72\x43\x59\xDF\x72\x44\x43\xDF\x72\x44\x51\xDF\x72\x44\x59\xDF\x72\x44\x69\xDF\x72\x45\x43\xDF\x72\x45\x59\xDF\x72\x45\x65\xDF\x72\x45\x69\xDF\x72\x46\x42\xDF\x72\x46\x44\xDF\x72\x46\x46\xDF\x72\x46\x48\xDF\x72\x46\x4A\xDF\x72\x46\x52" -# define EXTRA_CLOSING_UTF8_BRACKETS "\x5D\x6E\xBD\xD0\x80\x6A\x80\x52\xB8\x67\x48\xBA\x68\x6A\xBA\x68\x71\xBC\x63\x70\xCA\x41\x68\xCA\x41\x67\xCA\x41\x71\xCA\x41\x70\xCA\x42\x59\xCA\x42\x62\xCA\x42\x63\xCA\x42\x69\xCA\x42\x68\xCA\x43\x47\xCA\x43\x53\xCA\x44\x72\xCA\x45\x55\xCA\x53\x57\xCA\x53\x69\xCA\x53\x70\xCA\x53\x72\xCA\x54\x43\xCA\x54\x45\xCA\x54\x4A\xCA\x54\x52\xCA\x54\x57\xCA\x54\x59\xCA\x54\x70\xCA\x54\x71\xCA\x55\x48\xCA\x55\x54\xCA\x55\x57\xCA\x55\x69\xCA\x55\x70\xCA\x56\x41\xCA\x56\x45\xCA\x56\x47\xCC\x68\x57\xCC\x68\x58\xCA\x56\x66\xCA\x56\x69\xCA\x56\x71\xCA\x57\x52\xCA\x57\x53\xCA\x57\x54\xCA\x62\x46\xCA\x62\x48\xCA\x62\x4A\xCA\x62\x52\xCA\x62\x56\xCA\x62\x58\xCA\x62\x62\xCA\x62\x64\xCA\x62\x6A\xCA\x62\x71\xCA\x62\x73\xCA\x63\x42\xCA\x63\x44\xCA\x63\x46\xCA\x63\x48\xCA\x63\x4A\xCA\x63\x52\xCA\x64\x43\xCC\x65\x72\xCC\x66\x45\xCC\x66\x44\xCA\x64\x58\xCA\x65\x58\xCA\x65\x66\xCA\x65\x68\xCA\x65\x71\xCA\x65\x73\xCA\x66\x42\xCA\x66\x48\xCA\x66\x4A\xCA\x66\x69\xCA\x66\x6A\xCA\x66\x70\xCA\x66\x71\xCA\x66\x72\xCA\x67\x4A\xCA\x67\x52\xCA\x68\x52\xCA\x68\x51\xCA\x69\x48\xCA\x73\x51\xCA\x73\x55\xCB\x57\x69\xCB\x57\x70\xCB\x63\x73\xCB\x6A\x4A\xCB\x6A\x52\xCB\x6A\x54\xCB\x6A\x56\xCB\x6A\x58\xCB\x6A\x62\xCB\x6A\x64\xCB\x72\x45\xCB\x72\x47\xCB\x72\x4A\xCB\x72\x71\xCB\x73\x48\xCB\x73\x4A\xCB\x73\x52\xCB\x73\x54\xCB\x73\x56\xCC\x68\x59\xCB\x73\x64\xCB\x73\x67\xCB\x73\x6A\xCB\x73\x71\xCC\x68\x62\xCC\x68\x63\xCC\x68\x64\xCC\x49\x43\xCC\x68\x65\xCC\x49\x47\xCC\x49\x53\xCC\x49\x55\xCC\x68\x66\xCC\x68\x67\xCC\x68\x68\xCC\x68\x69\xCC\x68\x6A\xCC\x68\x70\xCC\x68\x71\xCC\x49\x68\xCC\x49\x6A\xCC\x49\x71\xCC\x49\x73\xCC\x68\x73\xCC\x4A\x65\xCC\x51\x47\xCC\x68\x72\xCC\x51\x59\xCC\x51\x65\xCC\x51\x69\xCC\x51\x72\xCC\x52\x43\xCC\x52\x51\xCC\x52\x52\xCC\x69\x41\xCC\x69\x42\xCC\x69\x52\xCC\x69\x43\xCC\x52\x6A\xCC\x53\x45\xCC\x53\x47\xCC\x53\x49\xCC\x53\x51\xCC\x53\x53\xCC\x53\x57\xCC\x53\x55\xCC\x53\x59\xCC\x53\x63\xCC\x53\x65\xCC\x53\x67\xCC\x54\x4A\xCC\x54\x52\xCC\x54\x63\xCC\x55\x42\xCC\x55\x68\xCC\x55\x6A\xCC\x56\x71\xCC\x62\x69\xCC\x62\x70\xCC\x62\x72\xCC\x63\x41\xCC\x63\x43\xCC\x63\x45\xCC\x63\x47\xCC\x63\x49\xCC\x63\x51\xCC\x63\x55\xCC\x63\x65\xCC\x63\x67\xCC\x63\x69\xCC\x63\x70\xCC\x63\x72\xCC\x64\x41\xCC\x64\x43\xCC\x64\x48\xCC\x64\x4A\xCC\x64\x52\xCC\x64\x54\xCC\x64\x57\xCC\x64\x59\xCC\x64\x63\xCC\x64\x65\xCC\x64\x67\xCC\x64\x69\xCC\x64\x70\xCC\x64\x72\xCC\x65\x41\xCC\x65\x43\xCC\x65\x45\xCC\x65\x47\xCC\x65\x49\xCC\x65\x51\xCC\x65\x53\xCC\x65\x57\xCC\x65\x59\xCC\x65\x65\xCA\x64\x52\xCC\x66\x67\xCC\x66\x69\xCC\x69\x46\xCC\x69\x4A\xCC\x69\x51\xCC\x52\x62\xCC\x6A\x41\xCC\x6A\x51\xCC\x6A\x57\xCC\x6A\x69\xCC\x70\x45\xCC\x70\x49\xCC\x67\x46\xCC\x70\x67\xCC\x70\x70\xCC\x71\x41\xCC\x71\x43\xCC\x71\x49\xCC\x71\x51\xCC\x71\x57\xCC\x71\x59\xCC\x73\x53\xCD\x57\x44\xCD\x57\x43\xCD\x57\x46\xCD\x57\x45\xCD\x57\x51\xCD\x57\x4A\xCD\x57\x54\xCD\x57\x53\xCD\x57\x57\xCD\x57\x71\xCD\x57\x70\xCD\x58\x42\xCD\x58\x41\xCD\x58\x44\xCD\x58\x46\xCD\x58\x48\xCD\x58\x4A\xCD\x58\x66\xCA\x41\x72\xCD\x59\x65\xCD\x59\x67\xCD\x59\x69\xCD\x59\x70\xCE\x41\x4A\xCE\x41\x52\xCE\x41\x54\xCE\x41\x56\xCE\x41\x58\xCE\x41\x64\xCE\x41\x66\xCE\x41\x68\xCE\x41\x6A\xCE\x41\x72\xDD\x51\x55\x43\xDD\x73\x4A\x73\xDD\x73\x59\x69\xDD\x73\x59\x70\xDD\x73\x59\x72\xDD\x73\x62\x46\xDD\x73\x67\x4A\xDD\x73\x67\x72\xDD\x73\x68\x71\xDD\x73\x69\x71\xDD\x73\x6A\x41\xDD\x73\x6A\x44\xDD\x73\x73\x4A\xDF\x63\x49\x43\xDF\x63\x49\x48\xDF\x71\x43\x49\xDF\x71\x52\x49\xDF\x71\x52\x4A\xDF\x71\x52\x51\xDF\x71\x52\x71\xDF\x71\x53\x67\xDF\x71\x53\x69\xDF\x71\x53\x70\xDF\x71\x56\x48\xDF\x72\x41\x41\xDF\x72\x41\x45\xDF\x72\x41\x49\xDF\x72\x41\x57\xDF\x72\x41\x63\xDF\x72\x41\x67\xDF\x72\x41\x70\xDF\x72\x42\x41\xDF\x72\x42\x45\xDF\x72\x42\x49\xDF\x72\x42\x53\xDF\x72\x42\x57\xDF\x72\x42\x63\xDF\x72\x42\x67\xDF\x72\x42\x70\xDF\x72\x43\x41\xDF\x72\x43\x45\xDF\x72\x43\x57\xDF\x72\x44\x41\xDF\x72\x44\x49\xDF\x72\x44\x57\xDF\x72\x44\x67\xDF\x72\x45\x41\xDF\x72\x45\x57\xDF\x72\x45\x63\xDF\x72\x45\x67\xDF\x72\x46\x41\xDF\x72\x46\x43\xDF\x72\x46\x47\xDF\x72\x46\x45\xDF\x72\x46\x49\xDF\x72\x46\x51" +# define EXTRA_OPENING_UTF8_BRACKETS "\x4D\x4C\xAD\xC0\x80\x52\x80\x6A\xBA\x68\x69\xBA\x68\x70\xBC\x63\x6A\xCA\x41\x67\xCA\x41\x68\xCA\x41\x70\xCA\x41\x71\xCA\x42\x64\xCA\x42\x65\xCA\x42\x66\xCA\x42\x68\xCA\x42\x69\xCA\x43\x46\xCA\x43\x54\xCA\x44\x71\xCA\x45\x54\xCA\x53\x59\xCA\x53\x6A\xCA\x53\x71\xCA\x54\x41\xCA\x54\x44\xCA\x54\x47\xCA\x54\x51\xCA\x54\x53\xCA\x54\x58\xCA\x54\x62\xCA\x55\x41\xCA\x55\x42\xCA\x55\x4A\xCA\x55\x56\xCA\x55\x59\xCA\x55\x6A\xCA\x55\x71\xCA\x56\x43\xCA\x56\x46\xCA\x56\x49\xCA\x56\x63\xCA\x56\x65\xCA\x56\x67\xCA\x56\x6A\xCA\x56\x72\xCA\x57\x49\xCA\x57\x4A\xCA\x57\x51\xCA\x62\x45\xCA\x62\x47\xCA\x62\x49\xCA\x62\x51\xCA\x62\x55\xCA\x62\x57\xCA\x62\x59\xCA\x62\x63\xCA\x62\x69\xCA\x62\x70\xCA\x62\x72\xCA\x63\x41\xCA\x63\x43\xCA\x63\x45\xCA\x63\x47\xCA\x63\x49\xCA\x63\x51\xCA\x64\x44\xCA\x64\x47\xCA\x64\x49\xCA\x64\x4A\xCA\x64\x57\xCA\x65\x57\xCA\x65\x65\xCA\x65\x67\xCA\x65\x70\xCA\x65\x72\xCA\x66\x41\xCA\x66\x47\xCA\x66\x49\xCA\x66\x59\xCA\x66\x62\xCA\x66\x63\xCA\x66\x65\xCA\x66\x66\xCA\x67\x49\xCA\x67\x51\xCA\x68\x47\xCA\x68\x4A\xCA\x69\x49\xCA\x73\x4A\xCA\x73\x54\xCB\x57\x6A\xCB\x57\x72\xCB\x63\x72\xCB\x6A\x49\xCB\x6A\x51\xCB\x6A\x53\xCB\x6A\x55\xCB\x6A\x57\xCB\x6A\x59\xCB\x6A\x63\xCB\x72\x44\xCB\x72\x46\xCB\x72\x49\xCB\x72\x72\xCB\x73\x47\xCB\x73\x49\xCB\x73\x51\xCB\x73\x53\xCB\x73\x55\xCB\x73\x63\xCB\x73\x65\xCB\x73\x68\xCB\x73\x70\xCB\x73\x72\xCB\x73\x73\xCC\x49\x41\xCC\x49\x42\xCC\x49\x44\xCC\x49\x46\xCC\x49\x48\xCC\x49\x54\xCC\x49\x56\xCC\x49\x57\xCC\x49\x58\xCC\x49\x63\xCC\x49\x64\xCC\x49\x65\xCC\x49\x66\xCC\x49\x67\xCC\x49\x69\xCC\x49\x70\xCC\x49\x72\xCC\x4A\x41\xCC\x4A\x62\xCC\x4A\x66\xCC\x51\x46\xCC\x51\x48\xCC\x51\x62\xCC\x51\x66\xCC\x51\x6A\xCC\x51\x73\xCC\x52\x45\xCC\x52\x53\xCC\x52\x54\xCC\x52\x58\xCC\x52\x59\xCC\x52\x63\xCC\x52\x64\xCC\x52\x68\xCC\x53\x44\xCC\x53\x46\xCC\x53\x48\xCC\x53\x4A\xCC\x53\x52\xCC\x53\x54\xCC\x53\x56\xCC\x53\x58\xCC\x53\x62\xCC\x53\x64\xCC\x53\x66\xCC\x54\x49\xCC\x54\x51\xCC\x54\x62\xCC\x55\x41\xCC\x55\x67\xCC\x55\x69\xCC\x56\x70\xCC\x62\x68\xCC\x62\x6A\xCC\x62\x71\xCC\x62\x73\xCC\x63\x42\xCC\x63\x44\xCC\x63\x46\xCC\x63\x48\xCC\x63\x4A\xCC\x63\x54\xCC\x63\x64\xCC\x63\x66\xCC\x63\x68\xCC\x63\x6A\xCC\x63\x71\xCC\x63\x73\xCC\x64\x42\xCC\x64\x47\xCC\x64\x49\xCC\x64\x51\xCC\x64\x53\xCC\x64\x56\xCC\x64\x58\xCC\x64\x62\xCC\x64\x64\xCC\x64\x66\xCC\x64\x68\xCC\x64\x6A\xCC\x64\x71\xCC\x64\x73\xCC\x65\x42\xCC\x65\x44\xCC\x65\x46\xCC\x65\x48\xCC\x65\x4A\xCC\x65\x52\xCC\x65\x56\xCC\x65\x58\xCC\x65\x64\xCC\x66\x46\xCC\x66\x66\xCC\x66\x68\xCC\x69\x47\xCC\x69\x48\xCC\x69\x49\xCC\x69\x53\xCC\x6A\x43\xCC\x6A\x53\xCC\x6A\x59\xCC\x6A\x70\xCC\x70\x47\xCC\x70\x51\xCC\x70\x64\xCC\x70\x69\xCC\x70\x72\xCC\x71\x42\xCC\x71\x44\xCC\x71\x4A\xCC\x71\x52\xCC\x71\x58\xCC\x71\x62\xCC\x73\x55\xCD\x57\x43\xCD\x57\x44\xCD\x57\x45\xCD\x57\x46\xCD\x57\x4A\xCD\x57\x51\xCD\x57\x53\xCD\x57\x54\xCD\x57\x58\xCD\x57\x70\xCD\x57\x71\xCD\x58\x41\xCD\x58\x42\xCD\x58\x43\xCD\x58\x45\xCD\x58\x47\xCD\x58\x49\xCD\x58\x65\xCD\x59\x43\xCD\x59\x64\xCD\x59\x66\xCD\x59\x68\xCD\x59\x6A\xCE\x41\x49\xCE\x41\x51\xCE\x41\x53\xCE\x41\x55\xCE\x41\x57\xCE\x41\x63\xCE\x41\x65\xCE\x41\x67\xCE\x41\x69\xCE\x41\x71\xDD\x51\x55\x42\xDD\x73\x4A\x72\xDD\x73\x59\x68\xDD\x73\x59\x6A\xDD\x73\x59\x71\xDD\x73\x62\x45\xDD\x73\x67\x49\xDD\x73\x67\x70\xDD\x73\x68\x6A\xDD\x73\x69\x6A\xDD\x73\x69\x73\xDD\x73\x6A\x43\xDD\x73\x73\x52\xDF\x63\x49\x44\xDF\x63\x49\x47\xDF\x71\x43\x4A\xDF\x71\x49\x49\xDF\x71\x49\x4A\xDF\x71\x49\x51\xDF\x71\x52\x6A\xDF\x71\x53\x68\xDF\x71\x53\x6A\xDF\x71\x53\x71\xDF\x71\x56\x47\xDF\x72\x41\x43\xDF\x72\x41\x47\xDF\x72\x41\x51\xDF\x72\x41\x59\xDF\x72\x41\x65\xDF\x72\x41\x69\xDF\x72\x41\x72\xDF\x72\x42\x43\xDF\x72\x42\x47\xDF\x72\x42\x51\xDF\x72\x42\x55\xDF\x72\x42\x59\xDF\x72\x42\x65\xDF\x72\x42\x69\xDF\x72\x42\x72\xDF\x72\x43\x43\xDF\x72\x43\x47\xDF\x72\x43\x59\xDF\x72\x44\x43\xDF\x72\x44\x51\xDF\x72\x44\x59\xDF\x72\x44\x69\xDF\x72\x45\x43\xDF\x72\x45\x59\xDF\x72\x45\x65\xDF\x72\x45\x69\xDF\x72\x46\x42\xDF\x72\x46\x44\xDF\x72\x46\x46\xDF\x72\x46\x48\xDF\x72\x46\x4A\xDF\x72\x46\x52" +# define EXTRA_CLOSING_UTF8_BRACKETS "\x5D\x6E\xBD\xD0\x80\x6A\x80\x52\xBA\x68\x6A\xBA\x68\x71\xBC\x63\x70\xCA\x41\x68\xCA\x41\x67\xCA\x41\x71\xCA\x41\x70\xCA\x42\x59\xCA\x42\x62\xCA\x42\x63\xCA\x42\x69\xCA\x42\x68\xCA\x43\x47\xCA\x43\x53\xCA\x44\x72\xCA\x45\x55\xCA\x53\x57\xCA\x53\x69\xCA\x53\x70\xCA\x53\x72\xCA\x54\x43\xCA\x54\x45\xCA\x54\x4A\xCA\x54\x52\xCA\x54\x57\xCA\x54\x59\xCA\x54\x70\xCA\x54\x71\xCA\x55\x48\xCA\x55\x54\xCA\x55\x57\xCA\x55\x69\xCA\x55\x70\xCA\x56\x41\xCA\x56\x45\xCA\x56\x47\xCC\x68\x57\xCC\x68\x58\xCA\x56\x66\xCA\x56\x69\xCA\x56\x71\xCA\x57\x52\xCA\x57\x53\xCA\x57\x54\xCA\x62\x46\xCA\x62\x48\xCA\x62\x4A\xCA\x62\x52\xCA\x62\x56\xCA\x62\x58\xCA\x62\x62\xCA\x62\x64\xCA\x62\x6A\xCA\x62\x71\xCA\x62\x73\xCA\x63\x42\xCA\x63\x44\xCA\x63\x46\xCA\x63\x48\xCA\x63\x4A\xCA\x63\x52\xCA\x64\x43\xCC\x65\x72\xCC\x66\x45\xCC\x66\x44\xCA\x64\x58\xCA\x65\x58\xCA\x65\x66\xCA\x65\x68\xCA\x65\x71\xCA\x65\x73\xCA\x66\x42\xCA\x66\x48\xCA\x66\x4A\xCA\x66\x69\xCA\x66\x6A\xCA\x66\x70\xCA\x66\x71\xCA\x66\x72\xCA\x67\x4A\xCA\x67\x52\xCA\x68\x52\xCA\x68\x51\xCA\x69\x48\xCA\x73\x51\xCA\x73\x55\xCB\x57\x69\xCB\x57\x70\xCB\x63\x73\xCB\x6A\x4A\xCB\x6A\x52\xCB\x6A\x54\xCB\x6A\x56\xCB\x6A\x58\xCB\x6A\x62\xCB\x6A\x64\xCB\x72\x45\xCB\x72\x47\xCB\x72\x4A\xCB\x72\x71\xCB\x73\x48\xCB\x73\x4A\xCB\x73\x52\xCB\x73\x54\xCB\x73\x56\xCC\x68\x59\xCB\x73\x64\xCB\x73\x67\xCB\x73\x6A\xCB\x73\x71\xCC\x68\x62\xCC\x68\x63\xCC\x68\x64\xCC\x49\x43\xCC\x68\x65\xCC\x49\x47\xCC\x49\x53\xCC\x49\x55\xCC\x68\x66\xCC\x68\x67\xCC\x68\x68\xCC\x68\x69\xCC\x68\x6A\xCC\x68\x70\xCC\x68\x71\xCC\x49\x68\xCC\x49\x6A\xCC\x49\x71\xCC\x49\x73\xCC\x68\x73\xCC\x4A\x65\xCC\x51\x47\xCC\x68\x72\xCC\x51\x59\xCC\x51\x65\xCC\x51\x69\xCC\x51\x72\xCC\x52\x43\xCC\x52\x51\xCC\x52\x52\xCC\x69\x41\xCC\x69\x42\xCC\x69\x52\xCC\x69\x43\xCC\x52\x6A\xCC\x53\x45\xCC\x53\x47\xCC\x53\x49\xCC\x53\x51\xCC\x53\x53\xCC\x53\x57\xCC\x53\x55\xCC\x53\x59\xCC\x53\x63\xCC\x53\x65\xCC\x53\x67\xCC\x54\x4A\xCC\x54\x52\xCC\x54\x63\xCC\x55\x42\xCC\x55\x68\xCC\x55\x6A\xCC\x56\x71\xCC\x62\x69\xCC\x62\x70\xCC\x62\x72\xCC\x63\x41\xCC\x63\x43\xCC\x63\x45\xCC\x63\x47\xCC\x63\x49\xCC\x63\x51\xCC\x63\x55\xCC\x63\x65\xCC\x63\x67\xCC\x63\x69\xCC\x63\x70\xCC\x63\x72\xCC\x64\x41\xCC\x64\x43\xCC\x64\x48\xCC\x64\x4A\xCC\x64\x52\xCC\x64\x54\xCC\x64\x57\xCC\x64\x59\xCC\x64\x63\xCC\x64\x65\xCC\x64\x67\xCC\x64\x69\xCC\x64\x70\xCC\x64\x72\xCC\x65\x41\xCC\x65\x43\xCC\x65\x45\xCC\x65\x47\xCC\x65\x49\xCC\x65\x51\xCC\x65\x53\xCC\x65\x57\xCC\x65\x59\xCC\x65\x65\xCA\x64\x52\xCC\x66\x67\xCC\x66\x69\xCC\x69\x46\xCC\x69\x4A\xCC\x69\x51\xCC\x52\x62\xCC\x6A\x41\xCC\x6A\x51\xCC\x6A\x57\xCC\x6A\x69\xCC\x70\x45\xCC\x70\x49\xCC\x67\x46\xCC\x70\x67\xCC\x70\x70\xCC\x71\x41\xCC\x71\x43\xCC\x71\x49\xCC\x71\x51\xCC\x71\x57\xCC\x71\x59\xCC\x73\x53\xCD\x57\x44\xCD\x57\x43\xCD\x57\x46\xCD\x57\x45\xCD\x57\x51\xCD\x57\x4A\xCD\x57\x54\xCD\x57\x53\xCD\x57\x57\xCD\x57\x71\xCD\x57\x70\xCD\x58\x42\xCD\x58\x41\xCD\x58\x44\xCD\x58\x46\xCD\x58\x48\xCD\x58\x4A\xCD\x58\x66\xCA\x41\x72\xCD\x59\x65\xCD\x59\x67\xCD\x59\x69\xCD\x59\x70\xCE\x41\x4A\xCE\x41\x52\xCE\x41\x54\xCE\x41\x56\xCE\x41\x58\xCE\x41\x64\xCE\x41\x66\xCE\x41\x68\xCE\x41\x6A\xCE\x41\x72\xDD\x51\x55\x43\xDD\x73\x4A\x73\xDD\x73\x59\x69\xDD\x73\x59\x70\xDD\x73\x59\x72\xDD\x73\x62\x46\xDD\x73\x67\x4A\xDD\x73\x67\x72\xDD\x73\x68\x71\xDD\x73\x69\x71\xDD\x73\x6A\x41\xDD\x73\x6A\x44\xDD\x73\x73\x4A\xDF\x63\x49\x43\xDF\x63\x49\x48\xDF\x71\x43\x49\xDF\x71\x52\x49\xDF\x71\x52\x4A\xDF\x71\x52\x51\xDF\x71\x52\x71\xDF\x71\x53\x67\xDF\x71\x53\x69\xDF\x71\x53\x70\xDF\x71\x56\x48\xDF\x72\x41\x41\xDF\x72\x41\x45\xDF\x72\x41\x49\xDF\x72\x41\x57\xDF\x72\x41\x63\xDF\x72\x41\x67\xDF\x72\x41\x70\xDF\x72\x42\x41\xDF\x72\x42\x45\xDF\x72\x42\x49\xDF\x72\x42\x53\xDF\x72\x42\x57\xDF\x72\x42\x63\xDF\x72\x42\x67\xDF\x72\x42\x70\xDF\x72\x43\x41\xDF\x72\x43\x45\xDF\x72\x43\x57\xDF\x72\x44\x41\xDF\x72\x44\x49\xDF\x72\x44\x57\xDF\x72\x44\x67\xDF\x72\x45\x41\xDF\x72\x45\x57\xDF\x72\x45\x63\xDF\x72\x45\x67\xDF\x72\x46\x41\xDF\x72\x46\x43\xDF\x72\x46\x47\xDF\x72\x46\x45\xDF\x72\x46\x49\xDF\x72\x46\x51" /* And not in UTF-8 */ # define EXTRA_OPENING_NON_UTF8_BRACKETS "\x4D\x4C\xAD\xC0\x8A\x8B" # define EXTRA_CLOSING_NON_UTF8_BRACKETS "\x5D\x6E\xBD\xD0\x8B\x8A" /* And what's deprecated */ -# define DEPRECATED_OPENING_UTF8_BRACKETS "\x80\x52\x80\x6A\x80\x6A\xB8\x67\x47\xB8\x67\x48\xBA\x68\x69\xBA\x68\x6A\xBA\x68\x70\xBA\x68\x71\xBC\x63\x6A\xBC\x63\x70\xCA\x41\x67\xCA\x41\x68\xCA\x41\x68\xCA\x41\x70\xCA\x41\x71\xCA\x41\x71\xCA\x42\x64\xCA\x42\x59\xCA\x42\x65\xCA\x42\x62\xCA\x42\x66\xCA\x42\x63\xCA\x42\x68\xCA\x42\x69\xCA\x42\x69\xCA\x43\x46\xCA\x43\x47\xCA\x43\x54\xCA\x43\x53\xCA\x44\x71\xCA\x44\x72\xCA\x45\x54\xCA\x45\x55\xCA\x53\x59\xCA\x53\x57\xCA\x53\x6A\xCA\x53\x69\xCA\x53\x71\xCA\x53\x70\xCA\x54\x41\xCA\x53\x72\xCA\x54\x44\xCA\x54\x43\xCA\x54\x47\xCA\x54\x45\xCA\x54\x51\xCA\x54\x4A\xCA\x54\x53\xCA\x54\x52\xCA\x54\x58\xCA\x54\x57\xCA\x54\x62\xCA\x54\x59\xCA\x55\x41\xCA\x54\x70\xCA\x55\x42\xCA\x54\x71\xCA\x55\x4A\xCA\x55\x48\xCA\x55\x56\xCA\x55\x54\xCA\x55\x59\xCA\x55\x57\xCA\x55\x6A\xCA\x55\x69\xCA\x55\x71\xCA\x55\x70\xCA\x56\x43\xCA\x56\x41\xCA\x56\x46\xCA\x56\x45\xCA\x56\x49\xCA\x56\x47\xCA\x56\x63\xCC\x68\x57\xCA\x56\x65\xCC\x68\x58\xCA\x56\x67\xCA\x56\x66\xCA\x56\x6A\xCA\x56\x69\xCA\x56\x72\xCA\x56\x71\xCA\x57\x49\xCA\x57\x52\xCA\x57\x4A\xCA\x57\x53\xCA\x57\x51\xCA\x57\x54\xCA\x62\x45\xCA\x62\x46\xCA\x62\x47\xCA\x62\x48\xCA\x62\x49\xCA\x62\x4A\xCA\x62\x51\xCA\x62\x52\xCA\x62\x55\xCA\x62\x56\xCA\x62\x57\xCA\x62\x58\xCA\x62\x59\xCA\x62\x62\xCA\x62\x63\xCA\x62\x64\xCA\x62\x69\xCA\x62\x6A\xCA\x62\x70\xCA\x62\x71\xCA\x62\x72\xCA\x62\x73\xCA\x63\x41\xCA\x63\x42\xCA\x63\x43\xCA\x63\x44\xCA\x63\x45\xCA\x63\x46\xCA\x63\x47\xCA\x63\x48\xCA\x63\x49\xCA\x63\x4A\xCA\x63\x51\xCA\x63\x52\xCA\x64\x44\xCA\x64\x43\xCA\x64\x47\xCC\x65\x72\xCA\x64\x49\xCC\x66\x45\xCA\x64\x4A\xCC\x66\x44\xCA\x64\x57\xCA\x64\x58\xCA\x65\x57\xCA\x65\x58\xCA\x65\x65\xCA\x65\x66\xCA\x65\x67\xCA\x65\x68\xCA\x65\x70\xCA\x65\x71\xCA\x65\x72\xCA\x65\x73\xCA\x66\x41\xCA\x66\x42\xCA\x66\x47\xCA\x66\x48\xCA\x66\x49\xCA\x66\x4A\xCA\x66\x59\xCA\x66\x69\xCA\x66\x62\xCA\x66\x6A\xCA\x66\x63\xCA\x66\x70\xCA\x66\x65\xCA\x66\x71\xCA\x66\x66\xCA\x66\x72\xCA\x67\x49\xCA\x67\x4A\xCA\x67\x51\xCA\x67\x52\xCA\x68\x47\xCA\x68\x52\xCA\x68\x4A\xCA\x68\x51\xCA\x69\x49\xCA\x69\x48\xCA\x73\x4A\xCA\x73\x51\xCA\x73\x54\xCA\x73\x55\xCB\x57\x6A\xCB\x57\x69\xCB\x57\x72\xCB\x57\x70\xCB\x63\x72\xCB\x63\x73\xCB\x6A\x49\xCB\x6A\x4A\xCB\x6A\x51\xCB\x6A\x52\xCB\x6A\x53\xCB\x6A\x54\xCB\x6A\x55\xCB\x6A\x56\xCB\x6A\x57\xCB\x6A\x58\xCB\x6A\x59\xCB\x6A\x62\xCB\x6A\x63\xCB\x6A\x64\xCB\x72\x44\xCB\x72\x45\xCB\x72\x46\xCB\x72\x47\xCB\x72\x49\xCB\x72\x4A\xCB\x72\x72\xCB\x72\x71\xCB\x73\x47\xCB\x73\x48\xCB\x73\x49\xCB\x73\x4A\xCB\x73\x51\xCB\x73\x52\xCB\x73\x53\xCB\x73\x54\xCB\x73\x55\xCB\x73\x56\xCB\x73\x63\xCC\x68\x59\xCB\x73\x65\xCB\x73\x64\xCB\x73\x68\xCB\x73\x67\xCB\x73\x70\xCB\x73\x6A\xCB\x73\x72\xCB\x73\x71\xCB\x73\x73\xCC\x68\x62\xCC\x49\x41\xCC\x68\x63\xCC\x49\x42\xCC\x68\x64\xCC\x49\x44\xCC\x49\x43\xCC\x49\x46\xCC\x68\x65\xCC\x49\x48\xCC\x49\x47\xCC\x49\x54\xCC\x49\x53\xCC\x49\x56\xCC\x49\x55\xCC\x49\x57\xCC\x68\x66\xCC\x49\x58\xCC\x68\x67\xCC\x49\x63\xCC\x68\x68\xCC\x49\x64\xCC\x68\x69\xCC\x49\x65\xCC\x68\x6A\xCC\x49\x66\xCC\x68\x70\xCC\x49\x67\xCC\x68\x71\xCC\x49\x69\xCC\x49\x68\xCC\x49\x70\xCC\x49\x6A\xCC\x49\x72\xCC\x49\x71\xCC\x4A\x41\xCC\x49\x73\xCC\x4A\x62\xCC\x68\x73\xCC\x4A\x66\xCC\x4A\x65\xCC\x51\x46\xCC\x51\x47\xCC\x51\x48\xCC\x68\x72\xCC\x51\x62\xCC\x51\x59\xCC\x51\x66\xCC\x51\x65\xCC\x51\x6A\xCC\x51\x69\xCC\x51\x73\xCC\x51\x72\xCC\x52\x45\xCC\x52\x43\xCC\x52\x53\xCC\x52\x51\xCC\x52\x54\xCC\x52\x52\xCC\x52\x58\xCC\x69\x41\xCC\x52\x59\xCC\x69\x42\xCC\x52\x63\xCC\x69\x52\xCC\x52\x64\xCC\x69\x43\xCC\x52\x68\xCC\x52\x6A\xCC\x53\x44\xCC\x53\x45\xCC\x53\x46\xCC\x53\x47\xCC\x53\x48\xCC\x53\x49\xCC\x53\x4A\xCC\x53\x51\xCC\x53\x52\xCC\x53\x53\xCC\x53\x54\xCC\x53\x57\xCC\x53\x56\xCC\x53\x55\xCC\x53\x58\xCC\x53\x59\xCC\x53\x62\xCC\x53\x63\xCC\x53\x64\xCC\x53\x65\xCC\x53\x66\xCC\x53\x67\xCC\x54\x49\xCC\x54\x4A\xCC\x54\x51\xCC\x54\x52\xCC\x54\x62\xCC\x54\x63\xCC\x55\x41\xCC\x55\x42\xCC\x55\x67\xCC\x55\x68\xCC\x55\x69\xCC\x55\x6A\xCC\x56\x70\xCC\x56\x71\xCC\x62\x68\xCC\x62\x69\xCC\x62\x6A\xCC\x62\x70\xCC\x62\x71\xCC\x62\x72\xCC\x62\x73\xCC\x63\x41\xCC\x63\x42\xCC\x63\x43\xCC\x63\x44\xCC\x63\x45\xCC\x63\x46\xCC\x63\x47\xCC\x63\x48\xCC\x63\x49\xCC\x63\x4A\xCC\x63\x51\xCC\x63\x54\xCC\x63\x55\xCC\x63\x64\xCC\x63\x65\xCC\x63\x66\xCC\x63\x67\xCC\x63\x68\xCC\x63\x69\xCC\x63\x6A\xCC\x63\x70\xCC\x63\x71\xCC\x63\x72\xCC\x63\x73\xCC\x64\x41\xCC\x64\x42\xCC\x64\x43\xCC\x64\x47\xCC\x64\x48\xCC\x64\x49\xCC\x64\x4A\xCC\x64\x51\xCC\x64\x52\xCC\x64\x53\xCC\x64\x54\xCC\x64\x56\xCC\x64\x57\xCC\x64\x58\xCC\x64\x59\xCC\x64\x62\xCC\x64\x63\xCC\x64\x64\xCC\x64\x65\xCC\x64\x66\xCC\x64\x67\xCC\x64\x68\xCC\x64\x69\xCC\x64\x6A\xCC\x64\x70\xCC\x64\x71\xCC\x64\x72\xCC\x64\x73\xCC\x65\x41\xCC\x65\x42\xCC\x65\x43\xCC\x65\x44\xCC\x65\x45\xCC\x65\x46\xCC\x65\x47\xCC\x65\x48\xCC\x65\x49\xCC\x65\x4A\xCC\x65\x51\xCC\x65\x52\xCC\x65\x53\xCC\x65\x56\xCC\x65\x57\xCC\x65\x58\xCC\x65\x59\xCC\x65\x64\xCC\x65\x65\xCC\x66\x46\xCA\x64\x52\xCC\x66\x66\xCC\x66\x67\xCC\x66\x68\xCC\x66\x69\xCC\x69\x47\xCC\x69\x46\xCC\x69\x48\xCC\x69\x4A\xCC\x69\x49\xCC\x69\x51\xCC\x69\x53\xCC\x52\x62\xCC\x6A\x43\xCC\x6A\x41\xCC\x6A\x53\xCC\x6A\x51\xCC\x6A\x59\xCC\x6A\x57\xCC\x6A\x70\xCC\x6A\x69\xCC\x70\x47\xCC\x70\x45\xCC\x70\x51\xCC\x70\x49\xCC\x70\x64\xCC\x67\x46\xCC\x70\x69\xCC\x70\x67\xCC\x70\x72\xCC\x70\x70\xCC\x71\x42\xCC\x71\x41\xCC\x71\x44\xCC\x71\x43\xCC\x71\x4A\xCC\x71\x49\xCC\x71\x52\xCC\x71\x51\xCC\x71\x58\xCC\x71\x57\xCC\x71\x62\xCC\x71\x59\xCC\x73\x55\xCC\x73\x53\xCD\x57\x43\xCD\x57\x44\xCD\x57\x44\xCD\x57\x45\xCD\x57\x46\xCD\x57\x46\xCD\x57\x4A\xCD\x57\x51\xCD\x57\x51\xCD\x57\x53\xCD\x57\x54\xCD\x57\x54\xCD\x57\x58\xCD\x57\x57\xCD\x57\x70\xCD\x57\x71\xCD\x57\x71\xCD\x58\x41\xCD\x58\x42\xCD\x58\x42\xCD\x58\x43\xCD\x58\x44\xCD\x58\x45\xCD\x58\x46\xCD\x58\x47\xCD\x58\x48\xCD\x58\x49\xCD\x58\x4A\xCD\x58\x65\xCD\x58\x66\xCD\x59\x43\xCA\x41\x72\xCD\x59\x64\xCD\x59\x65\xCD\x59\x66\xCD\x59\x67\xCD\x59\x68\xCD\x59\x69\xCD\x59\x6A\xCD\x59\x70\xCE\x41\x49\xCE\x41\x4A\xCE\x41\x51\xCE\x41\x52\xCE\x41\x53\xCE\x41\x54\xCE\x41\x55\xCE\x41\x56\xCE\x41\x57\xCE\x41\x58\xCE\x41\x63\xCE\x41\x64\xCE\x41\x65\xCE\x41\x66\xCE\x41\x67\xCE\x41\x68\xCE\x41\x69\xCE\x41\x6A\xCE\x41\x71\xCE\x41\x72\xDD\x51\x55\x42\xDD\x51\x55\x43\xDD\x73\x4A\x72\xDD\x73\x4A\x73\xDD\x73\x59\x68\xDD\x73\x59\x69\xDD\x73\x59\x6A\xDD\x73\x59\x70\xDD\x73\x59\x71\xDD\x73\x59\x72\xDD\x73\x62\x45\xDD\x73\x62\x46\xDD\x73\x67\x49\xDD\x73\x67\x4A\xDD\x73\x67\x70\xDD\x73\x67\x72\xDD\x73\x68\x6A\xDD\x73\x68\x71\xDD\x73\x69\x6A\xDD\x73\x69\x71\xDD\x73\x69\x73\xDD\x73\x6A\x41\xDD\x73\x6A\x43\xDD\x73\x6A\x44\xDD\x73\x73\x52\xDD\x73\x73\x4A\xDF\x63\x49\x44\xDF\x63\x49\x43\xDF\x63\x49\x47\xDF\x63\x49\x48\xDF\x71\x43\x4A\xDF\x71\x43\x49\xDF\x71\x49\x49\xDF\x71\x52\x49\xDF\x71\x49\x4A\xDF\x71\x52\x4A\xDF\x71\x49\x51\xDF\x71\x52\x51\xDF\x71\x52\x6A\xDF\x71\x52\x71\xDF\x71\x53\x68\xDF\x71\x53\x67\xDF\x71\x53\x6A\xDF\x71\x53\x69\xDF\x71\x53\x71\xDF\x71\x53\x70\xDF\x71\x56\x47\xDF\x71\x56\x48\xDF\x72\x41\x43\xDF\x72\x41\x41\xDF\x72\x41\x47\xDF\x72\x41\x45\xDF\x72\x41\x51\xDF\x72\x41\x49\xDF\x72\x41\x59\xDF\x72\x41\x57\xDF\x72\x41\x65\xDF\x72\x41\x63\xDF\x72\x41\x69\xDF\x72\x41\x67\xDF\x72\x41\x72\xDF\x72\x41\x70\xDF\x72\x42\x43\xDF\x72\x42\x41\xDF\x72\x42\x47\xDF\x72\x42\x45\xDF\x72\x42\x51\xDF\x72\x42\x49\xDF\x72\x42\x55\xDF\x72\x42\x53\xDF\x72\x42\x59\xDF\x72\x42\x57\xDF\x72\x42\x65\xDF\x72\x42\x63\xDF\x72\x42\x69\xDF\x72\x42\x67\xDF\x72\x42\x72\xDF\x72\x42\x70\xDF\x72\x43\x43\xDF\x72\x43\x41\xDF\x72\x43\x47\xDF\x72\x43\x45\xDF\x72\x43\x59\xDF\x72\x43\x57\xDF\x72\x44\x43\xDF\x72\x44\x41\xDF\x72\x44\x51\xDF\x72\x44\x49\xDF\x72\x44\x59\xDF\x72\x44\x57\xDF\x72\x44\x69\xDF\x72\x44\x67\xDF\x72\x45\x43\xDF\x72\x45\x41\xDF\x72\x45\x59\xDF\x72\x45\x57\xDF\x72\x45\x65\xDF\x72\x45\x63\xDF\x72\x45\x69\xDF\x72\x45\x67\xDF\x72\x46\x42\xDF\x72\x46\x41\xDF\x72\x46\x44\xDF\x72\x46\x43\xDF\x72\x46\x46\xDF\x72\x46\x47\xDF\x72\x46\x48\xDF\x72\x46\x45\xDF\x72\x46\x4A\xDF\x72\x46\x49\xDF\x72\x46\x52\xDF\x72\x46\x51" +# define DEPRECATED_OPENING_UTF8_BRACKETS "\x80\x52\x80\x6A\x80\x6A\xBA\x68\x69\xBA\x68\x6A\xBA\x68\x70\xBA\x68\x71\xBC\x63\x6A\xBC\x63\x70\xCA\x41\x67\xCA\x41\x68\xCA\x41\x68\xCA\x41\x70\xCA\x41\x71\xCA\x41\x71\xCA\x42\x64\xCA\x42\x59\xCA\x42\x65\xCA\x42\x62\xCA\x42\x66\xCA\x42\x63\xCA\x42\x68\xCA\x42\x69\xCA\x42\x69\xCA\x43\x46\xCA\x43\x47\xCA\x43\x54\xCA\x43\x53\xCA\x44\x71\xCA\x44\x72\xCA\x45\x54\xCA\x45\x55\xCA\x53\x59\xCA\x53\x57\xCA\x53\x6A\xCA\x53\x69\xCA\x53\x71\xCA\x53\x70\xCA\x54\x41\xCA\x53\x72\xCA\x54\x44\xCA\x54\x43\xCA\x54\x47\xCA\x54\x45\xCA\x54\x51\xCA\x54\x4A\xCA\x54\x53\xCA\x54\x52\xCA\x54\x58\xCA\x54\x57\xCA\x54\x62\xCA\x54\x59\xCA\x55\x41\xCA\x54\x70\xCA\x55\x42\xCA\x54\x71\xCA\x55\x4A\xCA\x55\x48\xCA\x55\x56\xCA\x55\x54\xCA\x55\x59\xCA\x55\x57\xCA\x55\x6A\xCA\x55\x69\xCA\x55\x71\xCA\x55\x70\xCA\x56\x43\xCA\x56\x41\xCA\x56\x46\xCA\x56\x45\xCA\x56\x49\xCA\x56\x47\xCA\x56\x63\xCC\x68\x57\xCA\x56\x65\xCC\x68\x58\xCA\x56\x67\xCA\x56\x66\xCA\x56\x6A\xCA\x56\x69\xCA\x56\x72\xCA\x56\x71\xCA\x57\x49\xCA\x57\x52\xCA\x57\x4A\xCA\x57\x53\xCA\x57\x51\xCA\x57\x54\xCA\x62\x45\xCA\x62\x46\xCA\x62\x47\xCA\x62\x48\xCA\x62\x49\xCA\x62\x4A\xCA\x62\x51\xCA\x62\x52\xCA\x62\x55\xCA\x62\x56\xCA\x62\x57\xCA\x62\x58\xCA\x62\x59\xCA\x62\x62\xCA\x62\x63\xCA\x62\x64\xCA\x62\x69\xCA\x62\x6A\xCA\x62\x70\xCA\x62\x71\xCA\x62\x72\xCA\x62\x73\xCA\x63\x41\xCA\x63\x42\xCA\x63\x43\xCA\x63\x44\xCA\x63\x45\xCA\x63\x46\xCA\x63\x47\xCA\x63\x48\xCA\x63\x49\xCA\x63\x4A\xCA\x63\x51\xCA\x63\x52\xCA\x64\x44\xCA\x64\x43\xCA\x64\x47\xCC\x65\x72\xCA\x64\x49\xCC\x66\x45\xCA\x64\x4A\xCC\x66\x44\xCA\x64\x57\xCA\x64\x58\xCA\x65\x57\xCA\x65\x58\xCA\x65\x65\xCA\x65\x66\xCA\x65\x67\xCA\x65\x68\xCA\x65\x70\xCA\x65\x71\xCA\x65\x72\xCA\x65\x73\xCA\x66\x41\xCA\x66\x42\xCA\x66\x47\xCA\x66\x48\xCA\x66\x49\xCA\x66\x4A\xCA\x66\x59\xCA\x66\x69\xCA\x66\x62\xCA\x66\x6A\xCA\x66\x63\xCA\x66\x70\xCA\x66\x65\xCA\x66\x71\xCA\x66\x66\xCA\x66\x72\xCA\x67\x49\xCA\x67\x4A\xCA\x67\x51\xCA\x67\x52\xCA\x68\x47\xCA\x68\x52\xCA\x68\x4A\xCA\x68\x51\xCA\x69\x49\xCA\x69\x48\xCA\x73\x4A\xCA\x73\x51\xCA\x73\x54\xCA\x73\x55\xCB\x57\x6A\xCB\x57\x69\xCB\x57\x72\xCB\x57\x70\xCB\x63\x72\xCB\x63\x73\xCB\x6A\x49\xCB\x6A\x4A\xCB\x6A\x51\xCB\x6A\x52\xCB\x6A\x53\xCB\x6A\x54\xCB\x6A\x55\xCB\x6A\x56\xCB\x6A\x57\xCB\x6A\x58\xCB\x6A\x59\xCB\x6A\x62\xCB\x6A\x63\xCB\x6A\x64\xCB\x72\x44\xCB\x72\x45\xCB\x72\x46\xCB\x72\x47\xCB\x72\x49\xCB\x72\x4A\xCB\x72\x72\xCB\x72\x71\xCB\x73\x47\xCB\x73\x48\xCB\x73\x49\xCB\x73\x4A\xCB\x73\x51\xCB\x73\x52\xCB\x73\x53\xCB\x73\x54\xCB\x73\x55\xCB\x73\x56\xCB\x73\x63\xCC\x68\x59\xCB\x73\x65\xCB\x73\x64\xCB\x73\x68\xCB\x73\x67\xCB\x73\x70\xCB\x73\x6A\xCB\x73\x72\xCB\x73\x71\xCB\x73\x73\xCC\x68\x62\xCC\x49\x41\xCC\x68\x63\xCC\x49\x42\xCC\x68\x64\xCC\x49\x44\xCC\x49\x43\xCC\x49\x46\xCC\x68\x65\xCC\x49\x48\xCC\x49\x47\xCC\x49\x54\xCC\x49\x53\xCC\x49\x56\xCC\x49\x55\xCC\x49\x57\xCC\x68\x66\xCC\x49\x58\xCC\x68\x67\xCC\x49\x63\xCC\x68\x68\xCC\x49\x64\xCC\x68\x69\xCC\x49\x65\xCC\x68\x6A\xCC\x49\x66\xCC\x68\x70\xCC\x49\x67\xCC\x68\x71\xCC\x49\x69\xCC\x49\x68\xCC\x49\x70\xCC\x49\x6A\xCC\x49\x72\xCC\x49\x71\xCC\x4A\x41\xCC\x49\x73\xCC\x4A\x62\xCC\x68\x73\xCC\x4A\x66\xCC\x4A\x65\xCC\x51\x46\xCC\x51\x47\xCC\x51\x48\xCC\x68\x72\xCC\x51\x62\xCC\x51\x59\xCC\x51\x66\xCC\x51\x65\xCC\x51\x6A\xCC\x51\x69\xCC\x51\x73\xCC\x51\x72\xCC\x52\x45\xCC\x52\x43\xCC\x52\x53\xCC\x52\x51\xCC\x52\x54\xCC\x52\x52\xCC\x52\x58\xCC\x69\x41\xCC\x52\x59\xCC\x69\x42\xCC\x52\x63\xCC\x69\x52\xCC\x52\x64\xCC\x69\x43\xCC\x52\x68\xCC\x52\x6A\xCC\x53\x44\xCC\x53\x45\xCC\x53\x46\xCC\x53\x47\xCC\x53\x48\xCC\x53\x49\xCC\x53\x4A\xCC\x53\x51\xCC\x53\x52\xCC\x53\x53\xCC\x53\x54\xCC\x53\x57\xCC\x53\x56\xCC\x53\x55\xCC\x53\x58\xCC\x53\x59\xCC\x53\x62\xCC\x53\x63\xCC\x53\x64\xCC\x53\x65\xCC\x53\x66\xCC\x53\x67\xCC\x54\x49\xCC\x54\x4A\xCC\x54\x51\xCC\x54\x52\xCC\x54\x62\xCC\x54\x63\xCC\x55\x41\xCC\x55\x42\xCC\x55\x67\xCC\x55\x68\xCC\x55\x69\xCC\x55\x6A\xCC\x56\x70\xCC\x56\x71\xCC\x62\x68\xCC\x62\x69\xCC\x62\x6A\xCC\x62\x70\xCC\x62\x71\xCC\x62\x72\xCC\x62\x73\xCC\x63\x41\xCC\x63\x42\xCC\x63\x43\xCC\x63\x44\xCC\x63\x45\xCC\x63\x46\xCC\x63\x47\xCC\x63\x48\xCC\x63\x49\xCC\x63\x4A\xCC\x63\x51\xCC\x63\x54\xCC\x63\x55\xCC\x63\x64\xCC\x63\x65\xCC\x63\x66\xCC\x63\x67\xCC\x63\x68\xCC\x63\x69\xCC\x63\x6A\xCC\x63\x70\xCC\x63\x71\xCC\x63\x72\xCC\x63\x73\xCC\x64\x41\xCC\x64\x42\xCC\x64\x43\xCC\x64\x47\xCC\x64\x48\xCC\x64\x49\xCC\x64\x4A\xCC\x64\x51\xCC\x64\x52\xCC\x64\x53\xCC\x64\x54\xCC\x64\x56\xCC\x64\x57\xCC\x64\x58\xCC\x64\x59\xCC\x64\x62\xCC\x64\x63\xCC\x64\x64\xCC\x64\x65\xCC\x64\x66\xCC\x64\x67\xCC\x64\x68\xCC\x64\x69\xCC\x64\x6A\xCC\x64\x70\xCC\x64\x71\xCC\x64\x72\xCC\x64\x73\xCC\x65\x41\xCC\x65\x42\xCC\x65\x43\xCC\x65\x44\xCC\x65\x45\xCC\x65\x46\xCC\x65\x47\xCC\x65\x48\xCC\x65\x49\xCC\x65\x4A\xCC\x65\x51\xCC\x65\x52\xCC\x65\x53\xCC\x65\x56\xCC\x65\x57\xCC\x65\x58\xCC\x65\x59\xCC\x65\x64\xCC\x65\x65\xCC\x66\x46\xCA\x64\x52\xCC\x66\x66\xCC\x66\x67\xCC\x66\x68\xCC\x66\x69\xCC\x69\x47\xCC\x69\x46\xCC\x69\x48\xCC\x69\x4A\xCC\x69\x49\xCC\x69\x51\xCC\x69\x53\xCC\x52\x62\xCC\x6A\x43\xCC\x6A\x41\xCC\x6A\x53\xCC\x6A\x51\xCC\x6A\x59\xCC\x6A\x57\xCC\x6A\x70\xCC\x6A\x69\xCC\x70\x47\xCC\x70\x45\xCC\x70\x51\xCC\x70\x49\xCC\x70\x64\xCC\x67\x46\xCC\x70\x69\xCC\x70\x67\xCC\x70\x72\xCC\x70\x70\xCC\x71\x42\xCC\x71\x41\xCC\x71\x44\xCC\x71\x43\xCC\x71\x4A\xCC\x71\x49\xCC\x71\x52\xCC\x71\x51\xCC\x71\x58\xCC\x71\x57\xCC\x71\x62\xCC\x71\x59\xCC\x73\x55\xCC\x73\x53\xCD\x57\x43\xCD\x57\x44\xCD\x57\x44\xCD\x57\x45\xCD\x57\x46\xCD\x57\x46\xCD\x57\x4A\xCD\x57\x51\xCD\x57\x51\xCD\x57\x53\xCD\x57\x54\xCD\x57\x54\xCD\x57\x58\xCD\x57\x57\xCD\x57\x70\xCD\x57\x71\xCD\x57\x71\xCD\x58\x41\xCD\x58\x42\xCD\x58\x42\xCD\x58\x43\xCD\x58\x44\xCD\x58\x45\xCD\x58\x46\xCD\x58\x47\xCD\x58\x48\xCD\x58\x49\xCD\x58\x4A\xCD\x58\x65\xCD\x58\x66\xCD\x59\x43\xCA\x41\x72\xCD\x59\x64\xCD\x59\x65\xCD\x59\x66\xCD\x59\x67\xCD\x59\x68\xCD\x59\x69\xCD\x59\x6A\xCD\x59\x70\xCE\x41\x49\xCE\x41\x4A\xCE\x41\x51\xCE\x41\x52\xCE\x41\x53\xCE\x41\x54\xCE\x41\x55\xCE\x41\x56\xCE\x41\x57\xCE\x41\x58\xCE\x41\x63\xCE\x41\x64\xCE\x41\x65\xCE\x41\x66\xCE\x41\x67\xCE\x41\x68\xCE\x41\x69\xCE\x41\x6A\xCE\x41\x71\xCE\x41\x72\xDD\x51\x55\x42\xDD\x51\x55\x43\xDD\x73\x4A\x72\xDD\x73\x4A\x73\xDD\x73\x59\x68\xDD\x73\x59\x69\xDD\x73\x59\x6A\xDD\x73\x59\x70\xDD\x73\x59\x71\xDD\x73\x59\x72\xDD\x73\x62\x45\xDD\x73\x62\x46\xDD\x73\x67\x49\xDD\x73\x67\x4A\xDD\x73\x67\x70\xDD\x73\x67\x72\xDD\x73\x68\x6A\xDD\x73\x68\x71\xDD\x73\x69\x6A\xDD\x73\x69\x71\xDD\x73\x69\x73\xDD\x73\x6A\x41\xDD\x73\x6A\x43\xDD\x73\x6A\x44\xDD\x73\x73\x52\xDD\x73\x73\x4A\xDF\x63\x49\x44\xDF\x63\x49\x43\xDF\x63\x49\x47\xDF\x63\x49\x48\xDF\x71\x43\x4A\xDF\x71\x43\x49\xDF\x71\x49\x49\xDF\x71\x52\x49\xDF\x71\x49\x4A\xDF\x71\x52\x4A\xDF\x71\x49\x51\xDF\x71\x52\x51\xDF\x71\x52\x6A\xDF\x71\x52\x71\xDF\x71\x53\x68\xDF\x71\x53\x67\xDF\x71\x53\x6A\xDF\x71\x53\x69\xDF\x71\x53\x71\xDF\x71\x53\x70\xDF\x71\x56\x47\xDF\x71\x56\x48\xDF\x72\x41\x43\xDF\x72\x41\x41\xDF\x72\x41\x47\xDF\x72\x41\x45\xDF\x72\x41\x51\xDF\x72\x41\x49\xDF\x72\x41\x59\xDF\x72\x41\x57\xDF\x72\x41\x65\xDF\x72\x41\x63\xDF\x72\x41\x69\xDF\x72\x41\x67\xDF\x72\x41\x72\xDF\x72\x41\x70\xDF\x72\x42\x43\xDF\x72\x42\x41\xDF\x72\x42\x47\xDF\x72\x42\x45\xDF\x72\x42\x51\xDF\x72\x42\x49\xDF\x72\x42\x55\xDF\x72\x42\x53\xDF\x72\x42\x59\xDF\x72\x42\x57\xDF\x72\x42\x65\xDF\x72\x42\x63\xDF\x72\x42\x69\xDF\x72\x42\x67\xDF\x72\x42\x72\xDF\x72\x42\x70\xDF\x72\x43\x43\xDF\x72\x43\x41\xDF\x72\x43\x47\xDF\x72\x43\x45\xDF\x72\x43\x59\xDF\x72\x43\x57\xDF\x72\x44\x43\xDF\x72\x44\x41\xDF\x72\x44\x51\xDF\x72\x44\x49\xDF\x72\x44\x59\xDF\x72\x44\x57\xDF\x72\x44\x69\xDF\x72\x44\x67\xDF\x72\x45\x43\xDF\x72\x45\x41\xDF\x72\x45\x59\xDF\x72\x45\x57\xDF\x72\x45\x65\xDF\x72\x45\x63\xDF\x72\x45\x69\xDF\x72\x45\x67\xDF\x72\x46\x42\xDF\x72\x46\x41\xDF\x72\x46\x44\xDF\x72\x46\x43\xDF\x72\x46\x46\xDF\x72\x46\x47\xDF\x72\x46\x48\xDF\x72\x46\x45\xDF\x72\x46\x4A\xDF\x72\x46\x49\xDF\x72\x46\x52\xDF\x72\x46\x51" # define DEPRECATED_OPENING_NON_UTF8_BRACKETS "\x8A\x8B" # endif @@ -210,18 +220,22 @@ bytes. # define LATIN_SMALL_LETTER_Y_WITH_DIAERESIS_NATIVE 0xDF /* U+00FF */ # define MICRO_SIGN_NATIVE 0xA0 /* U+00B5 */ # define MICRO_SIGN_UTF8 "\x78\x63" /* U+00B5 */ +# define ARABIC_DECIMAL_SEPARATOR_UTF8 "\xB7\x5F\x52" /* U+066B */ +# define ARABIC_DECIMAL_SEPARATOR_UTF8_FIRST_BYTE 0xB7 /* U+066B */ +# define ARABIC_DECIMAL_SEPARATOR_UTF8_TAIL "\x5F\x52" /* U+066B */ +# define ARABIC_DECIMAL_SEPARATOR_UTF8_FIRST_BYTE_s "\xB7" /* U+066B */ # ifdef PERL_IN_TOKE_C /* Paired characters for quote-like operators, in UTF-8 */ -# define EXTRA_OPENING_UTF8_BRACKETS "\x4D\x4C\xBA\xC0\x78\x52\x78\x69\xB7\x66\x47\xB9\x67\x68\xB9\x67\x6A\xBD\x62\x69\xCA\x41\x66\xCA\x41\x67\xCA\x41\x6A\xCA\x41\x70\xCA\x42\x63\xCA\x42\x64\xCA\x42\x65\xCA\x42\x67\xCA\x42\x68\xCA\x43\x46\xCA\x43\x54\xCA\x44\x70\xCA\x45\x54\xCA\x53\x59\xCA\x53\x69\xCA\x53\x70\xCA\x54\x41\xCA\x54\x44\xCA\x54\x47\xCA\x54\x51\xCA\x54\x53\xCA\x54\x58\xCA\x54\x5F\xCA\x55\x41\xCA\x55\x42\xCA\x55\x4A\xCA\x55\x56\xCA\x55\x59\xCA\x55\x69\xCA\x55\x70\xCA\x56\x43\xCA\x56\x46\xCA\x56\x49\xCA\x56\x62\xCA\x56\x64\xCA\x56\x66\xCA\x56\x69\xCA\x56\x71\xCA\x57\x49\xCA\x57\x4A\xCA\x57\x51\xCA\x5F\x45\xCA\x5F\x47\xCA\x5F\x49\xCA\x5F\x51\xCA\x5F\x55\xCA\x5F\x57\xCA\x5F\x59\xCA\x5F\x62\xCA\x5F\x68\xCA\x5F\x6A\xCA\x5F\x71\xCA\x62\x41\xCA\x62\x43\xCA\x62\x45\xCA\x62\x47\xCA\x62\x49\xCA\x62\x51\xCA\x63\x44\xCA\x63\x47\xCA\x63\x49\xCA\x63\x4A\xCA\x63\x57\xCA\x64\x57\xCA\x64\x64\xCA\x64\x66\xCA\x64\x6A\xCA\x64\x71\xCA\x65\x41\xCA\x65\x47\xCA\x65\x49\xCA\x65\x59\xCA\x65\x5F\xCA\x65\x62\xCA\x65\x64\xCA\x65\x65\xCA\x66\x49\xCA\x66\x51\xCA\x67\x47\xCA\x67\x4A\xCA\x68\x49\xCA\x72\x4A\xCA\x72\x54\xCB\x57\x69\xCB\x57\x71\xCB\x62\x71\xCB\x69\x49\xCB\x69\x51\xCB\x69\x53\xCB\x69\x55\xCB\x69\x57\xCB\x69\x59\xCB\x69\x62\xCB\x71\x44\xCB\x71\x46\xCB\x71\x49\xCB\x71\x71\xCB\x72\x47\xCB\x72\x49\xCB\x72\x51\xCB\x72\x53\xCB\x72\x55\xCB\x72\x62\xCB\x72\x64\xCB\x72\x67\xCB\x72\x6A\xCB\x72\x71\xCB\x72\x72\xCC\x49\x41\xCC\x49\x42\xCC\x49\x44\xCC\x49\x46\xCC\x49\x48\xCC\x49\x54\xCC\x49\x56\xCC\x49\x57\xCC\x49\x58\xCC\x49\x62\xCC\x49\x63\xCC\x49\x64\xCC\x49\x65\xCC\x49\x66\xCC\x49\x68\xCC\x49\x6A\xCC\x49\x71\xCC\x4A\x41\xCC\x4A\x5F\xCC\x4A\x65\xCC\x51\x46\xCC\x51\x48\xCC\x51\x5F\xCC\x51\x65\xCC\x51\x69\xCC\x51\x72\xCC\x52\x45\xCC\x52\x53\xCC\x52\x54\xCC\x52\x58\xCC\x52\x59\xCC\x52\x62\xCC\x52\x63\xCC\x52\x67\xCC\x53\x44\xCC\x53\x46\xCC\x53\x48\xCC\x53\x4A\xCC\x53\x52\xCC\x53\x54\xCC\x53\x56\xCC\x53\x58\xCC\x53\x5F\xCC\x53\x63\xCC\x53\x65\xCC\x54\x49\xCC\x54\x51\xCC\x54\x5F\xCC\x55\x41\xCC\x55\x66\xCC\x55\x68\xCC\x56\x6A\xCC\x5F\x67\xCC\x5F\x69\xCC\x5F\x70\xCC\x5F\x72\xCC\x62\x42\xCC\x62\x44\xCC\x62\x46\xCC\x62\x48\xCC\x62\x4A\xCC\x62\x54\xCC\x62\x63\xCC\x62\x65\xCC\x62\x67\xCC\x62\x69\xCC\x62\x70\xCC\x62\x72\xCC\x63\x42\xCC\x63\x47\xCC\x63\x49\xCC\x63\x51\xCC\x63\x53\xCC\x63\x56\xCC\x63\x58\xCC\x63\x5F\xCC\x63\x63\xCC\x63\x65\xCC\x63\x67\xCC\x63\x69\xCC\x63\x70\xCC\x63\x72\xCC\x64\x42\xCC\x64\x44\xCC\x64\x46\xCC\x64\x48\xCC\x64\x4A\xCC\x64\x52\xCC\x64\x56\xCC\x64\x58\xCC\x64\x63\xCC\x65\x46\xCC\x65\x65\xCC\x65\x67\xCC\x68\x47\xCC\x68\x48\xCC\x68\x49\xCC\x68\x53\xCC\x69\x43\xCC\x69\x53\xCC\x69\x59\xCC\x69\x6A\xCC\x6A\x47\xCC\x6A\x51\xCC\x6A\x63\xCC\x6A\x68\xCC\x6A\x71\xCC\x70\x42\xCC\x70\x44\xCC\x70\x4A\xCC\x70\x52\xCC\x70\x58\xCC\x70\x5F\xCC\x72\x55\xCD\x57\x43\xCD\x57\x44\xCD\x57\x45\xCD\x57\x46\xCD\x57\x4A\xCD\x57\x51\xCD\x57\x53\xCD\x57\x54\xCD\x57\x58\xCD\x57\x6A\xCD\x57\x70\xCD\x58\x41\xCD\x58\x42\xCD\x58\x43\xCD\x58\x45\xCD\x58\x47\xCD\x58\x49\xCD\x58\x64\xCD\x59\x43\xCD\x59\x63\xCD\x59\x65\xCD\x59\x67\xCD\x59\x69\xCE\x41\x49\xCE\x41\x51\xCE\x41\x53\xCE\x41\x55\xCE\x41\x57\xCE\x41\x62\xCE\x41\x64\xCE\x41\x66\xCE\x41\x68\xCE\x41\x70\xDD\x51\x55\x42\xDD\x72\x4A\x71\xDD\x72\x59\x67\xDD\x72\x59\x69\xDD\x72\x59\x70\xDD\x72\x5F\x45\xDD\x72\x66\x49\xDD\x72\x66\x6A\xDD\x72\x67\x69\xDD\x72\x68\x69\xDD\x72\x68\x72\xDD\x72\x69\x43\xDD\x72\x72\x52\xDF\x62\x49\x44\xDF\x62\x49\x47\xDF\x70\x43\x4A\xDF\x70\x49\x49\xDF\x70\x49\x4A\xDF\x70\x49\x51\xDF\x70\x52\x69\xDF\x70\x53\x67\xDF\x70\x53\x69\xDF\x70\x53\x70\xDF\x70\x56\x47\xDF\x71\x41\x43\xDF\x71\x41\x47\xDF\x71\x41\x51\xDF\x71\x41\x59\xDF\x71\x41\x64\xDF\x71\x41\x68\xDF\x71\x41\x71\xDF\x71\x42\x43\xDF\x71\x42\x47\xDF\x71\x42\x51\xDF\x71\x42\x55\xDF\x71\x42\x59\xDF\x71\x42\x64\xDF\x71\x42\x68\xDF\x71\x42\x71\xDF\x71\x43\x43\xDF\x71\x43\x47\xDF\x71\x43\x59\xDF\x71\x44\x43\xDF\x71\x44\x51\xDF\x71\x44\x59\xDF\x71\x44\x68\xDF\x71\x45\x43\xDF\x71\x45\x59\xDF\x71\x45\x64\xDF\x71\x45\x68\xDF\x71\x46\x42\xDF\x71\x46\x44\xDF\x71\x46\x46\xDF\x71\x46\x48\xDF\x71\x46\x4A\xDF\x71\x46\x52" -# define EXTRA_CLOSING_UTF8_BRACKETS "\x5D\x6E\xBB\xD0\x78\x69\x78\x52\xB7\x66\x48\xB9\x67\x69\xB9\x67\x70\xBD\x62\x6A\xCA\x41\x67\xCA\x41\x66\xCA\x41\x70\xCA\x41\x6A\xCA\x42\x59\xCA\x42\x5F\xCA\x42\x62\xCA\x42\x68\xCA\x42\x67\xCA\x43\x47\xCA\x43\x53\xCA\x44\x71\xCA\x45\x55\xCA\x53\x57\xCA\x53\x68\xCA\x53\x6A\xCA\x53\x71\xCA\x54\x43\xCA\x54\x45\xCA\x54\x4A\xCA\x54\x52\xCA\x54\x57\xCA\x54\x59\xCA\x54\x6A\xCA\x54\x70\xCA\x55\x48\xCA\x55\x54\xCA\x55\x57\xCA\x55\x68\xCA\x55\x6A\xCA\x56\x41\xCA\x56\x45\xCA\x56\x47\xCC\x67\x57\xCC\x67\x58\xCA\x56\x65\xCA\x56\x68\xCA\x56\x70\xCA\x57\x52\xCA\x57\x53\xCA\x57\x54\xCA\x5F\x46\xCA\x5F\x48\xCA\x5F\x4A\xCA\x5F\x52\xCA\x5F\x56\xCA\x5F\x58\xCA\x5F\x5F\xCA\x5F\x63\xCA\x5F\x69\xCA\x5F\x70\xCA\x5F\x72\xCA\x62\x42\xCA\x62\x44\xCA\x62\x46\xCA\x62\x48\xCA\x62\x4A\xCA\x62\x52\xCA\x63\x43\xCC\x64\x71\xCC\x65\x45\xCC\x65\x44\xCA\x63\x58\xCA\x64\x58\xCA\x64\x65\xCA\x64\x67\xCA\x64\x70\xCA\x64\x72\xCA\x65\x42\xCA\x65\x48\xCA\x65\x4A\xCA\x65\x68\xCA\x65\x69\xCA\x65\x6A\xCA\x65\x70\xCA\x65\x71\xCA\x66\x4A\xCA\x66\x52\xCA\x67\x52\xCA\x67\x51\xCA\x68\x48\xCA\x72\x51\xCA\x72\x55\xCB\x57\x68\xCB\x57\x6A\xCB\x62\x72\xCB\x69\x4A\xCB\x69\x52\xCB\x69\x54\xCB\x69\x56\xCB\x69\x58\xCB\x69\x5F\xCB\x69\x63\xCB\x71\x45\xCB\x71\x47\xCB\x71\x4A\xCB\x71\x70\xCB\x72\x48\xCB\x72\x4A\xCB\x72\x52\xCB\x72\x54\xCB\x72\x56\xCC\x67\x59\xCB\x72\x63\xCB\x72\x66\xCB\x72\x69\xCB\x72\x70\xCC\x67\x5F\xCC\x67\x62\xCC\x67\x63\xCC\x49\x43\xCC\x67\x64\xCC\x49\x47\xCC\x49\x53\xCC\x49\x55\xCC\x67\x65\xCC\x67\x66\xCC\x67\x67\xCC\x67\x68\xCC\x67\x69\xCC\x67\x6A\xCC\x67\x70\xCC\x49\x67\xCC\x49\x69\xCC\x49\x70\xCC\x49\x72\xCC\x67\x72\xCC\x4A\x64\xCC\x51\x47\xCC\x67\x71\xCC\x51\x59\xCC\x51\x64\xCC\x51\x68\xCC\x51\x71\xCC\x52\x43\xCC\x52\x51\xCC\x52\x52\xCC\x68\x41\xCC\x68\x42\xCC\x68\x52\xCC\x68\x43\xCC\x52\x69\xCC\x53\x45\xCC\x53\x47\xCC\x53\x49\xCC\x53\x51\xCC\x53\x53\xCC\x53\x57\xCC\x53\x55\xCC\x53\x59\xCC\x53\x62\xCC\x53\x64\xCC\x53\x66\xCC\x54\x4A\xCC\x54\x52\xCC\x54\x62\xCC\x55\x42\xCC\x55\x67\xCC\x55\x69\xCC\x56\x70\xCC\x5F\x68\xCC\x5F\x6A\xCC\x5F\x71\xCC\x62\x41\xCC\x62\x43\xCC\x62\x45\xCC\x62\x47\xCC\x62\x49\xCC\x62\x51\xCC\x62\x55\xCC\x62\x64\xCC\x62\x66\xCC\x62\x68\xCC\x62\x6A\xCC\x62\x71\xCC\x63\x41\xCC\x63\x43\xCC\x63\x48\xCC\x63\x4A\xCC\x63\x52\xCC\x63\x54\xCC\x63\x57\xCC\x63\x59\xCC\x63\x62\xCC\x63\x64\xCC\x63\x66\xCC\x63\x68\xCC\x63\x6A\xCC\x63\x71\xCC\x64\x41\xCC\x64\x43\xCC\x64\x45\xCC\x64\x47\xCC\x64\x49\xCC\x64\x51\xCC\x64\x53\xCC\x64\x57\xCC\x64\x59\xCC\x64\x64\xCA\x63\x52\xCC\x65\x66\xCC\x65\x68\xCC\x68\x46\xCC\x68\x4A\xCC\x68\x51\xCC\x52\x5F\xCC\x69\x41\xCC\x69\x51\xCC\x69\x57\xCC\x69\x68\xCC\x6A\x45\xCC\x6A\x49\xCC\x66\x46\xCC\x6A\x66\xCC\x6A\x6A\xCC\x70\x41\xCC\x70\x43\xCC\x70\x49\xCC\x70\x51\xCC\x70\x57\xCC\x70\x59\xCC\x72\x53\xCD\x57\x44\xCD\x57\x43\xCD\x57\x46\xCD\x57\x45\xCD\x57\x51\xCD\x57\x4A\xCD\x57\x54\xCD\x57\x53\xCD\x57\x57\xCD\x57\x70\xCD\x57\x6A\xCD\x58\x42\xCD\x58\x41\xCD\x58\x44\xCD\x58\x46\xCD\x58\x48\xCD\x58\x4A\xCD\x58\x65\xCA\x41\x71\xCD\x59\x64\xCD\x59\x66\xCD\x59\x68\xCD\x59\x6A\xCE\x41\x4A\xCE\x41\x52\xCE\x41\x54\xCE\x41\x56\xCE\x41\x58\xCE\x41\x63\xCE\x41\x65\xCE\x41\x67\xCE\x41\x69\xCE\x41\x71\xDD\x51\x55\x43\xDD\x72\x4A\x72\xDD\x72\x59\x68\xDD\x72\x59\x6A\xDD\x72\x59\x71\xDD\x72\x5F\x46\xDD\x72\x66\x4A\xDD\x72\x66\x71\xDD\x72\x67\x70\xDD\x72\x68\x70\xDD\x72\x69\x41\xDD\x72\x69\x44\xDD\x72\x72\x4A\xDF\x62\x49\x43\xDF\x62\x49\x48\xDF\x70\x43\x49\xDF\x70\x52\x49\xDF\x70\x52\x4A\xDF\x70\x52\x51\xDF\x70\x52\x70\xDF\x70\x53\x66\xDF\x70\x53\x68\xDF\x70\x53\x6A\xDF\x70\x56\x48\xDF\x71\x41\x41\xDF\x71\x41\x45\xDF\x71\x41\x49\xDF\x71\x41\x57\xDF\x71\x41\x62\xDF\x71\x41\x66\xDF\x71\x41\x6A\xDF\x71\x42\x41\xDF\x71\x42\x45\xDF\x71\x42\x49\xDF\x71\x42\x53\xDF\x71\x42\x57\xDF\x71\x42\x62\xDF\x71\x42\x66\xDF\x71\x42\x6A\xDF\x71\x43\x41\xDF\x71\x43\x45\xDF\x71\x43\x57\xDF\x71\x44\x41\xDF\x71\x44\x49\xDF\x71\x44\x57\xDF\x71\x44\x66\xDF\x71\x45\x41\xDF\x71\x45\x57\xDF\x71\x45\x62\xDF\x71\x45\x66\xDF\x71\x46\x41\xDF\x71\x46\x43\xDF\x71\x46\x47\xDF\x71\x46\x45\xDF\x71\x46\x49\xDF\x71\x46\x51" +# define EXTRA_OPENING_UTF8_BRACKETS "\x4D\x4C\xBA\xC0\x78\x52\x78\x69\xB9\x67\x68\xB9\x67\x6A\xBD\x62\x69\xCA\x41\x66\xCA\x41\x67\xCA\x41\x6A\xCA\x41\x70\xCA\x42\x63\xCA\x42\x64\xCA\x42\x65\xCA\x42\x67\xCA\x42\x68\xCA\x43\x46\xCA\x43\x54\xCA\x44\x70\xCA\x45\x54\xCA\x53\x59\xCA\x53\x69\xCA\x53\x70\xCA\x54\x41\xCA\x54\x44\xCA\x54\x47\xCA\x54\x51\xCA\x54\x53\xCA\x54\x58\xCA\x54\x5F\xCA\x55\x41\xCA\x55\x42\xCA\x55\x4A\xCA\x55\x56\xCA\x55\x59\xCA\x55\x69\xCA\x55\x70\xCA\x56\x43\xCA\x56\x46\xCA\x56\x49\xCA\x56\x62\xCA\x56\x64\xCA\x56\x66\xCA\x56\x69\xCA\x56\x71\xCA\x57\x49\xCA\x57\x4A\xCA\x57\x51\xCA\x5F\x45\xCA\x5F\x47\xCA\x5F\x49\xCA\x5F\x51\xCA\x5F\x55\xCA\x5F\x57\xCA\x5F\x59\xCA\x5F\x62\xCA\x5F\x68\xCA\x5F\x6A\xCA\x5F\x71\xCA\x62\x41\xCA\x62\x43\xCA\x62\x45\xCA\x62\x47\xCA\x62\x49\xCA\x62\x51\xCA\x63\x44\xCA\x63\x47\xCA\x63\x49\xCA\x63\x4A\xCA\x63\x57\xCA\x64\x57\xCA\x64\x64\xCA\x64\x66\xCA\x64\x6A\xCA\x64\x71\xCA\x65\x41\xCA\x65\x47\xCA\x65\x49\xCA\x65\x59\xCA\x65\x5F\xCA\x65\x62\xCA\x65\x64\xCA\x65\x65\xCA\x66\x49\xCA\x66\x51\xCA\x67\x47\xCA\x67\x4A\xCA\x68\x49\xCA\x72\x4A\xCA\x72\x54\xCB\x57\x69\xCB\x57\x71\xCB\x62\x71\xCB\x69\x49\xCB\x69\x51\xCB\x69\x53\xCB\x69\x55\xCB\x69\x57\xCB\x69\x59\xCB\x69\x62\xCB\x71\x44\xCB\x71\x46\xCB\x71\x49\xCB\x71\x71\xCB\x72\x47\xCB\x72\x49\xCB\x72\x51\xCB\x72\x53\xCB\x72\x55\xCB\x72\x62\xCB\x72\x64\xCB\x72\x67\xCB\x72\x6A\xCB\x72\x71\xCB\x72\x72\xCC\x49\x41\xCC\x49\x42\xCC\x49\x44\xCC\x49\x46\xCC\x49\x48\xCC\x49\x54\xCC\x49\x56\xCC\x49\x57\xCC\x49\x58\xCC\x49\x62\xCC\x49\x63\xCC\x49\x64\xCC\x49\x65\xCC\x49\x66\xCC\x49\x68\xCC\x49\x6A\xCC\x49\x71\xCC\x4A\x41\xCC\x4A\x5F\xCC\x4A\x65\xCC\x51\x46\xCC\x51\x48\xCC\x51\x5F\xCC\x51\x65\xCC\x51\x69\xCC\x51\x72\xCC\x52\x45\xCC\x52\x53\xCC\x52\x54\xCC\x52\x58\xCC\x52\x59\xCC\x52\x62\xCC\x52\x63\xCC\x52\x67\xCC\x53\x44\xCC\x53\x46\xCC\x53\x48\xCC\x53\x4A\xCC\x53\x52\xCC\x53\x54\xCC\x53\x56\xCC\x53\x58\xCC\x53\x5F\xCC\x53\x63\xCC\x53\x65\xCC\x54\x49\xCC\x54\x51\xCC\x54\x5F\xCC\x55\x41\xCC\x55\x66\xCC\x55\x68\xCC\x56\x6A\xCC\x5F\x67\xCC\x5F\x69\xCC\x5F\x70\xCC\x5F\x72\xCC\x62\x42\xCC\x62\x44\xCC\x62\x46\xCC\x62\x48\xCC\x62\x4A\xCC\x62\x54\xCC\x62\x63\xCC\x62\x65\xCC\x62\x67\xCC\x62\x69\xCC\x62\x70\xCC\x62\x72\xCC\x63\x42\xCC\x63\x47\xCC\x63\x49\xCC\x63\x51\xCC\x63\x53\xCC\x63\x56\xCC\x63\x58\xCC\x63\x5F\xCC\x63\x63\xCC\x63\x65\xCC\x63\x67\xCC\x63\x69\xCC\x63\x70\xCC\x63\x72\xCC\x64\x42\xCC\x64\x44\xCC\x64\x46\xCC\x64\x48\xCC\x64\x4A\xCC\x64\x52\xCC\x64\x56\xCC\x64\x58\xCC\x64\x63\xCC\x65\x46\xCC\x65\x65\xCC\x65\x67\xCC\x68\x47\xCC\x68\x48\xCC\x68\x49\xCC\x68\x53\xCC\x69\x43\xCC\x69\x53\xCC\x69\x59\xCC\x69\x6A\xCC\x6A\x47\xCC\x6A\x51\xCC\x6A\x63\xCC\x6A\x68\xCC\x6A\x71\xCC\x70\x42\xCC\x70\x44\xCC\x70\x4A\xCC\x70\x52\xCC\x70\x58\xCC\x70\x5F\xCC\x72\x55\xCD\x57\x43\xCD\x57\x44\xCD\x57\x45\xCD\x57\x46\xCD\x57\x4A\xCD\x57\x51\xCD\x57\x53\xCD\x57\x54\xCD\x57\x58\xCD\x57\x6A\xCD\x57\x70\xCD\x58\x41\xCD\x58\x42\xCD\x58\x43\xCD\x58\x45\xCD\x58\x47\xCD\x58\x49\xCD\x58\x64\xCD\x59\x43\xCD\x59\x63\xCD\x59\x65\xCD\x59\x67\xCD\x59\x69\xCE\x41\x49\xCE\x41\x51\xCE\x41\x53\xCE\x41\x55\xCE\x41\x57\xCE\x41\x62\xCE\x41\x64\xCE\x41\x66\xCE\x41\x68\xCE\x41\x70\xDD\x51\x55\x42\xDD\x72\x4A\x71\xDD\x72\x59\x67\xDD\x72\x59\x69\xDD\x72\x59\x70\xDD\x72\x5F\x45\xDD\x72\x66\x49\xDD\x72\x66\x6A\xDD\x72\x67\x69\xDD\x72\x68\x69\xDD\x72\x68\x72\xDD\x72\x69\x43\xDD\x72\x72\x52\xDF\x62\x49\x44\xDF\x62\x49\x47\xDF\x70\x43\x4A\xDF\x70\x49\x49\xDF\x70\x49\x4A\xDF\x70\x49\x51\xDF\x70\x52\x69\xDF\x70\x53\x67\xDF\x70\x53\x69\xDF\x70\x53\x70\xDF\x70\x56\x47\xDF\x71\x41\x43\xDF\x71\x41\x47\xDF\x71\x41\x51\xDF\x71\x41\x59\xDF\x71\x41\x64\xDF\x71\x41\x68\xDF\x71\x41\x71\xDF\x71\x42\x43\xDF\x71\x42\x47\xDF\x71\x42\x51\xDF\x71\x42\x55\xDF\x71\x42\x59\xDF\x71\x42\x64\xDF\x71\x42\x68\xDF\x71\x42\x71\xDF\x71\x43\x43\xDF\x71\x43\x47\xDF\x71\x43\x59\xDF\x71\x44\x43\xDF\x71\x44\x51\xDF\x71\x44\x59\xDF\x71\x44\x68\xDF\x71\x45\x43\xDF\x71\x45\x59\xDF\x71\x45\x64\xDF\x71\x45\x68\xDF\x71\x46\x42\xDF\x71\x46\x44\xDF\x71\x46\x46\xDF\x71\x46\x48\xDF\x71\x46\x4A\xDF\x71\x46\x52" +# define EXTRA_CLOSING_UTF8_BRACKETS "\x5D\x6E\xBB\xD0\x78\x69\x78\x52\xB9\x67\x69\xB9\x67\x70\xBD\x62\x6A\xCA\x41\x67\xCA\x41\x66\xCA\x41\x70\xCA\x41\x6A\xCA\x42\x59\xCA\x42\x5F\xCA\x42\x62\xCA\x42\x68\xCA\x42\x67\xCA\x43\x47\xCA\x43\x53\xCA\x44\x71\xCA\x45\x55\xCA\x53\x57\xCA\x53\x68\xCA\x53\x6A\xCA\x53\x71\xCA\x54\x43\xCA\x54\x45\xCA\x54\x4A\xCA\x54\x52\xCA\x54\x57\xCA\x54\x59\xCA\x54\x6A\xCA\x54\x70\xCA\x55\x48\xCA\x55\x54\xCA\x55\x57\xCA\x55\x68\xCA\x55\x6A\xCA\x56\x41\xCA\x56\x45\xCA\x56\x47\xCC\x67\x57\xCC\x67\x58\xCA\x56\x65\xCA\x56\x68\xCA\x56\x70\xCA\x57\x52\xCA\x57\x53\xCA\x57\x54\xCA\x5F\x46\xCA\x5F\x48\xCA\x5F\x4A\xCA\x5F\x52\xCA\x5F\x56\xCA\x5F\x58\xCA\x5F\x5F\xCA\x5F\x63\xCA\x5F\x69\xCA\x5F\x70\xCA\x5F\x72\xCA\x62\x42\xCA\x62\x44\xCA\x62\x46\xCA\x62\x48\xCA\x62\x4A\xCA\x62\x52\xCA\x63\x43\xCC\x64\x71\xCC\x65\x45\xCC\x65\x44\xCA\x63\x58\xCA\x64\x58\xCA\x64\x65\xCA\x64\x67\xCA\x64\x70\xCA\x64\x72\xCA\x65\x42\xCA\x65\x48\xCA\x65\x4A\xCA\x65\x68\xCA\x65\x69\xCA\x65\x6A\xCA\x65\x70\xCA\x65\x71\xCA\x66\x4A\xCA\x66\x52\xCA\x67\x52\xCA\x67\x51\xCA\x68\x48\xCA\x72\x51\xCA\x72\x55\xCB\x57\x68\xCB\x57\x6A\xCB\x62\x72\xCB\x69\x4A\xCB\x69\x52\xCB\x69\x54\xCB\x69\x56\xCB\x69\x58\xCB\x69\x5F\xCB\x69\x63\xCB\x71\x45\xCB\x71\x47\xCB\x71\x4A\xCB\x71\x70\xCB\x72\x48\xCB\x72\x4A\xCB\x72\x52\xCB\x72\x54\xCB\x72\x56\xCC\x67\x59\xCB\x72\x63\xCB\x72\x66\xCB\x72\x69\xCB\x72\x70\xCC\x67\x5F\xCC\x67\x62\xCC\x67\x63\xCC\x49\x43\xCC\x67\x64\xCC\x49\x47\xCC\x49\x53\xCC\x49\x55\xCC\x67\x65\xCC\x67\x66\xCC\x67\x67\xCC\x67\x68\xCC\x67\x69\xCC\x67\x6A\xCC\x67\x70\xCC\x49\x67\xCC\x49\x69\xCC\x49\x70\xCC\x49\x72\xCC\x67\x72\xCC\x4A\x64\xCC\x51\x47\xCC\x67\x71\xCC\x51\x59\xCC\x51\x64\xCC\x51\x68\xCC\x51\x71\xCC\x52\x43\xCC\x52\x51\xCC\x52\x52\xCC\x68\x41\xCC\x68\x42\xCC\x68\x52\xCC\x68\x43\xCC\x52\x69\xCC\x53\x45\xCC\x53\x47\xCC\x53\x49\xCC\x53\x51\xCC\x53\x53\xCC\x53\x57\xCC\x53\x55\xCC\x53\x59\xCC\x53\x62\xCC\x53\x64\xCC\x53\x66\xCC\x54\x4A\xCC\x54\x52\xCC\x54\x62\xCC\x55\x42\xCC\x55\x67\xCC\x55\x69\xCC\x56\x70\xCC\x5F\x68\xCC\x5F\x6A\xCC\x5F\x71\xCC\x62\x41\xCC\x62\x43\xCC\x62\x45\xCC\x62\x47\xCC\x62\x49\xCC\x62\x51\xCC\x62\x55\xCC\x62\x64\xCC\x62\x66\xCC\x62\x68\xCC\x62\x6A\xCC\x62\x71\xCC\x63\x41\xCC\x63\x43\xCC\x63\x48\xCC\x63\x4A\xCC\x63\x52\xCC\x63\x54\xCC\x63\x57\xCC\x63\x59\xCC\x63\x62\xCC\x63\x64\xCC\x63\x66\xCC\x63\x68\xCC\x63\x6A\xCC\x63\x71\xCC\x64\x41\xCC\x64\x43\xCC\x64\x45\xCC\x64\x47\xCC\x64\x49\xCC\x64\x51\xCC\x64\x53\xCC\x64\x57\xCC\x64\x59\xCC\x64\x64\xCA\x63\x52\xCC\x65\x66\xCC\x65\x68\xCC\x68\x46\xCC\x68\x4A\xCC\x68\x51\xCC\x52\x5F\xCC\x69\x41\xCC\x69\x51\xCC\x69\x57\xCC\x69\x68\xCC\x6A\x45\xCC\x6A\x49\xCC\x66\x46\xCC\x6A\x66\xCC\x6A\x6A\xCC\x70\x41\xCC\x70\x43\xCC\x70\x49\xCC\x70\x51\xCC\x70\x57\xCC\x70\x59\xCC\x72\x53\xCD\x57\x44\xCD\x57\x43\xCD\x57\x46\xCD\x57\x45\xCD\x57\x51\xCD\x57\x4A\xCD\x57\x54\xCD\x57\x53\xCD\x57\x57\xCD\x57\x70\xCD\x57\x6A\xCD\x58\x42\xCD\x58\x41\xCD\x58\x44\xCD\x58\x46\xCD\x58\x48\xCD\x58\x4A\xCD\x58\x65\xCA\x41\x71\xCD\x59\x64\xCD\x59\x66\xCD\x59\x68\xCD\x59\x6A\xCE\x41\x4A\xCE\x41\x52\xCE\x41\x54\xCE\x41\x56\xCE\x41\x58\xCE\x41\x63\xCE\x41\x65\xCE\x41\x67\xCE\x41\x69\xCE\x41\x71\xDD\x51\x55\x43\xDD\x72\x4A\x72\xDD\x72\x59\x68\xDD\x72\x59\x6A\xDD\x72\x59\x71\xDD\x72\x5F\x46\xDD\x72\x66\x4A\xDD\x72\x66\x71\xDD\x72\x67\x70\xDD\x72\x68\x70\xDD\x72\x69\x41\xDD\x72\x69\x44\xDD\x72\x72\x4A\xDF\x62\x49\x43\xDF\x62\x49\x48\xDF\x70\x43\x49\xDF\x70\x52\x49\xDF\x70\x52\x4A\xDF\x70\x52\x51\xDF\x70\x52\x70\xDF\x70\x53\x66\xDF\x70\x53\x68\xDF\x70\x53\x6A\xDF\x70\x56\x48\xDF\x71\x41\x41\xDF\x71\x41\x45\xDF\x71\x41\x49\xDF\x71\x41\x57\xDF\x71\x41\x62\xDF\x71\x41\x66\xDF\x71\x41\x6A\xDF\x71\x42\x41\xDF\x71\x42\x45\xDF\x71\x42\x49\xDF\x71\x42\x53\xDF\x71\x42\x57\xDF\x71\x42\x62\xDF\x71\x42\x66\xDF\x71\x42\x6A\xDF\x71\x43\x41\xDF\x71\x43\x45\xDF\x71\x43\x57\xDF\x71\x44\x41\xDF\x71\x44\x49\xDF\x71\x44\x57\xDF\x71\x44\x66\xDF\x71\x45\x41\xDF\x71\x45\x57\xDF\x71\x45\x62\xDF\x71\x45\x66\xDF\x71\x46\x41\xDF\x71\x46\x43\xDF\x71\x46\x47\xDF\x71\x46\x45\xDF\x71\x46\x49\xDF\x71\x46\x51" /* And not in UTF-8 */ # define EXTRA_OPENING_NON_UTF8_BRACKETS "\x4D\x4C\xBA\xC0\x8A\x8B" # define EXTRA_CLOSING_NON_UTF8_BRACKETS "\x5D\x6E\xBB\xD0\x8B\x8A" /* And what's deprecated */ -# define DEPRECATED_OPENING_UTF8_BRACKETS "\x78\x52\x78\x69\x78\x69\xB7\x66\x47\xB7\x66\x48\xB9\x67\x68\xB9\x67\x69\xB9\x67\x6A\xB9\x67\x70\xBD\x62\x69\xBD\x62\x6A\xCA\x41\x66\xCA\x41\x67\xCA\x41\x67\xCA\x41\x6A\xCA\x41\x70\xCA\x41\x70\xCA\x42\x63\xCA\x42\x59\xCA\x42\x64\xCA\x42\x5F\xCA\x42\x65\xCA\x42\x62\xCA\x42\x67\xCA\x42\x68\xCA\x42\x68\xCA\x43\x46\xCA\x43\x47\xCA\x43\x54\xCA\x43\x53\xCA\x44\x70\xCA\x44\x71\xCA\x45\x54\xCA\x45\x55\xCA\x53\x59\xCA\x53\x57\xCA\x53\x69\xCA\x53\x68\xCA\x53\x70\xCA\x53\x6A\xCA\x54\x41\xCA\x53\x71\xCA\x54\x44\xCA\x54\x43\xCA\x54\x47\xCA\x54\x45\xCA\x54\x51\xCA\x54\x4A\xCA\x54\x53\xCA\x54\x52\xCA\x54\x58\xCA\x54\x57\xCA\x54\x5F\xCA\x54\x59\xCA\x55\x41\xCA\x54\x6A\xCA\x55\x42\xCA\x54\x70\xCA\x55\x4A\xCA\x55\x48\xCA\x55\x56\xCA\x55\x54\xCA\x55\x59\xCA\x55\x57\xCA\x55\x69\xCA\x55\x68\xCA\x55\x70\xCA\x55\x6A\xCA\x56\x43\xCA\x56\x41\xCA\x56\x46\xCA\x56\x45\xCA\x56\x49\xCA\x56\x47\xCA\x56\x62\xCC\x67\x57\xCA\x56\x64\xCC\x67\x58\xCA\x56\x66\xCA\x56\x65\xCA\x56\x69\xCA\x56\x68\xCA\x56\x71\xCA\x56\x70\xCA\x57\x49\xCA\x57\x52\xCA\x57\x4A\xCA\x57\x53\xCA\x57\x51\xCA\x57\x54\xCA\x5F\x45\xCA\x5F\x46\xCA\x5F\x47\xCA\x5F\x48\xCA\x5F\x49\xCA\x5F\x4A\xCA\x5F\x51\xCA\x5F\x52\xCA\x5F\x55\xCA\x5F\x56\xCA\x5F\x57\xCA\x5F\x58\xCA\x5F\x59\xCA\x5F\x5F\xCA\x5F\x62\xCA\x5F\x63\xCA\x5F\x68\xCA\x5F\x69\xCA\x5F\x6A\xCA\x5F\x70\xCA\x5F\x71\xCA\x5F\x72\xCA\x62\x41\xCA\x62\x42\xCA\x62\x43\xCA\x62\x44\xCA\x62\x45\xCA\x62\x46\xCA\x62\x47\xCA\x62\x48\xCA\x62\x49\xCA\x62\x4A\xCA\x62\x51\xCA\x62\x52\xCA\x63\x44\xCA\x63\x43\xCA\x63\x47\xCC\x64\x71\xCA\x63\x49\xCC\x65\x45\xCA\x63\x4A\xCC\x65\x44\xCA\x63\x57\xCA\x63\x58\xCA\x64\x57\xCA\x64\x58\xCA\x64\x64\xCA\x64\x65\xCA\x64\x66\xCA\x64\x67\xCA\x64\x6A\xCA\x64\x70\xCA\x64\x71\xCA\x64\x72\xCA\x65\x41\xCA\x65\x42\xCA\x65\x47\xCA\x65\x48\xCA\x65\x49\xCA\x65\x4A\xCA\x65\x59\xCA\x65\x68\xCA\x65\x5F\xCA\x65\x69\xCA\x65\x62\xCA\x65\x6A\xCA\x65\x64\xCA\x65\x70\xCA\x65\x65\xCA\x65\x71\xCA\x66\x49\xCA\x66\x4A\xCA\x66\x51\xCA\x66\x52\xCA\x67\x47\xCA\x67\x52\xCA\x67\x4A\xCA\x67\x51\xCA\x68\x49\xCA\x68\x48\xCA\x72\x4A\xCA\x72\x51\xCA\x72\x54\xCA\x72\x55\xCB\x57\x69\xCB\x57\x68\xCB\x57\x71\xCB\x57\x6A\xCB\x62\x71\xCB\x62\x72\xCB\x69\x49\xCB\x69\x4A\xCB\x69\x51\xCB\x69\x52\xCB\x69\x53\xCB\x69\x54\xCB\x69\x55\xCB\x69\x56\xCB\x69\x57\xCB\x69\x58\xCB\x69\x59\xCB\x69\x5F\xCB\x69\x62\xCB\x69\x63\xCB\x71\x44\xCB\x71\x45\xCB\x71\x46\xCB\x71\x47\xCB\x71\x49\xCB\x71\x4A\xCB\x71\x71\xCB\x71\x70\xCB\x72\x47\xCB\x72\x48\xCB\x72\x49\xCB\x72\x4A\xCB\x72\x51\xCB\x72\x52\xCB\x72\x53\xCB\x72\x54\xCB\x72\x55\xCB\x72\x56\xCB\x72\x62\xCC\x67\x59\xCB\x72\x64\xCB\x72\x63\xCB\x72\x67\xCB\x72\x66\xCB\x72\x6A\xCB\x72\x69\xCB\x72\x71\xCB\x72\x70\xCB\x72\x72\xCC\x67\x5F\xCC\x49\x41\xCC\x67\x62\xCC\x49\x42\xCC\x67\x63\xCC\x49\x44\xCC\x49\x43\xCC\x49\x46\xCC\x67\x64\xCC\x49\x48\xCC\x49\x47\xCC\x49\x54\xCC\x49\x53\xCC\x49\x56\xCC\x49\x55\xCC\x49\x57\xCC\x67\x65\xCC\x49\x58\xCC\x67\x66\xCC\x49\x62\xCC\x67\x67\xCC\x49\x63\xCC\x67\x68\xCC\x49\x64\xCC\x67\x69\xCC\x49\x65\xCC\x67\x6A\xCC\x49\x66\xCC\x67\x70\xCC\x49\x68\xCC\x49\x67\xCC\x49\x6A\xCC\x49\x69\xCC\x49\x71\xCC\x49\x70\xCC\x4A\x41\xCC\x49\x72\xCC\x4A\x5F\xCC\x67\x72\xCC\x4A\x65\xCC\x4A\x64\xCC\x51\x46\xCC\x51\x47\xCC\x51\x48\xCC\x67\x71\xCC\x51\x5F\xCC\x51\x59\xCC\x51\x65\xCC\x51\x64\xCC\x51\x69\xCC\x51\x68\xCC\x51\x72\xCC\x51\x71\xCC\x52\x45\xCC\x52\x43\xCC\x52\x53\xCC\x52\x51\xCC\x52\x54\xCC\x52\x52\xCC\x52\x58\xCC\x68\x41\xCC\x52\x59\xCC\x68\x42\xCC\x52\x62\xCC\x68\x52\xCC\x52\x63\xCC\x68\x43\xCC\x52\x67\xCC\x52\x69\xCC\x53\x44\xCC\x53\x45\xCC\x53\x46\xCC\x53\x47\xCC\x53\x48\xCC\x53\x49\xCC\x53\x4A\xCC\x53\x51\xCC\x53\x52\xCC\x53\x53\xCC\x53\x54\xCC\x53\x57\xCC\x53\x56\xCC\x53\x55\xCC\x53\x58\xCC\x53\x59\xCC\x53\x5F\xCC\x53\x62\xCC\x53\x63\xCC\x53\x64\xCC\x53\x65\xCC\x53\x66\xCC\x54\x49\xCC\x54\x4A\xCC\x54\x51\xCC\x54\x52\xCC\x54\x5F\xCC\x54\x62\xCC\x55\x41\xCC\x55\x42\xCC\x55\x66\xCC\x55\x67\xCC\x55\x68\xCC\x55\x69\xCC\x56\x6A\xCC\x56\x70\xCC\x5F\x67\xCC\x5F\x68\xCC\x5F\x69\xCC\x5F\x6A\xCC\x5F\x70\xCC\x5F\x71\xCC\x5F\x72\xCC\x62\x41\xCC\x62\x42\xCC\x62\x43\xCC\x62\x44\xCC\x62\x45\xCC\x62\x46\xCC\x62\x47\xCC\x62\x48\xCC\x62\x49\xCC\x62\x4A\xCC\x62\x51\xCC\x62\x54\xCC\x62\x55\xCC\x62\x63\xCC\x62\x64\xCC\x62\x65\xCC\x62\x66\xCC\x62\x67\xCC\x62\x68\xCC\x62\x69\xCC\x62\x6A\xCC\x62\x70\xCC\x62\x71\xCC\x62\x72\xCC\x63\x41\xCC\x63\x42\xCC\x63\x43\xCC\x63\x47\xCC\x63\x48\xCC\x63\x49\xCC\x63\x4A\xCC\x63\x51\xCC\x63\x52\xCC\x63\x53\xCC\x63\x54\xCC\x63\x56\xCC\x63\x57\xCC\x63\x58\xCC\x63\x59\xCC\x63\x5F\xCC\x63\x62\xCC\x63\x63\xCC\x63\x64\xCC\x63\x65\xCC\x63\x66\xCC\x63\x67\xCC\x63\x68\xCC\x63\x69\xCC\x63\x6A\xCC\x63\x70\xCC\x63\x71\xCC\x63\x72\xCC\x64\x41\xCC\x64\x42\xCC\x64\x43\xCC\x64\x44\xCC\x64\x45\xCC\x64\x46\xCC\x64\x47\xCC\x64\x48\xCC\x64\x49\xCC\x64\x4A\xCC\x64\x51\xCC\x64\x52\xCC\x64\x53\xCC\x64\x56\xCC\x64\x57\xCC\x64\x58\xCC\x64\x59\xCC\x64\x63\xCC\x64\x64\xCC\x65\x46\xCA\x63\x52\xCC\x65\x65\xCC\x65\x66\xCC\x65\x67\xCC\x65\x68\xCC\x68\x47\xCC\x68\x46\xCC\x68\x48\xCC\x68\x4A\xCC\x68\x49\xCC\x68\x51\xCC\x68\x53\xCC\x52\x5F\xCC\x69\x43\xCC\x69\x41\xCC\x69\x53\xCC\x69\x51\xCC\x69\x59\xCC\x69\x57\xCC\x69\x6A\xCC\x69\x68\xCC\x6A\x47\xCC\x6A\x45\xCC\x6A\x51\xCC\x6A\x49\xCC\x6A\x63\xCC\x66\x46\xCC\x6A\x68\xCC\x6A\x66\xCC\x6A\x71\xCC\x6A\x6A\xCC\x70\x42\xCC\x70\x41\xCC\x70\x44\xCC\x70\x43\xCC\x70\x4A\xCC\x70\x49\xCC\x70\x52\xCC\x70\x51\xCC\x70\x58\xCC\x70\x57\xCC\x70\x5F\xCC\x70\x59\xCC\x72\x55\xCC\x72\x53\xCD\x57\x43\xCD\x57\x44\xCD\x57\x44\xCD\x57\x45\xCD\x57\x46\xCD\x57\x46\xCD\x57\x4A\xCD\x57\x51\xCD\x57\x51\xCD\x57\x53\xCD\x57\x54\xCD\x57\x54\xCD\x57\x58\xCD\x57\x57\xCD\x57\x6A\xCD\x57\x70\xCD\x57\x70\xCD\x58\x41\xCD\x58\x42\xCD\x58\x42\xCD\x58\x43\xCD\x58\x44\xCD\x58\x45\xCD\x58\x46\xCD\x58\x47\xCD\x58\x48\xCD\x58\x49\xCD\x58\x4A\xCD\x58\x64\xCD\x58\x65\xCD\x59\x43\xCA\x41\x71\xCD\x59\x63\xCD\x59\x64\xCD\x59\x65\xCD\x59\x66\xCD\x59\x67\xCD\x59\x68\xCD\x59\x69\xCD\x59\x6A\xCE\x41\x49\xCE\x41\x4A\xCE\x41\x51\xCE\x41\x52\xCE\x41\x53\xCE\x41\x54\xCE\x41\x55\xCE\x41\x56\xCE\x41\x57\xCE\x41\x58\xCE\x41\x62\xCE\x41\x63\xCE\x41\x64\xCE\x41\x65\xCE\x41\x66\xCE\x41\x67\xCE\x41\x68\xCE\x41\x69\xCE\x41\x70\xCE\x41\x71\xDD\x51\x55\x42\xDD\x51\x55\x43\xDD\x72\x4A\x71\xDD\x72\x4A\x72\xDD\x72\x59\x67\xDD\x72\x59\x68\xDD\x72\x59\x69\xDD\x72\x59\x6A\xDD\x72\x59\x70\xDD\x72\x59\x71\xDD\x72\x5F\x45\xDD\x72\x5F\x46\xDD\x72\x66\x49\xDD\x72\x66\x4A\xDD\x72\x66\x6A\xDD\x72\x66\x71\xDD\x72\x67\x69\xDD\x72\x67\x70\xDD\x72\x68\x69\xDD\x72\x68\x70\xDD\x72\x68\x72\xDD\x72\x69\x41\xDD\x72\x69\x43\xDD\x72\x69\x44\xDD\x72\x72\x52\xDD\x72\x72\x4A\xDF\x62\x49\x44\xDF\x62\x49\x43\xDF\x62\x49\x47\xDF\x62\x49\x48\xDF\x70\x43\x4A\xDF\x70\x43\x49\xDF\x70\x49\x49\xDF\x70\x52\x49\xDF\x70\x49\x4A\xDF\x70\x52\x4A\xDF\x70\x49\x51\xDF\x70\x52\x51\xDF\x70\x52\x69\xDF\x70\x52\x70\xDF\x70\x53\x67\xDF\x70\x53\x66\xDF\x70\x53\x69\xDF\x70\x53\x68\xDF\x70\x53\x70\xDF\x70\x53\x6A\xDF\x70\x56\x47\xDF\x70\x56\x48\xDF\x71\x41\x43\xDF\x71\x41\x41\xDF\x71\x41\x47\xDF\x71\x41\x45\xDF\x71\x41\x51\xDF\x71\x41\x49\xDF\x71\x41\x59\xDF\x71\x41\x57\xDF\x71\x41\x64\xDF\x71\x41\x62\xDF\x71\x41\x68\xDF\x71\x41\x66\xDF\x71\x41\x71\xDF\x71\x41\x6A\xDF\x71\x42\x43\xDF\x71\x42\x41\xDF\x71\x42\x47\xDF\x71\x42\x45\xDF\x71\x42\x51\xDF\x71\x42\x49\xDF\x71\x42\x55\xDF\x71\x42\x53\xDF\x71\x42\x59\xDF\x71\x42\x57\xDF\x71\x42\x64\xDF\x71\x42\x62\xDF\x71\x42\x68\xDF\x71\x42\x66\xDF\x71\x42\x71\xDF\x71\x42\x6A\xDF\x71\x43\x43\xDF\x71\x43\x41\xDF\x71\x43\x47\xDF\x71\x43\x45\xDF\x71\x43\x59\xDF\x71\x43\x57\xDF\x71\x44\x43\xDF\x71\x44\x41\xDF\x71\x44\x51\xDF\x71\x44\x49\xDF\x71\x44\x59\xDF\x71\x44\x57\xDF\x71\x44\x68\xDF\x71\x44\x66\xDF\x71\x45\x43\xDF\x71\x45\x41\xDF\x71\x45\x59\xDF\x71\x45\x57\xDF\x71\x45\x64\xDF\x71\x45\x62\xDF\x71\x45\x68\xDF\x71\x45\x66\xDF\x71\x46\x42\xDF\x71\x46\x41\xDF\x71\x46\x44\xDF\x71\x46\x43\xDF\x71\x46\x46\xDF\x71\x46\x47\xDF\x71\x46\x48\xDF\x71\x46\x45\xDF\x71\x46\x4A\xDF\x71\x46\x49\xDF\x71\x46\x52\xDF\x71\x46\x51" +# define DEPRECATED_OPENING_UTF8_BRACKETS "\x78\x52\x78\x69\x78\x69\xB9\x67\x68\xB9\x67\x69\xB9\x67\x6A\xB9\x67\x70\xBD\x62\x69\xBD\x62\x6A\xCA\x41\x66\xCA\x41\x67\xCA\x41\x67\xCA\x41\x6A\xCA\x41\x70\xCA\x41\x70\xCA\x42\x63\xCA\x42\x59\xCA\x42\x64\xCA\x42\x5F\xCA\x42\x65\xCA\x42\x62\xCA\x42\x67\xCA\x42\x68\xCA\x42\x68\xCA\x43\x46\xCA\x43\x47\xCA\x43\x54\xCA\x43\x53\xCA\x44\x70\xCA\x44\x71\xCA\x45\x54\xCA\x45\x55\xCA\x53\x59\xCA\x53\x57\xCA\x53\x69\xCA\x53\x68\xCA\x53\x70\xCA\x53\x6A\xCA\x54\x41\xCA\x53\x71\xCA\x54\x44\xCA\x54\x43\xCA\x54\x47\xCA\x54\x45\xCA\x54\x51\xCA\x54\x4A\xCA\x54\x53\xCA\x54\x52\xCA\x54\x58\xCA\x54\x57\xCA\x54\x5F\xCA\x54\x59\xCA\x55\x41\xCA\x54\x6A\xCA\x55\x42\xCA\x54\x70\xCA\x55\x4A\xCA\x55\x48\xCA\x55\x56\xCA\x55\x54\xCA\x55\x59\xCA\x55\x57\xCA\x55\x69\xCA\x55\x68\xCA\x55\x70\xCA\x55\x6A\xCA\x56\x43\xCA\x56\x41\xCA\x56\x46\xCA\x56\x45\xCA\x56\x49\xCA\x56\x47\xCA\x56\x62\xCC\x67\x57\xCA\x56\x64\xCC\x67\x58\xCA\x56\x66\xCA\x56\x65\xCA\x56\x69\xCA\x56\x68\xCA\x56\x71\xCA\x56\x70\xCA\x57\x49\xCA\x57\x52\xCA\x57\x4A\xCA\x57\x53\xCA\x57\x51\xCA\x57\x54\xCA\x5F\x45\xCA\x5F\x46\xCA\x5F\x47\xCA\x5F\x48\xCA\x5F\x49\xCA\x5F\x4A\xCA\x5F\x51\xCA\x5F\x52\xCA\x5F\x55\xCA\x5F\x56\xCA\x5F\x57\xCA\x5F\x58\xCA\x5F\x59\xCA\x5F\x5F\xCA\x5F\x62\xCA\x5F\x63\xCA\x5F\x68\xCA\x5F\x69\xCA\x5F\x6A\xCA\x5F\x70\xCA\x5F\x71\xCA\x5F\x72\xCA\x62\x41\xCA\x62\x42\xCA\x62\x43\xCA\x62\x44\xCA\x62\x45\xCA\x62\x46\xCA\x62\x47\xCA\x62\x48\xCA\x62\x49\xCA\x62\x4A\xCA\x62\x51\xCA\x62\x52\xCA\x63\x44\xCA\x63\x43\xCA\x63\x47\xCC\x64\x71\xCA\x63\x49\xCC\x65\x45\xCA\x63\x4A\xCC\x65\x44\xCA\x63\x57\xCA\x63\x58\xCA\x64\x57\xCA\x64\x58\xCA\x64\x64\xCA\x64\x65\xCA\x64\x66\xCA\x64\x67\xCA\x64\x6A\xCA\x64\x70\xCA\x64\x71\xCA\x64\x72\xCA\x65\x41\xCA\x65\x42\xCA\x65\x47\xCA\x65\x48\xCA\x65\x49\xCA\x65\x4A\xCA\x65\x59\xCA\x65\x68\xCA\x65\x5F\xCA\x65\x69\xCA\x65\x62\xCA\x65\x6A\xCA\x65\x64\xCA\x65\x70\xCA\x65\x65\xCA\x65\x71\xCA\x66\x49\xCA\x66\x4A\xCA\x66\x51\xCA\x66\x52\xCA\x67\x47\xCA\x67\x52\xCA\x67\x4A\xCA\x67\x51\xCA\x68\x49\xCA\x68\x48\xCA\x72\x4A\xCA\x72\x51\xCA\x72\x54\xCA\x72\x55\xCB\x57\x69\xCB\x57\x68\xCB\x57\x71\xCB\x57\x6A\xCB\x62\x71\xCB\x62\x72\xCB\x69\x49\xCB\x69\x4A\xCB\x69\x51\xCB\x69\x52\xCB\x69\x53\xCB\x69\x54\xCB\x69\x55\xCB\x69\x56\xCB\x69\x57\xCB\x69\x58\xCB\x69\x59\xCB\x69\x5F\xCB\x69\x62\xCB\x69\x63\xCB\x71\x44\xCB\x71\x45\xCB\x71\x46\xCB\x71\x47\xCB\x71\x49\xCB\x71\x4A\xCB\x71\x71\xCB\x71\x70\xCB\x72\x47\xCB\x72\x48\xCB\x72\x49\xCB\x72\x4A\xCB\x72\x51\xCB\x72\x52\xCB\x72\x53\xCB\x72\x54\xCB\x72\x55\xCB\x72\x56\xCB\x72\x62\xCC\x67\x59\xCB\x72\x64\xCB\x72\x63\xCB\x72\x67\xCB\x72\x66\xCB\x72\x6A\xCB\x72\x69\xCB\x72\x71\xCB\x72\x70\xCB\x72\x72\xCC\x67\x5F\xCC\x49\x41\xCC\x67\x62\xCC\x49\x42\xCC\x67\x63\xCC\x49\x44\xCC\x49\x43\xCC\x49\x46\xCC\x67\x64\xCC\x49\x48\xCC\x49\x47\xCC\x49\x54\xCC\x49\x53\xCC\x49\x56\xCC\x49\x55\xCC\x49\x57\xCC\x67\x65\xCC\x49\x58\xCC\x67\x66\xCC\x49\x62\xCC\x67\x67\xCC\x49\x63\xCC\x67\x68\xCC\x49\x64\xCC\x67\x69\xCC\x49\x65\xCC\x67\x6A\xCC\x49\x66\xCC\x67\x70\xCC\x49\x68\xCC\x49\x67\xCC\x49\x6A\xCC\x49\x69\xCC\x49\x71\xCC\x49\x70\xCC\x4A\x41\xCC\x49\x72\xCC\x4A\x5F\xCC\x67\x72\xCC\x4A\x65\xCC\x4A\x64\xCC\x51\x46\xCC\x51\x47\xCC\x51\x48\xCC\x67\x71\xCC\x51\x5F\xCC\x51\x59\xCC\x51\x65\xCC\x51\x64\xCC\x51\x69\xCC\x51\x68\xCC\x51\x72\xCC\x51\x71\xCC\x52\x45\xCC\x52\x43\xCC\x52\x53\xCC\x52\x51\xCC\x52\x54\xCC\x52\x52\xCC\x52\x58\xCC\x68\x41\xCC\x52\x59\xCC\x68\x42\xCC\x52\x62\xCC\x68\x52\xCC\x52\x63\xCC\x68\x43\xCC\x52\x67\xCC\x52\x69\xCC\x53\x44\xCC\x53\x45\xCC\x53\x46\xCC\x53\x47\xCC\x53\x48\xCC\x53\x49\xCC\x53\x4A\xCC\x53\x51\xCC\x53\x52\xCC\x53\x53\xCC\x53\x54\xCC\x53\x57\xCC\x53\x56\xCC\x53\x55\xCC\x53\x58\xCC\x53\x59\xCC\x53\x5F\xCC\x53\x62\xCC\x53\x63\xCC\x53\x64\xCC\x53\x65\xCC\x53\x66\xCC\x54\x49\xCC\x54\x4A\xCC\x54\x51\xCC\x54\x52\xCC\x54\x5F\xCC\x54\x62\xCC\x55\x41\xCC\x55\x42\xCC\x55\x66\xCC\x55\x67\xCC\x55\x68\xCC\x55\x69\xCC\x56\x6A\xCC\x56\x70\xCC\x5F\x67\xCC\x5F\x68\xCC\x5F\x69\xCC\x5F\x6A\xCC\x5F\x70\xCC\x5F\x71\xCC\x5F\x72\xCC\x62\x41\xCC\x62\x42\xCC\x62\x43\xCC\x62\x44\xCC\x62\x45\xCC\x62\x46\xCC\x62\x47\xCC\x62\x48\xCC\x62\x49\xCC\x62\x4A\xCC\x62\x51\xCC\x62\x54\xCC\x62\x55\xCC\x62\x63\xCC\x62\x64\xCC\x62\x65\xCC\x62\x66\xCC\x62\x67\xCC\x62\x68\xCC\x62\x69\xCC\x62\x6A\xCC\x62\x70\xCC\x62\x71\xCC\x62\x72\xCC\x63\x41\xCC\x63\x42\xCC\x63\x43\xCC\x63\x47\xCC\x63\x48\xCC\x63\x49\xCC\x63\x4A\xCC\x63\x51\xCC\x63\x52\xCC\x63\x53\xCC\x63\x54\xCC\x63\x56\xCC\x63\x57\xCC\x63\x58\xCC\x63\x59\xCC\x63\x5F\xCC\x63\x62\xCC\x63\x63\xCC\x63\x64\xCC\x63\x65\xCC\x63\x66\xCC\x63\x67\xCC\x63\x68\xCC\x63\x69\xCC\x63\x6A\xCC\x63\x70\xCC\x63\x71\xCC\x63\x72\xCC\x64\x41\xCC\x64\x42\xCC\x64\x43\xCC\x64\x44\xCC\x64\x45\xCC\x64\x46\xCC\x64\x47\xCC\x64\x48\xCC\x64\x49\xCC\x64\x4A\xCC\x64\x51\xCC\x64\x52\xCC\x64\x53\xCC\x64\x56\xCC\x64\x57\xCC\x64\x58\xCC\x64\x59\xCC\x64\x63\xCC\x64\x64\xCC\x65\x46\xCA\x63\x52\xCC\x65\x65\xCC\x65\x66\xCC\x65\x67\xCC\x65\x68\xCC\x68\x47\xCC\x68\x46\xCC\x68\x48\xCC\x68\x4A\xCC\x68\x49\xCC\x68\x51\xCC\x68\x53\xCC\x52\x5F\xCC\x69\x43\xCC\x69\x41\xCC\x69\x53\xCC\x69\x51\xCC\x69\x59\xCC\x69\x57\xCC\x69\x6A\xCC\x69\x68\xCC\x6A\x47\xCC\x6A\x45\xCC\x6A\x51\xCC\x6A\x49\xCC\x6A\x63\xCC\x66\x46\xCC\x6A\x68\xCC\x6A\x66\xCC\x6A\x71\xCC\x6A\x6A\xCC\x70\x42\xCC\x70\x41\xCC\x70\x44\xCC\x70\x43\xCC\x70\x4A\xCC\x70\x49\xCC\x70\x52\xCC\x70\x51\xCC\x70\x58\xCC\x70\x57\xCC\x70\x5F\xCC\x70\x59\xCC\x72\x55\xCC\x72\x53\xCD\x57\x43\xCD\x57\x44\xCD\x57\x44\xCD\x57\x45\xCD\x57\x46\xCD\x57\x46\xCD\x57\x4A\xCD\x57\x51\xCD\x57\x51\xCD\x57\x53\xCD\x57\x54\xCD\x57\x54\xCD\x57\x58\xCD\x57\x57\xCD\x57\x6A\xCD\x57\x70\xCD\x57\x70\xCD\x58\x41\xCD\x58\x42\xCD\x58\x42\xCD\x58\x43\xCD\x58\x44\xCD\x58\x45\xCD\x58\x46\xCD\x58\x47\xCD\x58\x48\xCD\x58\x49\xCD\x58\x4A\xCD\x58\x64\xCD\x58\x65\xCD\x59\x43\xCA\x41\x71\xCD\x59\x63\xCD\x59\x64\xCD\x59\x65\xCD\x59\x66\xCD\x59\x67\xCD\x59\x68\xCD\x59\x69\xCD\x59\x6A\xCE\x41\x49\xCE\x41\x4A\xCE\x41\x51\xCE\x41\x52\xCE\x41\x53\xCE\x41\x54\xCE\x41\x55\xCE\x41\x56\xCE\x41\x57\xCE\x41\x58\xCE\x41\x62\xCE\x41\x63\xCE\x41\x64\xCE\x41\x65\xCE\x41\x66\xCE\x41\x67\xCE\x41\x68\xCE\x41\x69\xCE\x41\x70\xCE\x41\x71\xDD\x51\x55\x42\xDD\x51\x55\x43\xDD\x72\x4A\x71\xDD\x72\x4A\x72\xDD\x72\x59\x67\xDD\x72\x59\x68\xDD\x72\x59\x69\xDD\x72\x59\x6A\xDD\x72\x59\x70\xDD\x72\x59\x71\xDD\x72\x5F\x45\xDD\x72\x5F\x46\xDD\x72\x66\x49\xDD\x72\x66\x4A\xDD\x72\x66\x6A\xDD\x72\x66\x71\xDD\x72\x67\x69\xDD\x72\x67\x70\xDD\x72\x68\x69\xDD\x72\x68\x70\xDD\x72\x68\x72\xDD\x72\x69\x41\xDD\x72\x69\x43\xDD\x72\x69\x44\xDD\x72\x72\x52\xDD\x72\x72\x4A\xDF\x62\x49\x44\xDF\x62\x49\x43\xDF\x62\x49\x47\xDF\x62\x49\x48\xDF\x70\x43\x4A\xDF\x70\x43\x49\xDF\x70\x49\x49\xDF\x70\x52\x49\xDF\x70\x49\x4A\xDF\x70\x52\x4A\xDF\x70\x49\x51\xDF\x70\x52\x51\xDF\x70\x52\x69\xDF\x70\x52\x70\xDF\x70\x53\x67\xDF\x70\x53\x66\xDF\x70\x53\x69\xDF\x70\x53\x68\xDF\x70\x53\x70\xDF\x70\x53\x6A\xDF\x70\x56\x47\xDF\x70\x56\x48\xDF\x71\x41\x43\xDF\x71\x41\x41\xDF\x71\x41\x47\xDF\x71\x41\x45\xDF\x71\x41\x51\xDF\x71\x41\x49\xDF\x71\x41\x59\xDF\x71\x41\x57\xDF\x71\x41\x64\xDF\x71\x41\x62\xDF\x71\x41\x68\xDF\x71\x41\x66\xDF\x71\x41\x71\xDF\x71\x41\x6A\xDF\x71\x42\x43\xDF\x71\x42\x41\xDF\x71\x42\x47\xDF\x71\x42\x45\xDF\x71\x42\x51\xDF\x71\x42\x49\xDF\x71\x42\x55\xDF\x71\x42\x53\xDF\x71\x42\x59\xDF\x71\x42\x57\xDF\x71\x42\x64\xDF\x71\x42\x62\xDF\x71\x42\x68\xDF\x71\x42\x66\xDF\x71\x42\x71\xDF\x71\x42\x6A\xDF\x71\x43\x43\xDF\x71\x43\x41\xDF\x71\x43\x47\xDF\x71\x43\x45\xDF\x71\x43\x59\xDF\x71\x43\x57\xDF\x71\x44\x43\xDF\x71\x44\x41\xDF\x71\x44\x51\xDF\x71\x44\x49\xDF\x71\x44\x59\xDF\x71\x44\x57\xDF\x71\x44\x68\xDF\x71\x44\x66\xDF\x71\x45\x43\xDF\x71\x45\x41\xDF\x71\x45\x59\xDF\x71\x45\x57\xDF\x71\x45\x64\xDF\x71\x45\x62\xDF\x71\x45\x68\xDF\x71\x45\x66\xDF\x71\x46\x42\xDF\x71\x46\x41\xDF\x71\x46\x44\xDF\x71\x46\x43\xDF\x71\x46\x46\xDF\x71\x46\x47\xDF\x71\x46\x48\xDF\x71\x46\x45\xDF\x71\x46\x4A\xDF\x71\x46\x49\xDF\x71\x46\x52\xDF\x71\x46\x51" # define DEPRECATED_OPENING_NON_UTF8_BRACKETS "\x8A\x8B" # endif Index: gnu/usr.bin/perl/universal.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/universal.c,v diff -u -p -a -u -p -r1.23 universal.c --- gnu/usr.bin/perl/universal.c 14 May 2024 19:38:54 -0000 1.23 +++ gnu/usr.bin/perl/universal.c 22 Jan 2025 00:37:45 -0000 @@ -397,6 +397,7 @@ A specialised variant of C for works out the package name and subroutine name from C, and then calls C. Hence if C is C<&ouch::awk>, it would call C as: + diag_listed_as: SKIPME Perl_croak(aTHX_ "Usage: %" SVf "::%" SVf "(%s)", "ouch" "awk", "eee_yow"); @@ -454,6 +455,34 @@ XS(XS_UNIVERSAL_isa) } } +XS(XS_UNIVERSAL_import_unimport); /* prototype to pass -Wmissing-prototypes */ +XS(XS_UNIVERSAL_import_unimport) +{ + dXSARGS; + dXSI32; + + if (items > 1) { + char *class_pv= SvPV_nolen(ST(0)); + if (strEQ(class_pv,"UNIVERSAL")) + Perl_croak(aTHX_ "UNIVERSAL does not export anything"); + /* _charnames is special - ignore it for now as the code that + * depends on it has its own "no import" logic that produces better + * warnings than this does. */ + if (strNE(class_pv,"_charnames")) + Perl_ck_warner_d(aTHX_ + packWARN(WARN_DEPRECATED__MISSING_IMPORT_CALLED_WITH_ARGS), + "Attempt to call undefined %s method with arguments " + "(%" SVf_QUOTEDPREFIX "%s) via package " + "%" SVf_QUOTEDPREFIX " (Perhaps you forgot to load the package?)", + ix ? "unimport" : "import", + SVfARG(ST(1)), + (items > 2 ? " ..." : ""), + SVfARG(ST(0))); + } + XSRETURN_EMPTY; +} + + XS(XS_UNIVERSAL_can); /* prototype to pass -Wmissing-prototypes */ XS(XS_UNIVERSAL_can) { @@ -753,6 +782,20 @@ XS(XS_Internals_hv_clear_placehold) } } +XS(XS_Internals_stack_refcounted); /* prototype to pass -Wmissing-prototypes */ +XS(XS_Internals_stack_refcounted) +{ + dXSARGS; + UV val = 0; + + if (items != 0) + croak_xs_usage(cv, ""); +#ifdef PERL_RC_STACK + val |= 1; +#endif + XSRETURN_UV(val); +} + XS(XS_PerlIO_get_layers); /* prototype to pass -Wmissing-prototypes */ XS(XS_PerlIO_get_layers) { @@ -993,6 +1036,7 @@ XS(XS_re_regnames) entry = av_fetch(av, i, FALSE); if (!entry) + /* diag_listed_as: SKIPME */ Perl_croak(aTHX_ "NULL array element in re::regnames()"); mPUSHs(SvREFCNT_inc_simple_NN(*entry)); @@ -1287,6 +1331,8 @@ static const struct xsub_details these_d {"UNIVERSAL::isa", XS_UNIVERSAL_isa, NULL, 0 }, {"UNIVERSAL::can", XS_UNIVERSAL_can, NULL, 0 }, {"UNIVERSAL::DOES", XS_UNIVERSAL_DOES, NULL, 0 }, + {"UNIVERSAL::import", XS_UNIVERSAL_import_unimport, NULL, 0}, + {"UNIVERSAL::unimport", XS_UNIVERSAL_import_unimport, NULL, 1}, #define VXS_XSUB_DETAILS #include "vxs.inc" #undef VXS_XSUB_DETAILS @@ -1301,6 +1347,7 @@ static const struct xsub_details these_d {"Internals::SvREADONLY", XS_Internals_SvREADONLY, "\\[$%@];$", 0 }, {"Internals::SvREFCNT", XS_Internals_SvREFCNT, "\\[$%@];$", 0 }, {"Internals::hv_clear_placeholders", XS_Internals_hv_clear_placehold, "\\%", 0 }, + {"Internals::stack_refcounted", XS_Internals_stack_refcounted, NULL, 0 }, {"constant::_make_const", XS_constant__make_const, "\\[$@]", 0 }, {"PerlIO::get_layers", XS_PerlIO_get_layers, "*;@", 0 }, {"re::is_regexp", XS_re_is_regexp, "$", 0 }, Index: gnu/usr.bin/perl/unixish.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/unixish.h,v diff -u -p -a -u -p -r1.18 unixish.h --- gnu/usr.bin/perl/unixish.h 14 May 2024 19:38:54 -0000 1.18 +++ gnu/usr.bin/perl/unixish.h 22 Jan 2025 00:37:45 -0000 @@ -15,8 +15,6 @@ * here. */ -#ifndef PERL_MICRO - /* HAS_IOCTL: * This symbol, if defined, indicates that the ioctl() routine is * available to set I/O characteristics @@ -46,8 +44,6 @@ #define HAS_KILL #define HAS_WAIT -#endif /* !PERL_MICRO */ - /* USEMYBINMODE * This symbol, if defined, indicates that the program should * use the routine my_binmode(FILE *fp, char iotype) to insure Index: gnu/usr.bin/perl/utf8.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/utf8.c,v diff -u -p -a -u -p -r1.7 utf8.c --- gnu/usr.bin/perl/utf8.c 14 May 2024 19:38:54 -0000 1.7 +++ gnu/usr.bin/perl/utf8.c 22 Jan 2025 00:37:45 -0000 @@ -935,7 +935,7 @@ Perl_is_utf8_FF_helper_(const U8 * const return (require_partial) ? 0 : UTF8_MAXBYTES; } -char * +const char * Perl__byte_dump_string(pTHX_ const U8 * const start, const STRLEN len, const bool format) { /* Returns a mortalized C string that is a displayable copy of the 'len' @@ -945,6 +945,10 @@ Perl__byte_dump_string(pTHX_ const U8 * * 1 ab (that is a space between two hex digit bytes) */ + if (start == NULL) { + return "(nil)"; + } + const STRLEN output_len = 4 * len + 1; /* 4 bytes per each input, plus a trailing NUL */ const U8 * s = start; @@ -2255,7 +2259,7 @@ Perl_utf8_length(pTHX_ const U8 * const do { /* Process per-word */ /* The idea for counting continuation bytes came from - * http://www.daemonology.net/blog/2008-06-05-faster-utf8-strlen.html + * https://www.daemonology.net/blog/2008-06-05-faster-utf8-strlen.html * One thing it does that this doesn't is to prefetch the buffer * __builtin_prefetch(&s[256], 0, 0); * Index: gnu/usr.bin/perl/utf8.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/utf8.h,v diff -u -p -a -u -p -r1.11 utf8.h --- gnu/usr.bin/perl/utf8.h 14 May 2024 19:39:39 -0000 1.11 +++ gnu/usr.bin/perl/utf8.h 22 Jan 2025 00:37:45 -0000 @@ -374,7 +374,8 @@ are in the character. */ /* For use in UTF8_IS_CONTINUATION(). This turns out to be 0xC0 in UTF-8, * E0 in UTF-EBCDIC */ -#define UTF_IS_CONTINUATION_MASK ((U8) (0xFF << UTF_ACCUMULATION_SHIFT)) +#define UTF_IS_CONTINUATION_MASK \ + ((U8) ((0xFF << UTF_ACCUMULATION_SHIFT) & 0xFF)) /* This defines the bits that are to be in the continuation bytes of a * multi-byte UTF-8 encoded character that mark it is a continuation byte. Index: gnu/usr.bin/perl/util.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/util.c,v diff -u -p -a -u -p -r1.44 util.c --- gnu/usr.bin/perl/util.c 14 May 2024 19:39:39 -0000 1.44 +++ gnu/usr.bin/perl/util.c 22 Jan 2025 00:37:45 -0000 @@ -30,12 +30,10 @@ #include "perliol.h" /* For PerlIOUnix_refcnt */ #endif -#ifndef PERL_MICRO #include #ifndef SIG_ERR # define SIG_ERR ((Sighandler_t) -1) #endif -#endif #include #include @@ -207,7 +205,7 @@ Perl_safesysmalloc(MEM_SIZE size) if (PL_nomemok) ptr = NULL; else - croak_no_mem(); + croak_no_mem_ext(STR_WITH_LEN("util:safesysmalloc")); } } return ptr; @@ -254,8 +252,8 @@ Perl_safesysrealloc(Malloc_t where,MEM_S # ifdef PERL_TRACK_MEMPOOL if (header->interpreter != aTHX) { - Perl_croak_nocontext("panic: realloc from wrong pool, %p!=%p", - header->interpreter, aTHX); + Perl_croak_nocontext("panic: realloc %p from wrong pool, %p!=%p", + where, header->interpreter, aTHX); } assert(header->next->prev == header); assert(header->prev->next == header); @@ -274,7 +272,8 @@ Perl_safesysrealloc(Malloc_t where,MEM_S #endif #ifdef DEBUGGING if ((SSize_t)size < 0) - Perl_croak_nocontext("panic: realloc, size=%" UVuf, (UV)size); + Perl_croak_nocontext("panic: realloc %p , size=%" UVuf, + where, (UV)size); #endif #ifdef PERL_DEBUG_READONLY_COW if ((ptr = mmap(0, size, PROT_READ|PROT_WRITE, @@ -341,7 +340,7 @@ Perl_safesysrealloc(Malloc_t where,MEM_S if (PL_nomemok) ptr = NULL; else - croak_no_mem(); + croak_no_mem_ext(STR_WITH_LEN("util:safesysrealloc")); } } } @@ -374,18 +373,19 @@ Perl_safesysfree(Malloc_t where) # endif # ifdef PERL_TRACK_MEMPOOL if (header->interpreter != aTHX) { - Perl_croak_nocontext("panic: free from wrong pool, %p!=%p", - header->interpreter, aTHX); + Perl_croak_nocontext("panic: free %p from wrong pool, %p!=%p", + where, header->interpreter, aTHX); } if (!header->prev) { Perl_croak_nocontext("panic: duplicate free"); } if (!(header->next)) - Perl_croak_nocontext("panic: bad free, header->next==NULL"); + Perl_croak_nocontext("panic: bad free of %p, header->next==NULL", + where); if (header->next->prev != header || header->prev->next != header) { - Perl_croak_nocontext("panic: bad free, ->next->prev=%p, " + Perl_croak_nocontext("panic: bad free of %p, ->next->prev=%p, " "header=%p, ->prev->next=%p", - header->next->prev, header, + where, header->next->prev, header, header->prev->next); } /* Unlink us from the chain. */ @@ -512,7 +512,7 @@ Perl_safesyscalloc(MEM_SIZE count, MEM_S #endif if (PL_nomemok) return NULL; - croak_no_mem(); + croak_no_mem_ext(STR_WITH_LEN("util:safesyscalloc")); } } @@ -1342,7 +1342,7 @@ Perl_savesharedpv(pTHX_ const char *pv) pvlen = strlen(pv)+1; newaddr = (char*)PerlMemShared_malloc(pvlen); if (!newaddr) { - croak_no_mem(); + croak_no_mem_ext(STR_WITH_LEN("util:savesharedpv")); } return (char*)memcpy(newaddr, pv, pvlen); } @@ -1365,7 +1365,7 @@ Perl_savesharedpvn(pTHX_ const char *con /* PERL_ARGS_ASSERT_SAVESHAREDPVN; */ if (!newaddr) { - croak_no_mem(); + croak_no_mem_ext(STR_WITH_LEN("util:savesharedpvn")); } newaddr[len] = '\0'; return (char*)memcpy(newaddr, pv, len); @@ -1419,22 +1419,29 @@ Perl_form_nocontext(const char* pat, ... These take a sprintf-style format pattern and conventional (non-SV) arguments and return the formatted string. - (char *) Perl_form(pTHX_ const char* pat, ...) + (char *) Perl_form(aTHX_ const char* pat, ...) + +They can be used any place a string (char *) is required: -can be used any place a string (char *) is required: + char * s = form_nocontext("%d.%d", major, minor); - char * s = Perl_form("%d.%d",major,minor); +They each return a temporary that will be freed "soon", automatically by the +system, at the same time that SVs operated on by C> are freed. -They use a single (per-thread) private buffer so if you want to format several -strings you must explicitly copy the earlier strings away (and free the copies -when you are done). +Use the result immediately, or copy to a stable place for longer retention. +This is contrary to the incorrect previous documentation of these that claimed +that the return was a single per-thread buffer. That was (and is) actually +true only when these are called during global destruction. The two forms differ only in that C does not take a thread context (C) parameter, so is used in situations where the caller doesn't already have the thread context. +C> is the same except the arguments are an encapsulated argument list. + =for apidoc vform -Like C> but but the arguments are an encapsulated argument list. + +Like C> except the arguments are an encapsulated argument list. =cut */ @@ -1970,20 +1977,35 @@ Perl_croak_no_modify(void) This is typically called when malloc returns NULL. */ void -Perl_croak_no_mem(void) +Perl_croak_no_mem_ext(const char *context, STRLEN len) { dTHX; + PERL_ARGS_ASSERT_CROAK_NO_MEM_EXT; + int fd = PerlIO_fileno(Perl_error_log); if (fd < 0) SETERRNO(EBADF,RMS_IFI); else { /* Can't use PerlIO to write as it allocates memory */ - PERL_UNUSED_RESULT(PerlLIO_write(fd, PL_no_mem, sizeof(PL_no_mem)-1)); + static const char oomp[] = "Out of memory in perl:"; + if ( + PerlLIO_write(fd, oomp, sizeof oomp - 1) >= 0 + && PerlLIO_write(fd, context, len) >= 0 + && PerlLIO_write(fd, "\n", 1) >= 0 + ) { + /* nop */ + } } my_exit(1); } +void +Perl_croak_no_mem(void) +{ + croak_no_mem_ext(STR_WITH_LEN("???")); +} + /* does not return, used only in POPSTACK */ void Perl_croak_popstack(void) @@ -2135,6 +2157,27 @@ any of the categories are by default ena =for apidoc vwarner This is like C>, but C are an encapsulated argument list. +=for apidoc fatal_warner + +Like L except that it acts as if fatal warnings are enabled +for the warning. + +If called when there are pending compilation errors this function may +return. + +This is currently used to generate "used only once" fatal warnings +since the COP where the name being reported is no longer the current +COP when the warning is generated and may be useful for similar cases. + +C must be one of the C>, C, C, +C macros populated with the appropriate number of warning +categories. + +=for apidoc vfatal_warner + +This is like C> but C are an encapsulated +argument list. + =cut */ @@ -2195,21 +2238,42 @@ Perl_vwarner(pTHX_ U32 err, const char* (PL_warnhook == PERL_WARNHOOK_FATAL || ckDEAD(err)) && !(PL_in_eval & EVAL_KEEPERR) ) { - SV * const msv = vmess(pat, args); - - if (PL_parser && PL_parser->error_count) { - qerror(msv); - } - else { - invoke_exception_hook(msv, FALSE); - die_unwind(msv); - } + vfatal_warner(err, pat, args); } else { Perl_vwarn(aTHX_ pat, args); } } +void +Perl_fatal_warner(pTHX_ U32 err, const char *pat, ...) +{ + PERL_ARGS_ASSERT_FATAL_WARNER; + + va_list args; + va_start(args, pat); + vfatal_warner(err, pat, &args); + va_end(args); +} + +void +Perl_vfatal_warner(pTHX_ U32 err, const char *pat, va_list *args) +{ + PERL_ARGS_ASSERT_VFATAL_WARNER; + + PERL_UNUSED_ARG(err); + + SV * const msv = vmess(pat, args); + + if (PL_parser && PL_parser->error_count) { + qerror(msv); + } + else { + invoke_exception_hook(msv, FALSE); + die_unwind(msv); + } +} + /* implements the ckWARN? macros */ bool @@ -2341,30 +2405,36 @@ void Perl_my_setenv(pTHX_ const char *nam, const char *val) { # if defined(USE_ITHREADS) && !defined(WIN32) - /* only parent thread can modify process environment, so no need to use a - * mutex */ + /* only parent thread can modify process environment */ if (PL_curinterp != aTHX) return; # endif # if defined(HAS_SETENV) && defined(HAS_UNSETENV) + ENV_LOCK; if (val == NULL) { unsetenv(nam); } else { setenv(nam, val, 1); } + ENV_UNLOCK; # elif defined(HAS_UNSETENV) if (val == NULL) { - if (environ) /* old glibc can crash with null environ */ + if (environ) { /* old glibc can crash with null environ */ + ENV_LOCK; unsetenv(nam); + ENV_UNLOCK; + } } else { const Size_t nlen = strlen(nam); const Size_t vlen = strlen(val); char * const new_env = S_env_alloc(NULL, nlen, vlen, 2, 1); my_setenv_format(new_env, nam, nlen, val, vlen); + ENV_LOCK; putenv(new_env); + ENV_UNLOCK; } # else /* ! HAS_UNSETENV */ @@ -2378,7 +2448,9 @@ Perl_my_setenv(pTHX_ const char *nam, co /* all that work just for this */ my_setenv_format(new_env, nam, nlen, val, vlen); # ifndef WIN32 + ENV_LOCK; putenv(new_env); + ENV_UNLOCK; # else PerlEnv_putenv(new_env); safesysfree(new_env); @@ -2881,7 +2953,6 @@ dup2(int oldfd, int newfd) } #endif -#ifndef PERL_MICRO #ifdef HAS_SIGACTION /* @@ -3049,7 +3120,6 @@ Perl_rsignal_restore(pTHX_ int signo, Si } #endif /* !HAS_SIGACTION */ -#endif /* !PERL_MICRO */ /* VMS' my_pclose() is in VMS.c */ @@ -3256,7 +3326,7 @@ all. #define PERL_REPEATCPY_LINEAR 4 void -Perl_repeatcpy(char *to, const char *from, I32 len, IV count) +Perl_repeatcpy(char *to, const char *from, SSize_t len, IV count) { PERL_ARGS_ASSERT_REPEATCPY; @@ -3591,7 +3661,7 @@ Perl_set_context(void *t) } # endif - PERL_SET_NON_tTHX_CONTEXT(t); + PERL_SET_NON_tTHX_CONTEXT((PerlInterpreter *) t); #else PERL_UNUSED_ARG(t); @@ -4055,7 +4125,6 @@ Fill C with current working director int Perl_getcwd_sv(pTHX_ SV *sv) { -#ifndef PERL_MICRO SvTAINTED_on(sv); PERL_ARGS_ASSERT_GETCWD_SV; @@ -4192,9 +4261,6 @@ Perl_getcwd_sv(pTHX_ SV *sv) return TRUE; #endif -#else - return FALSE; -#endif } #include "vutil.c" @@ -4612,7 +4678,7 @@ PERL_STATIC_INLINE U32 S_ptr_hash(PTRV u #else /* * This is one of Bob Jenkins' hash functions for 32-bit integers - * from: http://burtleburtle.net/bob/hash/integer.html + * from: https://burtleburtle.net/bob/hash/integer.html */ u = (u + 0x7ed55d16) + (u << 12); u = (u ^ 0xc761c23c) ^ (u >> 19); @@ -5348,22 +5414,23 @@ Perl_my_vsnprintf(char *buffer, const Si void Perl_my_clearenv(pTHX) { -#if ! defined(PERL_MICRO) # if defined(PERL_IMPLICIT_SYS) || defined(WIN32) PerlEnv_clearenv(); # else /* ! (PERL_IMPLICIT_SYS || WIN32) */ # if defined(USE_ENVIRON_ARRAY) # if defined(USE_ITHREADS) - /* only the parent thread can clobber the process environment, so no need - * to use a mutex */ + /* only the parent thread can clobber the process environment */ if (PL_curinterp != aTHX) return; # endif /* USE_ITHREADS */ # if defined(HAS_CLEARENV) + ENV_LOCK; clearenv(); + ENV_UNLOCK; # elif defined(HAS_UNSETENV) int bsiz = 80; /* Most envvar names will be shorter than this. */ char *buf = (char*)safesysmalloc(bsiz); + ENV_LOCK; while (*environ != NULL) { char *e = strchr(*environ, '='); int l = e ? e - *environ : (int)strlen(*environ); @@ -5376,6 +5443,7 @@ Perl_my_clearenv(pTHX) buf[l] = '\0'; unsetenv(buf); } + ENV_UNLOCK; safesysfree(buf); # else /* ! HAS_CLEARENV && ! HAS_UNSETENV */ /* Just null environ and accept the leakage. */ @@ -5383,7 +5451,6 @@ Perl_my_clearenv(pTHX) # endif /* HAS_CLEARENV || HAS_UNSETENV */ # endif /* USE_ENVIRON_ARRAY */ # endif /* PERL_IMPLICIT_SYS || WIN32 */ -#endif /* PERL_MICRO */ } #ifdef MULTIPLICITY @@ -5486,11 +5553,12 @@ Perl_my_cxt_init(pTHX_ int *indexp, size 'file' is the source filename of the caller. */ -I32 +Stack_off_t Perl_xs_handshake(const U32 key, void * v_my_perl, const char * file, ...) { va_list args; - U32 items, ax; + Stack_off_t items; + Stack_off_t ax; void * got; void * need; const char *stage = "first"; @@ -5552,13 +5620,15 @@ Perl_xs_handshake(const U32 key, void * ax = POPMARK; { SV **mark = PL_stack_base + ax++; { dSP; - items = (I32)(SP - MARK); + items = (Stack_off_t)(SP - MARK); } } } else { - items = va_arg(args, U32); - ax = va_arg(args, U32); + items = va_arg(args, Stack_off_t); + ax = va_arg(args, Stack_off_t); } + assert(ax >= 0); + assert(items >= 0); { U32 apiverlen; assert(HS_GETAPIVERLEN(key) <= UCHAR_MAX); @@ -5585,7 +5655,7 @@ Perl_xs_handshake(const U32 key, void * STATIC void -S_xs_version_bootcheck(pTHX_ U32 items, U32 ax, const char *xs_p, +S_xs_version_bootcheck(pTHX_ SSize_t items, SSize_t ax, const char *xs_p, STRLEN xs_len) { SV *sv; Index: gnu/usr.bin/perl/vutil.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/vutil.c,v diff -u -p -a -u -p -r1.20 vutil.c --- gnu/usr.bin/perl/vutil.c 14 May 2024 19:39:39 -0000 1.20 +++ gnu/usr.bin/perl/vutil.c 22 Jan 2025 00:37:45 -0000 @@ -7,6 +7,28 @@ #define VERSION_MAX 0x7FFFFFFF +#ifndef STRLENs +# define STRLENs(s) (sizeof("" s "") - 1) +#endif +#ifndef POSIX_SETLOCALE_LOCK +# ifdef gwLOCALE_LOCK +# define POSIX_SETLOCALE_LOCK gwLOCALE_LOCK +# define POSIX_SETLOCALE_UNLOCK gwLOCALE_UNLOCK +# else +# define POSIX_SETLOCALE_LOCK NOOP +# define POSIX_SETLOCALE_UNLOCK NOOP +# endif +#endif +#ifndef DISABLE_LC_NUMERIC_CHANGES +# ifdef LOCK_LC_NUMERIC_STANDARD +# define DISABLE_LC_NUMERIC_CHANGES() LOCK_LC_NUMERIC_STANDARD() +# define REENABLE_LC_NUMERIC_CHANGES() UNLOCK_LC_NUMERIC_STANDARD() +# else +# define DISABLE_LC_NUMERIC_CHANGES() NOOP +# define REENABLE_LC_NUMERIC_CHANGES() NOOP +# endif +#endif + /* =for apidoc prescan_version @@ -23,8 +45,8 @@ Perl_prescan_version2(pTHX_ const char * #else Perl_prescan_version(pTHX_ const char *s, bool strict, #endif - const char **errstr, - bool *sqv, int *ssaw_decimal, int *swidth, bool *salpha) { + const char **errstr, + bool *sqv, int *ssaw_decimal, int *swidth, bool *salpha) { bool qv = (sqv ? *sqv : FALSE); int width = 3; int saw_decimal = 0; @@ -35,200 +57,200 @@ Perl_prescan_version(pTHX_ const char *s PERL_UNUSED_CONTEXT; if (qv && isDIGIT(*d)) - goto dotted_decimal_version; + goto dotted_decimal_version; if (*d == 'v') { /* explicit v-string */ - d++; - if (isDIGIT(*d)) { - qv = TRUE; - } - else { /* degenerate v-string */ - /* requires v1.2.3 */ - BADVERSION(s,errstr,"Invalid version format (dotted-decimal versions require at least three parts)"); - } + d++; + if (isDIGIT(*d)) { + qv = TRUE; + } + else { /* degenerate v-string */ + /* requires v1.2.3 */ + BADVERSION(s,errstr,"Invalid version format (dotted-decimal versions require at least three parts)"); + } dotted_decimal_version: - if (strict && d[0] == '0' && isDIGIT(d[1])) { - /* no leading zeros allowed */ - BADVERSION(s,errstr,"Invalid version format (no leading zeros)"); - } - - while (isDIGIT(*d)) /* integer part */ - d++; - - if (*d == '.') - { - saw_decimal++; - d++; /* decimal point */ - } - else - { - if (strict) { - /* require v1.2.3 */ - BADVERSION(s,errstr,"Invalid version format (dotted-decimal versions require at least three parts)"); - } - else { - goto version_prescan_finish; - } - } - - { - int i = 0; - int j = 0; - while (isDIGIT(*d)) { /* just keep reading */ - i++; - while (isDIGIT(*d)) { - d++; j++; - /* maximum 3 digits between decimal */ - if (strict && j > 3) { - BADVERSION(s,errstr,"Invalid version format (maximum 3 digits between decimals)"); - } - } - if (*d == '_') { - if (strict) { - BADVERSION(s,errstr,"Invalid version format (no underscores)"); - } - if ( alpha ) { - BADVERSION(s,errstr,"Invalid version format (multiple underscores)"); - } - d++; - alpha = TRUE; - } - else if (*d == '.') { - if (alpha) { - BADVERSION(s,errstr,"Invalid version format (underscores before decimal)"); - } - saw_decimal++; - d++; - } - else if (!isDIGIT(*d)) { - break; - } - j = 0; - } - - if (strict && i < 2) { - /* requires v1.2.3 */ - BADVERSION(s,errstr,"Invalid version format (dotted-decimal versions require at least three parts)"); - } - } - } /* end if dotted-decimal */ + if (strict && d[0] == '0' && isDIGIT(d[1])) { + /* no leading zeros allowed */ + BADVERSION(s,errstr,"Invalid version format (no leading zeros)"); + } + + while (isDIGIT(*d)) /* integer part */ + d++; + + if (*d == '.') + { + saw_decimal++; + d++; /* decimal point */ + } + else + { + if (strict) { + /* require v1.2.3 */ + BADVERSION(s,errstr,"Invalid version format (dotted-decimal versions require at least three parts)"); + } + else { + goto version_prescan_finish; + } + } + + { + int i = 0; + int j = 0; + while (isDIGIT(*d)) { /* just keep reading */ + i++; + while (isDIGIT(*d)) { + d++; j++; + /* maximum 3 digits between decimal */ + if (strict && j > 3) { + BADVERSION(s,errstr,"Invalid version format (maximum 3 digits between decimals)"); + } + } + if (*d == '_') { + if (strict) { + BADVERSION(s,errstr,"Invalid version format (no underscores)"); + } + if ( alpha ) { + BADVERSION(s,errstr,"Invalid version format (multiple underscores)"); + } + d++; + alpha = TRUE; + } + else if (*d == '.') { + if (alpha) { + BADVERSION(s,errstr,"Invalid version format (underscores before decimal)"); + } + saw_decimal++; + d++; + } + else if (!isDIGIT(*d)) { + break; + } + j = 0; + } + + if (strict && i < 2) { + /* requires v1.2.3 */ + BADVERSION(s,errstr,"Invalid version format (dotted-decimal versions require at least three parts)"); + } + } + } /* end if dotted-decimal */ else - { /* decimal versions */ - int j = 0; /* may need this later */ - /* special strict case for leading '.' or '0' */ - if (strict) { - if (*d == '.') { - BADVERSION(s,errstr,"Invalid version format (0 before decimal required)"); - } - if (*d == '0' && isDIGIT(d[1])) { - BADVERSION(s,errstr,"Invalid version format (no leading zeros)"); - } - } - - /* and we never support negative versions */ - if ( *d == '-') { - BADVERSION(s,errstr,"Invalid version format (negative version number)"); - } - - /* consume all of the integer part */ - while (isDIGIT(*d)) - d++; - - /* look for a fractional part */ - if (*d == '.') { - /* we found it, so consume it */ - saw_decimal++; - d++; - } - else if (!*d || *d == ';' || isSPACE(*d) || *d == '{' || *d == '}') { - if ( d == s ) { - /* found nothing */ - BADVERSION(s,errstr,"Invalid version format (version required)"); - } - /* found just an integer */ - goto version_prescan_finish; - } - else if ( d == s ) { - /* didn't find either integer or period */ - BADVERSION(s,errstr,"Invalid version format (non-numeric data)"); - } - else if (*d == '_') { - /* underscore can't come after integer part */ - if (strict) { - BADVERSION(s,errstr,"Invalid version format (no underscores)"); - } - else if (isDIGIT(d[1])) { - BADVERSION(s,errstr,"Invalid version format (alpha without decimal)"); - } - else { - BADVERSION(s,errstr,"Invalid version format (misplaced underscore)"); - } - } - else { - /* anything else after integer part is just invalid data */ - BADVERSION(s,errstr,"Invalid version format (non-numeric data)"); - } - - /* scan the fractional part after the decimal point*/ - - if (!isDIGIT(*d) && (strict || ! (!*d || *d == ';' || isSPACE(*d) || *d == '{' || *d == '}') )) { - /* strict or lax-but-not-the-end */ - BADVERSION(s,errstr,"Invalid version format (fractional part required)"); - } - - while (isDIGIT(*d)) { - d++; j++; - if (*d == '.' && isDIGIT(d[-1])) { - if (alpha) { - BADVERSION(s,errstr,"Invalid version format (underscores before decimal)"); - } - if (strict) { - BADVERSION(s,errstr,"Invalid version format (dotted-decimal versions must begin with 'v')"); - } - d = (char *)s; /* start all over again */ - qv = TRUE; - goto dotted_decimal_version; - } - if (*d == '_') { - if (strict) { - BADVERSION(s,errstr,"Invalid version format (no underscores)"); - } - if ( alpha ) { - BADVERSION(s,errstr,"Invalid version format (multiple underscores)"); - } - if ( ! isDIGIT(d[1]) ) { - BADVERSION(s,errstr,"Invalid version format (misplaced underscore)"); - } - width = j; - d++; - alpha = TRUE; - } - } + { /* decimal versions */ + int j = 0; /* may need this later */ + /* special strict case for leading '.' or '0' */ + if (strict) { + if (*d == '.') { + BADVERSION(s,errstr,"Invalid version format (0 before decimal required)"); + } + if (*d == '0' && isDIGIT(d[1])) { + BADVERSION(s,errstr,"Invalid version format (no leading zeros)"); + } + } + + /* and we never support negative versions */ + if ( *d == '-') { + BADVERSION(s,errstr,"Invalid version format (negative version number)"); + } + + /* consume all of the integer part */ + while (isDIGIT(*d)) + d++; + + /* look for a fractional part */ + if (*d == '.') { + /* we found it, so consume it */ + saw_decimal++; + d++; + } + else if (!*d || *d == ';' || isSPACE(*d) || *d == '{' || *d == '}') { + if ( d == s ) { + /* found nothing */ + BADVERSION(s,errstr,"Invalid version format (version required)"); + } + /* found just an integer */ + goto version_prescan_finish; + } + else if ( d == s ) { + /* didn't find either integer or period */ + BADVERSION(s,errstr,"Invalid version format (non-numeric data)"); + } + else if (*d == '_') { + /* underscore can't come after integer part */ + if (strict) { + BADVERSION(s,errstr,"Invalid version format (no underscores)"); + } + else if (isDIGIT(d[1])) { + BADVERSION(s,errstr,"Invalid version format (alpha without decimal)"); + } + else { + BADVERSION(s,errstr,"Invalid version format (misplaced underscore)"); + } + } + else { + /* anything else after integer part is just invalid data */ + BADVERSION(s,errstr,"Invalid version format (non-numeric data)"); + } + + /* scan the fractional part after the decimal point*/ + + if (!isDIGIT(*d) && (strict || ! (!*d || *d == ';' || isSPACE(*d) || *d == '{' || *d == '}') )) { + /* strict or lax-but-not-the-end */ + BADVERSION(s,errstr,"Invalid version format (fractional part required)"); + } + + while (isDIGIT(*d)) { + d++; j++; + if (*d == '.' && isDIGIT(d[-1])) { + if (alpha) { + BADVERSION(s,errstr,"Invalid version format (underscores before decimal)"); + } + if (strict) { + BADVERSION(s,errstr,"Invalid version format (dotted-decimal versions must begin with 'v')"); + } + d = (char *)s; /* start all over again */ + qv = TRUE; + goto dotted_decimal_version; + } + if (*d == '_') { + if (strict) { + BADVERSION(s,errstr,"Invalid version format (no underscores)"); + } + if ( alpha ) { + BADVERSION(s,errstr,"Invalid version format (multiple underscores)"); + } + if ( ! isDIGIT(d[1]) ) { + BADVERSION(s,errstr,"Invalid version format (misplaced underscore)"); + } + width = j; + d++; + alpha = TRUE; + } + } } version_prescan_finish: while (isSPACE(*d)) - d++; + d++; - if (!isDIGIT(*d) && (! (!*d || *d == ';' || *d == '{' || *d == '}') )) { - /* trailing non-numeric data */ - BADVERSION(s,errstr,"Invalid version format (non-numeric data)"); + if (!isDIGIT(*d) && (! (!*d || *d == ';' || *d == ':' || *d == '{' || *d == '}') )) { + /* trailing non-numeric data */ + BADVERSION(s,errstr,"Invalid version format (non-numeric data)"); } if (saw_decimal > 1 && d[-1] == '.') { - /* no trailing period allowed */ - BADVERSION(s,errstr,"Invalid version format (trailing decimal)"); + /* no trailing period allowed */ + BADVERSION(s,errstr,"Invalid version format (trailing decimal)"); } if (sqv) - *sqv = qv; + *sqv = qv; if (swidth) - *swidth = width; + *swidth = width; if (ssaw_decimal) - *ssaw_decimal = saw_decimal; + *ssaw_decimal = saw_decimal; if (salpha) - *salpha = alpha; + *salpha = alpha; return d; } @@ -275,19 +297,19 @@ Perl_scan_version(pTHX_ const char *s, S PERL_ARGS_ASSERT_SCAN_VERSION; while (isSPACE(*s)) /* leading whitespace is OK */ - s++; + s++; last = PRESCAN_VERSION(s, FALSE, &errstr, &qv, &saw_decimal, &width, &alpha); if (errstr) { - /* "undef" is a special case and not an error */ - if ( ! ( *s == 'u' && strEQ(s+1,"ndef")) ) { - Perl_croak(aTHX_ "%s", errstr); - } + /* "undef" is a special case and not an error */ + if ( ! ( *s == 'u' && strEQ(s+1,"ndef")) ) { + Perl_croak(aTHX_ "%s", errstr); + } } start = s; if (*s == 'v') - s++; + s++; pos = s; /* Now that we are through the prescan, start creating the object */ @@ -300,66 +322,66 @@ Perl_scan_version(pTHX_ const char *s, S #endif if ( qv ) - (void)hv_stores(MUTABLE_HV(hv), "qv", newSViv(qv)); + (void)hv_stores(MUTABLE_HV(hv), "qv", newSViv(qv)); if ( alpha ) - (void)hv_stores(MUTABLE_HV(hv), "alpha", newSViv(alpha)); + (void)hv_stores(MUTABLE_HV(hv), "alpha", newSViv(alpha)); if ( !qv && width < 3 ) - (void)hv_stores(MUTABLE_HV(hv), "width", newSViv(width)); + (void)hv_stores(MUTABLE_HV(hv), "width", newSViv(width)); while (isDIGIT(*pos) || *pos == '_') - pos++; + pos++; if (!isALPHA(*pos)) { - I32 rev; + I32 rev; - for (;;) { - rev = 0; - { - /* this is atoi() that delimits on underscores */ - const char *end = pos; - I32 mult = 1; - I32 orev; - - /* the following if() will only be true after the decimal - * point of a version originally created with a bare - * floating point number, i.e. not quoted in any way - */ - if ( !qv && s > start && saw_decimal == 1 ) { - mult *= 100; - while ( s < end ) { - if (*s == '_') - continue; - orev = rev; - rev += (*s - '0') * mult; - mult /= 10; - if ( (PERL_ABS(orev) > PERL_ABS(rev)) - || (PERL_ABS(rev) > VERSION_MAX )) { - Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), - "Integer overflow in version %d",VERSION_MAX); - s = end - 1; - rev = VERSION_MAX; - vinf = 1; - } - s++; - if ( *s == '_' ) - s++; - } - } - else { - while (--end >= s) { - int i; - if (*end == '_') - continue; - i = (*end - '0'); + for (;;) { + rev = 0; + { + /* this is atoi() that delimits on underscores */ + const char *end = pos; + I32 mult = 1; + I32 orev; + + /* the following if() will only be true after the decimal + * point of a version originally created with a bare + * floating point number, i.e. not quoted in any way + */ + if ( !qv && s > start && saw_decimal == 1 ) { + mult *= 100; + while ( s < end ) { + if (*s == '_') + continue; + orev = rev; + rev += (*s - '0') * mult; + mult /= 10; + if ( (PERL_ABS(orev) > PERL_ABS(rev)) + || (PERL_ABS(rev) > VERSION_MAX )) { + Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), + "Integer overflow in version %d",VERSION_MAX); + s = end - 1; + rev = VERSION_MAX; + vinf = 1; + } + s++; + if ( *s == '_' ) + s++; + } + } + else { + while (--end >= s) { + int i; + if (*end == '_') + continue; + i = (*end - '0'); if ( (mult == VERSION_MAX) || (i > VERSION_MAX / mult) || (i * mult > VERSION_MAX - rev)) { - Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), - "Integer overflow in version"); - end = s - 1; - rev = VERSION_MAX; - vinf = 1; - } + Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), + "Integer overflow in version"); + end = s - 1; + rev = VERSION_MAX; + vinf = 1; + } else rev += i * mult; @@ -367,79 +389,79 @@ Perl_scan_version(pTHX_ const char *s, S mult = VERSION_MAX; else mult *= 10; - } - } - } - - /* Append revision */ - av_push(av, newSViv(rev)); - if ( vinf ) { - s = last; - break; - } - else if ( *pos == '.' ) { - pos++; - if (qv) { - while (*pos == '0') - ++pos; - } - s = pos; - } - else if ( *pos == '_' && isDIGIT(pos[1]) ) - s = ++pos; - else if ( *pos == ',' && isDIGIT(pos[1]) ) - s = ++pos; - else if ( isDIGIT(*pos) ) - s = pos; - else { - s = pos; - break; - } - if ( qv ) { - while ( isDIGIT(*pos) || *pos == '_') - pos++; - } - else { - int digits = 0; - while ( ( isDIGIT(*pos) || *pos == '_' ) && digits < 3 ) { - if ( *pos != '_' ) - digits++; - pos++; - } - } - } + } + } + } + + /* Append revision */ + av_push(av, newSViv(rev)); + if ( vinf ) { + s = last; + break; + } + else if ( *pos == '.' ) { + pos++; + if (qv) { + while (*pos == '0') + ++pos; + } + s = pos; + } + else if ( *pos == '_' && isDIGIT(pos[1]) ) + s = ++pos; + else if ( *pos == ',' && isDIGIT(pos[1]) ) + s = ++pos; + else if ( isDIGIT(*pos) ) + s = pos; + else { + s = pos; + break; + } + if ( qv ) { + while ( isDIGIT(*pos) || *pos == '_') + pos++; + } + else { + int digits = 0; + while ( ( isDIGIT(*pos) || *pos == '_' ) && digits < 3 ) { + if ( *pos != '_' ) + digits++; + pos++; + } + } + } } if ( qv ) { /* quoted versions always get at least three terms*/ - SSize_t len = AvFILLp(av); - /* This for loop appears to trigger a compiler bug on OS X, as it - loops infinitely. Yes, len is negative. No, it makes no sense. - Compiler in question is: - gcc version 3.3 20030304 (Apple Computer, Inc. build 1640) - for ( len = 2 - len; len > 0; len-- ) - av_push(MUTABLE_AV(sv), newSViv(0)); - */ - len = 2 - len; - while (len-- > 0) - av_push(av, newSViv(0)); + SSize_t len = AvFILLp(av); + /* This for loop appears to trigger a compiler bug on OS X, as it + loops infinitely. Yes, len is negative. No, it makes no sense. + Compiler in question is: + gcc version 3.3 20030304 (Apple Computer, Inc. build 1640) + for ( len = 2 - len; len > 0; len-- ) + av_push(MUTABLE_AV(sv), newSViv(0)); + */ + len = 2 - len; + while (len-- > 0) + av_push(av, newSViv(0)); } /* need to save off the current version string for later */ if ( vinf ) { - SV * orig = newSVpvn("v.Inf", sizeof("v.Inf")-1); - (void)hv_stores(MUTABLE_HV(hv), "original", orig); - (void)hv_stores(MUTABLE_HV(hv), "vinf", newSViv(1)); + SV * orig = newSVpvn("v.Inf", sizeof("v.Inf")-1); + (void)hv_stores(MUTABLE_HV(hv), "original", orig); + (void)hv_stores(MUTABLE_HV(hv), "vinf", newSViv(1)); } else if ( s > start ) { - SV * orig = newSVpvn(start,s-start); - if ( qv && saw_decimal == 1 && *start != 'v' ) { - /* need to insert a v to be consistent */ - sv_insert(orig, 0, 0, "v", 1); - } - (void)hv_stores(MUTABLE_HV(hv), "original", orig); + SV * orig = newSVpvn(start,s-start); + if ( qv && saw_decimal == 1 && *start != 'v' ) { + /* need to insert a v to be consistent */ + sv_insert(orig, 0, 0, "v", 1); + } + (void)hv_stores(MUTABLE_HV(hv), "original", orig); } else { - (void)hv_stores(MUTABLE_HV(hv), "original", newSVpvs("0")); - av_push(av, newSViv(0)); + (void)hv_stores(MUTABLE_HV(hv), "original", newSVpvs("0")); + av_push(av, newSViv(0)); } /* And finally, store the AV in the hash */ @@ -447,7 +469,7 @@ Perl_scan_version(pTHX_ const char *s, S /* fix RT#19517 - special case 'undef' as string */ if ( *s == 'u' && strEQ(s+1,"ndef") ) { - s += 5; + s += 5; } return s; @@ -477,74 +499,74 @@ Perl_new_version(pTHX_ SV *ver) PERL_ARGS_ASSERT_NEW_VERSION; if ( ISA_VERSION_OBJ(ver) ) /* can just copy directly */ { - SSize_t key; - AV * const av = newAV(); - AV *sav; - /* This will get reblessed later if a derived class*/ - SV * const hv = newSVrv(rv, "version"); - (void)sv_upgrade(hv, SVt_PVHV); /* needs to be an HV type */ + SSize_t key; + AV * const av = newAV(); + AV *sav; + /* This will get reblessed later if a derived class*/ + SV * const hv = newSVrv(rv, "version"); + (void)sv_upgrade(hv, SVt_PVHV); /* needs to be an HV type */ #ifndef NODEFAULT_SHAREKEYS - HvSHAREKEYS_on(hv); /* key-sharing on by default */ + HvSHAREKEYS_on(hv); /* key-sharing on by default */ #endif - if ( SvROK(ver) ) - ver = SvRV(ver); + if ( SvROK(ver) ) + ver = SvRV(ver); - /* Begin copying all of the elements */ - if ( hv_exists(MUTABLE_HV(ver), "qv", 2) ) - (void)hv_stores(MUTABLE_HV(hv), "qv", newSViv(1)); - - if ( hv_exists(MUTABLE_HV(ver), "alpha", 5) ) - (void)hv_stores(MUTABLE_HV(hv), "alpha", newSViv(1)); - { - SV ** svp = hv_fetchs(MUTABLE_HV(ver), "width", FALSE); - if(svp) { - const I32 width = SvIV(*svp); - (void)hv_stores(MUTABLE_HV(hv), "width", newSViv(width)); - } - } - { - SV ** svp = hv_fetchs(MUTABLE_HV(ver), "original", FALSE); - if(svp) - (void)hv_stores(MUTABLE_HV(hv), "original", newSVsv(*svp)); - } - sav = MUTABLE_AV(SvRV(*hv_fetchs(MUTABLE_HV(ver), "version", FALSE))); - /* This will get reblessed later if a derived class*/ - for ( key = 0; key <= av_len(sav); key++ ) - { - SV * const sv = *av_fetch(sav, key, FALSE); - const I32 rev = SvIV(sv); - av_push(av, newSViv(rev)); - } + /* Begin copying all of the elements */ + if ( hv_exists(MUTABLE_HV(ver), "qv", 2) ) + (void)hv_stores(MUTABLE_HV(hv), "qv", newSViv(1)); + + if ( hv_exists(MUTABLE_HV(ver), "alpha", 5) ) + (void)hv_stores(MUTABLE_HV(hv), "alpha", newSViv(1)); + { + SV ** svp = hv_fetchs(MUTABLE_HV(ver), "width", FALSE); + if(svp) { + const I32 width = SvIV(*svp); + (void)hv_stores(MUTABLE_HV(hv), "width", newSViv(width)); + } + } + { + SV ** svp = hv_fetchs(MUTABLE_HV(ver), "original", FALSE); + if(svp) + (void)hv_stores(MUTABLE_HV(hv), "original", newSVsv(*svp)); + } + sav = MUTABLE_AV(SvRV(*hv_fetchs(MUTABLE_HV(ver), "version", FALSE))); + /* This will get reblessed later if a derived class*/ + for ( key = 0; key <= av_len(sav); key++ ) + { + SV * const sv = *av_fetch(sav, key, FALSE); + const I32 rev = SvIV(sv); + av_push(av, newSViv(rev)); + } - (void)hv_stores(MUTABLE_HV(hv), "version", newRV_noinc(MUTABLE_SV(av))); - return rv; + (void)hv_stores(MUTABLE_HV(hv), "version", newRV_noinc(MUTABLE_SV(av))); + return rv; } #ifdef SvVOK { - const MAGIC* const mg = SvVSTRING_mg(ver); - if ( mg ) { /* already a v-string */ - const STRLEN len = mg->mg_len; - const char * const version = (const char*)mg->mg_ptr; - char *raw, *under; - static const char underscore[] = "_"; - sv_setpvn(rv,version,len); - raw = SvPV_nolen(rv); - under = ninstr(raw, raw+len, underscore, underscore + 1); - if (under) { - Move(under + 1, under, raw + len - under - 1, char); - SvCUR_set(rv, SvCUR(rv) - 1); - *SvEND(rv) = '\0'; - } - /* this is for consistency with the pure Perl class */ - if ( isDIGIT(*version) ) - sv_insert(rv, 0, 0, "v", 1); - } - else { + const MAGIC* const mg = SvVSTRING_mg(ver); + if ( mg ) { /* already a v-string */ + const STRLEN len = mg->mg_len; + const char * const version = (const char*)mg->mg_ptr; + char *raw, *under; + static const char underscore[] = "_"; + sv_setpvn(rv,version,len); + raw = SvPV_nolen(rv); + under = ninstr(raw, raw+len, underscore, underscore + 1); + if (under) { + Move(under + 1, under, raw + len - under - 1, char); + SvCUR_set(rv, SvCUR(rv) - 1); + *SvEND(rv) = '\0'; + } + /* this is for consistency with the pure Perl class */ + if ( isDIGIT(*version) ) + sv_insert(rv, 0, 0, "v", 1); + } + else { #endif - SvSetSV_nosteal(rv, ver); /* make a duplicate */ + SvSetSV_nosteal(rv, ver); /* make a duplicate */ #ifdef SvVOK - } + } } #endif sv_2mortal(rv); /* in case upg_version croaks before it returns */ @@ -564,6 +586,30 @@ to force this SV to be interpreted as an =cut */ +/* Macro to do the meat of getting the PV of an NV version number. This is + * macroized because can be called from several places */ +#define GET_NUMERIC_VERSION(ver, sv, tbuf, buf, len) \ + STMT_START { \ + \ + /* Prevent callees from trying to change the locale */ \ + DISABLE_LC_NUMERIC_CHANGES(); \ + \ + /* We earlier created 'sv' for very large version numbers, to rely \ + * on the specialized algorithms SV code has built-in for such \ + * values */ \ + if (sv) { \ + Perl_sv_setpvf(aTHX_ sv, "%.9" NVff, SvNVX(ver)); \ + len = SvCUR(sv); \ + buf = SvPVX(sv); \ + } \ + else { \ + len = my_snprintf(tbuf, sizeof(tbuf), "%.9" NVff, SvNVX(ver)); \ + buf = tbuf; \ + } \ + \ + REENABLE_LC_NUMERIC_CHANGES(); \ + } STMT_END + SV * #ifdef VUTIL_REPLACE_CORE Perl_upg_version2(pTHX_ SV *ver, bool qv) @@ -582,243 +628,271 @@ Perl_upg_version(pTHX_ SV *ver, bool qv) PERL_ARGS_ASSERT_UPG_VERSION; if ( (SvUOK(ver) && SvUVX(ver) > VERSION_MAX) - || (SvIOK(ver) && SvIVX(ver) > VERSION_MAX) ) { - /* out of bounds [unsigned] integer */ - STRLEN len; - char tbuf[64]; - len = my_snprintf(tbuf, sizeof(tbuf), "%d", VERSION_MAX); - version = savepvn(tbuf, len); - SAVEFREEPV(version); - Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), - "Integer overflow in version %d",VERSION_MAX); + || (SvIOK(ver) && SvIVX(ver) > VERSION_MAX) ) + { + /* out of bounds [unsigned] integer */ + STRLEN len; + char tbuf[64]; + len = my_snprintf(tbuf, sizeof(tbuf), "%d", VERSION_MAX); + version = savepvn(tbuf, len); + SAVEFREEPV(version); + Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), + "Integer overflow in version %d",VERSION_MAX); } else if ( SvUOK(ver) || SvIOK(ver)) #if PERL_VERSION_LT(5,17,2) VER_IV: #endif { - version = savesvpv(ver); - SAVEFREEPV(version); + version = savesvpv(ver); + SAVEFREEPV(version); } else if (SvNOK(ver) && !( SvPOK(ver) && SvCUR(ver) == 3 ) ) #if PERL_VERSION_LT(5,17,2) VER_NV: #endif { - STRLEN len; + STRLEN len; - /* may get too much accuracy */ - char tbuf[64]; + /* may get too much accuracy */ + char tbuf[64]; #ifdef __vax__ SV *sv = SvNVX(ver) > 10e37 ? newSV(64) : 0; #else - SV *sv = SvNVX(ver) > 10e50 ? newSV(64) : 0; + SV *sv = SvNVX(ver) > 10e50 ? newSV(64) : 0; #endif - char *buf; + char *buf; #if PERL_VERSION_GE(5,19,0) - if (SvPOK(ver)) { - /* dualvar? */ - goto VER_PV; - } + if (SvPOK(ver)) { + /* dualvar? */ + goto VER_PV; + } #endif -#ifdef USE_LOCALE_NUMERIC - - { - /* This may or may not be called from code that has switched - * locales without letting perl know, therefore we have to find it - * from first principals. See [perl #121930]. */ - /* In windows, or not threaded, or not thread-safe, if it isn't C, - * set it to C. */ + { -# ifndef USE_POSIX_2008_LOCALE +#ifdef USE_POSIX_2008_LOCALE - const char * locale_name_on_entry; - - LC_NUMERIC_LOCK(0); /* Start critical section */ - - locale_name_on_entry = setlocale(LC_NUMERIC, NULL); - if ( strNE(locale_name_on_entry, "C") - && strNE(locale_name_on_entry, "POSIX")) - { - /* the setlocale() call might free or overwrite the name */ - locale_name_on_entry = savepv(locale_name_on_entry); - setlocale(LC_NUMERIC, "C"); - } - else { /* This value indicates to the restore code that we didn't - change the locale */ - locale_name_on_entry = NULL; + /* With POSIX 2008, all we have to do is toggle to the C locale + * just long enough to get the value (which should have a dot). */ + const locale_t locale_obj_on_entry = uselocale(PL_C_locale_obj); + GET_NUMERIC_VERSION(ver, sv, tbuf, buf, len); + uselocale(locale_obj_on_entry); +#else + /* Without POSIX 2008, it could be that toggling will zap another + * thread's locale. Avoid that if possible by looking at the NV and + * changing a non-dot radix into a dot */ + + char * radix = NULL; + unsigned int radix_len = 0; + + GET_NUMERIC_VERSION(ver, sv, tbuf, buf, len); + +# ifndef ARABIC_DECIMAL_SEPARATOR_UTF8 + + /* This becomes feasible since there are only very few possible + * radix characters in the world. khw knows of just 3 possible + * ones. If we are being compiled on a perl without the very rare + * third one, ARABIC DECIMAL SEPARATOR, just scan for the other + * two: FULL STOP (dot) and COMMA */ + radix = strpbrk(buf, ".,"); + if (LIKELY(radix)) { + radix_len = 1; } +# else + /* Here, we have information about the third one; since it is + * multi-byte, it becomes a little more work. Scan for the dot, + * comma, or first byte of the arabic one */ + radix = strpbrk(buf, + ".," + ARABIC_DECIMAL_SEPARATOR_UTF8_FIRST_BYTE_s); + + if (LIKELY(radix)) { + if (LIKELY( (* (U8 *) radix) + != ARABIC_DECIMAL_SEPARATOR_UTF8_FIRST_BYTE)) + { + radix_len = 1; /* Dot and comma are length 1 */ + } + else { -# else - - const locale_t locale_obj_on_entry = uselocale((locale_t) 0); - const char * locale_name_on_entry = NULL; - DECLARATION_FOR_LC_NUMERIC_MANIPULATION; + /* Make sure that the rest of the bytes are what we expect + * for the remainder of the arabic radix. If not, we + * didn't find the radix. */ + radix_len = STRLENs(ARABIC_DECIMAL_SEPARATOR_UTF8); + if ( radix + radix_len >= buf + len + || memNEs(radix + 1, + STRLENs(ARABIC_DECIMAL_SEPARATOR_UTF8_TAIL), + ARABIC_DECIMAL_SEPARATOR_UTF8_TAIL)) + { + radix = NULL; + radix_len = 0; + } + } + } - if (locale_obj_on_entry == LC_GLOBAL_LOCALE) { +# endif - /* in the global locale, we can call system setlocale and if it - * isn't C, set it to C. */ - LC_NUMERIC_LOCK(0); + /* Now convert any found radix into a dot (if not already). This + * effectively does: ver =~ s/radix/dot/ */ + if (radix) { + if (*radix != '.') { + *radix = '.'; + + if (radix_len > 1) { + Move(radix + radix_len, /* from what follows the radix + */ + radix + 1, /* to just after the new dot */ + + /* the number of bytes remaining, plus the NUL + * */ + len - (radix - buf) - radix_len + 1, + char); + len -= radix_len - 1; + } + } - locale_name_on_entry = setlocale(LC_NUMERIC, NULL); - if ( strNE(locale_name_on_entry, "C") - && strNE(locale_name_on_entry, "POSIX")) - { - /* the setlocale() call might free or overwrite the name */ - locale_name_on_entry = savepv(locale_name_on_entry); - setlocale(LC_NUMERIC, "C"); + /* Guard against the very unlikely case that the radix is more + * than a single character, like ".."; that is, make sure the + * radix string we found above is the whole radix, and not just + * the prefix of a longer one. Success is indicated by it + * being at the end of the string, or the next byte should be a + * digit */ + if (radix < buf + len && ! inRANGE(radix[1], '0', '9')) { + radix = NULL; + radix_len = 0; } - else { /* This value indicates to the restore code that we - didn't change the locale */ - locale_name_on_entry = NULL; - } - } - else if (locale_obj_on_entry == PL_underlying_numeric_obj) { - /* Here, the locale appears to have been changed to use the - * program's underlying locale. Just use our mechanisms to - * switch back to C. It might be possible for this pointer to - * actually refer to something else if it got released and - * reused somehow. But it doesn't matter, our mechanisms will - * work even so */ - STORE_LC_NUMERIC_SET_STANDARD(); } - else if (locale_obj_on_entry != PL_C_locale_obj) { - /* The C object should be unchanged during a program's - * execution, so it should be safe to assume it means what it - * says, so if we are in it, no locale change is required. - * Otherwise, simply use the thread-safe operation. */ - uselocale(PL_C_locale_obj); - } - -# endif - /* Prevent recursed calls from trying to change back */ - LOCK_LC_NUMERIC_STANDARD(); + if (! radix) { -#endif + /* If we couldn't find what the radix is, or didn't find it in + * the PV, resort to toggling the locale to one known to have a + * dot radix. This may or may not be called from code that has + * switched locales without letting perl know, therefore we + * have to find it from first principals. See [perl #121930]. + * */ - if (sv) { - Perl_sv_setpvf(aTHX_ sv, "%.9" NVff, SvNVX(ver)); - len = SvCUR(sv); - buf = SvPVX(sv); - } - else { - len = my_snprintf(tbuf, sizeof(tbuf), "%.9" NVff, SvNVX(ver)); - buf = tbuf; - } +# if ! defined(LC_NUMERIC) || ! defined(USE_LOCALE_NUMERIC) -#ifdef USE_LOCALE_NUMERIC + Perl_croak(aTHX_ "panic: Unexpectedly didn't find a dot radix" + " character in '%s'", buf); +# else + const char * locale_name_on_entry = NULL; - UNLOCK_LC_NUMERIC_STANDARD(); + /* In windows, or not threaded, or not thread-safe, if it isn't + * C, set it to C. */ -# ifndef USE_POSIX_2008_LOCALE + POSIX_SETLOCALE_LOCK; /* Start critical section */ - if (locale_name_on_entry) { - setlocale(LC_NUMERIC, locale_name_on_entry); - Safefree(locale_name_on_entry); - } + locale_name_on_entry = setlocale(LC_NUMERIC, NULL); + if ( strEQ(locale_name_on_entry, "C") + || strEQ(locale_name_on_entry, "C.UTF-8") + || strEQ(locale_name_on_entry, "POSIX")) + { + /* No need to change the locale, since these all are known + * to have a dot radix. Change the variable to indicate to + * the restore code that nothing needs to be done */ + locale_name_on_entry = NULL; + } + else { + /* The setlocale() call might free or overwrite the name */ + locale_name_on_entry = savepv(locale_name_on_entry); + setlocale(LC_NUMERIC, "C"); + } - LC_NUMERIC_UNLOCK; /* End critical section */ + GET_NUMERIC_VERSION(ver, sv, tbuf, buf, len); -# else + if (locale_name_on_entry) { + setlocale(LC_NUMERIC, locale_name_on_entry); + Safefree(locale_name_on_entry); + } - if (locale_name_on_entry) { - setlocale(LC_NUMERIC, locale_name_on_entry); - Safefree(locale_name_on_entry); - LC_NUMERIC_UNLOCK; - } - else if (locale_obj_on_entry == PL_underlying_numeric_obj) { - RESTORE_LC_NUMERIC(); + POSIX_SETLOCALE_UNLOCK; /* End critical section */ +# endif } - else if (locale_obj_on_entry != PL_C_locale_obj) { - uselocale(locale_obj_on_entry); +#endif } -# endif - - } + /* Strip trailing zero's from the version number */ + while (buf[len-1] == '0' && len > 0) len--; -#endif /* USE_LOCALE_NUMERIC */ + if ( buf[len-1] == '.' ) len--; /* eat the trailing decimal */ - while (buf[len-1] == '0' && len > 0) len--; - if ( buf[len-1] == '.' ) len--; /* eat the trailing decimal */ - version = savepvn(buf, len); - SAVEFREEPV(version); - SvREFCNT_dec(sv); + version = savepvn(buf, len); + SAVEFREEPV(version); + SvREFCNT_dec(sv); } #ifdef SvVOK else if ( (mg = SvVSTRING_mg(ver)) ) { /* already a v-string */ - version = savepvn( (const char*)mg->mg_ptr,mg->mg_len ); - SAVEFREEPV(version); - qv = TRUE; + version = savepvn( (const char*)mg->mg_ptr,mg->mg_len ); + SAVEFREEPV(version); + qv = TRUE; } #endif else if ( SvPOK(ver))/* must be a string or something like a string */ VER_PV: { - STRLEN len; - version = savepvn(SvPV(ver,len), SvCUR(ver)); - SAVEFREEPV(version); + STRLEN len; + version = savepvn(SvPV(ver,len), SvCUR(ver)); + SAVEFREEPV(version); #ifndef SvVOK - /* This will only be executed for 5.6.0 - 5.8.0 inclusive */ - if ( len >= 3 && !instr(version,".") && !instr(version,"_")) { - /* may be a v-string */ - char *testv = (char *)version; - STRLEN tlen = len; - for (tlen=0; tlen < len; tlen++, testv++) { - /* if one of the characters is non-text assume v-string */ - if (testv[0] < ' ') { - SV * const nsv = sv_newmortal(); - const char *nver; - const char *pos; - int saw_decimal = 0; - sv_setpvf(nsv,"v%vd",ver); - pos = nver = savepv(SvPV_nolen(nsv)); + /* This will only be executed for 5.6.0 - 5.8.0 inclusive */ + if ( len >= 3 && !instr(version,".") && !instr(version,"_")) { + /* may be a v-string */ + char *testv = (char *)version; + STRLEN tlen = len; + for (tlen=0; tlen < len; tlen++, testv++) { + /* if one of the characters is non-text assume v-string */ + if (testv[0] < ' ') { + SV * const nsv = sv_newmortal(); + const char *nver; + const char *pos; + int saw_decimal = 0; + sv_setpvf(nsv,"v%vd",ver); + pos = nver = savepv(SvPV_nolen(nsv)); SAVEFREEPV(pos); - /* scan the resulting formatted string */ - pos++; /* skip the leading 'v' */ - while ( *pos == '.' || isDIGIT(*pos) ) { - if ( *pos == '.' ) - saw_decimal++ ; - pos++; - } - - /* is definitely a v-string */ - if ( saw_decimal >= 2 ) { - version = nver; - } - break; - } - } - } + /* scan the resulting formatted string */ + pos++; /* skip the leading 'v' */ + while ( *pos == '.' || isDIGIT(*pos) ) { + if ( *pos == '.' ) + saw_decimal++ ; + pos++; + } + + /* is definitely a v-string */ + if ( saw_decimal >= 2 ) { + version = nver; + } + break; + } + } + } #endif } #if PERL_VERSION_LT(5,17,2) else if (SvIOKp(ver)) { - goto VER_IV; + goto VER_IV; } else if (SvNOKp(ver)) { - goto VER_NV; + goto VER_NV; } else if (SvPOKp(ver)) { - goto VER_PV; + goto VER_PV; } #endif else { - /* no idea what this is */ - Perl_croak(aTHX_ "Invalid version format (non-numeric data)"); + /* no idea what this is */ + Perl_croak(aTHX_ "Invalid version format (non-numeric data)"); } s = SCAN_VERSION(version, ver, qv); - if ( *s != '\0' ) - Perl_ck_warner(aTHX_ packWARN(WARN_MISC), - "Version string '%s' contains invalid data; " - "ignoring: '%s'", version, s); + if ( *s != '\0' ) + Perl_ck_warner(aTHX_ packWARN(WARN_MISC), + "Version string '%s' contains invalid data; " + "ignoring: '%s'", version, s); #if PERL_VERSION_LT(5,19,8) && defined(USE_ITHREADS) LEAVE; @@ -866,16 +940,16 @@ Perl_vverify(pTHX_ SV *vs) PERL_ARGS_ASSERT_VVERIFY; if ( SvROK(vs) ) - vs = SvRV(vs); + vs = SvRV(vs); /* see if the appropriate elements exist */ if ( SvTYPE(vs) == SVt_PVHV - && (svp = hv_fetchs(MUTABLE_HV(vs), "version", FALSE)) - && (sv = SvRV(*svp)) - && SvTYPE(sv) == SVt_PVAV ) - return vs; + && (svp = hv_fetchs(MUTABLE_HV(vs), "version", FALSE)) + && (sv = SvRV(*svp)) + && SvTYPE(sv) == SVt_PVAV ) + return vs; else - return NULL; + return NULL; } /* @@ -912,42 +986,42 @@ Perl_vnumify(pTHX_ SV *vs) /* extract the HV from the object */ vs = VVERIFY(vs); if ( ! vs ) - Perl_croak(aTHX_ "Invalid version object"); + Perl_croak(aTHX_ "Invalid version object"); /* see if various flags exist */ if ( hv_exists(MUTABLE_HV(vs), "alpha", 5 ) ) - alpha = TRUE; + alpha = TRUE; if (alpha) { - Perl_ck_warner(aTHX_ packWARN(WARN_NUMERIC), - "alpha->numify() is lossy"); + Perl_ck_warner(aTHX_ packWARN(WARN_NUMERIC), + "alpha->numify() is lossy"); } /* attempt to retrieve the version array */ if ( !(av = MUTABLE_AV(SvRV(*hv_fetchs(MUTABLE_HV(vs), "version", FALSE))) ) ) { - return newSVpvs("0"); + return newSVpvs("0"); } len = av_len(av); if ( len == -1 ) { - return newSVpvs("0"); + return newSVpvs("0"); } { - SV * tsv = *av_fetch(av, 0, 0); - digit = SvIV(tsv); + SV * tsv = *av_fetch(av, 0, 0); + digit = SvIV(tsv); } sv = Perl_newSVpvf(aTHX_ "%d.", (int)PERL_ABS(digit)); for ( i = 1 ; i <= len ; i++ ) { - SV * tsv = *av_fetch(av, i, 0); - digit = SvIV(tsv); - Perl_sv_catpvf(aTHX_ sv, "%03d", (int)digit); + SV * tsv = *av_fetch(av, i, 0); + digit = SvIV(tsv); + Perl_sv_catpvf(aTHX_ sv, "%03d", (int)digit); } if ( len == 0 ) { - sv_catpvs(sv, "000"); + sv_catpvs(sv, "000"); } return sv; } @@ -984,29 +1058,29 @@ Perl_vnormal(pTHX_ SV *vs) /* extract the HV from the object */ vs = VVERIFY(vs); if ( ! vs ) - Perl_croak(aTHX_ "Invalid version object"); + Perl_croak(aTHX_ "Invalid version object"); av = MUTABLE_AV(SvRV(*hv_fetchs(MUTABLE_HV(vs), "version", FALSE))); len = av_len(av); if ( len == -1 ) { - return newSVpvs(""); + return newSVpvs(""); } { - SV * tsv = *av_fetch(av, 0, 0); - digit = SvIV(tsv); + SV * tsv = *av_fetch(av, 0, 0); + digit = SvIV(tsv); } sv = Perl_newSVpvf(aTHX_ "v%" IVdf, (IV)digit); for ( i = 1 ; i <= len ; i++ ) { - SV * tsv = *av_fetch(av, i, 0); - digit = SvIV(tsv); - Perl_sv_catpvf(aTHX_ sv, ".%" IVdf, (IV)digit); + SV * tsv = *av_fetch(av, i, 0); + digit = SvIV(tsv); + Perl_sv_catpvf(aTHX_ sv, ".%" IVdf, (IV)digit); } if ( len <= 2 ) { /* short version, must be at least three */ - for ( len = 2 - len; len != 0; len-- ) - sv_catpvs(sv,".0"); + for ( len = 2 - len; len != 0; len-- ) + sv_catpvs(sv,".0"); } return sv; } @@ -1037,33 +1111,33 @@ Perl_vstringify(pTHX_ SV *vs) /* extract the HV from the object */ vs = VVERIFY(vs); if ( ! vs ) - Perl_croak(aTHX_ "Invalid version object"); + Perl_croak(aTHX_ "Invalid version object"); svp = hv_fetchs(MUTABLE_HV(vs), "original", FALSE); if (svp) { - SV *pv; - pv = *svp; - if ( SvPOK(pv) + SV *pv; + pv = *svp; + if ( SvPOK(pv) #if PERL_VERSION_LT(5,17,2) - || SvPOKp(pv) + || SvPOKp(pv) #endif - ) - return newSVsv(pv); - else - return &PL_sv_undef; + ) + return newSVsv(pv); + else + return &PL_sv_undef; } else { - if ( hv_exists(MUTABLE_HV(vs), "qv", 2) ) - return VNORMAL(vs); - else - return VNUMIFY(vs); + if ( hv_exists(MUTABLE_HV(vs), "qv", 2) ) + return VNORMAL(vs); + else + return VNUMIFY(vs); } } /* =for apidoc vcmp -Version object aware cmp. Both operands must already have been +Version object aware cmp. Both operands must already have been converted into version objects. =cut @@ -1088,7 +1162,7 @@ Perl_vcmp(pTHX_ SV *lhv, SV *rhv) lhv = VVERIFY(lhv); rhv = VVERIFY(rhv); if ( ! ( lhv && rhv ) ) - Perl_croak(aTHX_ "Invalid version object"); + Perl_croak(aTHX_ "Invalid version object"); /* get the left hand term */ lav = MUTABLE_AV(SvRV(*hv_fetchs(MUTABLE_HV(lhv), "version", FALSE))); @@ -1103,40 +1177,40 @@ Perl_vcmp(pTHX_ SV *lhv, SV *rhv) i = 0; while ( i <= m && retval == 0 ) { - SV * const lsv = *av_fetch(lav,i,0); - SV * rsv; - left = SvIV(lsv); - rsv = *av_fetch(rav,i,0); - right = SvIV(rsv); - if ( left < right ) - retval = -1; - if ( left > right ) - retval = +1; - i++; + SV * const lsv = *av_fetch(lav,i,0); + SV * rsv; + left = SvIV(lsv); + rsv = *av_fetch(rav,i,0); + right = SvIV(rsv); + if ( left < right ) + retval = -1; + if ( left > right ) + retval = +1; + i++; } if ( l != r && retval == 0 ) /* possible match except for trailing 0's */ { - if ( l < r ) - { - while ( i <= r && retval == 0 ) - { - SV * const rsv = *av_fetch(rav,i,0); - if ( SvIV(rsv) != 0 ) - retval = -1; /* not a match after all */ - i++; - } - } - else - { - while ( i <= l && retval == 0 ) - { - SV * const lsv = *av_fetch(lav,i,0); - if ( SvIV(lsv) != 0 ) - retval = +1; /* not a match after all */ - i++; - } - } + if ( l < r ) + { + while ( i <= r && retval == 0 ) + { + SV * const rsv = *av_fetch(rav,i,0); + if ( SvIV(rsv) != 0 ) + retval = -1; /* not a match after all */ + i++; + } + } + else + { + while ( i <= l && retval == 0 ) + { + SV * const lsv = *av_fetch(lav,i,0); + if ( SvIV(lsv) != 0 ) + retval = +1; /* not a match after all */ + i++; + } + } } return retval; } Index: gnu/usr.bin/perl/warnings.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/warnings.h,v diff -u -p -a -u -p -r1.8 warnings.h --- gnu/usr.bin/perl/warnings.h 14 May 2024 19:38:54 -0000 1.8 +++ gnu/usr.bin/perl/warnings.h 22 Jan 2025 00:37:45 -0000 @@ -102,63 +102,69 @@ /* Warnings Categories added in Perl 5.021 */ -#define WARN_EXPERIMENTAL__CONST_ATTR 56 -#define WARN_EXPERIMENTAL__RE_STRICT 57 -#define WARN_EXPERIMENTAL__REFALIASING 58 -#define WARN_LOCALE 59 -#define WARN_MISSING 60 -#define WARN_REDUNDANT 61 +#define WARN_EXPERIMENTAL__RE_STRICT 56 +#define WARN_EXPERIMENTAL__REFALIASING 57 +#define WARN_LOCALE 58 +#define WARN_MISSING 59 +#define WARN_REDUNDANT 60 /* Warnings Categories added in Perl 5.025 */ -#define WARN_EXPERIMENTAL__DECLARED_REFS 62 +#define WARN_EXPERIMENTAL__DECLARED_REFS 61 /* Warnings Categories added in Perl 5.025011 */ -#define WARN_DEPRECATED__DOT_IN_INC 63 +#define WARN_DEPRECATED__DOT_IN_INC 62 /* Warnings Categories added in Perl 5.027 */ -#define WARN_SHADOW 64 +#define WARN_SHADOW 63 /* Warnings Categories added in Perl 5.029 */ -#define WARN_EXPERIMENTAL__PRIVATE_USE 65 -#define WARN_EXPERIMENTAL__UNIPROP_WILDCARDS 66 -#define WARN_EXPERIMENTAL__VLB 67 +#define WARN_EXPERIMENTAL__PRIVATE_USE 64 +#define WARN_EXPERIMENTAL__UNIPROP_WILDCARDS 65 +#define WARN_EXPERIMENTAL__VLB 66 /* Warnings Categories added in Perl 5.033 */ -#define WARN_EXPERIMENTAL__TRY 68 +#define WARN_EXPERIMENTAL__TRY 67 /* Warnings Categories added in Perl 5.035 */ -#define WARN_EXPERIMENTAL__ARGS_ARRAY_WITH_SIGNATURES 69 -#define WARN_EXPERIMENTAL__BUILTIN 70 -#define WARN_EXPERIMENTAL__DEFER 71 -#define WARN_EXPERIMENTAL__EXTRA_PAIRED_DELIMITERS 72 -#define WARN_EXPERIMENTAL__FOR_LIST 73 -#define WARN_SCALAR 74 +#define WARN_EXPERIMENTAL__ARGS_ARRAY_WITH_SIGNATURES 68 +#define WARN_EXPERIMENTAL__BUILTIN 69 +#define WARN_EXPERIMENTAL__DEFER 70 +#define WARN_EXPERIMENTAL__EXTRA_PAIRED_DELIMITERS 71 +#define WARN_SCALAR 72 /* Warnings Categories added in Perl 5.035009 */ -#define WARN_DEPRECATED__VERSION_DOWNGRADE 75 +#define WARN_DEPRECATED__VERSION_DOWNGRADE 73 /* Warnings Categories added in Perl 5.03501 */ -#define WARN_DEPRECATED__DELIMITER_WILL_BE_PAIRED 76 +#define WARN_DEPRECATED__DELIMITER_WILL_BE_PAIRED 74 /* Warnings Categories added in Perl 5.037 */ -#define WARN_EXPERIMENTAL__CLASS 77 +#define WARN_EXPERIMENTAL__CLASS 75 /* Warnings Categories added in Perl 5.037009 */ -#define WARN_DEPRECATED__APOSTROPHE_AS_PACKAGE_SEPARATOR 78 +#define WARN_DEPRECATED__APOSTROPHE_AS_PACKAGE_SEPARATOR 76 /* Warnings Categories added in Perl 5.03701 */ -#define WARN_DEPRECATED__SMARTMATCH 79 +#define WARN_DEPRECATED__SMARTMATCH 77 + +/* Warnings Categories added in Perl 5.039002 */ + +#define WARN_DEPRECATED__MISSING_IMPORT_CALLED_WITH_ARGS 78 + +/* Warnings Categories added in Perl 5.039008 */ + +#define WARN_DEPRECATED__SUBSEQUENT_USE_VERSION 79 #define WARNsize 20 #define WARN_ALLstring "\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125\125" #define WARN_NONEstring "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" @@ -329,7 +335,6 @@ category parameters passed. =for apidoc Amnh||WARN_EXPERIMENTAL =for apidoc Amnh||WARN_EXPERIMENTAL__REGEX_SETS =for apidoc Amnh||WARN_SYSCALLS -=for apidoc Amnh||WARN_EXPERIMENTAL__CONST_ATTR =for apidoc Amnh||WARN_EXPERIMENTAL__RE_STRICT =for apidoc Amnh||WARN_EXPERIMENTAL__REFALIASING =for apidoc Amnh||WARN_LOCALE @@ -346,13 +351,14 @@ category parameters passed. =for apidoc Amnh||WARN_EXPERIMENTAL__BUILTIN =for apidoc Amnh||WARN_EXPERIMENTAL__DEFER =for apidoc Amnh||WARN_EXPERIMENTAL__EXTRA_PAIRED_DELIMITERS -=for apidoc Amnh||WARN_EXPERIMENTAL__FOR_LIST =for apidoc Amnh||WARN_SCALAR =for apidoc Amnh||WARN_DEPRECATED__VERSION_DOWNGRADE =for apidoc Amnh||WARN_DEPRECATED__DELIMITER_WILL_BE_PAIRED =for apidoc Amnh||WARN_EXPERIMENTAL__CLASS =for apidoc Amnh||WARN_DEPRECATED__APOSTROPHE_AS_PACKAGE_SEPARATOR =for apidoc Amnh||WARN_DEPRECATED__SMARTMATCH +=for apidoc Amnh||WARN_DEPRECATED__MISSING_IMPORT_CALLED_WITH_ARGS +=for apidoc Amnh||WARN_DEPRECATED__SUBSEQUENT_USE_VERSION =cut */ Index: gnu/usr.bin/perl/write_buildcustomize.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/write_buildcustomize.pl,v diff -u -p -a -u -p -r1.5 write_buildcustomize.pl --- gnu/usr.bin/perl/write_buildcustomize.pl 15 Feb 2023 01:36:14 -0000 1.5 +++ gnu/usr.bin/perl/write_buildcustomize.pl 22 Jan 2025 00:37:45 -0000 @@ -53,6 +53,7 @@ push @toolchain, qw( dist/ExtUtils-ParseXS/lib cpan/parent/lib cpan/ExtUtils-Constant/lib + dist/base/lib ) if $^O eq 'MSWin32'; push @toolchain, 'ext/VMS-Filespec/lib' if $^O eq 'VMS'; Index: gnu/usr.bin/perl/Cross/Makefile-cross-SH =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Cross/Makefile-cross-SH,v diff -u -p -a -u -p -r1.4 Makefile-cross-SH --- gnu/usr.bin/perl/Cross/Makefile-cross-SH 15 Feb 2023 01:36:14 -0000 1.4 +++ gnu/usr.bin/perl/Cross/Makefile-cross-SH 22 Jan 2025 00:37:41 -0000 @@ -695,14 +695,6 @@ perl.gcov: perl.config.gcov $(MAKE) PERL_SUFFIX=.gcov PERL_PROFILE_LDFLAGS='' perl @echo "Now you may run perl.gcov and then run gcov some.c." -# Microperl. This is just a convenience thing if one happens to -# build also the full Perl and therefore the real big Makefile: -# usually one should manually explicitly issue the below command. - -.PHONY: microperl -microperl: - $(MAKE) -f Makefile.micro - !NO!SUBS! fi @@ -949,7 +941,7 @@ _mopup: -rm -f perl.pixie lib*.so.perl.pixie lib*.so.Addrs -rm -f perl.Addrs perl.Counts t/perl.Addrs t/perl.Counts *perl.xok -rm -f cygwin.c libperl*.def libperl*.dll cygperl*.dll *.exe.stackdump - -rm -f perl$(EXE_EXT) miniperl$(EXE_EXT) $(LIBPERL) libperl.* microperl + -rm -f perl$(EXE_EXT) miniperl$(EXE_EXT) $(LIBPERL) libperl.* -rm -f config.over # Do not 'make _tidy' directly. Index: gnu/usr.bin/perl/Cross/config.sh-arm-linux =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Cross/config.sh-arm-linux,v diff -u -p -a -u -p -r1.18 config.sh-arm-linux --- gnu/usr.bin/perl/Cross/config.sh-arm-linux 14 May 2024 19:38:54 -0000 1.18 +++ gnu/usr.bin/perl/Cross/config.sh-arm-linux 22 Jan 2025 00:37:41 -0000 @@ -32,11 +32,11 @@ alignbytes='4' aphostname='/bin/hostname' api_revision='5' api_subversion='0' -api_version='38' -api_versionstring='5.38.0' +api_version='40' +api_versionstring='5.40.0' ar='ar' -archlib='/usr/lib/perl5/5.38.2/armv4l-linux' -archlibexp='/usr/lib/perl5/5.38.2/armv4l-linux' +archlib='/usr/lib/perl5/5.40.1/armv4l-linux' +archlibexp='/usr/lib/perl5/5.40.1/armv4l-linux' archname64='' archname='armv4l-linux' archobjs='' @@ -55,7 +55,7 @@ castflags='0' cat='cat' cc='cc' cccdlflags='-fpic' -ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.38.2/armv4l-linux/CORE' +ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.40.1/armv4l-linux/CORE' ccflags='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64' ccflags_uselargefiles='-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64' ccname='arm-linux-gcc' @@ -433,6 +433,9 @@ d_open3='define' d_openat='undef' d_pathconf='define' d_pause='define' +d_perl_lc_all_category_positions_init='define' +d_perl_lc_all_separator='define' +d_perl_lc_all_uses_name_value_pairs='define' d_perl_otherlibdirs='undef' d_phostname='undef' d_pipe2='undef' @@ -835,7 +838,7 @@ inc_version_list=' ' inc_version_list_init='0' incpath='' inews='' -installarchlib='./install_me_here/usr/lib/perl5/5.38.2/armv4l-linux' +installarchlib='./install_me_here/usr/lib/perl5/5.40.1/armv4l-linux' installbin='./install_me_here/usr/bin' installhtml1dir='' installhtml3dir='' @@ -843,13 +846,13 @@ installman1dir='./install_me_here/usr/sh installman3dir='./install_me_here/usr/share/man/man3' installprefix='./install_me_here/usr' installprefixexp='./install_me_here/usr' -installprivlib='./install_me_here/usr/lib/perl5/5.38.2' +installprivlib='./install_me_here/usr/lib/perl5/5.40.1' installscript='./install_me_here/usr/bin' -installsitearch='./install_me_here/usr/lib/perl5/site_perl/5.38.2/armv4l-linux' +installsitearch='./install_me_here/usr/lib/perl5/site_perl/5.40.1/armv4l-linux' installsitebin='./install_me_here/usr/bin' installsitehtml1dir='' installsitehtml3dir='' -installsitelib='./install_me_here/usr/lib/perl5/site_perl/5.38.2' +installsitelib='./install_me_here/usr/lib/perl5/site_perl/5.40.1' installsiteman1dir='./install_me_here/usr/share/man/man1' installsiteman3dir='./install_me_here/usr/share/man/man3' installsitescript='./install_me_here/usr/bin' @@ -970,6 +973,8 @@ patchlevel='9' path_sep=':' perl5='/usr/bin/perl' perl='' +perl_lc_all_category_positions_init='define' +perl_lc_all_separator='define' perl_patchlevel='' perl_static_inline='static' perl_thread_local='' @@ -984,8 +989,8 @@ pmake='' pr='' prefix='/usr' prefixexp='/usr' -privlib='/usr/lib/perl5/5.38.2' -privlibexp='/usr/lib/perl5/5.38.2' +privlib='/usr/lib/perl5/5.40.1' +privlibexp='/usr/lib/perl5/5.40.1' procselfexe='"/proc/self/exe"' prototype='define' ptrsize='4' @@ -1050,17 +1055,17 @@ sig_num='0 1 2 3 4 5 6 7 8 9 10 11 12 13 sig_num_init='0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 6, 17, 29, 31, 0' sig_size='68' signal_t='void' -sitearch='/usr/lib/perl5/site_perl/5.38.2/armv4l-linux' -sitearchexp='/usr/lib/perl5/site_perl/5.38.2/armv4l-linux' +sitearch='/usr/lib/perl5/site_perl/5.40.1/armv4l-linux' +sitearchexp='/usr/lib/perl5/site_perl/5.40.1/armv4l-linux' sitebin='/usr/bin' sitebinexp='/usr/bin' sitehtml1dir='' sitehtml1direxp='' sitehtml3dir='' sitehtml3direxp='' -sitelib='/usr/lib/perl5/site_perl/5.38.2' +sitelib='/usr/lib/perl5/site_perl/5.40.1' sitelib_stem='/usr/lib/perl5/site_perl' -sitelibexp='/usr/lib/perl5/site_perl/5.38.2' +sitelibexp='/usr/lib/perl5/site_perl/5.40.1' siteman1dir='/usr/share/man/man1' siteman1direxp='/usr/share/man/man1' siteman3dir='/usr/share/man/man3' @@ -1101,7 +1106,7 @@ stdio_stream_array='' strerror_r_proto='0' strings='/usr/include/string.h' submit='' -subversion='2' +subversion='1' sysman='/usr/share/man/man1' tail='' tar='' @@ -1196,8 +1201,8 @@ vendorprefix='' vendorprefixexp='' vendorscript='' vendorscriptexp='' -version='5.38.2' -version_patchlevel_string='version 38 subversion 2' +version='5.40.1' +version_patchlevel_string='version 40 subversion 1' versiononly='undef' vi='' xlibpth='/usr/lib/386 /lib/386' @@ -1211,10 +1216,10 @@ config_arg0='Configure' config_args='' config_argc=0 PERL_REVISION=5 -PERL_VERSION=38 -PERL_SUBVERSION=2 +PERL_VERSION=40 +PERL_SUBVERSION=1 PERL_API_REVISION=5 -PERL_API_VERSION=38 +PERL_API_VERSION=40 PERL_API_SUBVERSION=0 PERL_PATCHLEVEL= PERL_CONFIG_SH=true Index: gnu/usr.bin/perl/Cross/config.sh-arm-linux-n770 =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Cross/config.sh-arm-linux-n770,v diff -u -p -a -u -p -r1.15 config.sh-arm-linux-n770 --- gnu/usr.bin/perl/Cross/config.sh-arm-linux-n770 14 May 2024 19:38:54 -0000 1.15 +++ gnu/usr.bin/perl/Cross/config.sh-arm-linux-n770 22 Jan 2025 00:37:41 -0000 @@ -32,11 +32,11 @@ alignbytes='4' aphostname='/bin/hostname' api_revision='5' api_subversion='0' -api_version='38' -api_versionstring='5.38.0' +api_version='40' +api_versionstring='5.40.0' ar='ar' -archlib='/usr/lib/perl5/5.38.2/armv4l-linux' -archlibexp='/usr/lib/perl5/5.38.2/armv4l-linux' +archlib='/usr/lib/perl5/5.40.1/armv4l-linux' +archlibexp='/usr/lib/perl5/5.40.1/armv4l-linux' archname64='' archname='armv4l-linux' archobjs='' @@ -54,7 +54,7 @@ castflags='0' cat='cat' cc='arm-none-linux-gnueabi-gcc' cccdlflags='-fpic' -ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.38.2/armv4l-linux/CORE' +ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.40.1/armv4l-linux/CORE' ccflags='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64' ccflags_uselargefiles='-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64' ccname='arm-linux-gcc' @@ -432,6 +432,9 @@ d_open3='define' d_openat='undef' d_pathconf='define' d_pause='define' +d_perl_lc_all_category_positions_init='define' +d_perl_lc_all_separator='define' +d_perl_lc_all_uses_name_value_pairs='define' d_perl_otherlibdirs='undef' d_phostname='undef' d_pipe2='undef' @@ -833,7 +836,7 @@ inc_version_list=' ' inc_version_list_init='0' incpath='' inews='' -installarchlib='./install_me_here/usr/lib/perl5/5.38.2/armv4l-linux' +installarchlib='./install_me_here/usr/lib/perl5/5.40.1/armv4l-linux' installbin='./install_me_here/usr/bin' installhtml1dir='' installhtml3dir='' @@ -841,13 +844,13 @@ installman1dir='./install_me_here/usr/sh installman3dir='./install_me_here/usr/share/man/man3' installprefix='./install_me_here/usr' installprefixexp='./install_me_here/usr' -installprivlib='./install_me_here/usr/lib/perl5/5.38.2' +installprivlib='./install_me_here/usr/lib/perl5/5.40.1' installscript='./install_me_here/usr/bin' -installsitearch='./install_me_here/usr/lib/perl5/site_perl/5.38.2/armv4l-linux' +installsitearch='./install_me_here/usr/lib/perl5/site_perl/5.40.1/armv4l-linux' installsitebin='./install_me_here/usr/bin' installsitehtml1dir='' installsitehtml3dir='' -installsitelib='./install_me_here/usr/lib/perl5/site_perl/5.38.2' +installsitelib='./install_me_here/usr/lib/perl5/site_perl/5.40.1' installsiteman1dir='./install_me_here/usr/share/man/man1' installsiteman3dir='./install_me_here/usr/share/man/man3' installsitescript='./install_me_here/usr/bin' @@ -968,6 +971,8 @@ patchlevel='11' path_sep=':' perl5='/usr/bin/perl' perl='' +perl_lc_all_category_positions_init='define' +perl_lc_all_separator='define' perl_patchlevel='' perl_static_inline='static' perl_thread_local='' @@ -982,8 +987,8 @@ pmake='' pr='' prefix='/usr' prefixexp='/usr' -privlib='/usr/lib/perl5/5.38.2' -privlibexp='/usr/lib/perl5/5.38.2' +privlib='/usr/lib/perl5/5.40.1' +privlibexp='/usr/lib/perl5/5.40.1' procselfexe='"/proc/self/exe"' prototype='define' ptrsize='4' @@ -1048,17 +1053,17 @@ sig_num='0 1 2 3 4 5 6 7 8 9 10 11 12 13 sig_num_init='0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 6, 17, 29, 31, 0' sig_size='68' signal_t='void' -sitearch='/usr/lib/perl5/site_perl/5.38.2/armv4l-linux' -sitearchexp='/usr/lib/perl5/site_perl/5.38.2/armv4l-linux' +sitearch='/usr/lib/perl5/site_perl/5.40.1/armv4l-linux' +sitearchexp='/usr/lib/perl5/site_perl/5.40.1/armv4l-linux' sitebin='/usr/bin' sitebinexp='/usr/bin' sitehtml1dir='' sitehtml1direxp='' sitehtml3dir='' sitehtml3direxp='' -sitelib='/usr/lib/perl5/site_perl/5.38.2' +sitelib='/usr/lib/perl5/site_perl/5.40.1' sitelib_stem='/usr/lib/perl5/site_perl' -sitelibexp='/usr/lib/perl5/site_perl/5.38.2' +sitelibexp='/usr/lib/perl5/site_perl/5.40.1' siteman1dir='/usr/share/man/man1' siteman1direxp='/usr/share/man/man1' siteman3dir='/usr/share/man/man3' @@ -1099,7 +1104,7 @@ stdio_stream_array='' strerror_r_proto='0' strings='/usr/include/string.h' submit='' -subversion='2' +subversion='1' sysman='/usr/share/man/man1' tail='' tar='' @@ -1194,8 +1199,8 @@ vendorprefix='' vendorprefixexp='' vendorscript='' vendorscriptexp='' -version='5.38.2' -version_patchlevel_string='version 38 subversion 2' +version='5.40.1' +version_patchlevel_string='version 40 subversion 1' versiononly='undef' vi='' xlibpth='/usr/lib/386 /lib/386' @@ -1209,10 +1214,10 @@ config_arg0='Configure' config_args='' config_argc=0 PERL_REVISION=5 -PERL_VERSION=38 -PERL_SUBVERSION=2 +PERL_VERSION=40 +PERL_SUBVERSION=1 PERL_API_REVISION=5 -PERL_API_VERSION=38 +PERL_API_VERSION=40 PERL_API_SUBVERSION=0 PERL_PATCHLEVEL= PERL_CONFIG_SH=true Index: gnu/usr.bin/perl/Porting/Glossary =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/Glossary,v diff -u -p -a -u -p -r1.20 Glossary --- gnu/usr.bin/perl/Porting/Glossary 14 May 2024 19:38:54 -0000 1.20 +++ gnu/usr.bin/perl/Porting/Glossary 22 Jan 2025 00:37:42 -0000 @@ -1903,10 +1903,9 @@ d_nl_langinfo (d_nl_langinfo.U): This variable conditionally defines the HAS_NL_LANGINFO symbol, which indicates to the C program that the nl_langinfo() routine is available. -d_nl_langinfo_l (d_nl_langinfo_l.U): - This variable contains the eventual value of the - HAS_NL_LANGINFO_L symbol, which indicates if the - nl_langinfo_l() function exists. +d_nl_langinfo_l (d_nl_langinfo.U): + This variable conditionally defines the HAS_NL_LANGINFO_L symbol, which + indicates to the C program that the nl_langinfo_l() routine is available. d_non_int_bitfields (d_bitfield.U): This variable conditionally defines HAS_NON_INT_BITFIELDS @@ -1958,6 +1957,19 @@ d_pause (d_pause.U): indicates to the C program that the pause() routine is available to suspend a process until a signal is received. +d_perl_lc_all_category_positions_init (disparate_lc_all.U): + This symbol, if defined, indicates that $lc_all_category_positions_init + is valid + +d_perl_lc_all_separator (disparate_lc_all.U): + This symbol, if defined, indicates that $perl_lc_all_separator is valid + +d_perl_lc_all_uses_name_value_pairs (disparate_lc_all.U): + This symbol, if defined, indicates that the string returned by + setlocale(LC_ALL, NULL) uses 'name=value;' pairs to indicate what each + category's locale is when they aren't all set to the same locale. + When not defined, the platform uses positional notation. + d_perl_otherlibdirs (otherlibdirs.U): This variable conditionally defines PERL_OTHERLIBDIRS, which contains a colon-separated set of paths for the perl binary to @@ -2799,11 +2811,6 @@ d_thread_local (d_thread_local.U): This variable conditionally defines the PERL_THREAD_LOCAL symbol. In turn that gives a linkage specification for thread-local storage. -d_thread_safe_nl_langinfo_l (d_nl_langinfo_l.U): - This variable contains the eventual value of the - HAS_THREAD_SAFE_NL_LANGINFO_L symbol, which indicates if the - nl_langinfo_l() function exists and is thread-safe. - d_time (d_time.U): This variable conditionally defines the HAS_TIME symbol, which indicates that the time() routine exists. The time() routine is normally @@ -4689,6 +4696,19 @@ PERL_API_VERSION (patchlevel.h): PERL_CONFIG_SH (Oldsyms.U): This is set to 'true' in config.sh so that a shell script sourcing config.sh can tell if it has been sourced already. + +perl_lc_all_category_positions_init (disparate_lc_all.U): + This symbol, when defined, gives the C initializer for an array whose + element [0] is the first category in the string returned by + setlocale(LC_ALL, NULL) when not all categories are the same, on + systems that use a positional notation. After element [0] is + $lc_all_separator_init, then the category given by element [1], and so on. + +perl_lc_all_separator (disparate_lc_all.U): + This symbol, when defined, gives the substring used to separate + categories in the aggregated string returned by setlocale(LC_ALL, NULL) + when not all categories are in the same locale. This is for systems + that use a positional notation as opposed to 'name=value' pairs. PERL_PATCHLEVEL (Oldsyms.U): This symbol reflects the patchlevel, if available. Will usually Index: gnu/usr.bin/perl/Porting/Maintainers.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/Maintainers.pl,v diff -u -p -a -u -p -r1.26 Maintainers.pl --- gnu/usr.bin/perl/Porting/Maintainers.pl 14 May 2024 19:39:39 -0000 1.26 +++ gnu/usr.bin/perl/Porting/Maintainers.pl 22 Jan 2025 00:37:42 -0000 @@ -8,6 +8,8 @@ package Maintainers; +use strict; +use warnings; use utf8; use File::Glob qw(:case); @@ -15,7 +17,7 @@ use File::Glob qw(:case); # distribution, need not appear in core (i.e. core-cpan-diff won't # complain if it can't find them) -@IGNORABLE = qw( +our @IGNORABLE = qw( .cvsignore .dualLivedDiffConfig .gitignore .github .perlcriticrc .perltidyrc .travis.yml ANNOUNCE Announce Artistic AUTHORS BENCHMARK BUGS Build.PL CHANGELOG ChangeLog Changelog CHANGES Changes CONTRIBUTING CONTRIBUTING.md @@ -124,15 +126,17 @@ use File::Glob qw(:case); # '' => 'lib/Foo/Bar/', # } -%Modules = ( +our %Modules = ( 'Archive::Tar' => { - 'DISTRIBUTION' => 'BINGOS/Archive-Tar-2.40.tar.gz', + 'DISTRIBUTION' => 'BINGOS/Archive-Tar-3.02_001.tar.gz', + 'SYNCINFO' => 'jkeenan on Tue Dec 5 07:32:24 2023', 'FILES' => q[cpan/Archive-Tar], 'BUGS' => 'bug-archive-tar@rt.cpan.org', 'EXCLUDED' => [ qw(t/07_ptardiff.t), qr{t/src/(long|short)/foo.txz}, + qw(t/90_symlink.t), ], }, @@ -142,7 +146,8 @@ use File::Glob qw(:case); }, 'autodie' => { - 'DISTRIBUTION' => 'TODDR/autodie-2.36.tar.gz', + 'DISTRIBUTION' => 'TODDR/autodie-2.37.tar.gz', + 'SYNCINFO' => 'jkeenan on Sat Dec 30 15:24:00 2023', 'FILES' => q[cpan/autodie], 'EXCLUDED' => [ qr{benchmarks}, @@ -187,7 +192,8 @@ use File::Glob qw(:case); }, 'bignum' => { - 'DISTRIBUTION' => 'PJACKLAM/bignum-0.66.tar.gz', + 'DISTRIBUTION' => 'PJACKLAM/bignum-0.67.tar.gz', + 'SYNCINFO' => 'jkeenan on Sat Dec 30 15:32:11 2023', 'FILES' => q[cpan/bignum], 'EXCLUDED' => [ qr{^xt/}, @@ -205,7 +211,8 @@ use File::Glob qw(:case); }, 'Compress::Raw::Bzip2' => { - 'DISTRIBUTION' => 'PMQS/Compress-Raw-Bzip2-2.204.tar.gz', + 'DISTRIBUTION' => 'PMQS/Compress-Raw-Bzip2-2.212.tar.gz', + 'SYNCINFO' => 'LeoNerd on Sat Apr 27 14:06:26 2024', 'FILES' => q[cpan/Compress-Raw-Bzip2], 'EXCLUDED' => [ qr{^t/Test/}, @@ -214,15 +221,11 @@ use File::Glob qw(:case); 'bzip2-src/bzip2-cpp.patch', 'bzip2-src/bzip2-unsigned.patch', ], - 'CUSTOMIZED' => [ - # https://github.com/pmqs/Compress-Raw-Bzip2/issues/11 - 'Bzip2.xs', - 'lib/Compress/Raw/Bzip.pm' - ], }, 'Compress::Raw::Zlib' => { - 'DISTRIBUTION' => 'PMQS/Compress-Raw-Zlib-2.204.tar.gz', + 'DISTRIBUTION' => 'PMQS/Compress-Raw-Zlib-2.212.tar.gz', + 'SYNCINFO' => 'LeoNerd on Sat Apr 27 14:15:07 2024', 'FILES' => q[cpan/Compress-Raw-Zlib], 'EXCLUDED' => [ qr{^examples/}, @@ -232,11 +235,6 @@ use File::Glob qw(:case); t/99pod.t ), ], - 'CUSTOMIZED' => [ - # https://github.com/pmqs/Compress-Raw-Zlib/issues/23 - 'lib/Compress/Raw/Zlib.pm', - 'Zlib.xs' - ], }, 'Config::Perl::V' => { @@ -316,7 +314,7 @@ use File::Glob qw(:case); }, 'CPAN::Meta::Requirements' => { - 'DISTRIBUTION' => 'DAGOLDEN/CPAN-Meta-Requirements-2.140.tar.gz', + 'DISTRIBUTION' => 'RJBS/CPAN-Meta-Requirements-2.143.tar.gz', 'FILES' => q[cpan/CPAN-Meta-Requirements], 'EXCLUDED' => [ qw(t/00-report-prereqs.t), @@ -342,7 +340,8 @@ use File::Glob qw(:case); }, 'DB_File' => { - 'DISTRIBUTION' => 'PMQS/DB_File-1.858.tar.gz', + 'DISTRIBUTION' => 'PMQS/DB_File-1.859.tar.gz', + 'SYNCINFO' => 'jkeenan on Tue Sep 5 20:46:44 2023', 'FILES' => q[cpan/DB_File], 'EXCLUDED' => [ qr{^patches/}, @@ -376,14 +375,10 @@ use File::Glob qw(:case); }, 'Digest::MD5' => { - 'DISTRIBUTION' => 'TODDR/Digest-MD5-2.58.tar.gz', + 'DISTRIBUTION' => 'TODDR/Digest-MD5-2.59.tar.gz', + 'SYNCINFO' => 'root on Sat Dec 30 21:42:47 2023', 'FILES' => q[cpan/Digest-MD5], 'EXCLUDED' => [ 'rfc1321.txt', 'bin/md5sum.pl' ], - 'CUSTOMIZED' => [ - # https://github.com/Dual-Life/digest-md5/pull/24 - 'MD5.pm', - 'MD5.xs' - ], }, 'Digest::SHA' => { @@ -404,7 +399,9 @@ use File::Glob qw(:case); }, 'Encode' => { - 'DISTRIBUTION' => 'DANKOGAI/Encode-3.19.tar.gz', + 'DISTRIBUTION' => 'DANKOGAI/Encode-3.21.tar.gz', + 'SYNCINFO' => 'jkeenan on Sun Feb 25 19:56:46 2024', + 'SYNCINFO' => 'jkeenan on Fri Nov 10 15:12:07 2023', 'FILES' => q[cpan/Encode], 'EXCLUDED' => [ qw( t/whatwg-aliases.json @@ -429,13 +426,14 @@ use File::Glob qw(:case); }, 'experimental' => { - 'DISTRIBUTION' => 'LEONT/experimental-0.031.tar.gz', + 'DISTRIBUTION' => 'LEONT/experimental-0.032.tar.gz', + 'SYNCINFO' => 'LeoNerd on Sat Apr 27 09:43:20 2024', 'FILES' => q[cpan/experimental], 'EXCLUDED' => [qr{^xt/}], }, 'Exporter' => { - 'DISTRIBUTION' => 'TODDR/Exporter-5.77.tar.gz', + 'DISTRIBUTION' => 'TODDR/Exporter-5.78.tar.gz', 'FILES' => q[dist/Exporter], 'EXCLUDED' => [ qw( t/pod.t @@ -513,7 +511,7 @@ use File::Glob qw(:case); }, 'ExtUtils::Manifest' => { - 'DISTRIBUTION' => 'ETHER/ExtUtils-Manifest-1.73.tar.gz', + 'DISTRIBUTION' => 'ETHER/ExtUtils-Manifest-1.75.tar.gz', 'FILES' => q[cpan/ExtUtils-Manifest], 'EXCLUDED' => [ qr(^t/00-report-prereqs), @@ -522,7 +520,7 @@ use File::Glob qw(:case); }, 'ExtUtils::ParseXS' => { - 'DISTRIBUTION' => 'XSAWYERX/ExtUtils-ParseXS-3.44.tar.gz', + 'DISTRIBUTION' => 'LEONT/ExtUtils-ParseXS-3.51.tar.gz', 'FILES' => q[dist/ExtUtils-ParseXS], }, @@ -607,12 +605,13 @@ use File::Glob qw(:case); }, 'FindBin' => { - 'DISTRIBUTION' => 'TODDR/FindBin-1.53.tar.gz', + 'DISTRIBUTION' => 'TODDR/FindBin-1.54.tar.gz', 'FILES' => q[dist/FindBin], }, 'Getopt::Long' => { - 'DISTRIBUTION' => 'JV/Getopt-Long-2.54.tar.gz', + 'DISTRIBUTION' => 'JV/Getopt-Long-2.57.tar.gz', + 'SYNCINFO' => 'jkeenan on Sat Nov 11 13:09:21 2023', 'FILES' => q[cpan/Getopt-Long], 'EXCLUDED' => [ qr{^examples/}, @@ -623,7 +622,8 @@ use File::Glob qw(:case); }, 'HTTP::Tiny' => { - 'DISTRIBUTION' => 'DAGOLDEN/HTTP-Tiny-0.086.tar.gz', + 'DISTRIBUTION' => 'DAGOLDEN/HTTP-Tiny-0.088.tar.gz', + 'SYNCINFO' => 'jkeenan on Sat Aug 12 14:49:17 2023', 'FILES' => q[cpan/HTTP-Tiny], 'EXCLUDED' => [ 'corpus/snake-oil.crt', # only used by 210_live_ssl.t @@ -653,19 +653,21 @@ use File::Glob qw(:case); }, 'IO' => { - 'DISTRIBUTION' => 'TODDR/IO-1.51.tar.gz', + 'DISTRIBUTION' => 'TODDR/IO-1.55.tar.gz', 'FILES' => q[dist/IO], 'EXCLUDED' => ['t/test.pl'], }, 'IO-Compress' => { - 'DISTRIBUTION' => 'PMQS/IO-Compress-2.204.tar.gz', + 'DISTRIBUTION' => 'PMQS/IO-Compress-2.212.tar.gz', + 'SYNCINFO' => 'LeoNerd on Sat Apr 27 14:31:39 2024', 'MAIN_MODULE' => 'IO::Compress::Base', 'FILES' => q[cpan/IO-Compress], 'EXCLUDED' => [ qr{^examples/}, qr{^t/Test/}, qr{^t/999meta-}, + 't/000prereq.t', 't/010examples-bzip2.t', 't/010examples-zlib.t', 't/cz-05examples.t', @@ -673,19 +675,17 @@ use File::Glob qw(:case); }, 'IO::Socket::IP' => { - 'DISTRIBUTION' => 'PEVANS/IO-Socket-IP-0.41.tar.gz', + 'DISTRIBUTION' => 'PEVANS/IO-Socket-IP-0.42.tar.gz', + 'SYNCINFO' => 'jkeenan on Wed Aug 16 21:34:20 2023', 'FILES' => q[cpan/IO-Socket-IP], 'EXCLUDED' => [ qr{^examples/}, ], - 'CUSTOMIZED' => [ - # https://rt.cpan.org/Ticket/Display.html?id=148293 - 'lib/IO/Socket/IP.pm' - ], }, 'IO::Zlib' => { - 'DISTRIBUTION' => 'TOMHUGHES/IO-Zlib-1.14.tar.gz', + 'DISTRIBUTION' => 'TOMHUGHES/IO-Zlib-1.15.tar.gz', + 'SYNCINFO' => 'jkeenan on Mon Mar 4 19:30:34 2024', 'FILES' => q[cpan/IO-Zlib], }, @@ -737,7 +737,7 @@ use File::Glob qw(:case); }, 'Locale::Maketext' => { - 'DISTRIBUTION' => 'TODDR/Locale-Maketext-1.32.tar.gz', + 'DISTRIBUTION' => 'TODDR/Locale-Maketext-1.33.tar.gz', 'FILES' => q[dist/Locale-Maketext], 'EXCLUDED' => [ qw( @@ -758,13 +758,13 @@ use File::Glob qw(:case); }, 'Math::BigInt' => { - 'DISTRIBUTION' => 'PJACKLAM/Math-BigInt-1.999837.tar.gz', + 'DISTRIBUTION' => 'PJACKLAM/Math-BigInt-2.003002.tar.gz', + 'SYNCINFO' => 'corion on Thu Jan 11 20:23:12 2024', + 'SYNCINFO' => 'book on Tue Dec 26 22:44:58 2023', 'FILES' => q[cpan/Math-BigInt], 'EXCLUDED' => [ qr{^xt/}, qr{^examples/}, - qr{^t/author-}, - qr{^t/release-}, qw( t/00sig.t t/01load.t ), @@ -772,13 +772,14 @@ use File::Glob qw(:case); }, 'Math::BigInt::FastCalc' => { - 'DISTRIBUTION' => 'PJACKLAM/Math-BigInt-FastCalc-0.5013.tar.gz', + 'DISTRIBUTION' => 'PJACKLAM/Math-BigInt-FastCalc-0.5018.tar.gz', + 'SYNCINFO' => 'corion on Thu Jan 11 20:24:21 2024', + 'SYNCINFO' => 'jkeenan on Sat Dec 30 14:31:28 2023', + 'SYNCINFO' => 'jkeenan on Sun Sep 24 08:29:56 2023', 'FILES' => q[cpan/Math-BigInt-FastCalc], 'EXCLUDED' => [ qr{^inc/}, qr{^xt/}, - qr{^t/author-}, - qr{^t/release-}, qr{^t/Math/BigInt/Lib/TestUtil.pm}, qw( t/00sig.t t/01load.t @@ -796,20 +797,6 @@ use File::Glob qw(:case); ], }, - 'Math::BigRat' => { - 'DISTRIBUTION' => 'PJACKLAM/Math-BigRat-0.2624.tar.gz', - 'FILES' => q[cpan/Math-BigRat], - 'EXCLUDED' => [ - qr{^xt/}, - qr{^math-bigrat-pod.diff}, - qr{^t/author-}, - qr{^t/release-}, - qw( t/00sig.t - t/01load.t - ), - ], - }, - 'Math::Complex' => { 'DISTRIBUTION' => 'ZEFRAM/Math-Complex-1.59.tar.gz', 'FILES' => q[dist/Math-Complex], @@ -833,13 +820,14 @@ use File::Glob qw(:case); 'CUSTOMIZED' => [ # https://github.com/Dual-Life/mime-base64/pull/17 'Base64.xs', - 'lib/MIME/Base64.pm' + 'lib/MIME/Base64.pm', + + 'lib/MIME/QuotedPrint.pm' ], }, 'Module::CoreList' => { - 'DISTRIBUTION' => 'BINGOS/Module-CoreList-5.20230320.tar.gz', - 'SYNCINFO' => 'yorton on Tue Mar 21 11:46:02 2023', + 'DISTRIBUTION' => 'BINGOS/Module-CoreList-5.20240420.tar.gz', 'FILES' => q[dist/Module-CoreList], }, @@ -859,7 +847,7 @@ use File::Glob qw(:case); }, 'Module::Metadata' => { - 'DISTRIBUTION' => 'ETHER/Module-Metadata-1.000037.tar.gz', + 'DISTRIBUTION' => 'ETHER/Module-Metadata-1.000038.tar.gz', 'FILES' => q[cpan/Module-Metadata], 'EXCLUDED' => [ qw(t/00-report-prereqs.t), @@ -922,7 +910,7 @@ use File::Glob qw(:case); }, 'perlfaq' => { - 'DISTRIBUTION' => 'ETHER/perlfaq-5.20210520.tar.gz', + 'DISTRIBUTION' => 'ETHER/perlfaq-5.20240218.tar.gz', 'FILES' => q[cpan/perlfaq], 'EXCLUDED' => [ qr/^inc/, qr/^xt/, qr{^t/00-} ], }, @@ -933,7 +921,9 @@ use File::Glob qw(:case); }, 'Pod::Checker' => { - 'DISTRIBUTION' => 'MAREKR/Pod-Checker-1.75.tar.gz', + 'DISTRIBUTION' => 'MAREKR/Pod-Checker-1.77.tar.gz', + 'SYNCINFO' => 'jkeenan on Mon Feb 5 16:37:53 2024', + 'SYNCINFO' => 'corion on Tue Jan 9 20:34:18 2024', 'FILES' => q[cpan/Pod-Checker], }, @@ -956,6 +946,9 @@ use File::Glob qw(:case); # utils first 'perldoc', + # files only used for manual testing + qr[^corpus/], + # https://rt.cpan.org/Ticket/Display.html?id=116827 't/02_module_pod_output.t' ], @@ -967,7 +960,8 @@ use File::Glob qw(:case); }, 'Pod::Simple' => { - 'DISTRIBUTION' => 'KHW/Pod-Simple-3.43.tar.gz', + 'DISTRIBUTION' => 'KHW/Pod-Simple-3.45.tar.gz', + 'SYNCINFO' => 'jkeenan on Wed Aug 2 19:32:39 2023', 'FILES' => q[cpan/Pod-Simple], 'EXCLUDED' => [ qw{.ChangeLog.swp}, @@ -992,7 +986,15 @@ use File::Glob qw(:case); qr{^\.github/dependabot\.yml}, qr{^\.github/workflows/build\.yaml}, ], - + 'CUSTOMIZED' => [ + # https://github.com/rra/podlators/pull/28 + 'lib/Pod/Man.pm', + 'lib/Pod/ParseLink.pm', + 'lib/Pod/Text.pm', + 'lib/Pod/Text/Color.pm', + 'lib/Pod/Text/Overstrike.pm', + 'lib/Pod/Text/Termcap.pm' + ], 'MAP' => { '' => 'cpan/podlators/', # this file lives outside the cpan/ directory @@ -1008,6 +1010,10 @@ use File::Glob qw(:case); 'Scalar::Util' => { 'DISTRIBUTION' => 'PEVANS/Scalar-List-Utils-1.63.tar.gz', 'FILES' => q[cpan/Scalar-List-Utils], + 'CUSTOMIZED' => [ + # https://github.com/Dual-Life/Scalar-List-Utils/pull/130 + 't/uniqnum.t' + ], }, 'Search::Dict' => { @@ -1022,8 +1028,10 @@ use File::Glob qw(:case); }, 'Socket' => { - 'DISTRIBUTION' => 'PEVANS/Socket-2.036.tar.gz', + 'DISTRIBUTION' => 'PEVANS/Socket-2.038.tar.gz', + 'SYNCINFO' => 'LeoNerd on Sat Apr 27 09:57:02 2024', 'FILES' => q[cpan/Socket], + 'EXCLUDED' => ['.editorconfig'], }, 'Storable' => { @@ -1081,13 +1089,23 @@ use File::Glob qw(:case); 'EXCLUDED' => [qr{^t/release-.*\.t}], }, + 'Term::Table' => { + 'DISTRIBUTION' => 'EXODIST/Term-Table-0.018.tar.gz', + 'SYNCINFO' => 'jkeenan on Wed Nov 1 19:16:24 2023', + 'FILES' => q[cpan/Term-Table], + 'EXCLUDED' => [ + qw( appveyor.yml ), + ], + }, + 'Test' => { 'DISTRIBUTION' => 'JESSE/Test-1.26.tar.gz', 'FILES' => q[dist/Test], }, 'Test::Harness' => { - 'DISTRIBUTION' => 'LEONT/Test-Harness-3.44.tar.gz', + 'DISTRIBUTION' => 'LEONT/Test-Harness-3.48.tar.gz', + 'SYNCINFO' => 'gknop on Sat Oct 21 15:01:02 2023', 'FILES' => q[cpan/Test-Harness], 'EXCLUDED' => [ qr{^examples/}, @@ -1100,15 +1118,12 @@ use File::Glob qw(:case); t/lib/if.pm ), ], - 'CUSTOMIZED' => [ - 't/harness.t' - ] }, 'Test::Simple' => { - 'DISTRIBUTION' => 'EXODIST/Test-Simple-1.302194.tar.gz', - 'SYNCINFO' => 'yorton on Tue Mar 14 13:43:38 2023', - 'SYNCINFO' => 'yorton on Mon Mar 6 19:16:42 2023', + 'DISTRIBUTION' => 'EXODIST/Test-Simple-1.302199.tar.gz', + 'SYNCINFO' => 'LeoNerd on Sat Apr 27 10:20:58 2024', + 'SYNCINFO' => 'jkeenan on Fri Dec 1 07:01:54 2023', 'FILES' => q[cpan/Test-Simple], 'EXCLUDED' => [ qr{^examples/}, @@ -1121,6 +1136,21 @@ use File::Glob qw(:case); ], }, + 'Test2::Suite' => { + 'DISTRIBUTION' => 'EXODIST/Test2-Suite-0.000162.tar.gz', + 'SYNCINFO' => 'LeoNerd on Sat Apr 27 10:12:36 2024', + 'SYNCINFO' => 'jkeenan on Wed Nov 1 20:18:33 2023', + 'FILES' => q[cpan/Test2-Suite], + 'EXCLUDED' => [ + qw( appveyor.yml + perltidyrc + t/00-report.t ), + + # https://github.com/Test-More/Test2-Suite/issues/208 + 't/acceptance/Workflow-Acceptance.t', + ], + }, + 'Text::Abbrev' => { 'DISTRIBUTION' => 'FLORA/Text-Abbrev-1.02.tar.gz', 'FILES' => q[dist/Text-Abbrev], @@ -1138,7 +1168,8 @@ use File::Glob qw(:case); }, 'Text-Tabs+Wrap' => { - 'DISTRIBUTION' => 'ARISTOTLE/Text-Tabs+Wrap-2021.0814.tar.gz', + 'DISTRIBUTION' => 'ARISTOTLE/Text-Tabs+Wrap-2024.001.tar.gz', + 'SYNCINFO' => 'jkeenan on Sun Feb 25 20:37:52 2024', 'MAIN_MODULE' => 'Text::Tabs', 'FILES' => q[cpan/Text-Tabs], 'EXCLUDED' => [ @@ -1222,15 +1253,17 @@ use File::Glob qw(:case); }, 'Time::Local' => { - 'DISTRIBUTION' => 'DROLSKY/Time-Local-1.30.tar.gz', + 'DISTRIBUTION' => 'DROLSKY/Time-Local-1.35.tar.gz', 'FILES' => q[cpan/Time-Local], 'EXCLUDED' => [ + qr{^dev-bin/}, + qr{^git/}, qr{^xt/}, qw( CODE_OF_CONDUCT.md azure-pipelines.yml perlcriticrc perltidyrc - tidyall.ini + precious.toml t/00-report-prereqs.t t/00-report-prereqs.dd ), @@ -1275,7 +1308,8 @@ use File::Glob qw(:case); }, 'version' => { - 'DISTRIBUTION' => 'LEONT/version-0.9929.tar.gz', + 'DISTRIBUTION' => 'LEONT/version-0.9930.tar.gz', + 'SYNCINFO' => 'LeoNerd on Mon Sep 18 21:49:09 2023', 'FILES' => q[cpan/version vutil.c vutil.h vxs.inc], 'EXCLUDED' => [ qr{^vutil/lib/}, @@ -1292,8 +1326,6 @@ use File::Glob qw(:case); # only necessary with the CPAN release. 'CUSTOMIZED' => [ 'lib/version.pm', - - 't/07locale.t' ], 'MAP' => { @@ -1312,7 +1344,7 @@ use File::Glob qw(:case); }, 'Win32' => { - 'DISTRIBUTION' => "JDB/Win32-0.59.tar.gz", + 'DISTRIBUTION' => 'JDB/Win32-0.59.tar.gz', 'FILES' => q[cpan/Win32], }, @@ -1452,8 +1484,8 @@ use File::Glob qw(:case); lib/_charnames.pm lib/blib.{pm,t} lib/builtin.{pm,t} + lib/builtin-taint.t lib/bytes.{pm,t} - lib/bytes_heavy.pl lib/charnames.{pm,t} lib/dbm_filter_util.pl lib/deprecate.pm @@ -1490,7 +1522,7 @@ use File::Glob qw(:case); }, ); - +our %DistName; # legacy CPAN flag for my $mod_name ( keys %Modules ) { my $data = $Modules{$mod_name}; @@ -1518,6 +1550,7 @@ for ( keys %Modules ) { } } +our %Maintainers; # legacy MAINTAINER field for ( keys %Modules ) { # Keep any existing MAINTAINER flag so that "overrides" can be applied Index: gnu/usr.bin/perl/Porting/bisect-runner.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/bisect-runner.pl,v diff -u -p -a -u -p -r1.6 bisect-runner.pl --- gnu/usr.bin/perl/Porting/bisect-runner.pl 14 May 2024 19:38:54 -0000 1.6 +++ gnu/usr.bin/perl/Porting/bisect-runner.pl 22 Jan 2025 00:37:42 -0000 @@ -1102,6 +1102,48 @@ L, it was +reported that the following one-liner was not emitting warnings in perl-5.16 +but was in perl-5.26 and later releases. + + perl -we '"ab" =~ /.{-1,4}/;' + +The reporter's concern was the negative repeat in this (generated) regular +expression. The warning being emitted was: + + Unescaped left brace in regex is passed through in regex; + marked by <-- HERE in m/.{ <-- HERE -1,4}/ at -e line 1. + +At what commit was that warning first emitted? + +=item * Solution + +We used F to narrow down the range needing testing to the 5.25 +development cycle. We then bisected with the C<--one-liner> switch and the +following invocation: + + export ERR=/tmp/err; rm $ERR + + perl Porting/bisect.pl \ + --start=v5.24.0 \ + --end=v5.26.0 \ + --one-liner 'system(qq|./perl -we "q{ab} =~ /.{-1,4}/" 2>$ENV{ERR}|); + die "See $ENV{ERR} for warnings thrown" if -s $ENV{ERR};' + +Bisection pointed to a commit where a modification had been made to a warning. + +=item * Reference + +L + +=back + =head2 When did perl stop segfaulting on certain code? =over 4 @@ -1184,6 +1226,50 @@ But it was observed that there was no wa L +=item * Problem + +An issue was identified during use of the Perl debugger, but soon a change in +C-level code became suspected. Identifying the breaking commit entailed +writing a Perl program which used a dummy C module. + +=item * Solution + +=over 4 + +=item * + +Create this file: + + $ cat /tmp/21564.pl + #!/usr/bin/perl + + use strict; no strict 'refs'; + use warnings; + use B qw(svref_2object SVf_IOK); + + use v5.10; + + my $b = svref_2object(\(${"_FLAGS & SVf_IOK) { + die "Fail!"; + } + say "Ok"; + +=item * + +Bisect with an invocation which calls a `perl` debugger program. + + $ PERL5DB='sub DB::DB {}' perl Porting/bisect.pl \ + --start=v5.35.5 \ + --end=v5.35.6 \ + -- ./perl -Ilib -d /tmp/21564b.pl + +=back + +=item * Reference + +L + =back =cut @@ -1520,23 +1606,27 @@ sub apply_patch { die_255("Can't $what$files: $?, $!"); } -sub apply_commit { - my ($commit, @files) = @_; - my $patch = `git show $commit @files`; +sub patch_from_commit { + my ($revert, $commit, @files) = @_; + my $flags = $revert ? '-R ' : ''; + my $patch = `git show --src-prefix=a/ --dst-prefix=b/ $flags$commit @files`; if (!defined $patch) { - die_255("Can't get commit $commit for @files: $?") if @files; - die_255("Can't get commit $commit: $?"); + my $thing = $revert ? 'revert commit' : 'commit'; + die_255("Can't get $thing $commit for @files: $?") if @files; + die_255("Can't get $thing $commit: $?"); } + return $patch; +} + +sub apply_commit { + my ($commit, @files) = @_; + my $patch = patch_from_commit(undef, $commit, @files); apply_patch($patch, "patch $commit", @files ? " for @files" : ''); } sub revert_commit { my ($commit, @files) = @_; - my $patch = `git show -R $commit @files`; - if (!defined $patch) { - die_255("Can't get revert commit $commit for @files: $?") if @files; - die_255("Can't get revert commit $commit: $?"); - } + my $patch = patch_from_commit('revert', $commit, @files); apply_patch($patch, "revert $commit", @files ? " for @files" : ''); } @@ -3909,7 +3999,7 @@ EOPATCH } if (my $token = extract_from_file('doio.c', qr!^#if (defined\(__sun(?:__)?\)) && defined\(__svr4__\) /\* XXX Need metaconfig test \*/$!)) { - my $patch = `git show -R 9b599b2a63d2324d doio.c`; + my $patch = patch_from_commit('revert', '9b599b2a63d2324d', 'doio.c'); $patch =~ s/defined\(__sun__\)/$token/g; apply_patch($patch); } Index: gnu/usr.bin/perl/Porting/bump-perl-version =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/bump-perl-version,v diff -u -p -a -u -p -r1.3 bump-perl-version --- gnu/usr.bin/perl/Porting/bump-perl-version 1 Mar 2021 23:19:44 -0000 1.3 +++ gnu/usr.bin/perl/Porting/bump-perl-version 22 Jan 2025 00:37:42 -0000 @@ -188,14 +188,6 @@ my @maps = ( "$oldx$oldy", qr/win32|hints/, # README.win32, win32/*, hints/* ], - - # microperl locations should be bumped for major versions - [ - qr{(/)(\d\.\d{2})(["'/])}, - sub { $2, "$1$newx.$newy$3" }, - "$oldx.$oldy", - qr/uconfig/, - ], ); Index: gnu/usr.bin/perl/Porting/checkcfguse.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/checkcfguse.pl,v diff -u -p -a -u -p -r1.3 checkcfguse.pl --- gnu/usr.bin/perl/Porting/checkcfguse.pl 15 Feb 2023 01:36:14 -0000 1.3 +++ gnu/usr.bin/perl/Porting/checkcfguse.pl 22 Jan 2025 00:37:42 -0000 @@ -78,7 +78,7 @@ while (<$mani>) { # Skip matches from the config files themselves, # from metaconfig generated files that refer to # the config symbols, and from pods. - next if $fn =~ m{^(?:config_h.SH|Configure|configure\.com|Porting/(?:config|Glossary)|(?:plan9|win32)/(?:config|(?:GNU)?[Mm]akefile)|uconfig)|\.pod$}; + next if $fn =~ m{^(?:config_h.SH|Configure|configure\.com|Porting/(?:config|Glossary)|(?:plan9|win32)/(?:config|(?:GNU)?[Mm]akefile))|\.pod$}; open my $fh, '<', $fn or die qq[$0: Failed to open $fn: $!]; while (<$fh>) { while (/\b($SYM)\b/go) { Index: gnu/usr.bin/perl/Porting/checkcfgvar.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/checkcfgvar.pl,v diff -u -p -a -u -p -r1.6 checkcfgvar.pl --- gnu/usr.bin/perl/Porting/checkcfgvar.pl 14 May 2024 19:38:54 -0000 1.6 +++ gnu/usr.bin/perl/Porting/checkcfgvar.pl 22 Jan 2025 00:37:42 -0000 @@ -44,8 +44,6 @@ my @CFG = ( # perl that we are running, not the version of the source tree. "Cross/config.sh-arm-linux", "Cross/config.sh-arm-linux-n770", - "uconfig.sh", - "uconfig64.sh", "plan9/config_sh.sample", "win32/config.gc", "win32/config.vc", Index: gnu/usr.bin/perl/Porting/cmpVERSION.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/cmpVERSION.pl,v diff -u -p -a -u -p -r1.7 cmpVERSION.pl --- gnu/usr.bin/perl/Porting/cmpVERSION.pl 14 May 2024 19:38:54 -0000 1.7 +++ gnu/usr.bin/perl/Porting/cmpVERSION.pl 22 Jan 2025 00:37:42 -0000 @@ -91,7 +91,7 @@ my $tag_date = `git for-each-ref --forma chomp($tag_date); my $tag_epoch= do { my ($Y,$M,$D,$h,$m,$s) = split /[- :]/, $tag_date; # 2023-03-20 22:49:09 - timelocal_posix($s,$m,$h,$D,$M,$Y); + timelocal_posix($s,$m,$h,$D,$M-1,$Y-1900); }; if ($commit_epoch - $tag_epoch > 60 * 24 * 60 * 60) { @@ -209,6 +209,13 @@ sub pm_file_from_xs { die "No idea which .pm file corresponds to '$xs', so aborting"; } +# .c files that correspond directly to a perl module +# universal.c is not here, since it powers many different modules, +# so we can't know which one would need its version bumped +my %c_mod = ( + "builtin.c" => "lib/builtin.pm", +); + # Key is the .pm file from which we check the version. # Value is a reference to an array of files to check for differences # The trivial case is a pure perl module, where the array holds one element, @@ -228,6 +235,8 @@ foreach (`git --no-pager diff --name-onl push @{$module_diffs{$_}}, $_; } elsif (/\.xs\z/ && !/\bt\b/) { push @{$module_diffs{pm_file_from_xs($_)}}, $_; + } elsif (my $mod = $c_mod{$_}) { + push @{$module_diffs{$mod}}, $_; } elsif (!/\bt\b/ && /\.[ch]\z/ && m!^((?:dist|ext|cpan)/[^/]+)/!) { push @{ $dist_diffs{$1} }, $_; } Index: gnu/usr.bin/perl/Porting/config.sh =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/config.sh,v diff -u -p -a -u -p -r1.18 config.sh --- gnu/usr.bin/perl/Porting/config.sh 14 May 2024 19:38:54 -0000 1.18 +++ gnu/usr.bin/perl/Porting/config.sh 22 Jan 2025 00:37:42 -0000 @@ -42,11 +42,11 @@ alignbytes='16' aphostname='/usr/bin/hostname' api_revision='5' api_subversion='0' -api_version='38' -api_versionstring='5.38.0' +api_version='40' +api_versionstring='5.40.0' ar='ar' -archlib='/pro/lib/perl5/5.38.2/x86_64-linux-thread-multi-quadmath' -archlibexp='/pro/lib/perl5/5.38.2/x86_64-linux-thread-multi-quadmath' +archlib='/pro/lib/perl5/5.40.1/x86_64-linux-thread-multi-quadmath' +archlibexp='/pro/lib/perl5/5.40.1/x86_64-linux-thread-multi-quadmath' archname64='' archname='x86_64-linux-thread-multi-quadmath' archobjs='' @@ -446,6 +446,9 @@ d_open3='define' d_openat='define' d_pathconf='define' d_pause='define' +d_perl_lc_all_category_positions_init='define' +d_perl_lc_all_separator='define' +d_perl_lc_all_uses_name_value_pairs='define' d_perl_otherlibdirs='undef' d_phostname='undef' d_pipe2='define' @@ -859,7 +862,7 @@ incpath='' incpth='/usr/lib64/gcc/x86_64-suse-linux/13/include /usr/local/include /usr/lib64/gcc/x86_64-suse-linux/13/include-fixed /usr/x86_64-suse-linux/include /usr/include' inews='' initialinstalllocation='/pro/bin' -installarchlib='/pro/lib/perl5/5.38.2/x86_64-linux-thread-multi-quadmath' +installarchlib='/pro/lib/perl5/5.40.1/x86_64-linux-thread-multi-quadmath' installbin='/pro/bin' installhtml1dir='' installhtml3dir='' @@ -867,13 +870,13 @@ installman1dir='/pro/local/man/man1' installman3dir='/pro/local/man/man3' installprefix='/pro' installprefixexp='/pro' -installprivlib='/pro/lib/perl5/5.38.2' +installprivlib='/pro/lib/perl5/5.40.1' installscript='/pro/bin' -installsitearch='/pro/lib/perl5/site_perl/5.38.2/x86_64-linux-thread-multi-quadmath' +installsitearch='/pro/lib/perl5/site_perl/5.40.1/x86_64-linux-thread-multi-quadmath' installsitebin='/pro/bin' installsitehtml1dir='' installsitehtml3dir='' -installsitelib='/pro/lib/perl5/site_perl/5.38.2' +installsitelib='/pro/lib/perl5/site_perl/5.40.1' installsiteman1dir='/pro/local/man/man1' installsiteman3dir='/pro/local/man/man3' installsitescript='/pro/bin' @@ -994,12 +997,14 @@ patchlevel='37' path_sep=':' perl5='/pro/bin/perl' perl='perl' +perl_lc_all_category_positions_init='define' +perl_lc_all_separator='define' perl_patchlevel='' perl_static_inline='static __inline__' perl_thread_local='_Thread_local' perladmin='hmbrand@cpan.org' perllibs='-lpthread -ldl -lm -lcrypt -lutil -lc -lquadmath' -perlpath='/pro/bin/perl5.38.2' +perlpath='/pro/bin/perl5.40.1' pg='pg' phostname='hostname' pidtype='pid_t' @@ -1008,8 +1013,8 @@ pmake='' pr='' prefix='/pro' prefixexp='/pro' -privlib='/pro/lib/perl5/5.38.2' -privlibexp='/pro/lib/perl5/5.38.2' +privlib='/pro/lib/perl5/5.40.1' +privlibexp='/pro/lib/perl5/5.40.1' procselfexe='"/proc/self/exe"' ptrsize='8' quadkind='2' @@ -1074,17 +1079,17 @@ sig_num='0 1 2 3 4 5 6 7 8 9 10 11 12 13 sig_num_init='0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 6, 17, 29, 0' sig_size='68' signal_t='void' -sitearch='/pro/lib/perl5/site_perl/5.38.2/x86_64-linux-thread-multi-quadmath' -sitearchexp='/pro/lib/perl5/site_perl/5.38.2/x86_64-linux-thread-multi-quadmath' +sitearch='/pro/lib/perl5/site_perl/5.40.1/x86_64-linux-thread-multi-quadmath' +sitearchexp='/pro/lib/perl5/site_perl/5.40.1/x86_64-linux-thread-multi-quadmath' sitebin='/pro/bin' sitebinexp='/pro/bin' sitehtml1dir='' sitehtml1direxp='' sitehtml3dir='' sitehtml3direxp='' -sitelib='/pro/lib/perl5/site_perl/5.38.2' +sitelib='/pro/lib/perl5/site_perl/5.40.1' sitelib_stem='/pro/lib/perl5/site_perl' -sitelibexp='/pro/lib/perl5/site_perl/5.38.2' +sitelibexp='/pro/lib/perl5/site_perl/5.40.1' siteman1dir='/pro/local/man/man1' siteman1direxp='/pro/local/man/man1' siteman3dir='/pro/local/man/man3' @@ -1112,7 +1117,7 @@ st_dev_sign='1' st_dev_size='8' st_ino_sign='1' st_ino_size='8' -startperl='#!/pro/bin/perl5.38.2' +startperl='#!/pro/bin/perl5.40.1' startsh='#!/bin/sh' static_ext=' ' stdchar='char' @@ -1124,7 +1129,7 @@ stdio_ptr='((fp)->_ptr)' stdio_stream_array='' strerror_r_proto='REENTRANT_PROTO_B_IBW' submit='' -subversion='2' +subversion='1' sysman='/usr/share/man/man1' sysroot='' tail='' @@ -1227,8 +1232,8 @@ vendorprefix='' vendorprefixexp='' vendorscript='' vendorscriptexp='' -version='5.38.2' -version_patchlevel_string='version 38 subversion 2' +version='5.40.1' +version_patchlevel_string='version 40 subversion 1' versiononly='define' vi='' xlibpth='/usr/lib/386 /lib/386 /usr/lib64/gcc/x86_64-suse-linux/13 /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64 /usr/lib64/gcc/x86_64-suse-linux/13/../../..' @@ -1238,10 +1243,10 @@ yaccflags='' zcat='' zip='zip' PERL_REVISION=5 -PERL_VERSION=38 -PERL_SUBVERSION=2 +PERL_VERSION=40 +PERL_SUBVERSION=1 PERL_API_REVISION=5 -PERL_API_VERSION=38 +PERL_API_VERSION=40 PERL_API_SUBVERSION=0 PERL_PATCHLEVEL='' PERL_CONFIG_SH=true Index: gnu/usr.bin/perl/Porting/config_H =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/config_H,v diff -u -p -a -u -p -r1.30 config_H --- gnu/usr.bin/perl/Porting/config_H 14 May 2024 19:38:54 -0000 1.30 +++ gnu/usr.bin/perl/Porting/config_H 22 Jan 2025 00:37:42 -0000 @@ -1239,8 +1239,8 @@ * This symbol contains the ~name expanded version of ARCHLIB, to be used * in programs that are not prepared to deal with ~ expansion at run-time. */ -#define ARCHLIB "/opt/perl/lib/5.38.2/x86_64-linux" /**/ -#define ARCHLIB_EXP "/opt/perl/lib/5.38.2/x86_64-linux" /**/ +#define ARCHLIB "/opt/perl/lib/5.40.1/x86_64-linux" /**/ +#define ARCHLIB_EXP "/opt/perl/lib/5.40.1/x86_64-linux" /**/ /* BIN: * This symbol holds the path of the bin directory where the package will @@ -1293,8 +1293,8 @@ * This symbol contains the ~name expanded version of PRIVLIB, to be used * in programs that are not prepared to deal with ~ expansion at run-time. */ -#define PRIVLIB "/opt/perl/lib/5.38.2" /**/ -#define PRIVLIB_EXP "/opt/perl/lib/5.38.2" /**/ +#define PRIVLIB "/opt/perl/lib/5.40.1" /**/ +#define PRIVLIB_EXP "/opt/perl/lib/5.40.1" /**/ /* SITEARCH: * This symbol contains the name of the private library for this package. @@ -1311,8 +1311,8 @@ * This symbol contains the ~name expanded version of SITEARCH, to be used * in programs that are not prepared to deal with ~ expansion at run-time. */ -#define SITEARCH "/opt/perl/lib/site_perl/5.38.2/x86_64-linux" /**/ -#define SITEARCH_EXP "/opt/perl/lib/site_perl/5.38.2/x86_64-linux" /**/ +#define SITEARCH "/opt/perl/lib/site_perl/5.40.1/x86_64-linux" /**/ +#define SITEARCH_EXP "/opt/perl/lib/site_perl/5.40.1/x86_64-linux" /**/ /* SITELIB: * This symbol contains the name of the private library for this package. @@ -1334,8 +1334,8 @@ * removed. The elements in inc_version_list (inc_version_list.U) can * be tacked onto this variable to generate a list of directories to search. */ -#define SITELIB "/opt/perl/lib/site_perl/5.38.2" /**/ -#define SITELIB_EXP "/opt/perl/lib/site_perl/5.38.2" /**/ +#define SITELIB "/opt/perl/lib/site_perl/5.40.1" /**/ +#define SITELIB_EXP "/opt/perl/lib/site_perl/5.40.1" /**/ #define SITELIB_STEM "/opt/perl/lib/site_perl" /**/ /* PERL_VENDORARCH: @@ -4109,7 +4109,7 @@ * script to make sure (one hopes) that it runs with perl and not * some shell. */ -#define STARTPERL "#!/opt/perl/bin/perl5.38.2" /**/ +#define STARTPERL "#!/opt/perl/bin/perl5.40.1" /**/ /* HAS_STDIO_STREAM_ARRAY: * This symbol, if defined, tells that there is an array Index: gnu/usr.bin/perl/Porting/core-cpan-diff =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/core-cpan-diff,v diff -u -p -a -u -p -r1.4 core-cpan-diff --- gnu/usr.bin/perl/Porting/core-cpan-diff 14 May 2024 19:38:54 -0000 1.4 +++ gnu/usr.bin/perl/Porting/core-cpan-diff 22 Jan 2025 00:37:42 -0000 @@ -9,7 +9,7 @@ use warnings; use 5.010; -use Getopt::Long; +use Getopt::Long qw(:config bundling); use File::Basename (); use File::Copy (); use File::Temp (); @@ -30,7 +30,7 @@ use Archive::Tar; use Cwd qw[cwd chdir]; use IPC::Open3; use IO::Select; -local $Archive::Tar::WARN=0; +local $Archive::Tar::WARN = 0; # where, under the cache dir, to download tarballs to use constant SRC_DIR => 'tarballs'; @@ -45,34 +45,34 @@ sub usage { print STDERR < [ { - 'name' => 'IO-Compress', + 'name' => 'IO::Compress', 'modification' => $getModifyType->( $changes{'IO::Compress::Base'} ), 'data' => $changes{'IO::Compress::Base'} } Index: gnu/usr.bin/perl/Porting/deparse-skips.txt =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/deparse-skips.txt,v diff -u -p -a -u -p -r1.5 deparse-skips.txt --- gnu/usr.bin/perl/Porting/deparse-skips.txt 14 May 2024 19:38:54 -0000 1.5 +++ gnu/usr.bin/perl/Porting/deparse-skips.txt 22 Jan 2025 00:37:42 -0000 @@ -33,6 +33,7 @@ __DEPARSE_FAILURES__ base/lex.t # checks regexp stringification # class/*.t generally failing because OP_METHSTART not recognised +class/accessor.t class/class.t class/construct.t class/destruct.t @@ -41,6 +42,8 @@ class/inherit.t class/method.t class/phasers.t class/threads.t +class/utf8.t + # comp/final_line_num.t # tests syntax error after BEGIN block comp/fold.t # mutability of folded constants @@ -51,7 +54,6 @@ mro/complex_c3_utf8.t mro/isarev.t mro/isarev_utf8.t op/attrhand.t # Custom attrs ignored; also AH provides none -op/caller.t op/goto.t op/gv.t # glob copy constants op/index.t @@ -122,7 +124,7 @@ uni/variables.t ../cpan/autodie/t/eval_error.t ../cpan/autodie/t/exception_class.t ../cpan/autodie/t/exception_nonref.t -../cpan/autodie/t/exceptions.t +../cpan/autodie/t/exceptions-smartmatch.t ../cpan/autodie/t/exec.t ../cpan/autodie/t/filehandles.t ../cpan/autodie/t/fileno.t @@ -214,10 +216,6 @@ uni/variables.t # of the test file from being compiled ../cpan/ExtUtils-MakeMaker/t/MM_VMS.t -# see comment above about bignum failures -../cpan/Math-BigRat/t/const-mbr.t - - ../cpan/Scalar-List-Utils/t/uniq.t ../cpan/Term-Cap/test.pl ../cpan/Test-Simple/t/Legacy/Builder/carp.t @@ -230,6 +228,25 @@ uni/variables.t ../cpan/Test-Simple/t/Legacy/subtest/predicate.t ../cpan/Test-Simple/t/regression/684-nested_todo_diag.t ../cpan/Test-Simple/t/Test2/behavior/run_subtest_inherit.t + +# These three are very sensitive to line numbers, and in particular +# to wrong line numbers being output for the closing braces of a function, +# e.g. +# +# sub foo { .... } # all on line 30 +# +# becomes +# +# #line 30 .... +# sub foo { +# ... +# #line 10 .... +# } +# +../cpan/Test2-Suite/t/behavior/filtering.t +../cpan/Test2-Suite/t/modules/Tools/Compare.t +../cpan/Test2-Suite/t/modules/Tools/Subtest.t + ../dist/Attribute-Handlers/t/constants.t ../dist/Attribute-Handlers/t/data_convert.t ../dist/Attribute-Handlers/t/linerep.t @@ -261,6 +278,7 @@ uni/variables.t ../lib/charnames.t ../lib/dumpvar.t ../lib/English.t + ../lib/overload.t Index: gnu/usr.bin/perl/Porting/epigraphs.pod =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/epigraphs.pod,v diff -u -p -a -u -p -r1.14 epigraphs.pod --- gnu/usr.bin/perl/Porting/epigraphs.pod 23 Dec 2023 21:02:20 -0000 1.14 +++ gnu/usr.bin/perl/Porting/epigraphs.pod 22 Jan 2025 00:37:42 -0000 @@ -17,6 +17,257 @@ Consult your favorite dictionary for det =head1 EPIGRAPHS +=head2 v5.41.7 - Martha Wells + +L + + Indah glared at me, but it was more wry than angry. "Is that what you think? + Because you keep insisting it's a mysterious ultra-hacker." + Okay, that one stung. "I didn't use the words 'mysteriious' or 'ultra.'" + Aylen watched like it was one of those human games where they threw + balls at each other. + +=head2 v5.41.6 - Jon Postel + +L + + Be conservative in what you do, and liberal in what you accept. + +=head2 v5.41.5 - Great P.I. of the Universe, Under A Killing Moon + +L + + PI: So, they've found it again, have they? I thought we'd taken care of it. + A: The forces of evil are persistent, Sir. + PI: I'm getting too old for this.... + PI: Who have we got lined up to deal with this problem? + A: Murphy, sir. + PI: Oh no! Not Murphy! + +=head2 v5.41.4 - Theodor Seuss Geisel + +L + + Sometimes you will never know the value of a moment + until it becomes a memory. + +=head2 v5.41.3 - Jasper Fforde, The Constant Rabbit + +L + + Somebody once said that the library is actually the dominant life + form on the planet. Humans simply exist as the reproductive means to + achieve more libraries. + +=head2 v5.41.2 - John Dryden + +L + + Errors, like straws, upon the surface flow; He who would search for + pearls must dive down below. + +=head2 v5.41.1 - Charles F. Kettering + +L + + We find that in research a certain amount of intelligent ignorance + is essential to progress; for, if you know too much, you won't try + the thing. + +=head2 v5.40.1-RC1 - E. H. Gombrich, trans. Caroline Mustill, "A Little History of the World" + +L + +Unlike Egypt, Mesopotamia was rarely ruled by just one king. Nor did +any single empire survive long within firm frontiers. Many tribes and +many kings held power at different times. The most important of these +were the Sumerians, the Babylonians and the Assyrians. For a long time +it was thought that the Egyptians were the first people to have +everything that goes to make up what we call a culture: towns and +tradesmen, noblemen and kings, temples and priests, administrators and +artists, writing and technical skills. Yet we now know that, in some +respects, the Sumerians were ahead of the Egyptians. + +=head2 v5.40.0 - Neil Gaiman, Coraline + +L + + “What’s your name,” Coraline asked the cat. “Look, I’m Coraline. Okay?” + “Cats don’t have names,” it said. + “No?” said Coraline. + “No,” said the cat. “Now you people have names. That’s because you + don’t know who you are. We know who we are, so we don’t need names.” + +=head2 v5.39.10 - Fernando Pessoa + +L + + The value of things is not the time they last, but the intensity + with which they occur. That is why there are unforgettable moments + and unique people! + +=head2 v5.39.9 - Terry Pratchett, Sourcery + +L + + "I meant," said Ipslore bitterly, "what is there in this world that + truly makes living worthwhile?" + Death thought about it. + CATS, he said eventually. CATS ARE NICE. + +=head2 v5.39.8 - Friedrich Schiller, "Ode to joy" + +L + + Be embraced, all ye millions! + With a kiss for all the world! + Brothers, beyond the stars + Surely dwells a loving Father. + Do you kneel before Him, oh millions? + Do you feel the Creator's presence? + Seek Him beyond the stars! + He must dwell beyond the stars + +=head2 v5.39.7 - PJ Caldas + +L + + On the screen the image of a frail-looking bigwig from Yale. + Between a mahogany desk and a wall filled with thick + books of all colors, he warns uus that the underpinnings + of the entire planet rely on the internet. + Food and water supply, electricity grid, defense systems... + "If the failure continues fo a few days, we go back to the + nineteen nineties. A couple extra weeks, and we are back to + the nineteenth century." + +=head2 v5.39.6 - Jasper Fforde + +L + +"Do I have to talk to insane people?" + +"You're a librarian now. I'm afraid it's mandatory." + +=head2 v5.39.5 - Epictetus + +L + +It is impossible for a man to learn what he thinks he already knows. + +=head2 v5.39.4 - None + +L + +This release does not have an epigraph. + +=head2 v5.39.3 - Porter Robinson and Madeon, "Shelter" + +L + + I could never find the right way to tell you + Have you noticed I've been gone? + 'Cause I left behind the home that you made me + But I will carry it along + + And it's a long way forward, so trust in me + I'll give them shelter, like you've done for me + And I know, I'm not alone, you'll be watching over us + Until you're gone + + When I'm older, I'll be silent beside you + I know words won't be enough + And they won't need to know the names or our faces + But they will carry on for us + + And it's a long way forward, so trust in me + I'll give them shelter, like you've done for me + And I know, I'm not alone, you'll be watching over us + Until you're gone + + Oh it's a long way forward, trust in me + I'll give them shelter, like you've done for me + And I know, I'm not alone, you'll be watching over us + Until + +=head2 v5.39.2 - U2, "The Fly" + +L + + It's no secret that a conscience can sometimes be a pest + It's no secret ambition bites the nails of success + Every artist is a cannibal, every poet is a thief + All kill their inspiration and sing about the grief + +=head2 v5.39.1 - Ben Aaronovitch, "Whispers Under Ground" + +L + +The British have always been madly over-ambitious and from one angle it +can seem like bravery, but from another it looks suspiciously like a +lack of foresight. The London Underground was no exception and was +built by a breed of entrepreneurs whose grasp was matched only by the +size of their sideburns. While their equally gloriously bewhiskered +counterparts across the Atlantic were busy blowing each other to pieces +in a Civil War, they embarked on the construction of the Metropolitan +Line knowing only one thing for certain - there was no way they were +going to be able to run steam trains through it. + +=head2 v5.38.3-RC1 - E. H. Gombrich, trans. Caroline Mustill, "A Little History of the World" + +L + +Because the Egyptians were so wise and so powerful their empire lasted +for a very long time. Longer than any empire the world has ever known: +nearly three thousand years. And they took just as much care as they +did with their corpses, when they preserved them from rotting away, in +preserving all their ancient traditions over the centuries. Their +priests made quite sure that no son did anything his father had not +done before him. To them, everything old was sacred. + +=head2 v5.38.2 - Kim Stanley Robinson + +(Same epigraph as for v5.34.3 and v5.36.3, as it was a joint release.) + +L + +You can never properly predict the future as it really turns out. So +you are doing something a little different when you write science +fiction. You are trying to take a different perspective on now. + +=head2 v5.38.1 - Kim Stanley Robinson, Blue Mars + +L + +Michel had a curious expression on his face. “You’re a very accurate +person, Sax.” “It’s just statistics,” Sax said defensively. “Every once +in a while language allows you to say things precisely.” + +=head2 v5.38.0 - Miguel de Cervantes, "Don Quixote" + +L + +Take my advice and live for a long, long time. Because the maddest thing +a man can do in this life is to let himself die. + +=head2 v5.38.0-RC2 - They Might Be Giants, "O Do Not Forsake Me" + +L + + Oh, do not forsake me, my indolent friends + Oh, do not forsake me though you know I must spend + All my darkest hours talking like this + For I am one thousand years old + +=head2 v5.38.0-RC1 - Kurt Vonnegut, "Good Bless You, Mr. Rosewater" + +L + +Welcome to Earth. It's hot in the summer and cold in the winter. It's +round and wet and crowded. On the outside, babies, you've got a hundred +years here. There's only one rule that I know of, babies—"God damn it, +you've got to be kind." + =head2 v5.37.11 - Ben Aaronovitch, "Moon Over Soho" L @@ -118,6 +369,13 @@ L + +Any physical action, properly studied and practiced, could no doubt be +accomplished with a reasonable amount of skill, if not flair. + =head2 v5.36.1 - Louis Kentner, "Piano" L @@ -362,6 +620,13 @@ L + +Each of us have a gift, you see, given us freely by the universe. And +each of us with every breath gives something back + =head2 v5.34.1 - Edward Lear, ed. Vivien Noakes, "The Complete Nonsense and Other Verse": Limericks published in "More Nonsense" L @@ -730,8 +995,8 @@ L -On Tuesday, January 20, 2004, I sent Joel Bleifuss, my editor at _In These -Times_, this fax: +On Tuesday, January 20, 2004, I sent Joel Bleifuss, my editor at I, this fax: ON ORANGE ALERT HERE. ECONOMIC TERRORIST ATTACK @@ -991,7 +1256,7 @@ L -=head2 v5.29.7 - Edsger W. Dijkstra: "Programming Considered as a Human Activity", IFIP Congress, New York, 1965. +=head2 v5.29.7 - Edsger W. Dijkstra: "Programming Considered as a Human Activity", IFIP Congress, New York, 1965 L @@ -2328,7 +2593,7 @@ L Index: gnu/usr.bin/perl/Porting/exec-bit.txt =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/exec-bit.txt,v diff -u -p -a -u -p -r1.7 exec-bit.txt --- gnu/usr.bin/perl/Porting/exec-bit.txt 14 May 2024 19:38:54 -0000 1.7 +++ gnu/usr.bin/perl/Porting/exec-bit.txt 22 Jan 2025 00:37:42 -0000 @@ -35,7 +35,6 @@ regen/feature.pl regen/keywords.pl regen/opcode.pl regen/regcharclass.pl -regen/uconfig_h.pl runtests.SH t/TEST Porting/Maintainers.pl @@ -52,6 +51,7 @@ Porting/checkcfgvar.pl Porting/checkpodencoding.pl Porting/cmpVERSION.pl Porting/config_h.pl +Porting/core-cpan-diff Porting/corecpan.pl Porting/corelist-perldelta.pl Porting/corelist.pl Index: gnu/usr.bin/perl/Porting/how_to_write_a_perldelta.pod =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/how_to_write_a_perldelta.pod,v diff -u -p -a -u -p -r1.5 how_to_write_a_perldelta.pod --- gnu/usr.bin/perl/Porting/how_to_write_a_perldelta.pod 15 Feb 2023 01:36:14 -0000 1.5 +++ gnu/usr.bin/perl/Porting/how_to_write_a_perldelta.pod 22 Jan 2025 00:37:42 -0000 @@ -42,7 +42,9 @@ Whilst modules could also be links, usua the reference is to code Cing them, rather than something within their documentation. -Be consistent in how bugs are referenced. One style is +Be consistent in how bugs are referenced. One common style, which is +expected by some commands given in the Release Manager's Guide, is as +follows: =over 4 Index: gnu/usr.bin/perl/Porting/make-rmg-checklist =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/make-rmg-checklist,v diff -u -p -a -u -p -r1.4 make-rmg-checklist --- gnu/usr.bin/perl/Porting/make-rmg-checklist 14 May 2024 19:38:54 -0000 1.4 +++ gnu/usr.bin/perl/Porting/make-rmg-checklist 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,10 @@ #!/usr/bin/perl + use strict; use warnings; + use Getopt::Long qw< :config no_ignore_case >; +use FindBin qw< $Bin >; sub pod { my $filename = shift; @@ -26,7 +29,7 @@ sub _help { print << "_END_HELP"; $0 --version VERSION -This script creates a release checklist as a simple HTML document. It accepts +This script creates a release checklist as a POD or HTML document. It accepts the following arguments: --version The version you are working on. This will infer the type @@ -140,7 +143,7 @@ if ($html) { my $type = _type_from_version($version); -chomp( my @pod_lines = @{ pod('Porting/release_managers_guide.pod') } ); +chomp( my @pod_lines = @{ pod("$Bin/release_managers_guide.pod") } ); my ( @items, $current_element, @leading_attrs ); my $skip_headers = qr/^=encoding/xms; Index: gnu/usr.bin/perl/Porting/makerel =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/makerel,v diff -u -p -a -u -p -r1.18 makerel --- gnu/usr.bin/perl/Porting/makerel 14 May 2024 19:38:54 -0000 1.18 +++ gnu/usr.bin/perl/Porting/makerel 22 Jan 2025 00:37:42 -0000 @@ -224,6 +224,8 @@ system("chmod +x @exe") == 0 or die "system: $!"; # MANIFEST may be resorted, so needs to be writable +# This list of files is parsed from this source code +# by t/porting/makerel.t my @writables = qw( feature.h lib/feature.pm @@ -241,7 +243,6 @@ my @writables = qw( mg_vtable.h dist/Devel-PPPort/module2.c dist/Devel-PPPort/module3.c - cpan/autodie/t/touch_me reentr.c reentr.h regcharclass.h @@ -252,7 +253,6 @@ my @writables = qw( win32/Makefile win32/config_H.gc win32/config_H.vc - uconfig.h ); my $out = `chmod u+w @writables 2>&1`; Index: gnu/usr.bin/perl/Porting/perldelta_template.pod =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/perldelta_template.pod,v diff -u -p -a -u -p -r1.14 perldelta_template.pod --- gnu/usr.bin/perl/Porting/perldelta_template.pod 14 May 2024 19:38:54 -0000 1.14 +++ gnu/usr.bin/perl/Porting/perldelta_template.pod 22 Jan 2025 00:37:42 -0000 @@ -58,7 +58,7 @@ future release, and will at that time ne Distributions on CPAN which require these modules will need to list them as prerequisites. -The core versions of these modules will now issue C<"deprecated">-category +The core versions of these modules will now issue C-category warnings to alert you to this fact. To silence these deprecation warnings, install the modules in question from CPAN. @@ -96,7 +96,7 @@ XXX =head1 Modules and Pragmata XXX All changes to installed files in F, F, F and F -go here. If Module::CoreList is updated, generate an initial draft of the +go here. If L is updated, generate an initial draft of the following sections using F. A paragraph summary for important changes should then be added by hand. In an ideal world, dual-life modules would have a F file that could be cribbed. @@ -115,7 +115,7 @@ release manager will have to investigate =item * -XXX Remove this section if Porting/corelist-perldelta.pl did not add any content here. +XXX Remove this section if F did not add any content here. =back @@ -137,7 +137,7 @@ XXX If there was something important to =item * -XXX Remove this section if Porting/corelist-perldelta.pl did not add any content here. +XXX Remove this section if F did not add any content here. =back @@ -187,8 +187,8 @@ include any changes in L that =head2 New Diagnostics -XXX Newly added diagnostic messages go under here, separated into New Errors -and New Warnings +XXX Newly added diagnostic messages go under here, separated into L +and L =head3 New Errors @@ -357,7 +357,7 @@ XXX XXX Important bug fixes in the core language are summarized here. Bug fixes in files in F and F are best summarized in L. -Include references to GitHub issues and PRs as: [GH #12345] and the release +XXX Include references to GitHub issues and PRs as: [GH #12345] and the release manager will later use a regex to expand these into links. [ List each fix as an =item entry ] @@ -393,7 +393,7 @@ XXX =item * XXX Add anything here that we forgot to add, or were mistaken about, in -the perldelta of a previous release. +the F of a previous release. =back @@ -406,13 +406,13 @@ died, add a short obituary here. XXX Generate this with: - perl Porting/acknowledgements.pl v5.37.12..HEAD + perl Porting/acknowledgements.pl v5.40.0..HEAD =head1 Reporting Bugs If you find what you think is a bug, you might check the perl bug database at L. There may also be information at -L, the Perl Home Page. +L, the Perl Home Page. If you believe you have an unreported bug, please open an issue at L. Be sure to trim your bug down to a Index: gnu/usr.bin/perl/Porting/pod_lib.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/pod_lib.pl,v diff -u -p -a -u -p -r1.6 pod_lib.pl --- gnu/usr.bin/perl/Porting/pod_lib.pl 15 Feb 2023 01:36:14 -0000 1.6 +++ gnu/usr.bin/perl/Porting/pod_lib.pl 22 Jan 2025 00:37:42 -0000 @@ -394,7 +394,6 @@ sub pods_to_install { my %state = ( # Don't copy these top level READMEs ignore => { - micro => 1, # vms => 1, }, ); Index: gnu/usr.bin/perl/Porting/pumpkin.pod =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/pumpkin.pod,v diff -u -p -a -u -p -r1.33 pumpkin.pod --- gnu/usr.bin/perl/Porting/pumpkin.pod 14 May 2024 19:39:39 -0000 1.33 +++ gnu/usr.bin/perl/Porting/pumpkin.pod 22 Jan 2025 00:37:42 -0000 @@ -109,7 +109,7 @@ to know I what you decide. =head2 Why is it called the patch pumpkin? -Chip Salzenberg gets credit for that, with a nod to his cow orker, +Chip Salzenberg gets credit for that, with a nod to his coworker, David Croy. We had passed around various names (baton, token, hot potato) but none caught on. Then, Chip asked: @@ -272,7 +272,7 @@ should be updated?)] We should never release a main version without testing it as a subversion first. -=head2 Test popular applications and modules. +=head2 Test popular applications and modules We should never release a main version without testing whether or not it breaks various popular modules and applications. A partial list of Index: gnu/usr.bin/perl/Porting/release_announcement_template.txt =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/release_announcement_template.txt,v diff -u -p -a -u -p -r1.7 release_announcement_template.txt --- gnu/usr.bin/perl/Porting/release_announcement_template.txt 14 May 2024 19:38:54 -0000 1.7 +++ gnu/usr.bin/perl/Porting/release_announcement_template.txt 22 Jan 2025 00:37:42 -0000 @@ -2,8 +2,8 @@ -- [ATTRIBUTION] -We are [SYNONYM FOR 'pleased'] to announce version [VERSION.SUBVERSION], -the [N-TH] development release of version [VERSION] of Perl 5. +We are [SYNONYM FOR 'pleased'] to announce version 5.[VERSION.SUBVERSION], +the [N-TH] development release of version 5.[VERSION] of Perl. You will soon be able to download Perl 5.[VERSION.SUBVERSION] from your favorite CPAN mirror or find it at: @@ -18,11 +18,11 @@ SHA256 digests for this release are: You can find a full list of changes in the file "perldelta.pod" located in the "pod" directory inside the release and on the web at -https://metacpan.org/pod/release/[AUTHOR]/perl-5.[VERSION.SUBVERSION]/pod/perldelta.pod +https://metacpan.org/release/[AUTHOR]/perl-5.[VERSION.SUBVERSION]/view/pod/perldelta.pod [ACKNOWLEDGEMENTS SECTION FROM PERLDELTA] -We expect to release version [NEXT BLEAD VERSION.SUBVERSION] on [FUTURE DATE]. -The next major stable release of Perl should appear in the first half of 2023. +We expect to release version 5.[NEXT BLEAD VERSION.SUBVERSION] on [FUTURE DATE]. +The next major stable release of Perl should appear in the first half of 2024. [YOUR SALUTATION HERE] Index: gnu/usr.bin/perl/Porting/release_managers_guide.pod =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/release_managers_guide.pod,v diff -u -p -a -u -p -r1.12 release_managers_guide.pod --- gnu/usr.bin/perl/Porting/release_managers_guide.pod 14 May 2024 19:38:54 -0000 1.12 +++ gnu/usr.bin/perl/Porting/release_managers_guide.pod 22 Jan 2025 00:37:42 -0000 @@ -159,7 +159,7 @@ release. You will need to have a GitHub and contact the Steering Council with your username to get membership in the L<< Perl-Releasers|https://github.com/orgs/Perl/teams/perl-releasers >> team. -=head3 web-based file share +=head3 Web-based file share You will need to be able to share tarballs with #p5p members for pre-release testing, and you may wish to upload to PAUSE via URL. @@ -197,7 +197,7 @@ The work of building a release candidate release candidate. Some of the following steps should be done regularly, but all I be done in the run up to a release. -=head3 dual-life CPAN module synchronisation +=head3 Dual-life CPAN module synchronisation To see which core distro versions differ from the current CPAN versions: @@ -257,9 +257,12 @@ F, as well as ch In most cases, once a new version of a distribution shipped with core has been uploaded to CPAN, the core version thereof can be synchronized automatically -with the program F. (But see the comments at the -beginning of that program. In particular, it has not yet been exercised on -Windows as much as it has on Unix-like platforms.) +with the program F. For example: + + perl Porting/sync-with-cpan Archive::Tar + +(But see the comments at the beginning of that program. In particular, it has +not yet been exercised on Windows as much as it has on Unix-like platforms.) If, however, F does not provide good results, follow the steps below. @@ -368,7 +371,7 @@ This comes down to: no - note it in perldelta as a significant bugfix (also, try to inform the module's author) -=head3 monitor smoke tests for failures +=head3 Monitor smoke tests for failures Similarly, monitor the smoking of core tests, and try to fix. See L, L @@ -379,13 +382,12 @@ the raw reports. Similarly, monitor the smoking of perl for compiler warnings, and try to fix. -Additionally both L and -L smokers run +Additionally L smokers run automatically. =for checklist skip BLEAD-POINT -=head3 monitor CPAN testers for failures +=head3 Monitor CPAN testers for failures For any release except a BLEAD-POINT: Examine the relevant analysis report(s) at L to see how the @@ -397,17 +399,60 @@ colon-delimited versions to use for comp L -=head3 update perldelta +=head3 Check POD errors + +F is a porting test that will fail if it finds new +problems in pods. However, it can be taught to ignore problems, and +sometimes people do so for problems that really should be fixed before +release. To see what it is ignoring, run + + ./perl -Ilib t/porting/podcheck.t --counts + +Any problems listed as pedantic aren't worth your time investigating. +These have a C at the beginning of the text, or are for the too-long +verbatim lines. + +But other warnings could be. In particular, a broken link can well +mean that someone clicking on the pod in a web page will get a 404. + +To find out more about any real problems, capture the output from + + ./perl -Ilib t/porting/podcheck.t --show-all + +and grep for those real problems. (It can take a minute or so to run.) + +If you decide any should be fixed, after that gets done, run + + ./perl -Ilib t/porting/podcheck.t + +to make sure those fixes were successful, and follow the directions in +the output about regenerating the data base. + +=for checklist skip BLEAD-FINAL BLEAD-POINT RC + +=head3 Update perlgov + +When doing a MAINT release, check that perlgov lists the I +Perl Steering Council and Core Team members, in case they have changed +since the corresponding stable release has been shipped. + +=head3 Update perldelta Get perldelta in a mostly finished state. +It is usual to send a call out to the Perl5-Porters mailing list a few days +ahead of the release to ask for recent committers to add their own notes +relating to their recent work. Getting other people to write it ahead of +time can save you from having to work out the details during the actual +release process. + Read F, and try to make sure that every section it lists is, if necessary, populated and complete. Copy edit the whole document. You won't be able to automatically fill in the "Updated Modules" section until -after Module::CoreList is updated (as described below in -L<"update Module::CoreList">). +after L is updated (as described below in +L). =head3 Bump the version number @@ -435,7 +480,7 @@ Use git status and git diff to select ch Be particularly careful with F, which contains a mixture of C<5.10.0>-type strings, some of which need bumping on every release, and some of which need to be left unchanged. -See below in L<"update INSTALL"> for more details. +See below in L for more details. For the first RC release leading up to a BLEAD-FINAL release, update the description of which releases are now "officially" supported in @@ -450,14 +495,7 @@ release and this is something you would When releasing a MAINT perl version, the C constants C be changed as we aim to guarantee binary compatibility in maint branches. -After editing, regenerate uconfig.h (this must be run on a system with a -/bin/sh available): - - $ perl regen/uconfig_h.pl - -This might not cause any new changes. - -You may also need to regen opcodes: +After editing, you may need to regen opcodes: $ ./perl -Ilib regen/opcode.pl @@ -484,17 +522,17 @@ see if they look similar. See commit f7 previous version bump. When the version number is bumped, you should also update Module::CoreList -(as described below in L<"update Module::CoreList">) to reflect the new +(as described below in L) to reflect the new version number. -=head3 update INSTALL +=head3 Update INSTALL Review and update INSTALL to account for the change in version number. INSTALL for a BLEAD-POINT release should already contain the expected version. -The lines in F about "is not binary compatible with" may require a -correct choice of earlier version to declare incompatibility with. These are -in the "Changes and Incompatibilities" and "Coexistence with earlier versions -of perl 5" sections. +For MAINT releases, the lines in F about "is not binary compatible +with" may require a correct choice of earlier version to declare +incompatibility with. These are in the "Changes and Incompatibilities" and +"Coexistence with earlier versions of perl 5" sections. Be particularly careful with the section "Upgrading from 5.X.Y or earlier". The "X.Y" needs to be changed to the most recent version that we are @@ -509,7 +547,7 @@ release (so for 5.15.3 this would be 5.1 followed instructions, this should have already been done after the last blead release, so you may find nothing to do here. -=head3 update AUTHORS +=head3 Update AUTHORS The AUTHORS file can be updated by running F. This shouldn't really be necessary anymore, and in theory nothing should @@ -556,18 +594,18 @@ C<-Dusethreads> If you have multiple compilers on your machine, you might also consider compiling with C<-Dcc=$other_compiler>. -You can also consider pushing the repo to GitHub where Travis CI is enabled +You can also consider pushing the repo to GitHub where GitHub Actions is enabled which would smoke different flavors of Perl for you. -=head3 update perlport +=head3 Update perlport L has a section currently named I that indicates which platforms are known to build in the current release. If necessary update the list and the indicated version number. -=head3 check a readonly build +=head3 Check a readonly build -Even before other prep work, follow the steps in L and test +Even before other prep work, follow the steps in L and test it locally. Because a perl source tarballs sets many files read-only, it could test differently than tests run from the repository. After you're sure permissions aren't a problem, delete the generated directory and tarballs. @@ -578,13 +616,13 @@ permissions aren't a problem, delete the This section describes the actions required to make a release that are performed near to, or on the actual release day. -=head3 re-check earlier actions +=head3 Re-check earlier actions Review all the actions in the previous section, -L<"Building a release - advance actions"> to ensure they are all done and +L to ensure they are all done and up-to-date. -=head3 create a release branch +=head3 Create a release branch For BLEAD-POINT releases, making a release from a release branch avoids the need to freeze blead during the release. This is less important for @@ -593,7 +631,7 @@ those cases. Create the branch by runnin git checkout -b release-5.X.Y -=head3 build a clean perl +=head3 Build a clean perl Make sure you have a gitwise-clean perl directory (no modified files, unpushed commits etc): @@ -611,7 +649,7 @@ For each Perl release since the previous for modules that have identical version numbers but different contents by running: - $ ./perl -Ilib Porting/cmpVERSION.pl --tag=v5.X.Y + $ ./perl -Ilib Porting/cmpVERSION.pl --tag=v5.LAST (This is done automatically by F for the previous release of the current branch, but not for any releases from other branches.) @@ -619,7 +657,7 @@ release of the current branch, but not f Any modules that fail will need a version bump, plus a nudge to the upstream maintainer for 'cpan' upstream modules. -=head3 update Module::CoreList +=head3 Update Module::CoreList =head4 Bump Module::CoreList* $VERSIONs @@ -648,7 +686,7 @@ F with module version data for the new release. +=head4 Update C with module version data for the new release Note that if this is a MAINT release, you should run the following actions from the maint branch, but commit the C changes in @@ -711,14 +749,18 @@ action from the last commit.) Add a perldelta entry for the new Module::CoreList version. You only need to do this if you want to add notes about the changes included with this version of Module::CoreList. Otherwise, its version bump -will be automatically filled in below in L. +will be automatically filled in below in L. =for checklist skip RC =head4 Update C<%Module::CoreList::released> For any release except an RC: Update this version's entry in the C<%released> -hash with today's date. +hash within dist/Module-Corelist/lib/Module/Corelist.pm with today's date. + +(BLEAD-POINT releases that happen on the expected date may not have to make +any changes to this file at this point. If the release happens not on the +scheduled day, the date may require manually changing.) =head4 Commit Module::CoreList changes @@ -736,15 +778,15 @@ cherry-pick it back). Build and test to get the changes into the currently built lib directory and to ensure all tests are passing. -=head3 finalize perldelta +=head3 Finalize perldelta Finalize the perldelta. In particular, fill in the Acknowledgements section, which can be generated with something like: $ perl Porting/acknowledgements.pl v5.LAST..HEAD -Fill in the "New/Updated Modules" sections now that Module::CoreList is -updated: +For non-MAINT releases, fill in the "New/Updated Modules" sections now +that Module::CoreList is updated: $ ./perl -Ilib Porting/corelist-perldelta.pl \ --mode=update pod/perldelta.pod @@ -757,6 +799,10 @@ For a MAINT release use something like t Ideally, also fill in a summary of the major changes to each module for which an entry has been added by F. +You should add pod links for GitHub issue references thusly: + + $ perl -gpi -e 's{\b(?:GH|github)\s*#(\d+)}{L}ig' pod/perldelta.pod + Re-read the perldelta to try to find any embarrassing typos and thinkos; remove any C or C flags; update the "Known Problems" section with any serious issues for which fixes are not going to happen now; and @@ -772,15 +818,11 @@ formatting, e.g. $ ./perl -Ilib ext/Pod-Html/bin/pod2html pod/perldelta.pod > \ ~/perldelta.html -You should add pod links for GitHub issue references thusly: - - $ perl -p -i -e'BEGIN{undef $/}; s{(GH\s+#)(\d+)}{L<$1$2|https://github.com/Perl/perl5/issues/$2>}mg' pod/perldelta.pod - If you make changes, be sure to commit them. =for checklist skip BLEAD-POINT MAINT RC -=head3 remove stale perldeltas +=head3 Remove stale perldeltas For the first RC release that is ONLY for a BLEAD-FINAL, the perldeltas from the BLEAD-POINT releases since the previous BLEAD-FINAL should have @@ -796,7 +838,7 @@ For example, for RC0 of 5.16.0: =for checklist skip BLEAD-FINAL BLEAD-POINT -=head3 add recent perldeltas +=head3 Add recent perldeltas For the first RC for a MAINT release, copy in any recent perldeltas from blead that have been added since the last release on this branch. This @@ -807,7 +849,7 @@ perldeltas from recent 5.10.x, 5.12.x et $ git add ... -=head3 update and commit perldelta files +=head3 Update and commit perldelta files If you have added or removed any perldelta files via the previous two steps, then edit F to add/remove them from its table of @@ -825,14 +867,14 @@ Then build a clean perl and do a full te Once all tests pass, commit your changes. -=head3 final check of perldelta placeholders +=head3 Final check of perldelta placeholders Check for any 'XXX' leftover section in the perldelta. Either fill them or remove these sections appropriately. $ git grep XX pod/perldelta.pod -=head3 build a clean perl +=head3 Build a clean perl If you skipped the previous step (adding/removing perldeltas), again, make sure you have a gitwise-clean perl directory (no modified files, @@ -847,7 +889,7 @@ then configure and build perl so that yo =for checklist skip BLEAD-FINAL BLEAD-POINT -=head3 synchronise from blead's perlhist.pod +=head3 Synchronise from blead's perlhist.pod For the first RC for a MAINT release, copy in the latest F from blead; this will include details of newer @@ -862,7 +904,7 @@ branch: $ git checkout -p origin/blead pod/perlhist.pod $ git commit -m 'Sync perlhist from blead' pod/perlhist.pod -=head3 update perlhist.pod +=head3 Update perlhist.pod Add an entry to F with the release date, e.g.: @@ -882,7 +924,7 @@ Be sure to commit your changes: =for checklist skip BLEAD-POINT -=head3 update patchlevel.h +=head3 Update patchlevel.h I @@ -900,7 +942,7 @@ Be sure to commit your change: $ git commit -m 'Bump version to RCnnn' patchlevel.h -=head3 run makemeta to update META files +=head3 Run makemeta to update META files $ ./perl -Ilib Porting/makemeta @@ -909,7 +951,7 @@ Be sure to commit any changes (if applic $ git status # any changes? $ git commit -m 'Update META files' META.* -=head3 build, test and check a fresh perl +=head3 Build, test and check a fresh perl Build perl, then make sure it passes its own test suite, and installs: @@ -936,7 +978,7 @@ and C<< deadbeef >> commit of that tag. Then delete the temporary installation. -=head3 create the release tag +=head3 Create the release tag Create the I tag identifying this release (e.g.): @@ -958,7 +1000,7 @@ The output must look similar to the foll Tagger: Jesse Vincent Date: Fri Oct 2 16:29:56 2009 -0400 -=head3 build the tarball +=head3 Build the tarball Before you run the following, you might want to install 7-Zip (the C package under Debian or the C port on MacPorts) or @@ -1005,7 +1047,7 @@ Finally, clean up the temporary director $ rm -rf ../perl-x.y.z-RC1 -=head3 test the tarball +=head3 Test the tarball Once you have a tarball it's time to test the tarball (not the repository). @@ -1132,7 +1174,7 @@ the "Locally applied patches" section. =for checklist skip BLEAD-POINT -=head3 monitor smokes +=head3 Monitor smokes XXX This is probably irrelevant if working on a release branch, though MAINT or RC might want to push a smoke branch and wait. @@ -1150,7 +1192,7 @@ releases, but for I release to plead with people on IRC to test stuff on their platforms, fire away, and then hope for the best. -=head3 upload to PAUSE +=head3 Upload to PAUSE Once smoking is okay, upload it to PAUSE. This is the point of no return. If anything goes wrong after this point, you will need to re-prepare @@ -1193,7 +1235,7 @@ which may be faster. =for checklist skip RC BLEAD-POINT -=head3 wait for indexing +=head3 Wait for indexing I @@ -1204,7 +1246,7 @@ This is considered normal. =for checklist skip BLEAD-POINT -=head3 disarm patchlevel.h +=head3 Disarm patchlevel.h I @@ -1221,7 +1263,7 @@ Be sure to commit your change: $ git commit -m 'Disarm RCnnn bump' patchlevel.h -=head3 announce to p5p +=head3 Announce to p5p Mail perl5-porters@perl.org to announce your new release, with a quote you prepared earlier. Get the SHA256 digests from the PAUSE email responses. @@ -1233,7 +1275,7 @@ Send a carbon copy to C and commit it. You can include the customary link to the release announcement even before your message reaches the web-visible archives by looking for the X-List-Archive header in your message after receiving it back via perl5-porters. -=head3 blog about your epigraph +=head3 Blog about your epigraph If you have a blog, please consider writing an entry in your blog explaining why you chose that particular quote for your epigraph. -=head3 update the link to the latest perl on perlweb +=head3 Update the link to the latest perl on perlweb Submit a pull request to L. For a dev release, update the link in F. For a stable @@ -1294,7 +1336,7 @@ to CPAN. =for checklist skip RC -=head3 new perldelta +=head3 New perldelta I @@ -1340,7 +1382,7 @@ previous version bump. =for checklist skip MAINT RC -=head3 bump version +=head3 Bump version I @@ -1357,13 +1399,13 @@ marker); e.g. Run F to propagate the changes to F. -Then follow the section L<"Bump the version number"> to bump the version +Then follow the section L to bump the version in the remaining files and test and commit. If this was a BLEAD-POINT release, then just follow the section -L<"Bump the version number">. +L. -After bumping the version, follow the section L<"update INSTALL"> to +After bumping the version, follow the section L to ensure all version number references are correct. (Note: The version is NOT bumped immediately after a MAINT release in order @@ -1378,7 +1420,7 @@ reports to arise. (The opposite problem introduced later -- shouldn't arise for MAINT releases since they should, in theory, only contain bug fixes but never regressions.)) -=head3 clean build and test +=head3 Clean build and test Run a clean build and test to make sure nothing obvious is broken. This is very important, as commands run after this point must be run using the perl @@ -1415,7 +1457,7 @@ update its exceptions database. =back -=head3 push commits +=head3 Push commits Finally, push any commits done above. @@ -1423,7 +1465,7 @@ Finally, push any commits done above. =for checklist skip BLEAD-POINT MAINT RC -=head3 create maint branch +=head3 Create maint branch I @@ -1439,7 +1481,7 @@ Assuming you're using git 1.7.x or newer =for checklist skip BLEAD-POINT MAINT RC -=head3 make the maint branch available in the APC +=head3 Make the maint branch available in the APC Clone the new branch into /srv/gitcommon/branches on camel so the APC will receive its changes. @@ -1454,7 +1496,7 @@ XXX Who are the sysadmins? Contact info =for checklist skip BLEAD-POINT RC -=head3 copy perldelta.pod to blead +=head3 Copy perldelta.pod to blead I @@ -1482,7 +1524,7 @@ Finally, commit and push: =for checklist skip BLEAD-POINT -=head3 copy perlhist.pod entries to blead +=head3 Copy perlhist.pod entries to blead Make sure any recent F entries are copied to F on blead. e.g. @@ -1500,7 +1542,7 @@ Thanks for releasing perl! =for checklist skip BLEAD-FINAL MAINT RC -=head3 update Module::CoreList +=head3 Update Module::CoreList I @@ -1568,7 +1610,7 @@ Commit and push your changes. =back -=head3 check tarball availability +=head3 Check tarball availability Check various website entries to make sure the that tarball has appeared and is properly indexed: @@ -1605,7 +1647,7 @@ It should be visible at a URL like C with any fixes or information that @@ -1628,7 +1670,7 @@ be considered. =head1 SOURCE Based on -L, +L, plus a whole bunch of other sources, including private correspondence. =cut Index: gnu/usr.bin/perl/Porting/release_schedule.pod =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/release_schedule.pod,v diff -u -p -a -u -p -r1.11 release_schedule.pod --- gnu/usr.bin/perl/Porting/release_schedule.pod 23 Dec 2023 21:02:20 -0000 1.11 +++ gnu/usr.bin/perl/Porting/release_schedule.pod 22 Jan 2025 00:37:42 -0000 @@ -11,15 +11,20 @@ release schedules for the next, current of Perl. Dates with two or more question marks will only be releases if deemed necessary by the Steering Council. -=head2 Perl 5.36 +=head2 Perl 5.42 - 2022-05-27 5.36.0 ✓ Ricardo Signes - 2023-04-23 5.36.1 ✓ Steve Hay + 2025-??-?? 5.42.0 -=head2 Perl 5.34 +=head2 Perl 5.40 - 2021-05-20 5.34.0 ✓ Sawyer X - 2022-03-13 5.34.1 ✓ Steve Hay + 2024-06-09 5.40.0 ✓ Graham Knop + 2025-01-18 5.40.1 Steve Hay + +=head2 Perl 5.38 + + 2023-07-01 5.38.0 ✓ Ricardo Signes + 2023-11-29 5.38.2 ✓ Paul Evans + 2025-01-18 5.38.3 Steve Hay =head1 DEVELOPMENT RELEASE SCHEDULE @@ -35,23 +40,23 @@ When shipping a release, you should incl the next four releases. If a stable version of Perl is released, you should reset the version numbers to the next blead series. -=head2 Perl 5.37 +=head2 Perl 5.41 - 2022-05-27 5.37.0 ✓ Ricardo Signes - 2022-06-20 5.37.1 ✓ Matthew Horsfall - 2022-07-20 5.37.2 ✓ Nicolas R - 2022-08-20 5.37.3 ✓ Neil Bowers - 2022-09-20 5.37.4 ✓ Karen Etheridge - 2022-10-20 5.37.5 ✓ Todd Rinaldo - 2022-11-20 5.37.6 ✓ Max Maischein - 2022-12-20 5.37.7 ✓ Richard Leach - 2023-01-20 5.37.8 ✓ Renée Bäcker - 2023-02-20 5.37.9 ✓ Karen Etheridge Contentious changes freeze - 2023-03-20 5.37.10 ✓ Yves Orton User-visible changes to + 2024-06-10 5.41.0 ✓ Graham K (tag only) + 2024-06-20 5.41.1 ✓ Graham K + 2024-07-20 5.41.2 ✓ Karen Etheridge + 2024-08-20 5.41.3 ✓ Philippe Bruhat + 2024-09-20 5.41.4 ✓ Thibault Duponchelle + 2024-10-20 5.41.5 ✓ Richard Leach + 2024-11-20 5.41.6 ✓ Thibault Duponchelle + 2024-12-20 5.41.7 ✓ Max Maischein + 2025-01-20 5.41.8 Steve Hay + 2025-02-20 5.41.9 Paul Evans Contentious changes freeze + 2025-03-20 5.41.10 ? User-visible changes to correctly functioning programs freeze - 2023-04-20 5.37.11 ✓ Steve Hay Full code freeze - 2023-05-20 5.38.0 Ricardo Signes New perl! + 2025-04-20 5.41.11 ? Full program freeze + 2025-05-20 5.42.0 ? New perl! =head1 VICTIMS @@ -76,6 +81,7 @@ consent of the Steering Council.) Matt Trout Matthew Horsfall Max Maischein + Paul Evans Peter Martini Philippe Bruhat Ricardo Signes Index: gnu/usr.bin/perl/Porting/sync-with-cpan =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/sync-with-cpan,v diff -u -p -a -u -p -r1.7 sync-with-cpan --- gnu/usr.bin/perl/Porting/sync-with-cpan 14 May 2024 19:38:54 -0000 1.7 +++ gnu/usr.bin/perl/Porting/sync-with-cpan 22 Jan 2025 00:37:42 -0000 @@ -116,7 +116,11 @@ Do things we normally would refuse to do =item C<--tarball> -Use a predownloaded tarball and not one from CPAN. +Use a predownloaded tarball and not one from CPAN. Example: + + perl Porting/sync-with-cpan Text-Tabs+Wrap \ + --tarball /tmp/Text-Tabs+Wrap-2024.001.tar.gz \ + --yes =item C<--version> @@ -209,7 +213,7 @@ my $package_file = "$tmpdir/$package"; # my $type_dir = "cpan"; my @problematic = ( - # no current entries as of perl-5.38.2 (Jun 2023) + # no current entries as of perl-5.40.1 (Jan 2025) ); @@ -380,7 +384,7 @@ pause_for_input("\n"); # in the way, or other issues that might come up if the user bails out of the sync # script and then runs it again. my $clean_out= `git clean -dfx $type_dir`; # use backticks to hide the output -system git => 'checkout -f', +system git => 'checkout', '-f', $type_dir, 'MANIFEST', 'Porting/Maintainers.pl'; # let the user see the output @@ -406,9 +410,10 @@ chdir "$type_dir"; my $pkg_dir = $files[0]; $pkg_dir =~ s!.*/!!; -my $tail_pat = qr/(?:\.tar\.gz|\.tgz|\.zip)\z/; +my $tail_pat = qr/\.(?:tar\.(?:g?z|bz2|Z)|zip|tgz|tbz)/; +my $version_pat = qr/-v?([0-9._]+(?:-TRIAL[0-9]*)?)$tail_pat\z/; -my ($old_version) = $distribution =~ /-([0-9._]+(?:-TRIAL[0-9]*)?)$tail_pat/; +my ($old_version) = $distribution =~ $version_pat; if (!$old_version) { die "WTF: failed to parse old version from '$distribution'\n"; @@ -453,7 +458,7 @@ if (defined $tarball) { die "Tarball $tarball does not exist\n" if !-e $tarball; die "Tarball $tarball is not a plain file\n" if !-f _; $new_file = $tarball; - $new_version = $version // ($new_file =~ /-([0-9._]+(?:-TRIAL[0-9]*)?)$tail_pat/) [0]; + $new_version = $version // ($new_file =~ $version_pat) [0]; die "Blead and that tarball both have version $new_version of $module\n" if $new_version eq $old_version; } @@ -500,7 +505,7 @@ system git => 'clean', '-dfxq', $pkg_dir say "Unpacking $new_file"; Archive::Tar->extract_archive( $new_file ); -(my $new_dir = basename($new_file)) =~ s/$tail_pat//; +(my $new_dir = basename($new_file)) =~ s/$tail_pat\z//; # ensure 'make' will update all files my $t= time; for my $file (find_type_f($new_dir)) { Index: gnu/usr.bin/perl/Porting/todo.pod =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/todo.pod,v diff -u -p -a -u -p -r1.13 todo.pod --- gnu/usr.bin/perl/Porting/todo.pod 14 May 2024 19:38:54 -0000 1.13 +++ gnu/usr.bin/perl/Porting/todo.pod 22 Jan 2025 00:37:42 -0000 @@ -1183,7 +1183,7 @@ L function (in sv.c:Perl_dirp_dup). Fix Perl_sv_dup, et al so that threads can return objects. - -=head1 Tasks for microperl - - -[ Each and every one of these may be obsolete, but they were listed - in the old Todo.micro file] - -=head2 do away with fork/exec/wait? - -(system, popen should be enough?) - -=head2 some of the uconfig.sh really needs to be probed (using cc) in buildtime: - -(uConfigure? :-) native datatype widths and endianness come to mind - Index: gnu/usr.bin/perl/Porting/updateAUTHORS.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/updateAUTHORS.pl,v diff -u -p -a -u -p -r1.1.1.2 updateAUTHORS.pl --- gnu/usr.bin/perl/Porting/updateAUTHORS.pl 14 May 2024 19:36:38 -0000 1.1.1.2 +++ gnu/usr.bin/perl/Porting/updateAUTHORS.pl 22 Jan 2025 00:37:42 -0000 @@ -22,6 +22,7 @@ my @OPTSPEC= qw( man authors_file=s mailmap_file=s + source_dir=s validate|tap verbose+ @@ -362,7 +363,7 @@ To resolve this you can perform one or m Make sure the conributor is ok with the decisions you make before you merge. - 3. You are already an author but your git config is broken or + 4. You are already an author but your git config is broken or different from what you expect, or you are a new author but you havent configured your git details properly, in which case you can use something like the following commands: @@ -374,7 +375,7 @@ To resolve this you can perform one or m do. If you are not then you should perform option 2 or 4 as well afterwards. - 4. You do not want to be listed in AUTHORS: commit the changes, + 5. You do not want to be listed in AUTHORS: commit the changes, including any untracked unignored files, and then run Porting/updateAUTHORS.pl --exclude Index: gnu/usr.bin/perl/Porting/updateAUTHORS.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/updateAUTHORS.pm,v diff -u -p -a -u -p -r1.1.1.1 updateAUTHORS.pm --- gnu/usr.bin/perl/Porting/updateAUTHORS.pm 14 May 2024 19:36:38 -0000 1.1.1.1 +++ gnu/usr.bin/perl/Porting/updateAUTHORS.pm 22 Jan 2025 00:37:42 -0000 @@ -6,6 +6,7 @@ use Encode qw(encode_utf8 decode_utf8 de use Digest::SHA qw(sha256_base64); use Text::Wrap qw(wrap); use Unicode::Collate; +use Cwd qw(getcwd); use feature 'fc'; $Text::Wrap::columns= 80; @@ -213,8 +214,27 @@ sub read_commit_log { my $last_commit_info; my $cmd= qq(git -c diff.algorithm=myers log @args); $cmd =~ s/'/"/g if $^O =~ /Win/; + + # If we run under -Dmksymlinks git might not have access to the + # .mailmap unless we chdir into the git working tree. Ideally we + # would prefer to pass in the location of the .mailmap file to git, + # but it doesn't support that as a command line option. We can't + # just chdir into the source_dir as that would break scalar PerlIO + # layer operations which are loaded late. So we chdir before we + # read the git log, and then chdir right back after we have opened + # the handle. Note there is related code in read_mailmap_file(), + # if you change this also change that. + + my $cwd = getcwd(); + if ($self->{source_dir}) { + chdir $self->{source_dir}; + } + open my $fh, "-|", $cmd or die "Failed to open git log pipe: $!"; + + chdir $cwd; + binmode($fh); while (defined(my $line= <$fh>)) { chomp $line; @@ -472,8 +492,23 @@ sub read_mailmap_file { my ($self)= @_; my $mailmap_file= $self->{mailmap_file}; + # If we run under -Dmksymlinks the .mailmap might actually be + # located in a different directory than the one we are running from. + # We could munge the $mailmap_file to be relative to source_dir if + # it was not already an absolute path, but that would require + # loading File::Spec, and doing THAT wouldn't help us when we read + # the git log (see the related code for doing that in the + # read_commit_log() sub), so we use the same strategy of remembering + # our current working directory, chdir'ing into the source dir, + # opening the file, and then chdir'ing back in both cases. + + my $cwd = getcwd(); + if ($self->{source_dir}) { + chdir $self->{source_dir}; + } open my $in, "<", $mailmap_file or die "Failed to read '$mailmap_file': $!"; + chdir $cwd; my %mailmap_hash; my @mailmap_preamble; my $line_num= 0; @@ -536,6 +571,7 @@ sub update_mailmap_file { my $new_raw_text= ""; { + my $cwd = getcwd(); open my $out, ">", \$new_raw_text or die "Failed to open scalar buffer for write: $!"; foreach Index: gnu/usr.bin/perl/Porting/valgrindpp.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/Porting/valgrindpp.pl,v diff -u -p -a -u -p -r1.1.1.2 valgrindpp.pl --- gnu/usr.bin/perl/Porting/valgrindpp.pl 25 Mar 2013 20:09:31 -0000 1.1.1.2 +++ gnu/usr.bin/perl/Porting/valgrindpp.pl 22 Jan 2025 00:37:42 -0000 @@ -1,4 +1,5 @@ #!/usr/bin/perl + use IO::File (); use File::Find qw(find); use Text::Wrap qw(wrap); @@ -49,7 +50,7 @@ my $hidden = do { local $"='|'; $opt{hid # (do it early, as it may fail) my $fh = \*STDOUT; if (exists $opt{'output-file'}) { - $fh = new IO::File ">$opt{'output-file'}" + $fh = IO::File->new($opt{'output-file'}, 'w') or die "$0: cannot open $opt{'output-file'} ($!)\n"; } @@ -197,7 +198,7 @@ sub filter { # Get all the valgrind output lines my @l = do { - my $fh = new IO::File $_ or die "$0: cannot open $_ ($!)\n"; + my $fh = IO::File->new($_, 'r') or die "$0: cannot open $_ ($!)\n"; # Process outputs can interrupt each other, so sort by pid first my %pid; local $_; while (<$fh>) { @@ -269,7 +270,7 @@ __END__ =head1 NAME -valgrindpp.pl - A post processor for make test.valgrind +valgrindpp.pl - A post processor for C =head1 SYNOPSIS @@ -281,7 +282,7 @@ valgrindpp.pl [B<--dir>=I] [B<--fra =head1 DESCRIPTION B is a post processor for I<.valgrind> files -created during I. It collects all these +created during C. It collects all these files, extracts most of the information and produces a significantly shorter summary of all detected memory access errors and memory leaks. Index: gnu/usr.bin/perl/cpan/Archive-Tar/lib/Archive/Tar.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Archive-Tar/lib/Archive/Tar.pm,v diff -u -p -a -u -p -r1.8 Tar.pm --- gnu/usr.bin/perl/cpan/Archive-Tar/lib/Archive/Tar.pm 15 Feb 2023 01:36:15 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Archive-Tar/lib/Archive/Tar.pm 22 Jan 2025 00:37:42 -0000 @@ -1,8 +1,8 @@ ### the gnu tar specification: -### http://www.gnu.org/software/tar/manual/tar.html +### https://www.gnu.org/software/tar/manual/tar.html ### ### and the pax format spec, which tar derives from: -### http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html +### https://www.opengroup.org/onlinepubs/007904975/utilities/pax.html package Archive::Tar; require 5.005_03; @@ -24,6 +24,7 @@ use strict; use vars qw[$DEBUG $error $VERSION $WARN $FOLLOW_SYMLINK $CHOWN $CHMOD $DO_NOT_USE_PREFIX $HAS_PERLIO $HAS_IO_STRING $SAME_PERMISSIONS $INSECURE_EXTRACT_MODE $ZERO_PAD_NUMBERS @ISA @EXPORT $RESOLVE_SYMLINK + $EXTRACT_BLOCK_SIZE ]; @ISA = qw[Exporter]; @@ -31,7 +32,7 @@ use vars qw[$DEBUG $error $VERSION $WARN $DEBUG = 0; $WARN = 1; $FOLLOW_SYMLINK = 0; -$VERSION = "2.40"; +$VERSION = "3.02_001"; $CHOWN = 1; $CHMOD = 1; $SAME_PERMISSIONS = $> == 0 ? 1 : 0; @@ -39,6 +40,7 @@ $DO_NOT_USE_PREFIX = 0; $INSECURE_EXTRACT_MODE = 0; $ZERO_PAD_NUMBERS = 0; $RESOLVE_SYMLINK = $ENV{'PERL5_AT_RESOLVE_SYMLINK'} || 'speed'; +$EXTRACT_BLOCK_SIZE = 1024 * 1024 * 1024; BEGIN { use Config; @@ -423,7 +425,7 @@ sub _read_tar { } ### ignore labels: - ### http://www.gnu.org/software/tar/manual/html_chapter/Media.html#SEC159 + ### https://www.gnu.org/software/tar/manual/html_chapter/Media.html#SEC159 next if $entry->is_label; if( length $entry->type and ($entry->is_file || $entry->is_longlink) ) { @@ -894,10 +896,18 @@ sub _extract_file { if( $entry->size ) { binmode $fh; - syswrite $fh, $entry->data or ( - $self->_error( qq[Could not write data to '$full'] ), - return - ); + my $offset = 0; + my $content = $entry->get_content_by_ref(); + while ($offset < $entry->size) { + my $written + = syswrite $fh, $$content, $EXTRACT_BLOCK_SIZE, $offset; + if (defined $written) { + $offset += $written; + } else { + $self->_error( qq[Could not write data to '$full': $!] ); + return; + } + } } close $fh or ( @@ -2143,25 +2153,39 @@ numbers. Added for compatibility with C< =head2 Tuning the way RESOLVE_SYMLINK will works - You can tune the behaviour by setting the $Archive::Tar::RESOLVE_SYMLINK variable, - or $ENV{PERL5_AT_RESOLVE_SYMLINK} before loading the module Archive::Tar. +You can tune the behaviour by setting the $Archive::Tar::RESOLVE_SYMLINK variable, +or $ENV{PERL5_AT_RESOLVE_SYMLINK} before loading the module Archive::Tar. + +Values can be one of the following: + +=over 4 + +=item none - Values can be one of the following: +Disable this mechanism and failed as it was in previous version (<1.88) - none - Disable this mechanism and failed as it was in previous version (<1.88) +=item speed (default) - speed (default) - If you prefer speed - this will read again the whole archive using read() so all entries - will be available +If you prefer speed +this will read again the whole archive using read() so all entries +will be available - memory - If you prefer memory +=item memory - Limitation +If you prefer memory - It won't work for terminal, pipe or sockets or every non seekable source. +=back + +Limitation: It won't work for terminal, pipe or sockets or every non seekable +source. + +=head2 $Archive::Tar::EXTRACT_BLOCK_SIZE + +This variable holds an integer with the block size that should be used when +writing files during extraction. It defaults to 1 GiB. Please note that this +cannot be arbitrarily large since some operating systems limit the number of +bytes that can be written in one call to C, so if this is too large, +extraction may fail with an error. =cut @@ -2396,22 +2420,11 @@ to an uploaded file, which might be a co =item The GNU tar specification -C +L =item The PAX format specification -The specification which tar derives from; C< http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html> - -=item A comparison of GNU and POSIX tar standards; C - -=item GNU tar intends to switch to POSIX compatibility - -GNU Tar authors have expressed their intention to become completely -POSIX-compatible; C - -=item A Comparison between various tar implementations - -Lists known issues and incompatibilities; C +The specification which tar derives from; L =back Index: gnu/usr.bin/perl/cpan/Archive-Tar/lib/Archive/Tar/Constant.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Archive-Tar/lib/Archive/Tar/Constant.pm,v diff -u -p -a -u -p -r1.7 Constant.pm --- gnu/usr.bin/perl/cpan/Archive-Tar/lib/Archive/Tar/Constant.pm 15 Feb 2023 01:36:15 -0000 1.7 +++ gnu/usr.bin/perl/cpan/Archive-Tar/lib/Archive/Tar/Constant.pm 22 Jan 2025 00:37:42 -0000 @@ -8,7 +8,7 @@ use vars qw[$VERSION @ISA @EXPORT]; BEGIN { require Exporter; - $VERSION = '2.40'; + $VERSION = '3.02_001'; @ISA = qw[Exporter]; require Time::Local if $^O eq "MacOS"; Index: gnu/usr.bin/perl/cpan/Archive-Tar/lib/Archive/Tar/File.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Archive-Tar/lib/Archive/Tar/File.pm,v diff -u -p -a -u -p -r1.7 File.pm --- gnu/usr.bin/perl/cpan/Archive-Tar/lib/Archive/Tar/File.pm 15 Feb 2023 01:36:15 -0000 1.7 +++ gnu/usr.bin/perl/cpan/Archive-Tar/lib/Archive/Tar/File.pm 22 Jan 2025 00:37:42 -0000 @@ -11,7 +11,7 @@ use Archive::Tar::Constant; use vars qw[@ISA $VERSION]; #@ISA = qw[Archive::Tar]; -$VERSION = '2.40'; +$VERSION = '3.02_001'; ### set value to 1 to oct() it during the unpack ### @@ -71,7 +71,7 @@ Archive::Tar::File - a subclass for in-m =head1 DESCRIPTION -Archive::Tar::Files provides a neat little object layer for in-memory +Archive::Tar::File provides a neat little object layer for in-memory extracted files. It's mostly used internally in Archive::Tar to tidy up the code, but there's no reason users shouldn't use this API as well. @@ -486,7 +486,9 @@ sub full_path { return $self->name unless defined $self->prefix and length $self->prefix; ### or otherwise, catfile'd - return File::Spec::Unix->catfile( $self->prefix, $self->name ); + my $path = File::Spec::Unix->catfile( $self->prefix, $self->name ); + $path .= "/" if $self->name =~ m{/$}; # Re-add trailing slash if necessary, as catfile() strips them off. + return $path; } @@ -601,7 +603,7 @@ sub rename { return 1; } -=head2 $bool = $file->chmod $mode) +=head2 $bool = $file->chmod( $mode ) Change mode of $file to $mode. The mode can be a string or a number which is interpreted as octal whether or not a leading 0 is given. Index: gnu/usr.bin/perl/cpan/Archive-Tar/t/02_methods.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Archive-Tar/t/02_methods.t,v diff -u -p -a -u -p -r1.1.1.4 02_methods.t --- gnu/usr.bin/perl/cpan/Archive-Tar/t/02_methods.t 15 Feb 2023 01:32:35 -0000 1.1.1.4 +++ gnu/usr.bin/perl/cpan/Archive-Tar/t/02_methods.t 22 Jan 2025 00:37:42 -0000 @@ -570,6 +570,34 @@ SKIP: { ### } +### extract tests with different $EXTRACT_BLOCK_SIZE values ### +SKIP: { ### pesky warnings + skip $ebcdic_skip_msg, 431 if ord "A" != 65; + + skip('no IO::String', 431) if !$Archive::Tar::HAS_PERLIO && + !$Archive::Tar::HAS_PERLIO && + !$Archive::Tar::HAS_IO_STRING && + !$Archive::Tar::HAS_IO_STRING; + + my $tar = $Class->new; + ok( $tar->read( $TAR_FILE ), "Read in '$TAR_FILE'" ); + + for my $aref ( [$tar, \@EXPECT_NORMAL], + [$TARBIN, \@EXPECTBIN], + [$TARX, \@EXPECTX] + ) { + my($obj, $struct) = @$aref; + + for my $block_size ((1, BLOCK, 1024 * 1024, 2**31 - 4096, 2**31 - 1)) { + local $Archive::Tar::EXTRACT_BLOCK_SIZE = $block_size; + + ok( $obj->extract, " Extracted with 'extract'" ); + check_tar_extract( $obj, $struct ); + } + } +} + + ### clear tests ### SKIP: { ### pesky warnings skip $ebcdic_skip_msg, 3 if ord "A" != 65; Index: gnu/usr.bin/perl/cpan/Archive-Tar/t/04_resolved_issues.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Archive-Tar/t/04_resolved_issues.t,v diff -u -p -a -u -p -r1.1.1.5 04_resolved_issues.t --- gnu/usr.bin/perl/cpan/Archive-Tar/t/04_resolved_issues.t 15 Feb 2023 01:32:35 -0000 1.1.1.5 +++ gnu/usr.bin/perl/cpan/Archive-Tar/t/04_resolved_issues.t 22 Jan 2025 00:37:42 -0000 @@ -200,6 +200,7 @@ SKIP: { ### bug #78030 ### tests for symlinks with relative paths ### seen on MSWin32 +if ($^O ne 'msys') # symlink tests fail on Windows/msys2 { ok( 1, "Testing bug 78030" ); my $archname = 'tmp-symlink.tar.gz'; { #build archive Index: gnu/usr.bin/perl/cpan/Archive-Tar/t/09_roundtrip.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Archive-Tar/t/09_roundtrip.t,v diff -u -p -a -u -p -r1.1.1.3 09_roundtrip.t --- gnu/usr.bin/perl/cpan/Archive-Tar/t/09_roundtrip.t 15 Feb 2023 01:32:35 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/Archive-Tar/t/09_roundtrip.t 22 Jan 2025 00:37:42 -0000 @@ -53,6 +53,7 @@ push @file_only_archives, [qw( src short my @file_and_directory_archives = ( [qw( src long bar.tar )], + [qw( src long prefix-directory-concat.tar )], [qw( src linktest linktest_with_dir.tar )], ); push @file_and_directory_archives, [qw( src long foo.tgz )] Index: gnu/usr.bin/perl/cpan/Archive-Tar/t/90_symlink.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Archive-Tar/t/90_symlink.t diff -N gnu/usr.bin/perl/cpan/Archive-Tar/t/90_symlink.t --- gnu/usr.bin/perl/cpan/Archive-Tar/t/90_symlink.t 25 Mar 2013 20:06:44 -0000 1.1.1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,55 +0,0 @@ -BEGIN { chdir 't' if -d 't' } - -use lib '../lib'; - -use strict; -use File::Spec; -use File::Path; -use Test::More; - -### developer tests mostly, so enable them with an extra argument -plan skip_all => "Skipping tests on this platform" unless @ARGV; -plan 'no_plan'; - -my $Class = 'Archive::Tar'; -my $Dir = File::Spec->catdir( qw[src linktest] ); -my %Map = ( - File::Spec->catfile( $Dir, "linktest_with_dir.tar" ) => [ - [ 0, qr/SECURE EXTRACT MODE/ ], - [ 1, qr/^$/ ] - ], - File::Spec->catfile( $Dir, "linktest_missing_dir.tar" ) => [ - [ 0, qr/SECURE EXTRACT MODE/ ], - [ 0, qr/File exists/ ], - ], -); - -use_ok( $Class ); - -{ while( my($file, $aref) = each %Map ) { - - for my $mode ( 0, 1 ) { - my $expect = $aref->[$mode]->[0]; - my $regex = $aref->[$mode]->[1]; - - my $tar = $Class->new( $file ); - ok( $tar, "Object created from $file" ); - - ### damn warnings - local $Archive::Tar::INSECURE_EXTRACT_MODE = $mode; - local $Archive::Tar::INSECURE_EXTRACT_MODE = $mode; - - ok( 1, " Extracting with insecure mode: $mode" ); - - my $warning; - local $SIG{__WARN__} = sub { $warning .= "@_"; warn @_; }; - - my $rv = eval { $tar->extract } || 0; - ok( !$@, " No fatal error" ); - is( !!$rv, !!$expect, " RV as expected" ); - like( $warning, $regex, " Error matches $regex" ); - - rmtree( 'linktest' ); - } - } -} Index: gnu/usr.bin/perl/cpan/Archive-Tar/t/src/long/prefix-directory-concat.tar =================================================================== RCS file: gnu/usr.bin/perl/cpan/Archive-Tar/t/src/long/prefix-directory-concat.tar diff -N gnu/usr.bin/perl/cpan/Archive-Tar/t/src/long/prefix-directory-concat.tar --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Archive-Tar/t/src/long/prefix-directory-concat.tar 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,3 @@ +pax_global_header00006660000000000000000000000064130414626600014514gustar00rootroot0000000000000052 comment=2b8856503fe5141c398bf9316fcd8d2c0f56cd1c +directory-that-fits-into-the-tar-name-field-but-will-be-put-into-prefix-for-subdirectories-or-files/000077500000000000000000000000001304146266000340145ustar00rootroot00000000000000subdir/000077500000000000000000000000001304146266000352255ustar00rootroot00000000000000directory-that-fits-into-the-tar-name-field-but-will-be-put-into-prefix-for-subdirectories-or-filesfile000066400000000000000000000000041304146266000360610ustar00rootroot00000000000000directory-that-fits-into-the-tar-name-field-but-will-be-put-into-prefix-for-subdirectories-or-files/subdirhey + \ No newline at end of file Index: gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements.pm,v diff -u -p -a -u -p -r1.2 Requirements.pm --- gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements.pm 5 Feb 2017 00:31:55 -0000 1.2 +++ gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements.pm 22 Jan 2025 00:37:42 -0000 @@ -1,10 +1,12 @@ -use 5.006; # keep at v5.6 for CPAN.pm +use v5.10; use strict; use warnings; package CPAN::Meta::Requirements; # ABSTRACT: a set of version requirements for a CPAN dist -our $VERSION = '2.140'; +our $VERSION = '2.143'; + +use CPAN::Meta::Requirements::Range; #pod =head1 SYNOPSIS #pod @@ -24,7 +26,7 @@ our $VERSION = '2.140'; #pod #pod A CPAN::Meta::Requirements object models a set of version constraints like #pod those specified in the F or F files in CPAN distributions, -#pod and as defined by L; +#pod and as defined by L. #pod It can be built up by adding more and more constraints, and it will reduce them #pod to the simplest representation. #pod @@ -35,25 +37,6 @@ our $VERSION = '2.140'; use Carp (); -# To help ExtUtils::MakeMaker bootstrap CPAN::Meta::Requirements on perls -# before 5.10, we fall back to the EUMM bundled compatibility version module if -# that's the only thing available. This shouldn't ever happen in a normal CPAN -# install of CPAN::Meta::Requirements, as version.pm will be picked up from -# prereqs and be available at runtime. - -BEGIN { - eval "use version ()"; ## no critic - if ( my $err = $@ ) { - eval "use ExtUtils::MakeMaker::version" or die $err; ## no critic - } -} - -# Perl 5.10.0 didn't have "is_qv" in version.pm -*_is_qv = version->can('is_qv') ? sub { $_[0]->is_qv } : sub { exists $_[0]->{qv} }; - -# construct once, reuse many times -my $V0 = version->new(0); - #pod =method new #pod #pod my $req = CPAN::Meta::Requirements->new; @@ -83,82 +66,6 @@ sub new { return bless \%self => $class; } -# from version::vpp -sub _find_magic_vstring { - my $value = shift; - my $tvalue = ''; - require B; - my $sv = B::svref_2object(\$value); - my $magic = ref($sv) eq 'B::PVMG' ? $sv->MAGIC : undef; - while ( $magic ) { - if ( $magic->TYPE eq 'V' ) { - $tvalue = $magic->PTR; - $tvalue =~ s/^v?(.+)$/v$1/; - last; - } - else { - $magic = $magic->MOREMAGIC; - } - } - return $tvalue; -} - -# safe if given an unblessed reference -sub _isa_version { - UNIVERSAL::isa( $_[0], 'UNIVERSAL' ) && $_[0]->isa('version') -} - -sub _version_object { - my ($self, $module, $version) = @_; - - my ($vobj, $err); - - if (not defined $version or (!ref($version) && $version eq '0')) { - return $V0; - } - elsif ( ref($version) eq 'version' || ( ref($version) && _isa_version($version) ) ) { - $vobj = $version; - } - else { - # hack around version::vpp not handling <3 character vstring literals - if ( $INC{'version/vpp.pm'} || $INC{'ExtUtils/MakeMaker/version/vpp.pm'} ) { - my $magic = _find_magic_vstring( $version ); - $version = $magic if length $magic; - } - # pad to 3 characters if before 5.8.1 and appears to be a v-string - if ( $] < 5.008001 && $version !~ /\A[0-9]/ && substr($version,0,1) ne 'v' && length($version) < 3 ) { - $version .= "\0" x (3 - length($version)); - } - eval { - local $SIG{__WARN__} = sub { die "Invalid version: $_[0]" }; - # avoid specific segfault on some older version.pm versions - die "Invalid version: $version" if $version eq 'version'; - $vobj = version->new($version); - }; - if ( my $err = $@ ) { - my $hook = $self->{bad_version_hook}; - $vobj = eval { $hook->($version, $module) } - if ref $hook eq 'CODE'; - unless (eval { $vobj->isa("version") }) { - $err =~ s{ at .* line \d+.*$}{}; - die "Can't convert '$version': $err"; - } - } - } - - # ensure no leading '.' - if ( $vobj =~ m{\A\.} ) { - $vobj = version->new("0$vobj"); - } - - # ensure normal v-string form - if ( _is_qv($vobj) ) { - $vobj = version->new($vobj->normal); - } - - return $vobj; -} - #pod =method add_minimum #pod #pod $req->add_minimum( $module => $version ); @@ -219,8 +126,6 @@ BEGIN { my $code = sub { my ($self, $name, $version) = @_; - $version = $self->_version_object( $name, $version ); - $self->__modify_entry_for($name, $method, $version); return $self; @@ -240,20 +145,29 @@ sub add_minimum { # which preserves the user's choice of "0.00" as the requirement if (not defined $version or "$version" eq '0') { return $self if $self->__entry_for($name); - Carp::confess("can't add new requirements to finalized requirements") + Carp::croak("can't add new requirements to finalized requirements") if $self->is_finalized; $self->{requirements}{ $name } = - CPAN::Meta::Requirements::_Range::Range->with_minimum($V0, $name); + CPAN::Meta::Requirements::Range->with_minimum('0', $name); } else { - $version = $self->_version_object( $name, $version ); - $self->__modify_entry_for($name, 'with_minimum', $version); } return $self; } +#pod =method version_range_for_module +#pod +#pod $req->version_range_for_module( $another_req_object ); +#pod +#pod =cut + +sub version_range_for_module { + my ($self, $module) = @_; + return $self->{requirements}{$module}; +} + #pod =method add_requirements #pod #pod $req->add_requirements( $another_req_object ); @@ -270,11 +184,8 @@ sub add_requirements { my ($self, $req) = @_; for my $module ($req->required_modules) { - my $modifiers = $req->__entry_for($module)->as_modifiers; - for my $modifier (@$modifiers) { - my ($method, @args) = @$modifier; - $self->$method($module => @args); - }; + my $new_range = $req->version_range_for_module($module); + $self->__modify_entry_for($module, 'with_range', $new_range); } return $self; @@ -300,10 +211,8 @@ sub add_requirements { sub accepts_module { my ($self, $module, $version) = @_; - $version = $self->_version_object( $module, $version ); - return 1 unless my $range = $self->__entry_for($module); - return $range->_accepts($version); + return $range->accepts($version); } #pod =method clear_requirement @@ -321,7 +230,7 @@ sub clear_requirement { return $self unless $self->__entry_for($module); - Carp::confess("can't clear requirements on finalized requirements") + Carp::croak("can't clear requirements on finalized requirements") if $self->is_finalized; delete $self->{requirements}{ $module }; @@ -400,13 +309,13 @@ sub __modify_entry_for { my $fin = $self->is_finalized; my $old = $self->__entry_for($name); - Carp::confess("can't add new requirements to finalized requirements") + Carp::croak("can't add new requirements to finalized requirements") if $fin and not $old; - my $new = ($old || 'CPAN::Meta::Requirements::_Range::Range') - ->$method($version, $name); + my $new = ($old || 'CPAN::Meta::Requirements::Range') + ->$method($version, $name, $self->{bad_version_hook}); - Carp::confess("can't modify finalized requirements") + Carp::croak("can't modify finalized requirements") if $fin and $old->as_string ne $new->as_string; $self->{requirements}{ $name } = $new; @@ -423,7 +332,7 @@ sub is_simple { my ($self) = @_; for my $module ($self->required_modules) { # XXX: This is a complete hack, but also entirely correct. - return if $self->__entry_for($module)->as_string =~ /\s/; + return if not $self->__entry_for($module)->is_simple; } return 1; @@ -529,43 +438,10 @@ sub as_string_hash { #pod #pod =cut -my %methods_for_op = ( - '==' => [ qw(exact_version) ], - '!=' => [ qw(add_exclusion) ], - '>=' => [ qw(add_minimum) ], - '<=' => [ qw(add_maximum) ], - '>' => [ qw(add_minimum add_exclusion) ], - '<' => [ qw(add_maximum add_exclusion) ], -); - sub add_string_requirement { my ($self, $module, $req) = @_; - unless ( defined $req && length $req ) { - $req = 0; - $self->_blank_carp($module); - } - - my $magic = _find_magic_vstring( $req ); - if (length $magic) { - $self->add_minimum($module => $magic); - return; - } - - my @parts = split qr{\s*,\s*}, $req; - - for my $part (@parts) { - my ($op, $ver) = $part =~ m{\A\s*(==|>=|>|<=|<|!=)\s*(.*)\z}; - - if (! defined $op) { - $self->add_minimum($module => $part); - } else { - Carp::confess("illegal requirement string: $req") - unless my $methods = $methods_for_op{ $op }; - - $self->$_($module => $ver) for @$methods; - } - } + $self->__modify_entry_for($module, 'with_string_requirement', $req); } #pod =method from_string_hash @@ -582,11 +458,6 @@ sub add_string_requirement { #pod #pod =cut -sub _blank_carp { - my ($self, $module) = @_; - Carp::carp("Undefined requirement for $module treated as '0'"); -} - sub from_string_hash { my ($class, $hash, $options) = @_; @@ -594,267 +465,12 @@ sub from_string_hash { for my $module (keys %$hash) { my $req = $hash->{$module}; - unless ( defined $req && length $req ) { - $req = 0; - $class->_blank_carp($module); - } $self->add_string_requirement($module, $req); } return $self; } -############################################################## - -{ - package - CPAN::Meta::Requirements::_Range::Exact; - sub _new { bless { version => $_[1] } => $_[0] } - - sub _accepts { return $_[0]{version} == $_[1] } - - sub as_string { return "== $_[0]{version}" } - - sub as_struct { return [ [ '==', "$_[0]{version}" ] ] } - - sub as_modifiers { return [ [ exact_version => $_[0]{version} ] ] } - - sub _reject_requirements { - my ($self, $module, $error) = @_; - Carp::confess("illegal requirements for $module: $error") - } - - sub _clone { - (ref $_[0])->_new( version->new( $_[0]{version} ) ) - } - - sub with_exact_version { - my ($self, $version, $module) = @_; - $module = 'module' unless defined $module; - - return $self->_clone if $self->_accepts($version); - - $self->_reject_requirements( - $module, - "can't be exactly $version when exact requirement is already $self->{version}", - ); - } - - sub with_minimum { - my ($self, $minimum, $module) = @_; - $module = 'module' unless defined $module; - - return $self->_clone if $self->{version} >= $minimum; - $self->_reject_requirements( - $module, - "minimum $minimum exceeds exact specification $self->{version}", - ); - } - - sub with_maximum { - my ($self, $maximum, $module) = @_; - $module = 'module' unless defined $module; - - return $self->_clone if $self->{version} <= $maximum; - $self->_reject_requirements( - $module, - "maximum $maximum below exact specification $self->{version}", - ); - } - - sub with_exclusion { - my ($self, $exclusion, $module) = @_; - $module = 'module' unless defined $module; - - return $self->_clone unless $exclusion == $self->{version}; - $self->_reject_requirements( - $module, - "tried to exclude $exclusion, which is already exactly specified", - ); - } -} - -############################################################## - -{ - package - CPAN::Meta::Requirements::_Range::Range; - - sub _self { ref($_[0]) ? $_[0] : (bless { } => $_[0]) } - - sub _clone { - return (bless { } => $_[0]) unless ref $_[0]; - - my ($s) = @_; - my %guts = ( - (exists $s->{minimum} ? (minimum => version->new($s->{minimum})) : ()), - (exists $s->{maximum} ? (maximum => version->new($s->{maximum})) : ()), - - (exists $s->{exclusions} - ? (exclusions => [ map { version->new($_) } @{ $s->{exclusions} } ]) - : ()), - ); - - bless \%guts => ref($s); - } - - sub as_modifiers { - my ($self) = @_; - my @mods; - push @mods, [ add_minimum => $self->{minimum} ] if exists $self->{minimum}; - push @mods, [ add_maximum => $self->{maximum} ] if exists $self->{maximum}; - push @mods, map {; [ add_exclusion => $_ ] } @{$self->{exclusions} || []}; - return \@mods; - } - - sub as_struct { - my ($self) = @_; - - return 0 if ! keys %$self; - - my @exclusions = @{ $self->{exclusions} || [] }; - - my @parts; - - for my $tuple ( - [ qw( >= > minimum ) ], - [ qw( <= < maximum ) ], - ) { - my ($op, $e_op, $k) = @$tuple; - if (exists $self->{$k}) { - my @new_exclusions = grep { $_ != $self->{ $k } } @exclusions; - if (@new_exclusions == @exclusions) { - push @parts, [ $op, "$self->{ $k }" ]; - } else { - push @parts, [ $e_op, "$self->{ $k }" ]; - @exclusions = @new_exclusions; - } - } - } - - push @parts, map {; [ "!=", "$_" ] } @exclusions; - - return \@parts; - } - - sub as_string { - my ($self) = @_; - - my @parts = @{ $self->as_struct }; - - return $parts[0][1] if @parts == 1 and $parts[0][0] eq '>='; - - return join q{, }, map {; join q{ }, @$_ } @parts; - } - - sub _reject_requirements { - my ($self, $module, $error) = @_; - Carp::confess("illegal requirements for $module: $error") - } - - sub with_exact_version { - my ($self, $version, $module) = @_; - $module = 'module' unless defined $module; - $self = $self->_clone; - - unless ($self->_accepts($version)) { - $self->_reject_requirements( - $module, - "exact specification $version outside of range " . $self->as_string - ); - } - - return CPAN::Meta::Requirements::_Range::Exact->_new($version); - } - - sub _simplify { - my ($self, $module) = @_; - - if (defined $self->{minimum} and defined $self->{maximum}) { - if ($self->{minimum} == $self->{maximum}) { - if (grep { $_ == $self->{minimum} } @{ $self->{exclusions} || [] }) { - $self->_reject_requirements( - $module, - "minimum and maximum are both $self->{minimum}, which is excluded", - ); - } - - return CPAN::Meta::Requirements::_Range::Exact->_new($self->{minimum}) - } - - if ($self->{minimum} > $self->{maximum}) { - $self->_reject_requirements( - $module, - "minimum $self->{minimum} exceeds maximum $self->{maximum}", - ); - } - } - - # eliminate irrelevant exclusions - if ($self->{exclusions}) { - my %seen; - @{ $self->{exclusions} } = grep { - (! defined $self->{minimum} or $_ >= $self->{minimum}) - and - (! defined $self->{maximum} or $_ <= $self->{maximum}) - and - ! $seen{$_}++ - } @{ $self->{exclusions} }; - } - - return $self; - } - - sub with_minimum { - my ($self, $minimum, $module) = @_; - $module = 'module' unless defined $module; - $self = $self->_clone; - - if (defined (my $old_min = $self->{minimum})) { - $self->{minimum} = (sort { $b cmp $a } ($minimum, $old_min))[0]; - } else { - $self->{minimum} = $minimum; - } - - return $self->_simplify($module); - } - - sub with_maximum { - my ($self, $maximum, $module) = @_; - $module = 'module' unless defined $module; - $self = $self->_clone; - - if (defined (my $old_max = $self->{maximum})) { - $self->{maximum} = (sort { $a cmp $b } ($maximum, $old_max))[0]; - } else { - $self->{maximum} = $maximum; - } - - return $self->_simplify($module); - } - - sub with_exclusion { - my ($self, $exclusion, $module) = @_; - $module = 'module' unless defined $module; - $self = $self->_clone; - - push @{ $self->{exclusions} ||= [] }, $exclusion; - - return $self->_simplify($module); - } - - sub _accepts { - my ($self, $version) = @_; - - return if defined $self->{minimum} and $version < $self->{minimum}; - return if defined $self->{maximum} and $version > $self->{maximum}; - return if defined $self->{exclusions} - and grep { $version == $_ } @{ $self->{exclusions} }; - - return 1; - } -} - 1; # vim: ts=2 sts=2 sw=2 et: @@ -870,7 +486,7 @@ CPAN::Meta::Requirements - a set of vers =head1 VERSION -version 2.140 +version 2.143 =head1 SYNOPSIS @@ -890,7 +506,7 @@ version 2.140 A CPAN::Meta::Requirements object models a set of version constraints like those specified in the F or F files in CPAN distributions, -and as defined by L; +and as defined by L. It can be built up by adding more and more constraints, and it will reduce them to the simplest representation. @@ -966,6 +582,10 @@ version. No other version would be cons This method returns the requirements object. +=head2 version_range_for_module + + $req->version_range_for_module( $another_req_object ); + =head2 add_requirements $req->add_requirements( $another_req_object ); @@ -1127,7 +747,7 @@ add_string_requirement, a version can be you can supply a hash-reference of options, exactly as with the L method. -=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan +=for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT @@ -1162,7 +782,7 @@ Ricardo Signes =head1 CONTRIBUTORS -=for stopwords Ed J Karen Etheridge Leon Timmermans robario +=for stopwords Ed J Graham Knop Karen Etheridge Leon Timmermans Paul Howarth Ricardo Signes robario Tatsuhiko Miyagawa =over 4 @@ -1172,6 +792,10 @@ Ed J =item * +Graham Knop + +=item * + Karen Etheridge =item * @@ -1180,7 +804,23 @@ Leon Timmermans =item * +Paul Howarth + +=item * + +Ricardo Signes + +=item * + robario + +=item * + +Tatsuhiko Miyagawa + +=item * + +Tatsuhiko Miyagawa =back Index: gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements/Range.pm =================================================================== RCS file: gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements/Range.pm diff -N gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements/Range.pm --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/lib/CPAN/Meta/Requirements/Range.pm 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,776 @@ +use v5.10; +use strict; +use warnings; +package CPAN::Meta::Requirements::Range; +# ABSTRACT: a set of version requirements for a CPAN dist + +our $VERSION = '2.143'; + +use Carp (); + +#pod =head1 SYNOPSIS +#pod +#pod use CPAN::Meta::Requirements::Range; +#pod +#pod my $range = CPAN::Meta::Requirements::Range->with_minimum(1); +#pod +#pod $range = $range->with_maximum('v2.2'); +#pod +#pod my $stringified = $range->as_string; +#pod +#pod =head1 DESCRIPTION +#pod +#pod A CPAN::Meta::Requirements::Range object models a set of version constraints like +#pod those specified in the F or F files in CPAN distributions, +#pod and as defined by L; +#pod It can be built up by adding more and more constraints, and it will reduce them +#pod to the simplest representation. +#pod +#pod Logically impossible constraints will be identified immediately by thrown +#pod exceptions. +#pod +#pod =cut + +use Carp (); + +package + CPAN::Meta::Requirements::Range::_Base; + +# To help ExtUtils::MakeMaker bootstrap CPAN::Meta::Requirements on perls +# before 5.10, we fall back to the EUMM bundled compatibility version module if +# that's the only thing available. This shouldn't ever happen in a normal CPAN +# install of CPAN::Meta::Requirements, as version.pm will be picked up from +# prereqs and be available at runtime. + +BEGIN { + eval "use version ()"; ## no critic + if ( my $err = $@ ) { + eval "use ExtUtils::MakeMaker::version" or die $err; ## no critic + } +} + +# from version::vpp +sub _find_magic_vstring { + my $value = shift; + my $tvalue = ''; + require B; + my $sv = B::svref_2object(\$value); + my $magic = ref($sv) eq 'B::PVMG' ? $sv->MAGIC : undef; + while ( $magic ) { + if ( $magic->TYPE eq 'V' ) { + $tvalue = $magic->PTR; + $tvalue =~ s/^v?(.+)$/v$1/; + last; + } + else { + $magic = $magic->MOREMAGIC; + } + } + return $tvalue; +} + +# Perl 5.10.0 didn't have "is_qv" in version.pm +*_is_qv = version->can('is_qv') ? sub { $_[0]->is_qv } : sub { exists $_[0]->{qv} }; + +# construct once, reuse many times +my $V0 = version->new(0); + +# safe if given an unblessed reference +sub _isa_version { + UNIVERSAL::isa( $_[0], 'UNIVERSAL' ) && $_[0]->isa('version') +} + +sub _version_object { + my ($self, $version, $module, $bad_version_hook) = @_; + + my ($vobj, $err); + + if (not defined $version or (!ref($version) && $version eq '0')) { + return $V0; + } + elsif ( ref($version) eq 'version' || ( ref($version) && _isa_version($version) ) ) { + $vobj = $version; + } + else { + # hack around version::vpp not handling <3 character vstring literals + if ( $INC{'version/vpp.pm'} || $INC{'ExtUtils/MakeMaker/version/vpp.pm'} ) { + my $magic = _find_magic_vstring( $version ); + $version = $magic if length $magic; + } + # pad to 3 characters if before 5.8.1 and appears to be a v-string + if ( $] < 5.008001 && $version !~ /\A[0-9]/ && substr($version,0,1) ne 'v' && length($version) < 3 ) { + $version .= "\0" x (3 - length($version)); + } + eval { + local $SIG{__WARN__} = sub { die "Invalid version: $_[0]" }; + # avoid specific segfault on some older version.pm versions + die "Invalid version: $version" if $version eq 'version'; + $vobj = version->new($version); + }; + if ( my $err = $@ ) { + $vobj = eval { $bad_version_hook->($version, $module) } + if ref $bad_version_hook eq 'CODE'; + unless (eval { $vobj->isa("version") }) { + $err =~ s{ at .* line \d+.*$}{}; + die "Can't convert '$version': $err"; + } + } + } + + # ensure no leading '.' + if ( $vobj =~ m{\A\.} ) { + $vobj = version->new("0$vobj"); + } + + # ensure normal v-string form + if ( _is_qv($vobj) ) { + $vobj = version->new($vobj->normal); + } + + return $vobj; +} + +#pod =method with_string_requirement +#pod +#pod $req->with_string_requirement('>= 1.208, <= 2.206'); +#pod $req->with_string_requirement(v1.208); +#pod +#pod This method parses the passed in string and adds the appropriate requirement. +#pod A version can be a Perl "v-string". It understands version ranges as described +#pod in the L. For example: +#pod +#pod =over 4 +#pod +#pod =item 1.3 +#pod +#pod =item >= 1.3 +#pod +#pod =item <= 1.3 +#pod +#pod =item == 1.3 +#pod +#pod =item != 1.3 +#pod +#pod =item > 1.3 +#pod +#pod =item < 1.3 +#pod +#pod =item >= 1.3, != 1.5, <= 2.0 +#pod +#pod A version number without an operator is equivalent to specifying a minimum +#pod (C=>). Extra whitespace is allowed. +#pod +#pod =back +#pod +#pod =cut + +my %methods_for_op = ( + '==' => [ qw(with_exact_version) ], + '!=' => [ qw(with_exclusion) ], + '>=' => [ qw(with_minimum) ], + '<=' => [ qw(with_maximum) ], + '>' => [ qw(with_minimum with_exclusion) ], + '<' => [ qw(with_maximum with_exclusion) ], +); + +sub with_string_requirement { + my ($self, $req, $module, $bad_version_hook) = @_; + $module //= 'module'; + + unless ( defined $req && length $req ) { + $req = 0; + Carp::carp("Undefined requirement for $module treated as '0'"); + } + + my $magic = _find_magic_vstring( $req ); + if (length $magic) { + return $self->with_minimum($magic, $module, $bad_version_hook); + } + + my @parts = split qr{\s*,\s*}, $req; + + for my $part (@parts) { + my ($op, $ver) = $part =~ m{\A\s*(==|>=|>|<=|<|!=)\s*(.*)\z}; + + if (! defined $op) { + $self = $self->with_minimum($part, $module, $bad_version_hook); + } else { + Carp::croak("illegal requirement string: $req") + unless my $methods = $methods_for_op{ $op }; + + $self = $self->$_($ver, $module, $bad_version_hook) for @$methods; + } + } + + return $self; +} + +#pod =method with_range +#pod +#pod $range->with_range($other_range) +#pod +#pod This creates a new range object that is a merge two others. +#pod +#pod =cut + +sub with_range { + my ($self, $other, $module, $bad_version_hook) = @_; + for my $modifier($other->_as_modifiers) { + my ($method, $arg) = @$modifier; + $self = $self->$method($arg, $module, $bad_version_hook); + } + return $self; +} + +package CPAN::Meta::Requirements::Range; + +our @ISA = 'CPAN::Meta::Requirements::Range::_Base'; + +sub _clone { + return (bless { } => $_[0]) unless ref $_[0]; + + my ($s) = @_; + my %guts = ( + (exists $s->{minimum} ? (minimum => version->new($s->{minimum})) : ()), + (exists $s->{maximum} ? (maximum => version->new($s->{maximum})) : ()), + + (exists $s->{exclusions} + ? (exclusions => [ map { version->new($_) } @{ $s->{exclusions} } ]) + : ()), + ); + + bless \%guts => ref($s); +} + +#pod =method with_exact_version +#pod +#pod $range->with_exact_version( $version ); +#pod +#pod This sets the version required to I the given +#pod version. No other version would be considered acceptable. +#pod +#pod This method returns the version range object. +#pod +#pod =cut + +sub with_exact_version { + my ($self, $version, $module, $bad_version_hook) = @_; + $module //= 'module'; + $self = $self->_clone; + $version = $self->_version_object($version, $module, $bad_version_hook); + + unless ($self->accepts($version)) { + $self->_reject_requirements( + $module, + "exact specification $version outside of range " . $self->as_string + ); + } + + return CPAN::Meta::Requirements::Range::_Exact->_new($version); +} + +sub _simplify { + my ($self, $module) = @_; + + if (defined $self->{minimum} and defined $self->{maximum}) { + if ($self->{minimum} == $self->{maximum}) { + if (grep { $_ == $self->{minimum} } @{ $self->{exclusions} || [] }) { + $self->_reject_requirements( + $module, + "minimum and maximum are both $self->{minimum}, which is excluded", + ); + } + + return CPAN::Meta::Requirements::Range::_Exact->_new($self->{minimum}); + } + + if ($self->{minimum} > $self->{maximum}) { + $self->_reject_requirements( + $module, + "minimum $self->{minimum} exceeds maximum $self->{maximum}", + ); + } + } + + # eliminate irrelevant exclusions + if ($self->{exclusions}) { + my %seen; + @{ $self->{exclusions} } = grep { + (! defined $self->{minimum} or $_ >= $self->{minimum}) + and + (! defined $self->{maximum} or $_ <= $self->{maximum}) + and + ! $seen{$_}++ + } @{ $self->{exclusions} }; + } + + return $self; +} + +#pod =method with_minimum +#pod +#pod $range->with_minimum( $version ); +#pod +#pod This adds a new minimum version requirement. If the new requirement is +#pod redundant to the existing specification, this has no effect. +#pod +#pod Minimum requirements are inclusive. C<$version> is required, along with any +#pod greater version number. +#pod +#pod This method returns the version range object. +#pod +#pod =cut + +sub with_minimum { + my ($self, $minimum, $module, $bad_version_hook) = @_; + $module //= 'module'; + $self = $self->_clone; + $minimum = $self->_version_object( $minimum, $module, $bad_version_hook ); + + if (defined (my $old_min = $self->{minimum})) { + $self->{minimum} = (sort { $b cmp $a } ($minimum, $old_min))[0]; + } else { + $self->{minimum} = $minimum; + } + + return $self->_simplify($module); +} + +#pod =method with_maximum +#pod +#pod $range->with_maximum( $version ); +#pod +#pod This adds a new maximum version requirement. If the new requirement is +#pod redundant to the existing specification, this has no effect. +#pod +#pod Maximum requirements are inclusive. No version strictly greater than the given +#pod version is allowed. +#pod +#pod This method returns the version range object. +#pod +#pod =cut + +sub with_maximum { + my ($self, $maximum, $module, $bad_version_hook) = @_; + $module //= 'module'; + $self = $self->_clone; + $maximum = $self->_version_object( $maximum, $module, $bad_version_hook ); + + if (defined (my $old_max = $self->{maximum})) { + $self->{maximum} = (sort { $a cmp $b } ($maximum, $old_max))[0]; + } else { + $self->{maximum} = $maximum; + } + + return $self->_simplify($module); +} + +#pod =method with_exclusion +#pod +#pod $range->with_exclusion( $version ); +#pod +#pod This adds a new excluded version. For example, you might use these three +#pod method calls: +#pod +#pod $range->with_minimum( '1.00' ); +#pod $range->with_maximum( '1.82' ); +#pod +#pod $range->with_exclusion( '1.75' ); +#pod +#pod Any version between 1.00 and 1.82 inclusive would be acceptable, except for +#pod 1.75. +#pod +#pod This method returns the requirements object. +#pod +#pod =cut + +sub with_exclusion { + my ($self, $exclusion, $module, $bad_version_hook) = @_; + $module //= 'module'; + $self = $self->_clone; + $exclusion = $self->_version_object( $exclusion, $module, $bad_version_hook ); + + push @{ $self->{exclusions} ||= [] }, $exclusion; + + return $self->_simplify($module); +} + +sub _as_modifiers { + my ($self) = @_; + my @mods; + push @mods, [ with_minimum => $self->{minimum} ] if exists $self->{minimum}; + push @mods, [ with_maximum => $self->{maximum} ] if exists $self->{maximum}; + push @mods, map {; [ with_exclusion => $_ ] } @{$self->{exclusions} || []}; + return @mods; +} + +#pod =method as_struct +#pod +#pod $range->as_struct( $module ); +#pod +#pod This returns a data structure containing the version requirements. This should +#pod not be used for version checks (see L instead). +#pod +#pod =cut + +sub as_struct { + my ($self) = @_; + + return 0 if ! keys %$self; + + my @exclusions = @{ $self->{exclusions} || [] }; + + my @parts; + + for my $tuple ( + [ qw( >= > minimum ) ], + [ qw( <= < maximum ) ], + ) { + my ($op, $e_op, $k) = @$tuple; + if (exists $self->{$k}) { + my @new_exclusions = grep { $_ != $self->{ $k } } @exclusions; + if (@new_exclusions == @exclusions) { + push @parts, [ $op, "$self->{ $k }" ]; + } else { + push @parts, [ $e_op, "$self->{ $k }" ]; + @exclusions = @new_exclusions; + } + } + } + + push @parts, map {; [ "!=", "$_" ] } @exclusions; + + return \@parts; +} + +#pod =method as_string +#pod +#pod $range->as_string; +#pod +#pod This returns a string containing the version requirements in the format +#pod described in L. This should only be used for informational +#pod purposes such as error messages and should not be interpreted or used for +#pod comparison (see L instead). +#pod +#pod =cut + +sub as_string { + my ($self) = @_; + + my @parts = @{ $self->as_struct }; + + return $parts[0][1] if @parts == 1 and $parts[0][0] eq '>='; + + return join q{, }, map {; join q{ }, @$_ } @parts; +} + +sub _reject_requirements { + my ($self, $module, $error) = @_; + Carp::croak("illegal requirements for $module: $error") +} + +#pod =method accepts +#pod +#pod my $bool = $range->accepts($version); +#pod +#pod Given a version, this method returns true if the version specification +#pod accepts the provided version. In other words, given: +#pod +#pod '>= 1.00, < 2.00' +#pod +#pod We will accept 1.00 and 1.75 but not 0.50 or 2.00. +#pod +#pod =cut + +sub accepts { + my ($self, $version) = @_; + + return if defined $self->{minimum} and $version < $self->{minimum}; + return if defined $self->{maximum} and $version > $self->{maximum}; + return if defined $self->{exclusions} + and grep { $version == $_ } @{ $self->{exclusions} }; + + return 1; +} + +#pod =method is_simple +#pod +#pod This method returns true if and only if the range is an inclusive minimum +#pod -- that is, if their string expression is just the version number. +#pod +#pod =cut + +sub is_simple { + my ($self) = @_; + # XXX: This is a complete hack, but also entirely correct. + return if $self->as_string =~ /\s/; + + return 1; +} + +package + CPAN::Meta::Requirements::Range::_Exact; + +our @ISA = 'CPAN::Meta::Requirements::Range::_Base'; + +our $VERSION = '2.141'; + +BEGIN { + eval "use version ()"; ## no critic + if ( my $err = $@ ) { + eval "use ExtUtils::MakeMaker::version" or die $err; ## no critic + } +} + +sub _new { bless { version => $_[1] } => $_[0] } + +sub accepts { return $_[0]{version} == $_[1] } + +sub _reject_requirements { + my ($self, $module, $error) = @_; + Carp::croak("illegal requirements for $module: $error") +} + +sub _clone { + (ref $_[0])->_new( version->new( $_[0]{version} ) ) +} + +sub with_exact_version { + my ($self, $version, $module, $bad_version_hook) = @_; + $module //= 'module'; + $version = $self->_version_object($version, $module, $bad_version_hook); + + return $self->_clone if $self->accepts($version); + + $self->_reject_requirements( + $module, + "can't be exactly $version when exact requirement is already $self->{version}", + ); +} + +sub with_minimum { + my ($self, $minimum, $module, $bad_version_hook) = @_; + $module //= 'module'; + $minimum = $self->_version_object( $minimum, $module, $bad_version_hook ); + + return $self->_clone if $self->{version} >= $minimum; + $self->_reject_requirements( + $module, + "minimum $minimum exceeds exact specification $self->{version}", + ); +} + +sub with_maximum { + my ($self, $maximum, $module, $bad_version_hook) = @_; + $module //= 'module'; + $maximum = $self->_version_object( $maximum, $module, $bad_version_hook ); + + return $self->_clone if $self->{version} <= $maximum; + $self->_reject_requirements( + $module, + "maximum $maximum below exact specification $self->{version}", + ); +} + +sub with_exclusion { + my ($self, $exclusion, $module, $bad_version_hook) = @_; + $module //= 'module'; + $exclusion = $self->_version_object( $exclusion, $module, $bad_version_hook ); + + return $self->_clone unless $exclusion == $self->{version}; + $self->_reject_requirements( + $module, + "tried to exclude $exclusion, which is already exactly specified", + ); +} + +sub as_string { return "== $_[0]{version}" } + +sub as_struct { return [ [ '==', "$_[0]{version}" ] ] } + +sub _as_modifiers { return [ with_exact_version => $_[0]{version} ] } + + +1; + +# vim: ts=2 sts=2 sw=2 et: + +__END__ + +=pod + +=encoding UTF-8 + +=head1 NAME + +CPAN::Meta::Requirements::Range - a set of version requirements for a CPAN dist + +=head1 VERSION + +version 2.143 + +=head1 SYNOPSIS + + use CPAN::Meta::Requirements::Range; + + my $range = CPAN::Meta::Requirements::Range->with_minimum(1); + + $range = $range->with_maximum('v2.2'); + + my $stringified = $range->as_string; + +=head1 DESCRIPTION + +A CPAN::Meta::Requirements::Range object models a set of version constraints like +those specified in the F or F files in CPAN distributions, +and as defined by L; +It can be built up by adding more and more constraints, and it will reduce them +to the simplest representation. + +Logically impossible constraints will be identified immediately by thrown +exceptions. + +=head1 METHODS + +=head2 with_string_requirement + + $req->with_string_requirement('>= 1.208, <= 2.206'); + $req->with_string_requirement(v1.208); + +This method parses the passed in string and adds the appropriate requirement. +A version can be a Perl "v-string". It understands version ranges as described +in the L. For example: + +=over 4 + +=item 1.3 + +=item >= 1.3 + +=item <= 1.3 + +=item == 1.3 + +=item != 1.3 + +=item > 1.3 + +=item < 1.3 + +=item >= 1.3, != 1.5, <= 2.0 + +A version number without an operator is equivalent to specifying a minimum +(C=>). Extra whitespace is allowed. + +=back + +=head2 with_range + + $range->with_range($other_range) + +This creates a new range object that is a merge two others. + +=head2 with_exact_version + + $range->with_exact_version( $version ); + +This sets the version required to I the given +version. No other version would be considered acceptable. + +This method returns the version range object. + +=head2 with_minimum + + $range->with_minimum( $version ); + +This adds a new minimum version requirement. If the new requirement is +redundant to the existing specification, this has no effect. + +Minimum requirements are inclusive. C<$version> is required, along with any +greater version number. + +This method returns the version range object. + +=head2 with_maximum + + $range->with_maximum( $version ); + +This adds a new maximum version requirement. If the new requirement is +redundant to the existing specification, this has no effect. + +Maximum requirements are inclusive. No version strictly greater than the given +version is allowed. + +This method returns the version range object. + +=head2 with_exclusion + + $range->with_exclusion( $version ); + +This adds a new excluded version. For example, you might use these three +method calls: + + $range->with_minimum( '1.00' ); + $range->with_maximum( '1.82' ); + + $range->with_exclusion( '1.75' ); + +Any version between 1.00 and 1.82 inclusive would be acceptable, except for +1.75. + +This method returns the requirements object. + +=head2 as_struct + + $range->as_struct( $module ); + +This returns a data structure containing the version requirements. This should +not be used for version checks (see L instead). + +=head2 as_string + + $range->as_string; + +This returns a string containing the version requirements in the format +described in L. This should only be used for informational +purposes such as error messages and should not be interpreted or used for +comparison (see L instead). + +=head2 accepts + + my $bool = $range->accepts($version); + +Given a version, this method returns true if the version specification +accepts the provided version. In other words, given: + + '>= 1.00, < 2.00' + +We will accept 1.00 and 1.75 but not 0.50 or 2.00. + +=head2 is_simple + +This method returns true if and only if the range is an inclusive minimum +-- that is, if their string expression is just the version number. + +=head1 AUTHORS + +=over 4 + +=item * + +David Golden + +=item * + +Ricardo Signes + +=back + +=head1 COPYRIGHT AND LICENSE + +This software is copyright (c) 2010 by David Golden and Ricardo Signes. + +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. + +=cut Index: gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/accepts.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/accepts.t,v diff -u -p -a -u -p -r1.2 accepts.t --- gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/accepts.t 5 Feb 2017 00:31:55 -0000 1.2 +++ gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/accepts.t 22 Jan 2025 00:37:42 -0000 @@ -36,4 +36,35 @@ use Test::More 0.88; ok(! $req->accepts_module(Foo => 1), "need !1, got 1"); } +{ + my $req = CPAN::Meta::Requirements::Range->with_minimum(1); + + ok( $req->accepts(1), "need 1, got 1"); + ok(! $req->accepts(0), "need 0, got 1"); +} + +{ + my $req = CPAN::Meta::Requirements::Range->with_minimum(0); + + ok( $req->accepts(1), "need 0, got 1"); + ok( $req->accepts(undef), "need 0, got undef"); + ok( $req->accepts("v0"), "need 0, got 'v0'"); + ok( $req->accepts(v1.2.3), "need 0, got v1.2.3"); + ok( $req->accepts("v1.2.3"), "need 0, got 'v1.2.3'"); +} + +{ + my $req = CPAN::Meta::Requirements::Range->with_maximum(1); + + ok( $req->accepts(1), "need <=1, got 1"); + ok(! $req->accepts(2), "need <=1, got 2"); +} + +{ + my $req = CPAN::Meta::Requirements::Range->with_exclusion(1); + + ok( $req->accepts(0), "need !1, got 0"); + ok(! $req->accepts(1), "need !1, got 1"); +} + done_testing; Index: gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/from-hash.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/from-hash.t,v diff -u -p -a -u -p -r1.2 from-hash.t --- gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/from-hash.t 5 Feb 2017 00:31:55 -0000 1.2 +++ gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/from-hash.t 22 Jan 2025 00:37:42 -0000 @@ -2,6 +2,7 @@ use strict; use warnings; use CPAN::Meta::Requirements; +use CPAN::Meta::Requirements::Range; use Test::More 0.88; @@ -19,6 +20,11 @@ sub dies_ok (&@) { } } +for my $string (10, '>= 2, <= 9, != 7') { + my $range = CPAN::Meta::Requirements::Range->with_string_requirement($string); + is ($range->as_string, $string, "'$string' roundtrips"); +} + { my $string_hash = { Left => 10, @@ -47,6 +53,17 @@ SKIP: { dies_ok { CPAN::Meta::Requirements->from_string_hash($string_hash) } qr/Can't convert/, "we die when we can't understand a version spec"; +} + +{ + my $warning; + local $SIG{__WARN__} = sub { $warning = join("\n",@_) }; + + my $range = CPAN::Meta::Requirements::Range->with_string_requirement(undef); + like ($warning, qr/Undefined requirement.*treated as '0'/, "undef requirement warns"); + $range->with_string_requirement(''); + like ($warning, qr/Undefined requirement.*treated as '0'/, "'' requirement warns"); + } { Index: gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/merge.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/merge.t,v diff -u -p -a -u -p -r1.2 merge.t --- gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/merge.t 5 Feb 2017 00:31:55 -0000 1.2 +++ gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/merge.t 22 Jan 2025 00:37:42 -0000 @@ -2,6 +2,7 @@ use strict; use warnings; use CPAN::Meta::Requirements; +use CPAN::Meta::Requirements::Range; use Test::More 0.88; @@ -18,6 +19,14 @@ sub dies_ok (&@) { like($@, $qr, $comment); } } + +{ + my $range = CPAN::Meta::Requirements::Range->with_minimum(2); + $range = $range->with_maximum(9); + $range = $range->with_exclusion(7); + is($range->as_string, '>= 2, <= 9, != 7'); +} + { my $req_1 = CPAN::Meta::Requirements->new; Index: gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/strings.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/strings.t,v diff -u -p -a -u -p -r1.1 strings.t --- gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/strings.t 5 Feb 2017 00:31:56 -0000 1.1 +++ gnu/usr.bin/perl/cpan/CPAN-Meta-Requirements/t/strings.t 22 Jan 2025 00:37:42 -0000 @@ -18,6 +18,54 @@ sub dies_ok (&@) { use CPAN::Meta::Requirements; + +my $base = 'CPAN::Meta::Requirements::Range'; + +# Test == +my $range = $base->with_string_requirement('== 1.3'); +ok($range->accepts('1.3'), 'exact version (==)'); +ok(!$range->accepts('1.2'), 'lower version (==)'); +ok(!$range->accepts('1.4'), 'higher version (==)'); + +# Test != +$range = $base->with_string_requirement('!= 1.3'); +ok(!$range->accepts('1.3'), 'exact version (!=)'); +ok($range->accepts('1.2'), 'lower version (!=)'); +ok($range->accepts('1.4'), 'higher version (!=)'); + +# Test >= +$range = $base->with_string_requirement('>= 1.3'); +ok($range->accepts('1.3'), 'exact version (>=)'); +ok(!$range->accepts('1.2'), 'lower version (>=)'); +ok($range->accepts('1.4'), 'higher version (>=)'); + +# Test <= +$range = $range = $base->with_string_requirement('<= 1.3'); +ok($range->accepts('1.3'), 'exact version (<=)'); +ok($range->accepts('1.2'), 'lower version (<=)'); +ok(!$range->accepts('1.4'), 'higher version (<=)'); + +# Test "" +$range = $base->with_string_requirement('1.3'); +ok($range->accepts('1.3'), 'exact version ("")'); +ok(!$range->accepts('1.2'), 'lower version ("")'); +ok($range->accepts('1.4'), 'higher version ("")'); + +# Test multiple requirements +$range = $base->with_string_requirement('>= 1.3, <= 2.0, != 1.6'); +ok($range->accepts('1.5'), 'middle version (>=, <=, !)'); +ok(!$range->accepts('1.2'), 'lower version (>=, <=, !)'); +ok(!$range->accepts('2.1'), 'higher version (>=, <=, !)'); +ok(!$range->accepts('1.6'), 'excluded version (>=, <=, !)'); + +# Test multiple requirements with implicit minimum +$range = $base->with_string_requirement('0.90, != 0.91'); +ok(!$range->accepts('0.88'), 'lower version ("", !)'); +ok($range->accepts('0.90'), 'exact version ("", !)'); +ok($range->accepts('0.901'), 'middle version ("", !)'); +ok(!$range->accepts('0.91'), 'excluded version ("", !)'); +ok($range->accepts('0.92'), 'higher version ("", !)'); + my $req = CPAN::Meta::Requirements->new; # Test == @@ -45,10 +93,10 @@ ok($req->accepts_module('Foo::Graz' => ' ok(!$req->accepts_module('Foo::Graz' => '1.4'), 'higher version (<=)'); # Test "" -$req->add_string_requirement('Foo::Blurb', '>= 1.3'); -ok($req->accepts_module('Foo::Blurb' => '1.3'), 'exact version (>=)'); -ok(!$req->accepts_module('Foo::Blurb' => '1.2'), 'lower version (>=)'); -ok($req->accepts_module('Foo::Blurb' => '1.4'), 'higher version (>=)'); +$req->add_string_requirement('Foo::Blurb', '1.3'); +ok($req->accepts_module('Foo::Blurb' => '1.3'), 'exact version ("")'); +ok(!$req->accepts_module('Foo::Blurb' => '1.2'), 'lower version ("")'); +ok($req->accepts_module('Foo::Blurb' => '1.4'), 'higher version ("")'); # Test multiple requirements $req->add_string_requirement('A::Tribe::Called', '>= 1.3, <= 2.0, != 1.6'); @@ -56,6 +104,21 @@ ok($req->accepts_module('A::Tribe::Calle ok(!$req->accepts_module('A::Tribe::Called' => '1.2'), 'lower version (>=, <=, !)'); ok(!$req->accepts_module('A::Tribe::Called' => '2.1'), 'higher version (>=, <=, !)'); ok(!$req->accepts_module('A::Tribe::Called' => '1.6'), 'excluded version (>=, <=, !)'); + +# Test multiple requirements with implicit minimum +{ + my $req = CPAN::Meta::Requirements->new; + + $req->add_string_requirement('Foo::MyModule', '0.90, != 0.91'); + + is_deeply( + $req->as_string_hash, + { + 'Foo::MyModule' => '>= 0.90, != 0.91' + }, + "multiple requirements with implicit minimum", + ); +} # Test precision { Index: gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/Makefile.PL =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/Makefile.PL,v diff -u -p -a -u -p -r1.1.1.6 Makefile.PL --- gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/Makefile.PL 15 Feb 2023 01:32:43 -0000 1.1.1.6 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/Makefile.PL 22 Jan 2025 00:37:42 -0000 @@ -8,11 +8,12 @@ use private::MakeUtil; use ExtUtils::MakeMaker 5.16 ; my $WALL= ''; -$WALL = ' -Wall -Wno-comment ' if $Config{'cc'} =~ /gcc/ ; +$WALL = ' -Wall -Wno-comment ' + if $Config{'cc'} =~ /gcc/ ; my $USE_PPPORT_H = ($ENV{PERL_CORE}) ? '' : '-DUSE_PPPORT_H'; -my $BUILD_BZIP2 = defined($ENV{BUILD_BZIP2}) ? $ENV{BUILD_BZIP2} : 1; +my $BUILD_BZIP2 = getBoolean('BUILD_BZIP2'); my $BZIP2_LIB = defined($ENV{BZIP2_LIB}) ? $ENV{BZIP2_LIB} : 'bzip2-src'; my $BZIP2_INCLUDE = defined($ENV{BZIP2_INCLUDE}) ? $ENV{BZIP2_INCLUDE} : '.'; @@ -26,10 +27,11 @@ WriteMakefile( VERSION_FROM => 'lib/Compress/Raw/Bzip2.pm', INC => "-I$BZIP2_INCLUDE" , DEFINE => "$WALL -DBZ_NO_STDIO $USE_PPPORT_H" , - XS => { 'Bzip2.xs' => 'Bzip2.c'}, - 'clean' => { FILES => '*.c bzip2.h bzlib.h bzlib_private.h constants.h constants.xs' }, - #'depend' => { 'Makefile' => 'config.in' }, - 'dist' => { COMPRESS => 'gzip', + XS => { 'Bzip2.xs' => 'Bzip2.c'}, + clean => { FILES => '*.c bzip2.h bzlib.h bzlib_private.h constants.h constants.xs' }, + depend => { manifypods => 'READMEmd' }, + postamble => { name => 'Bzip2'}, + dist => { COMPRESS => 'gzip', TARFLAGS => '-chvf', SUFFIX => 'gz', DIST_DEFAULT => 'MyTrebleCheck tardist', @@ -173,11 +175,18 @@ sub bzip2_files push @c_files, 'Bzip2.c' ; return ( - #'H' => [ @h_files ], - 'C' => [ @c_files ] , - #'OBJECT' => qq[ @o_files ], - 'OBJECT' => q[ $(O_FILES) ], - - + 'C' => [ @c_files ] , + 'OBJECT' => q[ $(O_FILES) ], ) ; } + +sub getBoolean +{ + my $name = shift ; + + # default is TRUE + return 1 + if ! defined $ENV{$name}; + + return ($ENV{$name} =~ /^yes|on|true|1$/i) ? 1 : 0; +} \ No newline at end of file Index: gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/bzip2-src/bzlib.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/bzip2-src/bzlib.c,v diff -u -p -a -u -p -r1.7 bzlib.c --- gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/bzip2-src/bzlib.c 14 May 2024 19:38:54 -0000 1.7 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/bzip2-src/bzlib.c 22 Jan 2025 00:37:42 -0000 @@ -859,9 +859,7 @@ int BZ_API(BZ2_bzDecompress) ( bz_stream } } - AssertH ( 0, 6001 ); - - return 0; /*NOTREACHED*/ + /*NOTREACHED*/ } Index: gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/bzip2-src/compress.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/bzip2-src/compress.c,v diff -u -p -a -u -p -r1.8 compress.c --- gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/bzip2-src/compress.c 14 May 2024 19:38:54 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/bzip2-src/compress.c 22 Jan 2025 00:37:42 -0000 @@ -28,6 +28,12 @@ #include "bzlib_private.h" +/* + Perl-specific change to allow building with C++ + The 'register' keyword not allowed from C++17 + see https://github.com/pmqs/Compress-Raw-Bzip2/issues/11 +*/ +#define register /*---------------------------------------------------*/ /*--- Bit stream I/O ---*/ @@ -187,15 +193,15 @@ void generateMTFValues ( EState* s ) zPend = 0; } { - UChar rtmp; - UChar* ryy_j; - UChar rll_i; + register UChar rtmp; + register UChar* ryy_j; + register UChar rll_i; rtmp = yy[1]; yy[1] = yy[0]; ryy_j = &(yy[1]); rll_i = ll_i; while ( rll_i != rtmp ) { - UChar rtmp2; + register UChar rtmp2; ryy_j++; rtmp2 = rtmp; rtmp = *ryy_j; @@ -240,7 +246,8 @@ void sendMTFValues ( EState* s ) { Int32 v, t, i, j, gs, ge, totc, bt, bc, iter; Int32 nSelectors, alphaSize, minLen, maxLen, selCtr; - Int32 nGroups, nBytes; + Int32 nGroups; + Int32 nBytes = 0; /*-- UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; @@ -358,8 +365,8 @@ void sendMTFValues ( EState* s ) if (nGroups == 6 && 50 == ge-gs+1) { /*--- fast track the common case ---*/ - UInt32 cost01, cost23, cost45; - UInt16 icv; + register UInt32 cost01, cost23, cost45; + register UInt16 icv; cost01 = cost23 = cost45 = 0; # define BZ_ITER(nn) \ Index: gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/lib/Compress/Raw/Bzip2.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/lib/Compress/Raw/Bzip2.pm,v diff -u -p -a -u -p -r1.12 Bzip2.pm --- gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/lib/Compress/Raw/Bzip2.pm 14 May 2024 19:38:54 -0000 1.12 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/lib/Compress/Raw/Bzip2.pm 22 Jan 2025 00:37:42 -0000 @@ -11,7 +11,7 @@ use Carp ; use bytes ; our ($VERSION, $XS_VERSION, @ISA, @EXPORT, $AUTOLOAD); -$VERSION = '2.204_001'; +$VERSION = '2.212'; $XS_VERSION = $VERSION; $VERSION = eval $VERSION; @@ -384,7 +384,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/private/MakeUtil.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/private/MakeUtil.pm,v diff -u -p -a -u -p -r1.22 MakeUtil.pm --- gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/private/MakeUtil.pm 14 May 2024 19:39:39 -0000 1.22 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/private/MakeUtil.pm 22 Jan 2025 00:37:42 -0000 @@ -45,7 +45,14 @@ sub MY::libscan sub MY::postamble { - return '' + my $self = shift ; + my %params = @_ ; + + return <){ next if 1 .. /^__END__/; print}' lib/Compress/Raw/$name.pm >.github/$name.pod + +EOM + } + else + { + $postamble .= <<"EOM"; + +READMEmd: + +EOM + } return $postamble; } Index: gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/t/000prereq.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/t/000prereq.t,v diff -u -p -a -u -p -r1.12 000prereq.t --- gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/t/000prereq.t 14 May 2024 19:38:54 -0000 1.12 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/t/000prereq.t 22 Jan 2025 00:37:42 -0000 @@ -19,7 +19,7 @@ BEGIN if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; - my $VERSION = '2.204'; + my $VERSION = '2.212'; my @NAMES = qw( ); Index: gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/t/01bzip2.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/t/01bzip2.t,v diff -u -p -a -u -p -r1.1.1.2 01bzip2.t --- gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/t/01bzip2.t 15 Feb 2023 01:32:43 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/t/01bzip2.t 22 Jan 2025 00:37:42 -0000 @@ -350,12 +350,18 @@ for my $consume ( 0 .. 1) } +SKIP: foreach (1 .. 2) { next if $] < 5.005 ; title 'test bzinflate/bzdeflate with a substr'; + # temp workaround for + # https://github.com/pmqs/Compress-Raw-Bzip2/issues/13 + skip "skipping substr tests for Perl 5.6.*", 15 + if $] < 5.008 ; + my $contents = '' ; foreach (1 .. 5000) { $contents .= chr int rand 255 } @@ -433,10 +439,16 @@ foreach (1 .. 2) } +SKIP: { if ($] >= 5.005) { title 'test bzinflate input parameter via substr'; + # temp workaround for + # https://github.com/pmqs/Compress-Raw-Bzip2/issues/13 + skip "skipping substr tests for Perl 5.6.*", 11 + if $] < 5.008 ; + my $hello = "I am a HAL 9000 computer" ; my $data = $hello ; @@ -470,6 +482,7 @@ if ($] >= 5.005) ok $hello eq $Z ; is $X, $keep; +} } Index: gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/t/19nonpv.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/t/19nonpv.t,v diff -u -p -a -u -p -r1.1.1.2 19nonpv.t --- gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/t/19nonpv.t 15 Feb 2023 01:32:43 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Bzip2/t/19nonpv.t 22 Jan 2025 00:37:42 -0000 @@ -33,11 +33,16 @@ EOM my $len = length $hello ; - +SKIP: { title "bzdeflate/bzinflate - non-PV buffers"; # ============================== + + # temp workaround for + # https://github.com/pmqs/Compress-Raw-Bzip2/issues/13 + skip "skipping tests for Perl 5.6.*", 19 + if $] < 5.008 ; my $hello = *hello; $hello = *hello; Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/Makefile.PL =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/Makefile.PL,v diff -u -p -a -u -p -r1.4 Makefile.PL --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/Makefile.PL 15 Feb 2023 01:38:21 -0000 1.4 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/Makefile.PL 22 Jan 2025 00:37:42 -0000 @@ -25,9 +25,6 @@ if ($Config{'gccversion'} and $OPTIMIZE # Windows uses a different name for the zlib library my $ZLIB_LIBRARY_NAME = $^O eq 'MSWin32' ? 'zlib' : 'z' ; -#$WALL = ' -pedantic ' if $Config{'cc'} =~ /gcc/ ; -#$WALL = ' -Wall -Wno-comment ' if $Config{'cc'} =~ /gcc/ ; - # Ticket #18986 says that ExtUtils::Install 1.39 fixes the in-use issue # on win32/cygwin, so make the code below conditional on the version of # ExtUtils::Install. @@ -56,15 +53,14 @@ EOM if ($answer =~ /^yes|y/i) { - print "continuing...\n" + print "continuing...\n" } else { - print "exiting...\n" ; - exit 1 ; + print "exiting...\n" ; + exit 1 ; } - } ParseCONFIG() ; @@ -78,9 +74,12 @@ my $OPT_ZLIB_LIB = "-L$ZLIB_LIB" ; my $OPT_SOLO = '-DZ_SOLO'; my $OPT_USE_ZLIB_NG = ""; -if (! $BUILD_ZLIB) +# For C++ only +my $OPT_CXX_DEFINES = '-Dregister=' ; # for https://github.com/pmqs/Compress-Raw-Zlib/issues/23 + +if (!$BUILD_ZLIB) { - # When using the system supplied zlib, we don't want to use our bespoke prefix + # When using the system supplied zlib, we don't want to use our bespoke prefix $OPT_Z_PREFIX = ''; $OPT_ZLIB_INCLUDE = '' @@ -98,15 +97,23 @@ if ( $USE_ZLIB_NG) $ZLIB_LIBRARY_NAME = $^O eq 'MSWin32' ? 'zlib-ng' : 'z-ng' ; } -WriteMakefile( +my %WriteMakefileArgs = ( + NAME => 'Compress::Raw::Zlib', VERSION_FROM => 'lib/Compress/Raw/Zlib.pm', INC => $OPT_ZLIB_INCLUDE , - DEFINE => "-DNO_VIZ $OPT_SOLO $OLD_ZLIB $WALL $OPT_Z_PREFIX $OPT_USE_ZLIB_NG -DGZIP_OS_CODE=$GZIP_OS_CODE $USE_PPPORT_H -DPerl_crz_BUILD_ZLIB=$BUILD_ZLIB" , + DEFINE => "-DNO_VIZ $OPT_SOLO $OLD_ZLIB $WALL $OPT_Z_PREFIX $OPT_USE_ZLIB_NG -DGZIP_OS_CODE=$GZIP_OS_CODE $USE_PPPORT_H -DPerl_crz_BUILD_ZLIB=$BUILD_ZLIB $OPT_CXX_DEFINES" , XS => { 'Zlib.xs' => 'Zlib.c'}, - 'depend' => { 'Makefile' => 'config.in' }, - 'clean' => { FILES => '*.c constants.h constants.xs' }, - 'dist' => { COMPRESS => 'gzip', + OPTIMIZE => $OPTIMIZE, + LICENSE => 'perl', + ABSTRACT => 'Perl interface to zlib/zlib-ng compression libraries', + AUTHOR => 'Paul Marquess ', + depend => { Makefile => 'config.in', + manifypods => 'READMEmd' + }, + postamble => { name => 'Zlib' }, + clean => { FILES => '*.c constants.h constants.xs' }, + dist => { COMPRESS => 'gzip', TARFLAGS => '-chvf', SUFFIX => 'gz', DIST_DEFAULT => 'MyTrebleCheck tardist', @@ -117,14 +124,12 @@ WriteMakefile( ? zlib_files($ZLIB_LIB) : (LIBS => [ "$OPT_ZLIB_LIB -l$ZLIB_LIBRARY_NAME " ]) ), - OPTIMIZE => $OPTIMIZE, - INSTALLDIRS => ($] >= 5.009 && $] < 5.011 ? 'perl' : 'site'), + INSTALLDIRS => ($] >= 5.009 && $] < 5.011 ? 'perl' : 'site'), - ( eval { ExtUtils::MakeMaker->VERSION(6.46) } - ? ( META_MERGE => { + META_MERGE => { - "meta-spec" => { version => 2 }, + 'meta-spec' => { version => 2 }, no_index => { directory => [ 't', 'private' ], @@ -144,16 +149,21 @@ WriteMakefile( web => 'https://github.com/pmqs/Compress-Raw-Zlib', }, }, - } - ) - : () - ), - - ((ExtUtils::MakeMaker->VERSION() gt '6.30') ? - ('LICENSE' => 'perl') : ()), + }, ) ; +delete $WriteMakefileArgs{LICENSE} + unless eval { ExtUtils::MakeMaker->VERSION(6.30) } ; + +delete $WriteMakefileArgs{META_MERGE} + unless eval { ExtUtils::MakeMaker->VERSION(6.46) } ; + +delete $WriteMakefileArgs{BUILD_REQUIRES} + unless eval { ExtUtils::MakeMaker->VERSION(6.55_03) } ; + +WriteMakefile(%WriteMakefileArgs); + sub version_Macro { my $ver = shift ; @@ -201,7 +211,6 @@ my @names = qw( ZLIBNG_VER_MAJOR ZLIBNG_VER_MINOR ZLIBNG_VER_REVISION - ZLIBNG_VER_STATUS ZLIBNG_VER_MODIFIED ); @@ -267,11 +276,22 @@ sub getBoolean my $name = shift ; my $info = shift; + my $x = getConfigValue($name, $info); + + return ($x =~ /^yes|on|true|1$/i) ? 1 : 0; +} + +sub getConfigValue +{ + my $name = shift ; + my $info = shift; + + # Environment variable takes priority my $x = defined $ENV{$name} ? $ENV{$name} : $info->{$name} ; - return ($x =~ /^yes|on|true|1$/i) ? 1 : 0; + return $x; } sub ParseCONFIG @@ -279,7 +299,7 @@ sub ParseCONFIG my ($k, $v) ; my @badkey = () ; my %Info = () ; - my @Options = qw( INCLUDE LIB BUILD_ZLIB OLD_ZLIB GZIP_OS_CODE USE_ZLIB_NG) ; + my @Options = qw( ZLIB_INCLUDE ZLIB_LIB BUILD_ZLIB OLD_ZLIB GZIP_OS_CODE USE_ZLIB_NG) ; my %ValidOption = map {$_, 1} @Options ; my %Parsed = %ValidOption ; my $CONFIG = 'config.in' ; @@ -288,84 +308,72 @@ sub ParseCONFIG open(F, "<$CONFIG") or die "Cannot open file $CONFIG: $!\n" ; while () { - s/^\s*|\s*$//g ; - next if /^\s*$/ or /^\s*#/ ; - s/\s*#\s*$// ; - - ($k, $v) = split(/\s+=\s+/, $_, 2) ; - $k = uc $k ; - if ($ValidOption{$k}) { - delete $Parsed{$k} ; - $Info{$k} = $v ; - } - else { - push(@badkey, $k) ; - } + s/^\s*|\s*$//g ; + next if /^\s*$/ or /^\s*#/ ; + s/\s*#\s*$// ; + + ($k, $v) = split(/\s+=\s+/, $_, 2) ; + $k = uc $k ; + if ($ValidOption{$k}) { + delete $Parsed{$k} ; + $Info{$k} = $v ; + } + else { + push(@badkey, $k) ; + } } close F ; print "Unknown keys in $CONFIG ignored [@badkey]\n" - if @badkey ; + if @badkey ; # check parsed values my @missing = () ; die "The following keys are missing from $CONFIG [@missing]\n" if @missing = keys %Parsed ; - $ZLIB_INCLUDE = defined $ENV{'ZLIB_INCLUDE'} - ? $ENV{'ZLIB_INCLUDE'} - : $Info{'INCLUDE'} ; - - $ZLIB_LIB = defined $ENV{'ZLIB_LIB'} - ?$ENV{'ZLIB_LIB'} - : $Info{'LIB'} ; - - $USE_ZLIB_NG = getBoolean('USE_ZLIB_NG', \%Info); + $ZLIB_INCLUDE = getConfigValue('ZLIB_INCLUDE', \%Info); + $ZLIB_LIB = getConfigValue('ZLIB_LIB', \%Info); + $GZIP_OS_CODE = getConfigValue('GZIP_OS_CODE', \%Info); + + $BUILD_ZLIB = getBoolean('BUILD_ZLIB', \%Info); + $USE_ZLIB_NG = getBoolean('USE_ZLIB_NG', \%Info); + $OLD_ZLIB = getBoolean('OLD_ZLIB', \%Info); if ($^O eq 'VMS') { $ZLIB_INCLUDE = VMS::Filespec::vmspath($ZLIB_INCLUDE); $ZLIB_LIB = VMS::Filespec::vmspath($ZLIB_LIB); } - $OLD_ZLIB = '-DOLD_ZLIB' - if getBoolean('OLD_ZLIB', \%Info); - - $BUILD_ZLIB = getBoolean('BUILD_ZLIB', \%Info); + $OLD_ZLIB = $OLD_ZLIB + ?'-DOLD_ZLIB' + : ''; if ($BUILD_ZLIB ) { + die "Cannot have USE_ZLIB_NG when BUILD_ZLIBis true\n" + if $USE_ZLIB_NG ; + # ZLIB_LIB & ZLIB_INCLUDE must point to the same place when # BUILD_ZLIB is specified. - die "INCLUDE & LIB must be the same when BUILD_ZLIB is True\n" + die "ZLIB_INCLUDE & ZLIB_LIB must be the same when BUILD_ZLIB is True\n" if $ZLIB_LIB ne $ZLIB_INCLUDE ; # Check the zlib source directory exists - die "LIB/INCLUDE directory '$ZLIB_LIB' does not exits\n" + die "ZLIB_LIB/ZLIB_INCLUDE directory '$ZLIB_LIB' does not exits\n" unless -d $ZLIB_LIB ; # check for a well known file - if ($USE_ZLIB_NG) - { - die "LIB/INCLUDE directory, '$ZLIB_LIB', doesn't seem to have the zlib-ng source files\n" - unless -e catfile($ZLIB_LIB, 'zlib-ng.h') ; - } - else - { - die "LIB/INCLUDE directory, '$ZLIB_LIB', doesn't seem to have the zlib source files\n" - unless -e catfile($ZLIB_LIB, 'zlib.h') ; - } + die "ZLIB_LIB/ZLIB_INCLUDE directory, '$ZLIB_LIB', doesn't seem to have the zlib source files\n" + unless -e catfile($ZLIB_LIB, 'zlib.h') ; # write the Makefile - print "Building Zlib enabled\n" ; + print "Building Zlib is enabled\n" ; } - $GZIP_OS_CODE = defined $ENV{'GZIP_OS_CODE'} - ? $ENV{'GZIP_OS_CODE'} - : $Info{'GZIP_OS_CODE'} ; - - die "GZIP_OS_CODE not 'AUTO_DETECT' or a number between 0 and 255\n" - unless uc $GZIP_OS_CODE eq 'AUTO_DETECT' - || ( $GZIP_OS_CODE =~ /^(\d+)$/ && $1 >= 0 && $1 <= 255) ; + die "GZIP_OS_CODE not 'AUTO_DETECT' or a number between 0 and 255\n" + unless uc $GZIP_OS_CODE eq 'AUTO_DETECT' + || ( $GZIP_OS_CODE =~ /^(\d+)$/ && $1 >= 0 && $1 <= 255) ; if (uc $GZIP_OS_CODE eq 'AUTO_DETECT') { @@ -403,24 +411,24 @@ sub zlib_files # zlib 1.2.0 or greater # @h_files = qw(crc32.h inffast.h inflate.h trees.h zconf.in.h - zutil.h deflate.h inffixed.h inftrees.h zconf.h - zlib.h - ); + zutil.h deflate.h inffixed.h inftrees.h zconf.h + zlib.h + ); @c_files = qw(adler32 crc32 infback inflate uncompr - compress deflate inffast inftrees - trees zutil - ); + compress deflate inffast inftrees + trees zutil + ); } else { # zlib 1.1.x @h_files = qw(deflate.h infcodes.h inftrees.h zconf.h zutil.h - infblock.h inffast.h infutil.h zlib.h - ); + infblock.h inffast.h infutil.h zlib.h + ); @c_files = qw(adler32 compress crc32 uncompr - deflate trees zutil inflate infblock - inftrees infcodes infutil inffast - ); + deflate trees zutil inflate infblock + inftrees infcodes infutil inffast + ); } @h_files = map { catfile($dir, $_) } @h_files ; @@ -431,12 +439,8 @@ sub zlib_files { copy(catfile($dir, $file), '.') } return ( - #'H' => [ @h_files ], - 'C' => [ @c_files ] , - #'OBJECT' => qq[ @o_files ], - 'OBJECT' => q[ $(O_FILES) ], - - + 'C' => [ @c_files ] , + 'OBJECT' => q[ $(O_FILES) ], ) ; } Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/Zlib.xs =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/Zlib.xs,v diff -u -p -a -u -p -r1.6 Zlib.xs --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/Zlib.xs 14 May 2024 19:38:54 -0000 1.6 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/Zlib.xs 22 Jan 2025 00:37:42 -0000 @@ -214,6 +214,22 @@ # define NEED_sv_2pv_nolen # define NEED_sv_pvn_force_flags # include "ppport.h" + +/* Proposed fix for https://github.com/Dual-Life/Devel-PPPort/issues/231 */ + +# if PERL_VERSION < 18 +# ifdef sv_2pv +# undef sv_2pv +# endif + +# if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) +# define sv_2pv(sv, lp) ({ SV *_sv_2pv = (sv); SvPOKp(_sv_2pv) ? ((*(lp) = SvCUR(_sv_2pv)), SvPVX(_sv_2pv)) : Perl_sv_2pv(aTHX_ _sv_2pv, (lp)); }) +# else +# define sv_2pv(sv, lp) (SvPOKp(sv) ? ((*(lp) = SvCUR(sv)), SvPVX(sv)) : Perl_sv_2pv(aTHX_ (sv), (lp))) +# endif + +#endif + #endif #if PERL_REVISION == 5 && PERL_VERSION == 9 @@ -640,7 +656,7 @@ voidpf my_zcalloc (voidpf opaque, unsign PERL_UNUSED_VAR(opaque); /* TODO - put back to calloc */ /* return safecalloc(items, size); */ - return safemalloc(items* size); + return (voidpf)safemalloc(items* size); } @@ -951,6 +967,17 @@ ZLIB_VERNUM() uLong Zip_zlibCompileFlags() +const char* +ZLIBNG_VER_STATUS() + CODE: +#ifdef ZLIBNG_VER_STATUS + RETVAL = STRINGIFY(ZLIBNG_VER_STATUS); +#else + RETVAL = "0"; +#endif + OUTPUT: + RETVAL + MODULE = Compress::Raw::Zlib PACKAGE = Compress::Raw::Zlib PREFIX = Zip_ #define Zip_adler32(buf, adler) CRZ_adler32(adler, buf, (uInt)len) @@ -1216,6 +1243,15 @@ deflate (s, buf, output) CODE: bufinc = s->bufsize; + /* + if (trace) { + printf("\nDEFLATE Before deRef of input buffer\n"); + printf("\nPerl_sv_dump\n"); + Perl_sv_dump(buf); + printf("\n"); + } + */ + /* If the input buffer is a reference, dereference it */ buf = deRef(buf, "deflate") ; @@ -1226,6 +1262,16 @@ deflate (s, buf, output) #endif s->stream.next_in = (Bytef*)SvPV_nomg(buf, origlen) ; s->stream.avail_in = origlen; + + if (trace) { + printf("\nDEFLATE Starts\n"); + DispStream(s, "START"); + /* + printf("\nPerl_sv_dump\n"); + Perl_sv_dump(buf); + printf("\n"); + */ + } if (s->flags & FLAG_CRC32) s->crc32 = CRZ_crc32(s->crc32, s->stream.next_in, s->stream.avail_in) ; Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/config.in =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/config.in,v diff -u -p -a -u -p -r1.8 config.in --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/config.in 14 May 2024 19:39:39 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/config.in 22 Jan 2025 00:37:42 -0000 @@ -1,24 +1,19 @@ # Filename: config.in # -# written by Paul Marquess -# last modified 28th October 2003 -# version 2.000 +# This file is used to control which zlib/zlib-ng library will be used by +# Compress::Raw::Zlib # +# Refer to the section names listed below in the README file for details of how +# to use this file. # -# This file is used to control which zlib library will be used by -# Compress::Zlib -# -# See to the sections below in the README file for details of how to -# use this file. -# -# Controlling the version of zlib used by Compress::Zlib +# Controlling the version of zlib/zlib-ng used by Compress::Raw::Zlib # # Setting the Gzip OS Code # BUILD_ZLIB = False -INCLUDE = /usr/include -LIB = /usr/lib +ZLIB_INCLUDE = /usr/include +ZLIB_LIB = /usr/lib OLD_ZLIB = False GZIP_OS_CODE = AUTO_DETECT USE_ZLIB_NG = False Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/lib/Compress/Raw/Zlib.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/lib/Compress/Raw/Zlib.pm,v diff -u -p -a -u -p -r1.8 Zlib.pm --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/lib/Compress/Raw/Zlib.pm 14 May 2024 19:38:54 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/lib/Compress/Raw/Zlib.pm 22 Jan 2025 00:37:42 -0000 @@ -10,7 +10,7 @@ use warnings ; use bytes ; our ($VERSION, $XS_VERSION, @ISA, @EXPORT, %EXPORT_TAGS, @EXPORT_OK, $AUTOLOAD, %DEFLATE_CONSTANTS, @DEFLATE_CONSTANTS); -$VERSION = '2.204_001'; +$VERSION = '2.212'; $XS_VERSION = $VERSION; $VERSION = eval $VERSION; @@ -1282,7 +1282,7 @@ simpler. last OUTER unless $status == Z_OK || $status == Z_BUF_ERROR ; } - while ($status == Z_OK && length $input); + while length $input; } die "inflation failed\n" @@ -1453,7 +1453,7 @@ Below is typical code that shows how to last OUTER unless $status == Z_OK || $status == Z_BUF_ERROR ; } - while ($status == Z_OK && length $input); + while length $input; } die "inflation failed\n" @@ -1637,7 +1637,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/private/MakeUtil.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/private/MakeUtil.pm,v diff -u -p -a -u -p -r1.22 MakeUtil.pm --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/private/MakeUtil.pm 14 May 2024 19:39:39 -0000 1.22 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/private/MakeUtil.pm 22 Jan 2025 00:37:42 -0000 @@ -45,8 +45,18 @@ sub MY::libscan sub MY::postamble { - return '' - if $ENV{PERL_CORE} ; + my $self = shift ; + my %params = @_ ; + + if ($ENV{PERL_CORE} ) + { + return <.github/$name.pod + +EOM + } + else + { + $postamble .= <<"EOM"; + +READMEmd: + +EOM + } return $postamble; } Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/t/01version.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/t/01version.t,v diff -u -p -a -u -p -r1.2 01version.t --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/t/01version.t 15 Feb 2023 01:38:21 -0000 1.2 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/t/01version.t 22 Jan 2025 00:37:42 -0000 @@ -37,7 +37,7 @@ SKIP: skip "Not github", 7 if ! (defined $ENV{GITHUB_ACTION} && defined $ENV{ZLIB_VERSION}) ; - my $expected_version = $ENV{ZLIB_VERSION} ; + my $expected_version = $ENV{ZLIB_VERSION} ; # zlib prefixes tags with a "v", so remove $expected_version =~ s/^v//i; @@ -67,6 +67,12 @@ SKIP: '2.0.4' => '1.2.11.zlib-ng', '2.0.5' => '1.2.11.zlib-ng', '2.0.6' => '1.2.11.zlib-ng', + '2.0.7' => '1.2.11.zlib-ng', + '2.1.2' => '1.2.13.zlib-ng', + '2.1.3' => '1.2.13.zlib-ng', + '2.1.4' => '1.3.0.zlib-ng', + '2.1.5' => '1.3.0.zlib-ng', + '2.1.6' => '1.3.0.zlib-ng', ); my $zv = Compress::Raw::Zlib::zlibng_version(); Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/t/02zlib.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/t/02zlib.t,v diff -u -p -a -u -p -r1.4 02zlib.t --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/t/02zlib.t 15 Feb 2023 01:38:21 -0000 1.4 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/t/02zlib.t 22 Jan 2025 00:37:42 -0000 @@ -635,18 +635,26 @@ SKIP: } +SKIP: foreach (1 .. 2) { next if $] < 5.005 ; title 'test inflate/deflate with a substr'; + # # temp workaround for + # # https://github.com/pmqs/Compress-Raw-Zlib/issues/27 + # skip "skipping substr tests for Perl 5.6.*", 15 + # if $] < 5.008 ; + my $contents = '' ; foreach (1 .. 5000) { $contents .= chr int rand 255 } ok my $x = new Compress::Raw::Zlib::Deflate(-AppendOutput => 1) ; my $X ; + # my $data = substr($contents,0) ; + # my $status = $x->deflate($data, $X); my $status = $x->deflate(substr($contents,0), $X); cmp_ok $status, '==', Z_OK ; @@ -718,10 +726,16 @@ foreach (1 .. 2) } +SKIP: { if ($] >= 5.005) { title 'test inflate input parameter via substr'; + # # temp workaround for + # # https://github.com/pmqs/Compress-Raw-Zlib/issues/27 + # skip "skipping substr tests for Perl 5.6.*", 11 + # if $] < 5.008 ; + my $hello = "I am a HAL 9000 computer" ; my $data = $hello ; @@ -750,12 +764,14 @@ if ($] >= 5.005) ok $k = new Compress::Raw::Zlib::Inflate ( -AppendOutput => 1, -ConsumeInput => 0 ) ; - cmp_ok $k->inflate(substr($X, 0, -1), $Z), '==', Z_STREAM_END ; ; - #cmp_ok $k->inflate(substr($X, 0), $Z), '==', Z_STREAM_END ; ; + # my $data = substr($X, 0, -1); + # cmp_ok $k->inflate($data, $Z), '==', Z_STREAM_END ; ; + cmp_ok $k->inflate(substr($X, 0), $Z), '==', Z_STREAM_END ; ; ok $hello eq $Z ; is $X, $keep; +} } { Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/t/19nonpv.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/t/19nonpv.t,v diff -u -p -a -u -p -r1.2 19nonpv.t --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/t/19nonpv.t 15 Feb 2023 01:38:21 -0000 1.2 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/t/19nonpv.t 22 Jan 2025 00:37:42 -0000 @@ -14,7 +14,7 @@ use Test::More ; BEGIN { # use Test::NoWarnings, if available - my $extra = 0 ; + my $extra = 0; $extra = 1 if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; @@ -37,10 +37,16 @@ my $len = length $hello ; test_zlib_header_matches_library(); +SKIP: { title 'non-PV dictionary'; # ============================== + # # temp workaround for + # # https://github.com/pmqs/Compress-Raw-Zlib/issues/27 + # skip "skipping tests for Perl 5.6.*", 7 + # if $] < 5.008 ; + my $dictionary = *hello ; ok my $x = new Compress::Raw::Zlib::Deflate({-Level => Z_BEST_COMPRESSION, @@ -61,10 +67,16 @@ test_zlib_header_matches_library(); } +SKIP: { title "deflate/inflate - non-PV buffers"; # ============================== + + # # temp workaround for + # # https://github.com/pmqs/Compress-Raw-Zlib/issues/27 + # skip "skipping tests for Perl 5.6.*", 27 + # if $] < 5.008 ; my $hello = *hello ; my ($err, $x, $X, $status); Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/adler32.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/adler32.c,v diff -u -p -a -u -p -r1.5 adler32.c --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/adler32.c 13 Feb 2019 21:15:08 -0000 1.5 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/adler32.c 22 Jan 2025 00:37:42 -0000 @@ -7,8 +7,6 @@ #include "zutil.h" -local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); - #define BASE 65521U /* largest prime smaller than 65536 */ #define NMAX 5552 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ @@ -60,11 +58,7 @@ local uLong adler32_combine_ OF((uLong a #endif /* ========================================================================= */ -uLong ZEXPORT adler32_z( - uLong adler, - const Bytef *buf, - z_size_t len) -{ +uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) { unsigned long sum2; unsigned n; @@ -131,20 +125,12 @@ uLong ZEXPORT adler32_z( } /* ========================================================================= */ -uLong ZEXPORT adler32( - uLong adler, - const Bytef *buf, - uInt len) -{ +uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len) { return adler32_z(adler, buf, len); } /* ========================================================================= */ -local uLong adler32_combine_( - uLong adler1, - uLong adler2, - z_off64_t len2) -{ +local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2) { unsigned long sum1; unsigned long sum2; unsigned rem; @@ -169,18 +155,10 @@ local uLong adler32_combine_( } /* ========================================================================= */ -uLong ZEXPORT adler32_combine( - uLong adler1, - uLong adler2, - z_off_t len2) -{ +uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2) { return adler32_combine_(adler1, adler2, len2); } -uLong ZEXPORT adler32_combine64( - uLong adler1, - uLong adler2, - z_off64_t len2) -{ +uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2) { return adler32_combine_(adler1, adler2, len2); } Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/compress.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/compress.c,v diff -u -p -a -u -p -r1.5 compress.c --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/compress.c 13 Feb 2019 21:15:08 -0000 1.5 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/compress.c 22 Jan 2025 00:37:42 -0000 @@ -19,13 +19,8 @@ memory, Z_BUF_ERROR if there was not enough room in the output buffer, Z_STREAM_ERROR if the level parameter is invalid. */ -int ZEXPORT compress2 ( - Bytef *dest, - uLongf *destLen, - const Bytef *source, - uLong sourceLen, - int level) -{ +int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source, + uLong sourceLen, int level) { z_stream stream; int err; const uInt max = (uInt)-1; @@ -65,12 +60,8 @@ int ZEXPORT compress2 ( /* =========================================================================== */ -int ZEXPORT compress ( - Bytef *dest, - uLongf *destLen, - const Bytef *source, - uLong sourceLen) -{ +int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, + uLong sourceLen) { return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); } @@ -78,9 +69,7 @@ int ZEXPORT compress ( If the default memLevel or windowBits for deflateInit() is changed, then this function needs to be updated. */ -uLong ZEXPORT compressBound ( - uLong sourceLen) -{ +uLong ZEXPORT compressBound(uLong sourceLen) { return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + (sourceLen >> 25) + 13; } Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/crc32.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/crc32.c,v diff -u -p -a -u -p -r1.7 crc32.c --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/crc32.c 14 May 2024 19:38:54 -0000 1.7 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/crc32.c 22 Jan 2025 00:37:42 -0000 @@ -103,19 +103,6 @@ # define ARMCRC32 #endif -/* Local functions. */ -local z_crc_t multmodp OF((z_crc_t a, z_crc_t b)); -local z_crc_t x2nmodp OF((z_off64_t n, unsigned k)); - -#if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) - local z_word_t byte_swap OF((z_word_t word)); -#endif - -#if defined(W) && !defined(ARMCRC32) - local z_crc_t crc_word OF((z_word_t data)); - local z_word_t crc_word_big OF((z_word_t data)); -#endif - #if defined(W) && (!defined(ARMCRC32) || defined(DYNAMIC_CRC_TABLE)) /* Swap the bytes in a z_word_t to convert between little and big endian. Any @@ -123,9 +110,7 @@ local z_crc_t x2nmodp OF((z_off64_t n, u instruction, if one is available. This assumes that word_t is either 32 bits or 64 bits. */ -local z_word_t byte_swap( - z_word_t word) -{ +local z_word_t byte_swap(z_word_t word) { # if W == 8 return (word & 0xff00000000000000) >> 56 | @@ -146,24 +131,77 @@ local z_word_t byte_swap( } #endif +#ifdef DYNAMIC_CRC_TABLE +/* ========================================================================= + * Table of powers of x for combining CRC-32s, filled in by make_crc_table() + * below. + */ + local z_crc_t FAR x2n_table[32]; +#else +/* ========================================================================= + * Tables for byte-wise and braided CRC-32 calculations, and a table of powers + * of x for combining CRC-32s, all made by make_crc_table(). + */ +# include "crc32.h" +#endif + /* CRC polynomial. */ #define POLY 0xedb88320 /* p(x) reflected, with x^32 implied */ -#ifdef DYNAMIC_CRC_TABLE +/* + Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, + reflected. For speed, this requires that a not be zero. + */ +local z_crc_t multmodp(z_crc_t a, z_crc_t b) { + z_crc_t m, p; + m = (z_crc_t)1 << 31; + p = 0; + for (;;) { + if (a & m) { + p ^= b; + if ((a & (m - 1)) == 0) + break; + } + m >>= 1; + b = b & 1 ? (b >> 1) ^ POLY : b >> 1; + } + return p; +} + +/* + Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been + initialized. + */ +local z_crc_t x2nmodp(z_off64_t n, unsigned k) { + z_crc_t p; + + p = (z_crc_t)1 << 31; /* x^0 == 1 */ + while (n) { + if (n & 1) + p = multmodp(x2n_table[k & 31], p); + n >>= 1; + k++; + } + return p; +} + +#ifdef DYNAMIC_CRC_TABLE +/* ========================================================================= + * Build the tables for byte-wise and braided CRC-32 calculations, and a table + * of powers of x for combining CRC-32s. + */ local z_crc_t FAR crc_table[256]; -local z_crc_t FAR x2n_table[32]; -local void make_crc_table OF((void)); #ifdef W local z_word_t FAR crc_big_table[256]; local z_crc_t FAR crc_braid_table[W][256]; local z_word_t FAR crc_braid_big_table[W][256]; - local void braid OF((z_crc_t [][256], z_word_t [][256], int, int)); + local void braid(z_crc_t [][256], z_word_t [][256], int, int); #endif #ifdef MAKECRCH - local void write_table OF((FILE *, const z_crc_t FAR *, int)); - local void write_table32hi OF((FILE *, const z_word_t FAR *, int)); - local void write_table64 OF((FILE *, const z_word_t FAR *, int)); + local void write_table(FILE *, const z_crc_t FAR *, int); + local void write_table32hi(FILE *, const z_word_t FAR *, int); + local void write_table64(FILE *, const z_word_t FAR *, int); #endif /* MAKECRCH */ /* @@ -176,7 +214,6 @@ local void make_crc_table OF((void)); /* Definition of once functionality. */ typedef struct once_s once_t; -local void once OF((once_t *, void (*)(void))); /* Check for the availability of atomics. */ #if defined(__STDC__) && __STDC_VERSION__ >= 201112L && \ @@ -196,10 +233,7 @@ struct once_s { invoke once() at the same time. The state must be a once_t initialized with ONCE_INIT. */ -local void once(state, init) - once_t *state; - void (*init)(void); -{ +local void once(once_t *state, void (*init)(void)) { if (!atomic_load(&state->done)) { if (atomic_flag_test_and_set(&state->begun)) while (!atomic_load(&state->done)) @@ -222,10 +256,7 @@ struct once_s { /* Test and set. Alas, not atomic, but tries to minimize the period of vulnerability. */ -local int test_and_set OF((int volatile *)); -local int test_and_set( - int volatile *flag) -{ +local int test_and_set(int volatile *flag) { int was; was = *flag; @@ -234,10 +265,7 @@ local int test_and_set( } /* Run the provided init() function once. This is not thread-safe. */ -local void once(state, init) - once_t *state; - void (*init)(void); -{ +local void once(once_t *state, void (*init)(void)) { if (!state->done) { if (test_and_set(&state->begun)) while (!state->done) @@ -279,8 +307,7 @@ local once_t made = ONCE_INIT; combinations of CRC register values and incoming bytes. */ -local void make_crc_table() -{ +local void make_crc_table(void) { unsigned i, j, n; z_crc_t p; @@ -447,11 +474,7 @@ local void make_crc_table() Write the 32-bit values in table[0..k-1] to out, five per line in hexadecimal separated by commas. */ -local void write_table( - FILE *out, - const z_crc_t FAR *table, - int k) -{ +local void write_table(FILE *out, const z_crc_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -464,11 +487,7 @@ local void write_table( Write the high 32-bits of each value in table[0..k-1] to out, five per line in hexadecimal separated by commas. */ -local void write_table32hi( - FILE *out, - const z_word_t FAR *table, - int k) -{ +local void write_table32hi(FILE *out, const z_word_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -484,11 +503,7 @@ local void write_table32hi( bits. If not, then the type cast and format string can be adjusted accordingly. */ -local void write_table64( - FILE *out, - const z_word_t FAR *table, - int k) -{ +local void write_table64(FILE *out, const z_word_t FAR *table, int k) { int n; for (n = 0; n < k; n++) @@ -498,8 +513,7 @@ local void write_table64( } /* Actually do the deed. */ -int main() -{ +int main(void) { make_crc_table(); return 0; } @@ -511,12 +525,7 @@ int main() Generate the little and big-endian braid tables for the given n and z_word_t size w. Each array must have room for w blocks of 256 elements. */ -local void braid(ltl, big, n, w) - z_crc_t ltl[][256]; - z_word_t big[][256]; - int n; - int w; -{ +local void braid(z_crc_t ltl[][256], z_word_t big[][256], int n, int w) { int k; z_crc_t i, p, q; for (k = 0; k < w; k++) { @@ -531,69 +540,13 @@ local void braid(ltl, big, n, w) } #endif -#else /* !DYNAMIC_CRC_TABLE */ -/* ======================================================================== - * Tables for byte-wise and braided CRC-32 calculations, and a table of powers - * of x for combining CRC-32s, all made by make_crc_table(). - */ -#include "crc32.h" #endif /* DYNAMIC_CRC_TABLE */ -/* ======================================================================== - * Routines used for CRC calculation. Some are also required for the table - * generation above. - */ - -/* - Return a(x) multiplied by b(x) modulo p(x), where p(x) is the CRC polynomial, - reflected. For speed, this requires that a not be zero. - */ -local z_crc_t multmodp( - z_crc_t a, - z_crc_t b) -{ - z_crc_t m, p; - - m = (z_crc_t)1 << 31; - p = 0; - for (;;) { - if (a & m) { - p ^= b; - if ((a & (m - 1)) == 0) - break; - } - m >>= 1; - b = b & 1 ? (b >> 1) ^ POLY : b >> 1; - } - return p; -} - -/* - Return x^(n * 2^k) modulo p(x). Requires that x2n_table[] has been - initialized. - */ -local z_crc_t x2nmodp( - z_off64_t n, - unsigned k) -{ - z_crc_t p; - - p = (z_crc_t)1 << 31; /* x^0 == 1 */ - while (n) { - if (n & 1) - p = multmodp(x2n_table[k & 31], p); - n >>= 1; - k++; - } - return p; -} - /* ========================================================================= * This function can be used by asm versions of crc32(), and to force the * generation of the CRC tables in a threaded application. */ -const z_crc_t FAR * ZEXPORT get_crc_table() -{ +const z_crc_t FAR * ZEXPORT get_crc_table(void) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -619,11 +572,8 @@ const z_crc_t FAR * ZEXPORT get_crc_tabl #define Z_BATCH_ZEROS 0xa10d3d0c /* computed from Z_BATCH = 3990 */ #define Z_BATCH_MIN 800 /* fewest words in a final batch */ -unsigned long ZEXPORT crc32_z( - unsigned long crc, - const unsigned char FAR *buf, - z_size_t len) -{ +unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, + z_size_t len) { z_crc_t val; z_word_t crc1, crc2; const z_word_t *word; @@ -723,18 +673,14 @@ unsigned long ZEXPORT crc32_z( least-significant byte of the word as the first byte of data, without any pre or post conditioning. This is used to combine the CRCs of each braid. */ -local z_crc_t crc_word( - z_word_t data) -{ +local z_crc_t crc_word(z_word_t data) { int k; for (k = 0; k < W; k++) data = (data >> 8) ^ crc_table[data & 0xff]; return (z_crc_t)data; } -local z_word_t crc_word_big( - z_word_t data) -{ +local z_word_t crc_word_big(z_word_t data) { int k; for (k = 0; k < W; k++) data = (data << 8) ^ @@ -745,11 +691,8 @@ local z_word_t crc_word_big( #endif /* ========================================================================= */ -unsigned long ZEXPORT crc32_z( - unsigned long crc, - const unsigned char FAR *buf, - z_size_t len) -{ +unsigned long ZEXPORT crc32_z(unsigned long crc, const unsigned char FAR *buf, + z_size_t len) { /* Return initial CRC, if requested. */ if (buf == Z_NULL) return 0; @@ -781,8 +724,8 @@ unsigned long ZEXPORT crc32_z( words = (z_word_t const *)buf; /* Do endian check at execution time instead of compile time, since ARM - processors can change the endianess at execution time. If the - compiler knows what the endianess will be, it can optimize out the + processors can change the endianness at execution time. If the + compiler knows what the endianness will be, it can optimize out the check and the unused branch. */ endian = 1; if (*(unsigned char *)&endian) { @@ -1069,20 +1012,13 @@ unsigned long ZEXPORT crc32_z( #endif /* ========================================================================= */ -unsigned long ZEXPORT crc32( - unsigned long crc, - const unsigned char FAR *buf, - uInt len) -{ +unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, + uInt len) { return crc32_z(crc, buf, len); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine64( - uLong crc1, - uLong crc2, - z_off64_t len2) -{ +uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -1090,18 +1026,12 @@ uLong ZEXPORT crc32_combine64( } /* ========================================================================= */ -uLong ZEXPORT crc32_combine( - uLong crc1, - uLong crc2, - z_off_t len2) -{ +uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2) { return crc32_combine64(crc1, crc2, (z_off64_t)len2); } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_gen64( - z_off64_t len2) -{ +uLong ZEXPORT crc32_combine_gen64(z_off64_t len2) { #ifdef DYNAMIC_CRC_TABLE once(&made, make_crc_table); #endif /* DYNAMIC_CRC_TABLE */ @@ -1109,17 +1039,11 @@ uLong ZEXPORT crc32_combine_gen64( } /* ========================================================================= */ -uLong ZEXPORT crc32_combine_gen( - z_off_t len2) -{ +uLong ZEXPORT crc32_combine_gen(z_off_t len2) { return crc32_combine_gen64((z_off64_t)len2); } /* ========================================================================= */ -uLong crc32_combine_op( - uLong crc1, - uLong crc2, - uLong op) -{ +uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op) { return multmodp(op, crc1) ^ (crc2 & 0xffffffff); } Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/deflate.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/deflate.c,v diff -u -p -a -u -p -r1.11 deflate.c --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/deflate.c 14 May 2024 19:38:54 -0000 1.11 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/deflate.c 22 Jan 2025 00:37:42 -0000 @@ -1,5 +1,5 @@ /* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler + * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -52,7 +52,7 @@ #include "deflate.h" const char deflate_copyright[] = - " deflate 1.2.13 Copyright 1995-2022 Jean-loup Gailly and Mark Adler "; + " deflate 1.3.1 Copyright 1995-2024 Jean-loup Gailly and Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -60,9 +60,6 @@ const char deflate_copyright[] = copyright string in the executable of your product. */ -/* =========================================================================== - * Function prototypes. - */ typedef enum { need_more, /* block not completed, need more input or more output */ block_done, /* block flush performed */ @@ -70,29 +67,16 @@ typedef enum { finish_done /* finish done, accept no more input or output */ } block_state; -typedef block_state (*compress_func) OF((deflate_state *s, int flush)); +typedef block_state (*compress_func)(deflate_state *s, int flush); /* Compression function. Returns the block state after the call. */ -local int deflateStateCheck OF((z_streamp strm)); -local void slide_hash OF((deflate_state *s)); -local void fill_window OF((deflate_state *s)); -local block_state deflate_stored OF((deflate_state *s, int flush)); -local block_state deflate_fast OF((deflate_state *s, int flush)); +local block_state deflate_stored(deflate_state *s, int flush); +local block_state deflate_fast(deflate_state *s, int flush); #ifndef FASTEST -local block_state deflate_slow OF((deflate_state *s, int flush)); -#endif -local block_state deflate_rle OF((deflate_state *s, int flush)); -local block_state deflate_huff OF((deflate_state *s, int flush)); -local void lm_init OF((deflate_state *s)); -local void putShortMSB OF((deflate_state *s, uInt b)); -local void flush_pending OF((z_streamp strm)); -local unsigned read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); -local uInt longest_match OF((deflate_state *s, IPos cur_match)); - -#ifdef ZLIB_DEBUG -local void check_match OF((deflate_state *s, IPos start, IPos match, - int length)); +local block_state deflate_slow(deflate_state *s, int flush); #endif +local block_state deflate_rle(deflate_state *s, int flush); +local block_state deflate_huff(deflate_state *s, int flush); /* =========================================================================== * Local data @@ -195,9 +179,12 @@ local const config configuration_table[1 * bit values at the expense of memory usage). We slide even when level == 0 to * keep the hash table consistent if we switch back to level > 0 later. */ -local void slide_hash( - deflate_state *s) -{ +#if defined(__has_feature) +# if __has_feature(memory_sanitizer) + __attribute__((no_sanitize("memory"))) +# endif +#endif +local void slide_hash(deflate_state *s) { unsigned n, m; Posf *p; uInt wsize = s->w_size; @@ -221,29 +208,177 @@ local void slide_hash( #endif } +/* =========================================================================== + * Read a new buffer from the current input stream, update the adler32 + * and total number of bytes read. All deflate() input goes through + * this function so some applications may wish to modify it to avoid + * allocating a large strm->next_in buffer and copying from it. + * (See also flush_pending()). + */ +local unsigned read_buf(z_streamp strm, Bytef *buf, unsigned size) { + unsigned len = strm->avail_in; + + if (len > size) len = size; + if (len == 0) return 0; + + strm->avail_in -= len; + + zmemcpy(buf, strm->next_in, len); + if (strm->state->wrap == 1) { + strm->adler = adler32(strm->adler, buf, len); + } +#ifdef GZIP + else if (strm->state->wrap == 2) { + strm->adler = crc32(strm->adler, buf, len); + } +#endif + strm->next_in += len; + strm->total_in += len; + + return len; +} + +/* =========================================================================== + * Fill the window when the lookahead becomes insufficient. + * Updates strstart and lookahead. + * + * IN assertion: lookahead < MIN_LOOKAHEAD + * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD + * At least one byte has been read, or avail_in == 0; reads are + * performed for at least two bytes (required for the zip translate_eol + * option -- not supported here). + */ +local void fill_window(deflate_state *s) { + unsigned n; + unsigned more; /* Amount of free space at the end of the window. */ + uInt wsize = s->w_size; + + Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); + + do { + more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); + + /* Deal with !@#$% 64K limit: */ + if (sizeof(int) <= 2) { + if (more == 0 && s->strstart == 0 && s->lookahead == 0) { + more = wsize; + + } else if (more == (unsigned)(-1)) { + /* Very unlikely, but possible on 16 bit machine if + * strstart == 0 && lookahead == 1 (input done a byte at time) + */ + more--; + } + } + + /* If the window is almost full and there is insufficient lookahead, + * move the upper half to the lower one to make room in the upper half. + */ + if (s->strstart >= wsize + MAX_DIST(s)) { + + zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more); + s->match_start -= wsize; + s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ + s->block_start -= (long) wsize; + if (s->insert > s->strstart) + s->insert = s->strstart; + slide_hash(s); + more += wsize; + } + if (s->strm->avail_in == 0) break; + + /* If there was no sliding: + * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && + * more == window_size - lookahead - strstart + * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) + * => more >= window_size - 2*WSIZE + 2 + * In the BIG_MEM or MMAP case (not yet supported), + * window_size == input_size + MIN_LOOKAHEAD && + * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. + * Otherwise, window_size == 2*WSIZE so more >= 2. + * If there was sliding, more >= WSIZE. So in all cases, more >= 2. + */ + Assert(more >= 2, "more < 2"); + + n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); + s->lookahead += n; + + /* Initialize the hash value now that we have some input: */ + if (s->lookahead + s->insert >= MIN_MATCH) { + uInt str = s->strstart - s->insert; + s->ins_h = s->window[str]; + UPDATE_HASH(s, s->ins_h, s->window[str + 1]); +#if MIN_MATCH != 3 + Call UPDATE_HASH() MIN_MATCH-3 more times +#endif + while (s->insert) { + UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); +#ifndef FASTEST + s->prev[str & s->w_mask] = s->head[s->ins_h]; +#endif + s->head[s->ins_h] = (Pos)str; + str++; + s->insert--; + if (s->lookahead + s->insert < MIN_MATCH) + break; + } + } + /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, + * but this is not important since only literal bytes will be emitted. + */ + + } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); + + /* If the WIN_INIT bytes after the end of the current data have never been + * written, then zero those bytes in order to avoid memory check reports of + * the use of uninitialized (or uninitialised as Julian writes) bytes by + * the longest match routines. Update the high water mark for the next + * time through here. WIN_INIT is set to MAX_MATCH since the longest match + * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. + */ + if (s->high_water < s->window_size) { + ulg curr = s->strstart + (ulg)(s->lookahead); + ulg init; + + if (s->high_water < curr) { + /* Previous high water mark below current data -- zero WIN_INIT + * bytes or up to end of window, whichever is less. + */ + init = s->window_size - curr; + if (init > WIN_INIT) + init = WIN_INIT; + zmemzero(s->window + curr, (unsigned)init); + s->high_water = curr + init; + } + else if (s->high_water < (ulg)curr + WIN_INIT) { + /* High water mark at or above current data, but below current data + * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up + * to end of window, whichever is less. + */ + init = (ulg)curr + WIN_INIT - s->high_water; + if (init > s->window_size - s->high_water) + init = s->window_size - s->high_water; + zmemzero(s->window + s->high_water, (unsigned)init); + s->high_water += init; + } + } + + Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, + "not enough room for search"); +} + /* ========================================================================= */ -int ZEXPORT deflateInit_( - z_streamp strm, - int level, - const char *version, - int stream_size) -{ +int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, + int stream_size) { return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, version, stream_size); /* To do: ignore strm->next_in if we use it as window */ } /* ========================================================================= */ -int ZEXPORT deflateInit2_( - z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy, - const char *version, - int stream_size) -{ +int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, + int windowBits, int memLevel, int strategy, + const char *version, int stream_size) { deflate_state *s; int wrap = 1; static const char my_version[] = ZLIB_VERSION; @@ -358,7 +493,7 @@ int ZEXPORT deflateInit2_( * symbols from which it is being constructed. */ - s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, 4); + s->pending_buf = (uchf *) ZALLOC(strm, s->lit_bufsize, LIT_BUFS); s->pending_buf_size = (ulg)s->lit_bufsize * 4; if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || @@ -368,8 +503,14 @@ int ZEXPORT deflateInit2_( deflateEnd (strm); return Z_MEM_ERROR; } +#ifdef LIT_MEM + s->d_buf = (ushf *)(s->pending_buf + (s->lit_bufsize << 1)); + s->l_buf = s->pending_buf + (s->lit_bufsize << 2); + s->sym_end = s->lit_bufsize - 1; +#else s->sym_buf = s->pending_buf + s->lit_bufsize; s->sym_end = (s->lit_bufsize - 1) * 3; +#endif /* We avoid equality with lit_bufsize*3 because of wraparound at 64K * on 16 bit machines and because stored blocks are restricted to * 64K-1 bytes. @@ -385,9 +526,7 @@ int ZEXPORT deflateInit2_( /* ========================================================================= * Check for a valid deflate stream state. Return 0 if ok, 1 if not. */ -local int deflateStateCheck ( - z_streamp strm) -{ +local int deflateStateCheck(z_streamp strm) { deflate_state *s; if (strm == Z_NULL || strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) @@ -408,11 +547,8 @@ local int deflateStateCheck ( } /* ========================================================================= */ -int ZEXPORT deflateSetDictionary ( - z_streamp strm, - const Bytef *dictionary, - uInt dictLength) -{ +int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength) { deflate_state *s; uInt str, n; int wrap; @@ -477,11 +613,8 @@ int ZEXPORT deflateSetDictionary ( } /* ========================================================================= */ -int ZEXPORT deflateGetDictionary ( - z_streamp strm, - Bytef *dictionary, - uInt *dictLength) -{ +int ZEXPORT deflateGetDictionary(z_streamp strm, Bytef *dictionary, + uInt *dictLength) { deflate_state *s; uInt len; @@ -499,9 +632,7 @@ int ZEXPORT deflateGetDictionary ( } /* ========================================================================= */ -int ZEXPORT deflateResetKeep ( - z_streamp strm) -{ +int ZEXPORT deflateResetKeep(z_streamp strm) { deflate_state *s; if (deflateStateCheck(strm)) { @@ -536,10 +667,32 @@ int ZEXPORT deflateResetKeep ( return Z_OK; } +/* =========================================================================== + * Initialize the "longest match" routines for a new zlib stream + */ +local void lm_init(deflate_state *s) { + s->window_size = (ulg)2L*s->w_size; + + CLEAR_HASH(s); + + /* Set the default configuration parameters: + */ + s->max_lazy_match = configuration_table[s->level].max_lazy; + s->good_match = configuration_table[s->level].good_length; + s->nice_match = configuration_table[s->level].nice_length; + s->max_chain_length = configuration_table[s->level].max_chain; + + s->strstart = 0; + s->block_start = 0L; + s->lookahead = 0; + s->insert = 0; + s->match_length = s->prev_length = MIN_MATCH-1; + s->match_available = 0; + s->ins_h = 0; +} + /* ========================================================================= */ -int ZEXPORT deflateReset ( - z_streamp strm) -{ +int ZEXPORT deflateReset(z_streamp strm) { int ret; ret = deflateResetKeep(strm); @@ -549,10 +702,7 @@ int ZEXPORT deflateReset ( } /* ========================================================================= */ -int ZEXPORT deflateSetHeader ( - z_streamp strm, - gz_headerp head) -{ +int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head) { if (deflateStateCheck(strm) || strm->state->wrap != 2) return Z_STREAM_ERROR; strm->state->gzhead = head; @@ -560,11 +710,7 @@ int ZEXPORT deflateSetHeader ( } /* ========================================================================= */ -int ZEXPORT deflatePending ( - z_streamp strm, - unsigned *pending, - int *bits) -{ +int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) { if (deflateStateCheck(strm)) return Z_STREAM_ERROR; if (pending != Z_NULL) *pending = strm->state->pending; @@ -574,19 +720,21 @@ int ZEXPORT deflatePending ( } /* ========================================================================= */ -int ZEXPORT deflatePrime ( - z_streamp strm, - int bits, - int value) -{ +int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) { deflate_state *s; int put; if (deflateStateCheck(strm)) return Z_STREAM_ERROR; s = strm->state; +#ifdef LIT_MEM + if (bits < 0 || bits > 16 || + (uchf *)s->d_buf < s->pending_out + ((Buf_size + 7) >> 3)) + return Z_BUF_ERROR; +#else if (bits < 0 || bits > 16 || s->sym_buf < s->pending_out + ((Buf_size + 7) >> 3)) return Z_BUF_ERROR; +#endif do { put = Buf_size - s->bi_valid; if (put > bits) @@ -601,11 +749,7 @@ int ZEXPORT deflatePrime ( } /* ========================================================================= */ -int ZEXPORT deflateParams( - z_streamp strm, - int level, - int strategy) -{ +int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) { deflate_state *s; compress_func func; @@ -650,13 +794,8 @@ int ZEXPORT deflateParams( } /* ========================================================================= */ -int ZEXPORT deflateTune( - z_streamp strm, - int good_length, - int max_lazy, - int nice_length, - int max_chain) -{ +int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, + int nice_length, int max_chain) { deflate_state *s; if (deflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -692,10 +831,7 @@ int ZEXPORT deflateTune( * * Shifts are used to approximate divisions, for speed. */ -uLong ZEXPORT deflateBound( - z_streamp strm, - uLong sourceLen) -{ +uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) { deflate_state *s; uLong fixedlen, storelen, wraplen; @@ -751,7 +887,8 @@ uLong ZEXPORT deflateBound( /* if not default parameters, return one of the conservative bounds */ if (s->w_bits != 15 || s->hash_bits != 8 + 7) - return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen; + return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) + + wraplen; /* default settings: return tight bound for that case -- ~0.03% overhead plus a small constant */ @@ -764,10 +901,7 @@ uLong ZEXPORT deflateBound( * IN assertion: the stream state is correct and there is enough room in * pending_buf. */ -local void putShortMSB ( - deflate_state *s, - uInt b) -{ +local void putShortMSB(deflate_state *s, uInt b) { put_byte(s, (Byte)(b >> 8)); put_byte(s, (Byte)(b & 0xff)); } @@ -778,9 +912,7 @@ local void putShortMSB ( * applications may wish to modify it to avoid allocating a large * strm->next_out buffer and copying into it. (See also read_buf()). */ -local void flush_pending( - z_streamp strm) -{ +local void flush_pending(z_streamp strm) { unsigned len; deflate_state *s = strm->state; @@ -811,10 +943,7 @@ local void flush_pending( } while (0) /* ========================================================================= */ -int ZEXPORT deflate ( - z_streamp strm, - int flush) -{ +int ZEXPORT deflate(z_streamp strm, int flush) { int old_flush; /* value of flush param for previous deflate call */ deflate_state *s; @@ -1126,9 +1255,7 @@ int ZEXPORT deflate ( } /* ========================================================================= */ -int ZEXPORT deflateEnd ( - z_streamp strm) -{ +int ZEXPORT deflateEnd(z_streamp strm) { int status; if (deflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1152,11 +1279,10 @@ int ZEXPORT deflateEnd ( * To simplify the source, this is not supported for 16-bit MSDOS (which * doesn't have enough memory anyway to duplicate compression states). */ -int ZEXPORT deflateCopy ( - z_streamp dest, - z_streamp source) -{ +int ZEXPORT deflateCopy(z_streamp dest, z_streamp source) { #ifdef MAXSEG_64K + (void)dest; + (void)source; return Z_STREAM_ERROR; #else deflate_state *ds; @@ -1169,18 +1295,18 @@ int ZEXPORT deflateCopy ( ss = source->state; - zmemcpy((Bytef*)dest, (Bytef*)source, sizeof(z_stream)); + zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); if (ds == Z_NULL) return Z_MEM_ERROR; dest->state = (struct internal_state FAR *) ds; - zmemcpy((Bytef*)ds, (Bytef*)ss, sizeof(deflate_state)); + zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); ds->strm = dest; ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, 4); + ds->pending_buf = (uchf *) ZALLOC(dest, ds->lit_bufsize, LIT_BUFS); if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || ds->pending_buf == Z_NULL) { @@ -1189,12 +1315,17 @@ int ZEXPORT deflateCopy ( } /* following zmemcpy do not work for 16-bit MSDOS */ zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); - zmemcpy((Bytef*)ds->prev, (Bytef*)ss->prev, ds->w_size * sizeof(Pos)); - zmemcpy((Bytef*)ds->head, (Bytef*)ss->head, ds->hash_size * sizeof(Pos)); - zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); + zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); + zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); + zmemcpy(ds->pending_buf, ss->pending_buf, ds->lit_bufsize * LIT_BUFS); ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); +#ifdef LIT_MEM + ds->d_buf = (ushf *)(ds->pending_buf + (ds->lit_bufsize << 1)); + ds->l_buf = ds->pending_buf + (ds->lit_bufsize << 2); +#else ds->sym_buf = ds->pending_buf + ds->lit_bufsize; +#endif ds->l_desc.dyn_tree = ds->dyn_ltree; ds->d_desc.dyn_tree = ds->dyn_dtree; @@ -1204,66 +1335,6 @@ int ZEXPORT deflateCopy ( #endif /* MAXSEG_64K */ } -/* =========================================================================== - * Read a new buffer from the current input stream, update the adler32 - * and total number of bytes read. All deflate() input goes through - * this function so some applications may wish to modify it to avoid - * allocating a large strm->next_in buffer and copying from it. - * (See also flush_pending()). - */ -local unsigned read_buf( - z_streamp strm, - Bytef *buf, - unsigned size) -{ - unsigned len = strm->avail_in; - - if (len > size) len = size; - if (len == 0) return 0; - - strm->avail_in -= len; - - zmemcpy(buf, strm->next_in, len); - if (strm->state->wrap == 1) { - strm->adler = adler32(strm->adler, buf, len); - } -#ifdef GZIP - else if (strm->state->wrap == 2) { - strm->adler = crc32(strm->adler, buf, len); - } -#endif - strm->next_in += len; - strm->total_in += len; - - return len; -} - -/* =========================================================================== - * Initialize the "longest match" routines for a new zlib stream - */ -local void lm_init ( - deflate_state *s) -{ - s->window_size = (ulg)2L*s->w_size; - - CLEAR_HASH(s); - - /* Set the default configuration parameters: - */ - s->max_lazy_match = configuration_table[s->level].max_lazy; - s->good_match = configuration_table[s->level].good_length; - s->nice_match = configuration_table[s->level].nice_length; - s->max_chain_length = configuration_table[s->level].max_chain; - - s->strstart = 0; - s->block_start = 0L; - s->lookahead = 0; - s->insert = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - s->ins_h = 0; -} - #ifndef FASTEST /* =========================================================================== * Set match_start to the longest match starting at the given string and @@ -1274,14 +1345,11 @@ local void lm_init ( * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 * OUT assertion: the match length is not greater than s->lookahead. */ -local uInt longest_match( - deflate_state *s, - IPos cur_match) -{ +local uInt longest_match(deflate_state *s, IPos cur_match) { unsigned chain_length = s->max_chain_length;/* max hash chain length */ - Bytef *scan = s->window + s->strstart; /* current string */ - Bytef *match; /* matched string */ - int len; /* length of current match */ + register Bytef *scan = s->window + s->strstart; /* current string */ + register Bytef *match; /* matched string */ + register int len; /* length of current match */ int best_len = (int)s->prev_length; /* best match length so far */ int nice_match = s->nice_match; /* stop if match long enough */ IPos limit = s->strstart > (IPos)MAX_DIST(s) ? @@ -1296,13 +1364,13 @@ local uInt longest_match( /* Compare two bytes at a time. Note: this is not always beneficial. * Try with and without -DUNALIGNED_OK to check. */ - Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; - ush scan_start = *(ushf*)scan; - ush scan_end = *(ushf*)(scan + best_len - 1); + register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; + register ush scan_start = *(ushf*)scan; + register ush scan_end = *(ushf*)(scan + best_len - 1); #else - Bytef *strend = s->window + s->strstart + MAX_MATCH; - Byte scan_end1 = scan[best_len - 1]; - Byte scan_end = scan[best_len]; + register Bytef *strend = s->window + s->strstart + MAX_MATCH; + register Byte scan_end1 = scan[best_len - 1]; + register Byte scan_end = scan[best_len]; #endif /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. @@ -1425,14 +1493,11 @@ local uInt longest_match( /* --------------------------------------------------------------------------- * Optimized version for FASTEST only */ -local uInt longest_match( - deflate_state *s, - IPos cur_match) -{ - Bytef *scan = s->window + s->strstart; /* current string */ - Bytef *match; /* matched string */ - int len; /* length of current match */ - Bytef *strend = s->window + s->strstart + MAX_MATCH; +local uInt longest_match(deflate_state *s, IPos cur_match) { + register Bytef *scan = s->window + s->strstart; /* current string */ + register Bytef *match; /* matched string */ + register int len; /* length of current match */ + register Bytef *strend = s->window + s->strstart + MAX_MATCH; /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. * It is easy to get rid of this optimization if necessary. @@ -1489,20 +1554,23 @@ local uInt longest_match( /* =========================================================================== * Check that the match at match_start is indeed a match. */ -local void check_match( - deflate_state *s, - IPos start, - IPos match, - int length) -{ +local void check_match(deflate_state *s, IPos start, IPos match, int length) { /* check that the match is indeed a match */ - if (zmemcmp(s->window + match, - s->window + start, length) != EQUAL) { - fprintf(stderr, " start %u, match %u, length %d\n", - start, match, length); + Bytef *back = s->window + (int)match, *here = s->window + start; + IPos len = length; + if (match == (IPos)-1) { + /* match starts one byte before the current window -- just compare the + subsequent length-1 bytes */ + back++; + here++; + len--; + } + if (zmemcmp(back, here, len) != EQUAL) { + fprintf(stderr, " start %u, match %d, length %d\n", + start, (int)match, length); do { - fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); - } while (--length != 0); + fprintf(stderr, "(%02x %02x)", *back++, *here++); + } while (--len != 0); z_error("invalid match"); } if (z_verbose > 1) { @@ -1515,137 +1583,6 @@ local void check_match( #endif /* ZLIB_DEBUG */ /* =========================================================================== - * Fill the window when the lookahead becomes insufficient. - * Updates strstart and lookahead. - * - * IN assertion: lookahead < MIN_LOOKAHEAD - * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD - * At least one byte has been read, or avail_in == 0; reads are - * performed for at least two bytes (required for the zip translate_eol - * option -- not supported here). - */ -local void fill_window( - deflate_state *s) -{ - unsigned n; - unsigned more; /* Amount of free space at the end of the window. */ - uInt wsize = s->w_size; - - Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); - - do { - more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); - - /* Deal with !@#$% 64K limit: */ - if (sizeof(int) <= 2) { - if (more == 0 && s->strstart == 0 && s->lookahead == 0) { - more = wsize; - - } else if (more == (unsigned)(-1)) { - /* Very unlikely, but possible on 16 bit machine if - * strstart == 0 && lookahead == 1 (input done a byte at time) - */ - more--; - } - } - - /* If the window is almost full and there is insufficient lookahead, - * move the upper half to the lower one to make room in the upper half. - */ - if (s->strstart >= wsize + MAX_DIST(s)) { - - zmemcpy(s->window, s->window + wsize, (unsigned)wsize - more); - s->match_start -= wsize; - s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ - s->block_start -= (long) wsize; - if (s->insert > s->strstart) - s->insert = s->strstart; - slide_hash(s); - more += wsize; - } - if (s->strm->avail_in == 0) break; - - /* If there was no sliding: - * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && - * more == window_size - lookahead - strstart - * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) - * => more >= window_size - 2*WSIZE + 2 - * In the BIG_MEM or MMAP case (not yet supported), - * window_size == input_size + MIN_LOOKAHEAD && - * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. - * Otherwise, window_size == 2*WSIZE so more >= 2. - * If there was sliding, more >= WSIZE. So in all cases, more >= 2. - */ - Assert(more >= 2, "more < 2"); - - n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); - s->lookahead += n; - - /* Initialize the hash value now that we have some input: */ - if (s->lookahead + s->insert >= MIN_MATCH) { - uInt str = s->strstart - s->insert; - s->ins_h = s->window[str]; - UPDATE_HASH(s, s->ins_h, s->window[str + 1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - while (s->insert) { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - s->insert--; - if (s->lookahead + s->insert < MIN_MATCH) - break; - } - } - /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, - * but this is not important since only literal bytes will be emitted. - */ - - } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); - - /* If the WIN_INIT bytes after the end of the current data have never been - * written, then zero those bytes in order to avoid memory check reports of - * the use of uninitialized (or uninitialised as Julian writes) bytes by - * the longest match routines. Update the high water mark for the next - * time through here. WIN_INIT is set to MAX_MATCH since the longest match - * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. - */ - if (s->high_water < s->window_size) { - ulg curr = s->strstart + (ulg)(s->lookahead); - ulg init; - - if (s->high_water < curr) { - /* Previous high water mark below current data -- zero WIN_INIT - * bytes or up to end of window, whichever is less. - */ - init = s->window_size - curr; - if (init > WIN_INIT) - init = WIN_INIT; - zmemzero(s->window + curr, (unsigned)init); - s->high_water = curr + init; - } - else if (s->high_water < (ulg)curr + WIN_INIT) { - /* High water mark at or above current data, but below current data - * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up - * to end of window, whichever is less. - */ - init = (ulg)curr + WIN_INIT - s->high_water; - if (init > s->window_size - s->high_water) - init = s->window_size - s->high_water; - zmemzero(s->window + s->high_water, (unsigned)init); - s->high_water += init; - } - } - - Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, - "not enough room for search"); -} - -/* =========================================================================== * Flush the current block, with given end-of-file flag. * IN assertion: strstart is set to the end of the current match. */ @@ -1687,10 +1624,7 @@ local void fill_window( * copied. It is most efficient with large input and output buffers, which * maximizes the opportunities to have a single copy from next_in to next_out. */ -local block_state deflate_stored( - deflate_state *s, - int flush) -{ +local block_state deflate_stored(deflate_state *s, int flush) { /* Smallest worthy block size when not flushing or finishing. By default * this is 32K. This can be as small as 507 bytes for memLevel == 1. For * large input and output buffers, the stored block size will be larger. @@ -1874,10 +1808,7 @@ local block_state deflate_stored( * new strings in the dictionary only for unmatched strings or for short * matches. It is used only for the fast compression options. */ -local block_state deflate_fast( - deflate_state *s, - int flush) -{ +local block_state deflate_fast(deflate_state *s, int flush) { IPos hash_head; /* head of the hash chain */ int bflush; /* set if current block must be flushed */ @@ -1976,10 +1907,7 @@ local block_state deflate_fast( * evaluation for matches: a match is finally adopted only if there is * no better match at the next window position. */ -local block_state deflate_slow( - deflate_state *s, - int flush) -{ +local block_state deflate_slow(deflate_state *s, int flush) { IPos hash_head; /* head of hash chain */ int bflush; /* set if current block must be flushed */ @@ -2107,10 +2035,7 @@ local block_state deflate_slow( * one. Do not maintain a hash table. (It will be regenerated if this run of * deflate switches away from Z_RLE.) */ -local block_state deflate_rle( - deflate_state *s, - int flush) -{ +local block_state deflate_rle(deflate_state *s, int flush) { int bflush; /* set if current block must be flushed */ uInt prev; /* byte at distance one to match */ Bytef *scan, *strend; /* scan goes up to strend for length of run */ @@ -2181,10 +2106,7 @@ local block_state deflate_rle( * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. * (It will be regenerated if this run of deflate switches away from Huffman.) */ -local block_state deflate_huff( - deflate_state *s, - int flush) -{ +local block_state deflate_huff(deflate_state *s, int flush) { int bflush; /* set if current block must be flushed */ for (;;) { Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/deflate.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/deflate.h,v diff -u -p -a -u -p -r1.10 deflate.h --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/deflate.h 14 May 2024 19:38:54 -0000 1.10 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/deflate.h 22 Jan 2025 00:37:42 -0000 @@ -1,5 +1,5 @@ /* deflate.h -- internal compression state - * Copyright (C) 1995-2018 Jean-loup Gailly + * Copyright (C) 1995-2024 Jean-loup Gailly * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -23,6 +23,10 @@ # define GZIP #endif +/* define LIT_MEM to slightly increase the speed of deflate (order 1% to 2%) at + the cost of a larger memory footprint */ +/* #define LIT_MEM */ + /* =========================================================================== * Internal compression state. */ @@ -217,7 +221,14 @@ typedef struct internal_state { /* Depth of each subtree used as tie breaker for trees of equal frequency */ +#ifdef LIT_MEM +# define LIT_BUFS 5 + ushf *d_buf; /* buffer for distances */ + uchf *l_buf; /* buffer for literals/lengths */ +#else +# define LIT_BUFS 4 uchf *sym_buf; /* buffer for distances and literals/lengths */ +#endif uInt lit_bufsize; /* Size of match buffer for literals/lengths. There are 4 reasons for @@ -239,7 +250,7 @@ typedef struct internal_state { * - I can't count above 4 */ - uInt sym_next; /* running index in sym_buf */ + uInt sym_next; /* running index in symbol buffer */ uInt sym_end; /* symbol table full when sym_next reaches this */ ulg opt_len; /* bit length of current block with optimal trees */ @@ -291,14 +302,14 @@ typedef struct internal_state { memory checker errors from longest match routines */ /* in trees.c */ -void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); -int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); -void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); -void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); +void ZLIB_INTERNAL _tr_init(deflate_state *s); +int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc); +void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, + ulg stored_len, int last); +void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s); +void ZLIB_INTERNAL _tr_align(deflate_state *s); +void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, + ulg stored_len, int last); #define d_code(dist) \ ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) @@ -318,6 +329,25 @@ void ZLIB_INTERNAL _tr_stored_block OF(( extern const uch ZLIB_INTERNAL _dist_code[]; #endif +#ifdef LIT_MEM +# define _tr_tally_lit(s, c, flush) \ + { uch cc = (c); \ + s->d_buf[s->sym_next] = 0; \ + s->l_buf[s->sym_next++] = cc; \ + s->dyn_ltree[cc].Freq++; \ + flush = (s->sym_next == s->sym_end); \ + } +# define _tr_tally_dist(s, distance, length, flush) \ + { uch len = (uch)(length); \ + ush dist = (ush)(distance); \ + s->d_buf[s->sym_next] = dist; \ + s->l_buf[s->sym_next++] = len; \ + dist--; \ + s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ + s->dyn_dtree[d_code(dist)].Freq++; \ + flush = (s->sym_next == s->sym_end); \ + } +#else # define _tr_tally_lit(s, c, flush) \ { uch cc = (c); \ s->sym_buf[s->sym_next++] = 0; \ @@ -337,6 +367,7 @@ void ZLIB_INTERNAL _tr_stored_block OF(( s->dyn_dtree[d_code(dist)].Freq++; \ flush = (s->sym_next == s->sym_end); \ } +#endif #else # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) # define _tr_tally_dist(s, distance, length, flush) \ Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/infback.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/infback.c,v diff -u -p -a -u -p -r1.1.1.7 infback.c --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/infback.c 14 May 2024 19:36:31 -0000 1.1.1.7 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/infback.c 22 Jan 2025 00:37:42 -0000 @@ -15,9 +15,6 @@ #include "inflate.h" #include "inffast.h" -/* function prototypes */ -local void fixedtables OF((struct inflate_state FAR *state)); - /* strm provides memory allocation functions in zalloc and zfree, or Z_NULL to use the library memory allocation functions. @@ -25,13 +22,9 @@ local void fixedtables OF((struct inflat windowBits is in the range 8..15, and window is a user-supplied window and output buffer that is 2**windowBits bytes. */ -int ZEXPORT inflateBackInit_( - z_streamp strm, - int windowBits, - unsigned char FAR *window, - const char *version, - int stream_size) -{ +int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, + unsigned char FAR *window, const char *version, + int stream_size) { struct inflate_state FAR *state; if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || @@ -80,9 +73,7 @@ int ZEXPORT inflateBackInit_( used for threaded applications, since the rewriting of the tables and virgin may not be thread-safe. */ -local void fixedtables( - struct inflate_state FAR *state) -{ +local void fixedtables(struct inflate_state FAR *state) { #ifdef BUILDFIXED static int virgin = 1; static code *lenfix, *distfix; @@ -248,13 +239,8 @@ local void fixedtables( inflateBack() can also return Z_STREAM_ERROR if the input parameters are not correct, i.e. strm is Z_NULL or the state was not initialized. */ -int ZEXPORT inflateBack( - z_streamp strm, - in_func in, - void FAR *in_desc, - out_func out, - void FAR *out_desc) -{ +int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc) { struct inflate_state FAR *state; z_const unsigned char FAR *next; /* next input */ unsigned char FAR *put; /* next output */ @@ -632,9 +618,7 @@ int ZEXPORT inflateBack( return ret; } -int ZEXPORT inflateBackEnd( - z_streamp strm) -{ +int ZEXPORT inflateBackEnd(z_streamp strm) { if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) return Z_STREAM_ERROR; ZFREE(strm, strm->state); Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inffast.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inffast.c,v diff -u -p -a -u -p -r1.1.1.5 inffast.c --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inffast.c 15 Feb 2023 01:32:40 -0000 1.1.1.5 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inffast.c 22 Jan 2025 00:37:42 -0000 @@ -47,10 +47,7 @@ requires strm->avail_out >= 258 for each loop to avoid checking for output space. */ -void ZLIB_INTERNAL inflate_fast( - z_streamp strm, - unsigned start) -{ +void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start) { struct inflate_state FAR *state; z_const unsigned char FAR *in; /* local strm->next_in */ z_const unsigned char FAR *last; /* have enough input while in < last */ Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inffast.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inffast.h,v diff -u -p -a -u -p -r1.1.1.2 inffast.h --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inffast.h 25 Mar 2013 20:06:49 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inffast.h 22 Jan 2025 00:37:42 -0000 @@ -8,4 +8,4 @@ subject to change. Applications should only use zlib.h. */ -void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); +void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start); Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inflate.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inflate.c,v diff -u -p -a -u -p -r1.6 inflate.c --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inflate.c 14 May 2024 19:38:54 -0000 1.6 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inflate.c 22 Jan 2025 00:37:42 -0000 @@ -91,20 +91,7 @@ # endif #endif -/* function prototypes */ -local int inflateStateCheck OF((z_streamp strm)); -local void fixedtables OF((struct inflate_state FAR *state)); -local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, - unsigned copy)); -#ifdef BUILDFIXED - void makefixed OF((void)); -#endif -local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, - unsigned len)); - -local int inflateStateCheck( - z_streamp strm) -{ +local int inflateStateCheck(z_streamp strm) { struct inflate_state FAR *state; if (strm == Z_NULL || strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) @@ -116,9 +103,7 @@ local int inflateStateCheck( return 0; } -int ZEXPORT inflateResetKeep( - z_streamp strm) -{ +int ZEXPORT inflateResetKeep(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -142,9 +127,7 @@ int ZEXPORT inflateResetKeep( return Z_OK; } -int ZEXPORT inflateReset( - z_streamp strm) -{ +int ZEXPORT inflateReset(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -155,10 +138,7 @@ int ZEXPORT inflateReset( return inflateResetKeep(strm); } -int ZEXPORT inflateReset2( - z_streamp strm, - int windowBits) -{ +int ZEXPORT inflateReset2(z_streamp strm, int windowBits) { int wrap; struct inflate_state FAR *state; @@ -195,12 +175,8 @@ int ZEXPORT inflateReset2( return inflateReset(strm); } -int ZEXPORT inflateInit2_( - z_streamp strm, - int windowBits, - const char *version, - int stream_size) -{ +int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, + const char *version, int stream_size) { int ret; struct inflate_state FAR *state; @@ -239,22 +215,17 @@ int ZEXPORT inflateInit2_( return ret; } -int ZEXPORT inflateInit_( - z_streamp strm, - const char *version, - int stream_size) -{ +int ZEXPORT inflateInit_(z_streamp strm, const char *version, + int stream_size) { return inflateInit2_(strm, DEF_WBITS, version, stream_size); } -int ZEXPORT inflatePrime( - z_streamp strm, - int bits, - int value) -{ +int ZEXPORT inflatePrime(z_streamp strm, int bits, int value) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; + if (bits == 0) + return Z_OK; state = (struct inflate_state FAR *)strm->state; if (bits < 0) { state->hold = 0; @@ -278,9 +249,7 @@ int ZEXPORT inflatePrime( used for threaded applications, since the rewriting of the tables and virgin may not be thread-safe. */ -local void fixedtables( - struct inflate_state FAR *state) -{ +local void fixedtables(struct inflate_state FAR *state) { #ifdef BUILDFIXED static int virgin = 1; static code *lenfix, *distfix; @@ -342,7 +311,7 @@ local void fixedtables( a.out > inffixed.h */ -void makefixed() +void makefixed(void) { unsigned low, size; struct inflate_state state; @@ -396,11 +365,7 @@ void makefixed() output will fall in the output data, making match copies simpler and faster. The advantage may be dependent on the size of the processor's data caches. */ -local int updatewindow( - z_streamp strm, - const Bytef *end, - unsigned copy) -{ +local int updatewindow(z_streamp strm, const Bytef *end, unsigned copy) { struct inflate_state FAR *state; unsigned dist; @@ -622,10 +587,7 @@ local int updatewindow( will return Z_BUF_ERROR if it has not reached the end of the stream. */ -int ZEXPORT inflate( - z_streamp strm, - int flush) -{ +int ZEXPORT inflate(z_streamp strm, int flush) { struct inflate_state FAR *state; z_const unsigned char FAR *next; /* next input */ unsigned char FAR *put; /* next output */ @@ -1301,9 +1263,7 @@ int ZEXPORT inflate( return ret; } -int ZEXPORT inflateEnd( - z_streamp strm) -{ +int ZEXPORT inflateEnd(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1315,11 +1275,8 @@ int ZEXPORT inflateEnd( return Z_OK; } -int ZEXPORT inflateGetDictionary( - z_streamp strm, - Bytef *dictionary, - uInt *dictLength) -{ +int ZEXPORT inflateGetDictionary(z_streamp strm, Bytef *dictionary, + uInt *dictLength) { struct inflate_state FAR *state; /* check state */ @@ -1338,11 +1295,8 @@ int ZEXPORT inflateGetDictionary( return Z_OK; } -int ZEXPORT inflateSetDictionary( - z_streamp strm, - const Bytef *dictionary, - uInt dictLength) -{ +int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, + uInt dictLength) { struct inflate_state FAR *state; unsigned long dictid; int ret; @@ -1373,10 +1327,7 @@ int ZEXPORT inflateSetDictionary( return Z_OK; } -int ZEXPORT inflateGetHeader( - z_streamp strm, - gz_headerp head) -{ +int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head) { struct inflate_state FAR *state; /* check state */ @@ -1401,11 +1352,8 @@ int ZEXPORT inflateGetHeader( called again with more data and the *have state. *have is initialized to zero for the first call. */ -local unsigned syncsearch( - unsigned FAR *have, - const unsigned char FAR *buf, - unsigned len) -{ +local unsigned syncsearch(unsigned FAR *have, const unsigned char FAR *buf, + unsigned len) { unsigned got; unsigned next; @@ -1424,9 +1372,7 @@ local unsigned syncsearch( return next; } -int ZEXPORT inflateSync( - z_streamp strm) -{ +int ZEXPORT inflateSync(z_streamp strm) { unsigned len; /* number of bytes to look at or looked at */ int flags; /* temporary to save header status */ unsigned long in, out; /* temporary to save total_in and total_out */ @@ -1441,7 +1387,7 @@ int ZEXPORT inflateSync( /* if first time, start search in bit buffer */ if (state->mode != SYNC) { state->mode = SYNC; - state->hold <<= state->bits & 7; + state->hold >>= state->bits & 7; state->bits -= state->bits & 7; len = 0; while (state->bits >= 8) { @@ -1482,9 +1428,7 @@ int ZEXPORT inflateSync( block. When decompressing, PPP checks that at the end of input packet, inflate is waiting for these length bytes. */ -int ZEXPORT inflateSyncPoint( - z_streamp strm) -{ +int ZEXPORT inflateSyncPoint(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1492,10 +1436,7 @@ int ZEXPORT inflateSyncPoint( return state->mode == STORED && state->bits == 0; } -int ZEXPORT inflateCopy( - z_streamp dest, - z_streamp source) -{ +int ZEXPORT inflateCopy(z_streamp dest, z_streamp source) { struct inflate_state FAR *state; struct inflate_state FAR *copy; unsigned char FAR *window; @@ -1521,8 +1462,8 @@ int ZEXPORT inflateCopy( } /* copy state */ - zmemcpy((Bytef*)dest, (Bytef*)source, sizeof(z_stream)); - zmemcpy((Bytef*)copy, (Bytef*)state, sizeof(struct inflate_state)); + zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); + zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); copy->strm = dest; if (state->lencode >= state->codes && state->lencode <= state->codes + ENOUGH - 1) { @@ -1539,10 +1480,7 @@ int ZEXPORT inflateCopy( return Z_OK; } -int ZEXPORT inflateUndermine( - z_streamp strm, - int subvert) -{ +int ZEXPORT inflateUndermine(z_streamp strm, int subvert) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1557,10 +1495,7 @@ int ZEXPORT inflateUndermine( #endif } -int ZEXPORT inflateValidate( - z_streamp strm, - int check) -{ +int ZEXPORT inflateValidate(z_streamp strm, int check) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return Z_STREAM_ERROR; @@ -1572,9 +1507,7 @@ int ZEXPORT inflateValidate( return Z_OK; } -long ZEXPORT inflateMark( - z_streamp strm) -{ +long ZEXPORT inflateMark(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) @@ -1585,9 +1518,7 @@ long ZEXPORT inflateMark( (state->mode == MATCH ? state->was - state->length : 0)); } -unsigned long ZEXPORT inflateCodesUsed( - z_streamp strm) -{ +unsigned long ZEXPORT inflateCodesUsed(z_streamp strm) { struct inflate_state FAR *state; if (inflateStateCheck(strm)) return (unsigned long)-1; state = (struct inflate_state FAR *)strm->state; Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inftrees.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inftrees.c,v diff -u -p -a -u -p -r1.1.1.7 inftrees.c --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inftrees.c 14 May 2024 19:36:31 -0000 1.1.1.7 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inftrees.c 22 Jan 2025 00:37:42 -0000 @@ -1,5 +1,5 @@ /* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2022 Mark Adler + * Copyright (C) 1995-2024 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -9,7 +9,7 @@ #define MAXBITS 15 const char inflate_copyright[] = - " inflate 1.2.13 Copyright 1995-2022 Mark Adler "; + " inflate 1.3.1 Copyright 1995-2024 Mark Adler "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -29,14 +29,9 @@ const char inflate_copyright[] = table index bits. It will differ if the request is greater than the longest code or if it is less than the shortest code. */ -int ZLIB_INTERNAL inflate_table( - codetype type, - unsigned short FAR *lens, - unsigned codes, - code FAR * FAR *table, - unsigned FAR *bits, - unsigned short FAR *work) -{ +int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, + unsigned codes, code FAR * FAR *table, + unsigned FAR *bits, unsigned short FAR *work) { unsigned len; /* a code's length in bits */ unsigned sym; /* index of code symbols */ unsigned min, max; /* minimum and maximum code lengths */ @@ -62,7 +57,7 @@ int ZLIB_INTERNAL inflate_table( 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; static const unsigned short lext[31] = { /* Length codes 257..285 extra */ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 194, 65}; + 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 203, 77}; static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inftrees.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inftrees.h,v diff -u -p -a -u -p -r1.1.1.3 inftrees.h --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inftrees.h 14 May 2024 19:36:31 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/inftrees.h 22 Jan 2025 00:37:42 -0000 @@ -41,8 +41,8 @@ typedef struct { examples/enough.c found in the zlib distribution. The arguments to that program are the number of symbols, the initial root table size, and the maximum bit length of a code. "enough 286 9 15" for literal/length codes - returns returns 852, and "enough 30 6 15" for distance codes returns 592. - The initial root table size (9 or 6) is found in the fifth argument of the + returns 852, and "enough 30 6 15" for distance codes returns 592. The + initial root table size (9 or 6) is found in the fifth argument of the inflate_table() calls in inflate.c and infback.c. If the root table size is changed, then these maximum sizes would be need to be recalculated and updated. */ @@ -57,6 +57,6 @@ typedef enum { DISTS } codetype; -int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, - unsigned codes, code FAR * FAR *table, - unsigned FAR *bits, unsigned short FAR *work)); +int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, + unsigned codes, code FAR * FAR *table, + unsigned FAR *bits, unsigned short FAR *work); Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/trees.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/trees.c,v diff -u -p -a -u -p -r1.10 trees.c --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/trees.c 14 May 2024 19:38:54 -0000 1.10 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/trees.c 22 Jan 2025 00:37:42 -0000 @@ -1,6 +1,5 @@ - /* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2021 Jean-loup Gailly + * Copyright (C) 1995-2024 Jean-loup Gailly * detect_data_type() function provided freely by Cosmin Truta, 2006 * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -123,39 +122,116 @@ struct static_tree_desc_s { int max_length; /* max bit length for the codes */ }; -local const static_tree_desc static_l_desc = +#ifdef NO_INIT_GLOBAL_POINTERS +# define TCONST +#else +# define TCONST const +#endif + +local TCONST static_tree_desc static_l_desc = {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; -local const static_tree_desc static_d_desc = +local TCONST static_tree_desc static_d_desc = {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; -local const static_tree_desc static_bl_desc = +local TCONST static_tree_desc static_bl_desc = {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; /* =========================================================================== - * Local (static) routines in this file. + * Output a short LSB first on the stream. + * IN assertion: there is enough room in pendingBuf. + */ +#define put_short(s, w) { \ + put_byte(s, (uch)((w) & 0xff)); \ + put_byte(s, (uch)((ush)(w) >> 8)); \ +} + +/* =========================================================================== + * Reverse the first len bits of a code, using straightforward code (a faster + * method would use a table) + * IN assertion: 1 <= len <= 15 */ +local unsigned bi_reverse(unsigned code, int len) { + register unsigned res = 0; + do { + res |= code & 1; + code >>= 1, res <<= 1; + } while (--len > 0); + return res >> 1; +} -local void tr_static_init OF((void)); -local void init_block OF((deflate_state *s)); -local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); -local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); -local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); -local void build_tree OF((deflate_state *s, tree_desc *desc)); -local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local int build_bl_tree OF((deflate_state *s)); -local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, - int blcodes)); -local void compress_block OF((deflate_state *s, const ct_data *ltree, - const ct_data *dtree)); -local int detect_data_type OF((deflate_state *s)); -local unsigned bi_reverse OF((unsigned code, int len)); -local void bi_windup OF((deflate_state *s)); -local void bi_flush OF((deflate_state *s)); +/* =========================================================================== + * Flush the bit buffer, keeping at most 7 bits in it. + */ +local void bi_flush(deflate_state *s) { + if (s->bi_valid == 16) { + put_short(s, s->bi_buf); + s->bi_buf = 0; + s->bi_valid = 0; + } else if (s->bi_valid >= 8) { + put_byte(s, (Byte)s->bi_buf); + s->bi_buf >>= 8; + s->bi_valid -= 8; + } +} + +/* =========================================================================== + * Flush the bit buffer and align the output on a byte boundary + */ +local void bi_windup(deflate_state *s) { + if (s->bi_valid > 8) { + put_short(s, s->bi_buf); + } else if (s->bi_valid > 0) { + put_byte(s, (Byte)s->bi_buf); + } + s->bi_buf = 0; + s->bi_valid = 0; +#ifdef ZLIB_DEBUG + s->bits_sent = (s->bits_sent + 7) & ~7; +#endif +} + +/* =========================================================================== + * Generate the codes for a given tree and bit counts (which need not be + * optimal). + * IN assertion: the array bl_count contains the bit length statistics for + * the given tree and the field len is set for all tree elements. + * OUT assertion: the field code is set for all tree elements of non + * zero code length. + */ +local void gen_codes(ct_data *tree, int max_code, ushf *bl_count) { + ush next_code[MAX_BITS+1]; /* next code value for each bit length */ + unsigned code = 0; /* running code value */ + int bits; /* bit index */ + int n; /* code index */ + + /* The distribution counts are first used to generate the code values + * without bit reversal. + */ + for (bits = 1; bits <= MAX_BITS; bits++) { + code = (code + bl_count[bits - 1]) << 1; + next_code[bits] = (ush)code; + } + /* Check that the bit counts in bl_count are consistent. The last code + * must be all ones. + */ + Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1, + "inconsistent bit counts"); + Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); + + for (n = 0; n <= max_code; n++) { + int len = tree[n].Len; + if (len == 0) continue; + /* Now reverse the bits */ + tree[n].Code = (ush)bi_reverse(next_code[len]++, len); + + Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", + n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1)); + } +} #ifdef GEN_TREES_H -local void gen_trees_header OF((void)); +local void gen_trees_header(void); #endif #ifndef ZLIB_DEBUG @@ -169,26 +245,11 @@ local void gen_trees_header OF((void)); #endif /* =========================================================================== - * Output a short LSB first on the stream. - * IN assertion: there is enough room in pendingBuf. - */ -#define put_short(s, w) { \ - put_byte(s, (uch)((w) & 0xff)); \ - put_byte(s, (uch)((ush)(w) >> 8)); \ -} - -/* =========================================================================== * Send a value on a given number of bits. * IN assertion: length <= 16 and value fits in length bits. */ #ifdef ZLIB_DEBUG -local void send_bits OF((deflate_state *s, int value, int length)); - -local void send_bits( - deflate_state *s, - int value, - int length) -{ +local void send_bits(deflate_state *s, int value, int length) { Tracevv((stderr," l %2d v %4x ", length, value)); Assert(length > 0 && length <= 15, "invalid length"); s->bits_sent += (ulg)length; @@ -230,8 +291,7 @@ local void send_bits( /* =========================================================================== * Initialize the various 'constant' tables. */ -local void tr_static_init() -{ +local void tr_static_init(void) { #if defined(GEN_TREES_H) || !defined(STDC) static int static_init_done = 0; int n; /* iterates over tree elements */ @@ -324,8 +384,7 @@ local void tr_static_init() ((i) == (last)? "\n};\n\n" : \ ((i) % (width) == (width) - 1 ? ",\n" : ", ")) -void gen_trees_header() -{ +void gen_trees_header(void) { FILE *header = fopen("trees.h", "w"); int i; @@ -375,11 +434,25 @@ void gen_trees_header() #endif /* GEN_TREES_H */ /* =========================================================================== + * Initialize a new block. + */ +local void init_block(deflate_state *s) { + int n; /* iterates over tree elements */ + + /* Initialize the trees. */ + for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; + for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; + for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; + + s->dyn_ltree[END_BLOCK].Freq = 1; + s->opt_len = s->static_len = 0L; + s->sym_next = s->matches = 0; +} + +/* =========================================================================== * Initialize the tree data structures for a new zlib stream. */ -void ZLIB_INTERNAL _tr_init( - deflate_state *s) -{ +void ZLIB_INTERNAL _tr_init(deflate_state *s) { tr_static_init(); s->l_desc.dyn_tree = s->dyn_ltree; @@ -402,24 +475,6 @@ void ZLIB_INTERNAL _tr_init( init_block(s); } -/* =========================================================================== - * Initialize a new block. - */ -local void init_block( - deflate_state *s) -{ - int n; /* iterates over tree elements */ - - /* Initialize the trees. */ - for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; - for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; - for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; - - s->dyn_ltree[END_BLOCK].Freq = 1; - s->opt_len = s->static_len = 0L; - s->sym_next = s->matches = 0; -} - #define SMALLEST 1 /* Index within the heap array of least frequent node in the Huffman tree */ @@ -449,11 +504,7 @@ local void init_block( * when the heap property is re-established (each father smaller than its * two sons). */ -local void pqdownheap( - deflate_state *s, - ct_data *tree, - int k) -{ +local void pqdownheap(deflate_state *s, ct_data *tree, int k) { int v = s->heap[k]; int j = k << 1; /* left son of k */ while (j <= s->heap_len) { @@ -484,10 +535,7 @@ local void pqdownheap( * The length opt_len is updated; static_len is also updated if stree is * not null. */ -local void gen_bitlen( - deflate_state *s, - tree_desc *desc) -{ +local void gen_bitlen(deflate_state *s, tree_desc *desc) { ct_data *tree = desc->dyn_tree; int max_code = desc->max_code; const ct_data *stree = desc->stat_desc->static_tree; @@ -562,48 +610,9 @@ local void gen_bitlen( } } -/* =========================================================================== - * Generate the codes for a given tree and bit counts (which need not be - * optimal). - * IN assertion: the array bl_count contains the bit length statistics for - * the given tree and the field len is set for all tree elements. - * OUT assertion: the field code is set for all tree elements of non - * zero code length. - */ -local void gen_codes ( - ct_data *tree, - int max_code, - ushf *bl_count) -{ - ush next_code[MAX_BITS+1]; /* next code value for each bit length */ - unsigned code = 0; /* running code value */ - int bits; /* bit index */ - int n; /* code index */ - - /* The distribution counts are first used to generate the code values - * without bit reversal. - */ - for (bits = 1; bits <= MAX_BITS; bits++) { - code = (code + bl_count[bits - 1]) << 1; - next_code[bits] = (ush)code; - } - /* Check that the bit counts in bl_count are consistent. The last code - * must be all ones. - */ - Assert (code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1, - "inconsistent bit counts"); - Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); - - for (n = 0; n <= max_code; n++) { - int len = tree[n].Len; - if (len == 0) continue; - /* Now reverse the bits */ - tree[n].Code = (ush)bi_reverse(next_code[len]++, len); - - Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", - n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len] - 1)); - } -} +#ifdef DUMP_BL_TREE +# include +#endif /* =========================================================================== * Construct one Huffman tree and assigns the code bit strings and lengths. @@ -613,10 +622,7 @@ local void gen_codes ( * and corresponding code. The length opt_len is updated; static_len is * also updated if stree is not null. The field max_code is set. */ -local void build_tree( - deflate_state *s, - tree_desc *desc) -{ +local void build_tree(deflate_state *s, tree_desc *desc) { ct_data *tree = desc->dyn_tree; const ct_data *stree = desc->stat_desc->static_tree; int elems = desc->stat_desc->elems; @@ -701,11 +707,7 @@ local void build_tree( * Scan a literal or distance tree to determine the frequencies of the codes * in the bit length tree. */ -local void scan_tree ( - deflate_state *s, - ct_data *tree, - int max_code) -{ +local void scan_tree(deflate_state *s, ct_data *tree, int max_code) { int n; /* iterates over all tree elements */ int prevlen = -1; /* last emitted length */ int curlen; /* length of current code */ @@ -746,11 +748,7 @@ local void scan_tree ( * Send a literal or distance tree in compressed form, using the codes in * bl_tree. */ -local void send_tree ( - deflate_state *s, - ct_data *tree, - int max_code) -{ +local void send_tree(deflate_state *s, ct_data *tree, int max_code) { int n; /* iterates over all tree elements */ int prevlen = -1; /* last emitted length */ int curlen; /* length of current code */ @@ -797,9 +795,7 @@ local void send_tree ( * Construct the Huffman tree for the bit lengths and return the index in * bl_order of the last bit length code to send. */ -local int build_bl_tree( - deflate_state *s) -{ +local int build_bl_tree(deflate_state *s) { int max_blindex; /* index of last bit length code of non zero freq */ /* Determine the bit length frequencies for literal and distance trees */ @@ -832,12 +828,8 @@ local int build_bl_tree( * lengths of the bit length codes, the literal tree and the distance tree. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. */ -local void send_all_trees( - deflate_state *s, - int lcodes, - int dcodes, - int blcodes) -{ +local void send_all_trees(deflate_state *s, int lcodes, int dcodes, + int blcodes) { int rank; /* index in bl_order */ Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); @@ -863,12 +855,8 @@ local void send_all_trees( /* =========================================================================== * Send a stored block */ -void ZLIB_INTERNAL _tr_stored_block( - deflate_state *s, - charf *buf, - ulg stored_len, - int last) -{ +void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, + ulg stored_len, int last) { send_bits(s, (STORED_BLOCK<<1) + last, 3); /* send block type */ bi_windup(s); /* align on byte boundary */ put_short(s, (ush)stored_len); @@ -887,9 +875,7 @@ void ZLIB_INTERNAL _tr_stored_block( /* =========================================================================== * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) */ -void ZLIB_INTERNAL _tr_flush_bits( - deflate_state *s) -{ +void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s) { bi_flush(s); } @@ -897,9 +883,7 @@ void ZLIB_INTERNAL _tr_flush_bits( * Send one empty static block to give enough lookahead for inflate. * This takes 10 bits, of which 7 may remain in the bit buffer. */ -void ZLIB_INTERNAL _tr_align( - deflate_state *s) -{ +void ZLIB_INTERNAL _tr_align(deflate_state *s) { send_bits(s, STATIC_TREES<<1, 3); send_code(s, END_BLOCK, static_ltree); #ifdef ZLIB_DEBUG @@ -909,15 +893,107 @@ void ZLIB_INTERNAL _tr_align( } /* =========================================================================== + * Send the block data compressed using the given Huffman trees + */ +local void compress_block(deflate_state *s, const ct_data *ltree, + const ct_data *dtree) { + unsigned dist; /* distance of matched string */ + int lc; /* match length or unmatched char (if dist == 0) */ + unsigned sx = 0; /* running index in symbol buffers */ + unsigned code; /* the code to send */ + int extra; /* number of extra bits to send */ + + if (s->sym_next != 0) do { +#ifdef LIT_MEM + dist = s->d_buf[sx]; + lc = s->l_buf[sx++]; +#else + dist = s->sym_buf[sx++] & 0xff; + dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; + lc = s->sym_buf[sx++]; +#endif + if (dist == 0) { + send_code(s, lc, ltree); /* send a literal byte */ + Tracecv(isgraph(lc), (stderr," '%c' ", lc)); + } else { + /* Here, lc is the match length - MIN_MATCH */ + code = _length_code[lc]; + send_code(s, code + LITERALS + 1, ltree); /* send length code */ + extra = extra_lbits[code]; + if (extra != 0) { + lc -= base_length[code]; + send_bits(s, lc, extra); /* send the extra length bits */ + } + dist--; /* dist is now the match distance - 1 */ + code = d_code(dist); + Assert (code < D_CODES, "bad d_code"); + + send_code(s, code, dtree); /* send the distance code */ + extra = extra_dbits[code]; + if (extra != 0) { + dist -= (unsigned)base_dist[code]; + send_bits(s, dist, extra); /* send the extra distance bits */ + } + } /* literal or match pair ? */ + + /* Check for no overlay of pending_buf on needed symbols */ +#ifdef LIT_MEM + Assert(s->pending < 2 * (s->lit_bufsize + sx), "pendingBuf overflow"); +#else + Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); +#endif + + } while (sx < s->sym_next); + + send_code(s, END_BLOCK, ltree); +} + +/* =========================================================================== + * Check if the data type is TEXT or BINARY, using the following algorithm: + * - TEXT if the two conditions below are satisfied: + * a) There are no non-portable control characters belonging to the + * "block list" (0..6, 14..25, 28..31). + * b) There is at least one printable character belonging to the + * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). + * - BINARY otherwise. + * - The following partially-portable control characters form a + * "gray list" that is ignored in this detection algorithm: + * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). + * IN assertion: the fields Freq of dyn_ltree are set. + */ +local int detect_data_type(deflate_state *s) { + /* block_mask is the bit mask of block-listed bytes + * set bits 0..6, 14..25, and 28..31 + * 0xf3ffc07f = binary 11110011111111111100000001111111 + */ + unsigned long block_mask = 0xf3ffc07fUL; + int n; + + /* Check for non-textual ("block-listed") bytes. */ + for (n = 0; n <= 31; n++, block_mask >>= 1) + if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0)) + return Z_BINARY; + + /* Check for textual ("allow-listed") bytes. */ + if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 + || s->dyn_ltree[13].Freq != 0) + return Z_TEXT; + for (n = 32; n < LITERALS; n++) + if (s->dyn_ltree[n].Freq != 0) + return Z_TEXT; + + /* There are no "block-listed" or "allow-listed" bytes: + * this stream either is empty or has tolerated ("gray-listed") bytes only. + */ + return Z_BINARY; +} + +/* =========================================================================== * Determine the best encoding for the current block: dynamic trees, static * trees or store, and write out the encoded block. */ -void ZLIB_INTERNAL _tr_flush_block( - deflate_state *s, - charf *buf, - ulg stored_len, - int last) -{ +void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, + ulg stored_len, int last) { ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ int max_blindex = 0; /* index of last bit length code of non zero freq */ @@ -1014,14 +1090,15 @@ void ZLIB_INTERNAL _tr_flush_block( * Save the match info and tally the frequency counts. Return true if * the current block must be flushed. */ -int ZLIB_INTERNAL _tr_tally ( - deflate_state *s, - unsigned dist, - unsigned lc) -{ +int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc) { +#ifdef LIT_MEM + s->d_buf[s->sym_next] = (ush)dist; + s->l_buf[s->sym_next++] = (uch)lc; +#else s->sym_buf[s->sym_next++] = (uch)dist; s->sym_buf[s->sym_next++] = (uch)(dist >> 8); s->sym_buf[s->sym_next++] = (uch)lc; +#endif if (dist == 0) { /* lc is the unmatched char */ s->dyn_ltree[lc].Freq++; @@ -1037,148 +1114,4 @@ int ZLIB_INTERNAL _tr_tally ( s->dyn_dtree[d_code(dist)].Freq++; } return (s->sym_next == s->sym_end); -} - -/* =========================================================================== - * Send the block data compressed using the given Huffman trees - */ -local void compress_block( - deflate_state *s, - const ct_data *ltree, - const ct_data *dtree) -{ - unsigned dist; /* distance of matched string */ - int lc; /* match length or unmatched char (if dist == 0) */ - unsigned sx = 0; /* running index in sym_buf */ - unsigned code; /* the code to send */ - int extra; /* number of extra bits to send */ - - if (s->sym_next != 0) do { - dist = s->sym_buf[sx++] & 0xff; - dist += (unsigned)(s->sym_buf[sx++] & 0xff) << 8; - lc = s->sym_buf[sx++]; - if (dist == 0) { - send_code(s, lc, ltree); /* send a literal byte */ - Tracecv(isgraph(lc), (stderr," '%c' ", lc)); - } else { - /* Here, lc is the match length - MIN_MATCH */ - code = _length_code[lc]; - send_code(s, code + LITERALS + 1, ltree); /* send length code */ - extra = extra_lbits[code]; - if (extra != 0) { - lc -= base_length[code]; - send_bits(s, lc, extra); /* send the extra length bits */ - } - dist--; /* dist is now the match distance - 1 */ - code = d_code(dist); - Assert (code < D_CODES, "bad d_code"); - - send_code(s, code, dtree); /* send the distance code */ - extra = extra_dbits[code]; - if (extra != 0) { - dist -= (unsigned)base_dist[code]; - send_bits(s, dist, extra); /* send the extra distance bits */ - } - } /* literal or match pair ? */ - - /* Check that the overlay between pending_buf and sym_buf is ok: */ - Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow"); - - } while (sx < s->sym_next); - - send_code(s, END_BLOCK, ltree); -} - -/* =========================================================================== - * Check if the data type is TEXT or BINARY, using the following algorithm: - * - TEXT if the two conditions below are satisfied: - * a) There are no non-portable control characters belonging to the - * "block list" (0..6, 14..25, 28..31). - * b) There is at least one printable character belonging to the - * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). - * - BINARY otherwise. - * - The following partially-portable control characters form a - * "gray list" that is ignored in this detection algorithm: - * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). - * IN assertion: the fields Freq of dyn_ltree are set. - */ -local int detect_data_type( - deflate_state *s) -{ - /* block_mask is the bit mask of block-listed bytes - * set bits 0..6, 14..25, and 28..31 - * 0xf3ffc07f = binary 11110011111111111100000001111111 - */ - unsigned long block_mask = 0xf3ffc07fUL; - int n; - - /* Check for non-textual ("block-listed") bytes. */ - for (n = 0; n <= 31; n++, block_mask >>= 1) - if ((block_mask & 1) && (s->dyn_ltree[n].Freq != 0)) - return Z_BINARY; - - /* Check for textual ("allow-listed") bytes. */ - if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 - || s->dyn_ltree[13].Freq != 0) - return Z_TEXT; - for (n = 32; n < LITERALS; n++) - if (s->dyn_ltree[n].Freq != 0) - return Z_TEXT; - - /* There are no "block-listed" or "allow-listed" bytes: - * this stream either is empty or has tolerated ("gray-listed") bytes only. - */ - return Z_BINARY; -} - -/* =========================================================================== - * Reverse the first len bits of a code, using straightforward code (a faster - * method would use a table) - * IN assertion: 1 <= len <= 15 - */ -local unsigned bi_reverse( - unsigned code, - int len) -{ - unsigned res = 0; - do { - res |= code & 1; - code >>= 1, res <<= 1; - } while (--len > 0); - return res >> 1; -} - -/* =========================================================================== - * Flush the bit buffer, keeping at most 7 bits in it. - */ -local void bi_flush( - deflate_state *s) -{ - if (s->bi_valid == 16) { - put_short(s, s->bi_buf); - s->bi_buf = 0; - s->bi_valid = 0; - } else if (s->bi_valid >= 8) { - put_byte(s, (Byte)s->bi_buf); - s->bi_buf >>= 8; - s->bi_valid -= 8; - } -} - -/* =========================================================================== - * Flush the bit buffer and align the output on a byte boundary - */ -local void bi_windup( - deflate_state *s) -{ - if (s->bi_valid > 8) { - put_short(s, s->bi_buf); - } else if (s->bi_valid > 0) { - put_byte(s, (Byte)s->bi_buf); - } - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef ZLIB_DEBUG - s->bits_sent = (s->bits_sent + 7) & ~7; -#endif } Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/uncompr.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/uncompr.c,v diff -u -p -a -u -p -r1.5 uncompr.c --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/uncompr.c 13 Feb 2019 21:15:08 -0000 1.5 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/uncompr.c 22 Jan 2025 00:37:42 -0000 @@ -24,12 +24,8 @@ Z_DATA_ERROR if the input data was corrupted, including if the input data is an incomplete zlib stream. */ -int ZEXPORT uncompress2 ( - Bytef *dest, - uLongf *destLen, - const Bytef *source, - uLong *sourceLen) -{ +int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source, + uLong *sourceLen) { z_stream stream; int err; const uInt max = (uInt)-1; @@ -83,11 +79,7 @@ int ZEXPORT uncompress2 ( err; } -int ZEXPORT uncompress ( - Bytef *dest, - uLongf *destLen, - const Bytef *source, - uLong sourceLen) -{ +int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, + uLong sourceLen) { return uncompress2(dest, destLen, source, &sourceLen); } Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zconf.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zconf.h,v diff -u -p -a -u -p -r1.8 zconf.h --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zconf.h 14 May 2024 19:38:54 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zconf.h 22 Jan 2025 00:37:42 -0000 @@ -1,5 +1,5 @@ /* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler + * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -38,6 +38,9 @@ # define crc32 Perl_crz_crc32 # define crc32_combine Perl_crz_crc32_combine # define crc32_combine64 Perl_crz_crc32_combine64 +# define crc32_combine_gen Perl_crz_crc32_combine_gen +# define crc32_combine_gen64 Perl_crz_crc32_combine_gen64 +# define crc32_combine_op Perl_crz_crc32_combine_op # define crc32_z Perl_crz_crc32_z # define deflate Perl_crz_deflate # define deflateBound Perl_crz_deflateBound @@ -238,7 +241,11 @@ #endif #ifdef Z_SOLO - typedef unsigned long z_size_t; +# ifdef _WIN64 + typedef unsigned long long z_size_t; +# else + typedef unsigned long z_size_t; +# endif #else # define z_longlong long long # if defined(NO_SIZE_T) @@ -293,14 +300,6 @@ # endif #endif -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - /* The following definitions for FAR are needed only for MSDOS mixed * model programming (small or medium model with some far allocations). * This was tested only with MSC; for other MSDOS compilers you may have @@ -409,12 +408,12 @@ typedef uLong FAR uLongf; #ifdef STDC typedef void const *voidpc; - typedef void FAR *voidpf; - typedef void *voidp; + typedef Bytef *voidpf; + typedef Bytef *voidp; #else typedef Byte const *voidpc; - typedef Byte FAR *voidpf; - typedef Byte *voidp; + typedef Bytef *voidpf; + typedef Bytef *voidp; #endif #if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) @@ -517,7 +516,7 @@ typedef uLong FAR uLongf; #if !defined(_WIN32) && defined(Z_LARGE64) # define z_off64_t off64_t #else -# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# if defined(_WIN32) && !defined(__GNUC__) # define z_off64_t __int64 # else # define z_off64_t z_off_t Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zlib.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zlib.h,v diff -u -p -a -u -p -r1.1.1.7 zlib.h --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zlib.h 14 May 2024 19:36:31 -0000 1.1.1.7 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zlib.h 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,7 @@ /* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.13, October 13th, 2022 + version 1.3.1, January 22nd, 2024 - Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler + Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -37,11 +37,11 @@ extern "C" { #endif -#define ZLIB_VERSION "1.2.13" -#define ZLIB_VERNUM 0x12d0 +#define ZLIB_VERSION "1.3.1" +#define ZLIB_VERNUM 0x1310 #define ZLIB_VER_MAJOR 1 -#define ZLIB_VER_MINOR 2 -#define ZLIB_VER_REVISION 13 +#define ZLIB_VER_MINOR 3 +#define ZLIB_VER_REVISION 1 #define ZLIB_VER_SUBREVISION 0 /* @@ -78,8 +78,8 @@ extern "C" { even in the case of corrupted input. */ -typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); -typedef void (*free_func) OF((voidpf opaque, voidpf address)); +typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size); +typedef void (*free_func)(voidpf opaque, voidpf address); struct internal_state; @@ -217,7 +217,7 @@ typedef gz_header FAR *gz_headerp; /* basic functions */ -ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +ZEXTERN const char * ZEXPORT zlibVersion(void); /* The application can compare zlibVersion and ZLIB_VERSION for consistency. If the first character differs, the library code actually used is not compatible with the zlib.h header file used by the application. This check @@ -225,12 +225,12 @@ ZEXTERN const char * ZEXPORT zlibVersion */ /* -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); +ZEXTERN int ZEXPORT deflateInit(z_streamp strm, int level); Initializes the internal stream state for compression. The fields zalloc, zfree and opaque must be initialized before by the caller. If zalloc and zfree are set to Z_NULL, deflateInit updates them to use default - allocation functions. + allocation functions. total_in, total_out, adler, and msg are initialized. The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all @@ -247,7 +247,7 @@ ZEXTERN int ZEXPORT deflateInit OF((z_st */ -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +ZEXTERN int ZEXPORT deflate(z_streamp strm, int flush); /* deflate compresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce @@ -320,8 +320,8 @@ ZEXTERN int ZEXPORT deflate OF((z_stream with the same value of the flush parameter and more output space (updated avail_out), until the flush is complete (deflate returns with non-zero avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that - avail_out is greater than six to avoid repeated flush markers due to - avail_out == 0 on return. + avail_out is greater than six when the flush marker begins, in order to avoid + repeated flush markers upon calling deflate() again when avail_out == 0. If the parameter flush is set to Z_FINISH, pending input is processed, pending output is flushed and deflate returns with Z_STREAM_END if there was @@ -360,7 +360,7 @@ ZEXTERN int ZEXPORT deflate OF((z_stream */ -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT deflateEnd(z_streamp strm); /* All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending @@ -375,7 +375,7 @@ ZEXTERN int ZEXPORT deflateEnd OF((z_str /* -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateInit(z_streamp strm); Initializes the internal stream state for decompression. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized before by @@ -383,7 +383,8 @@ ZEXTERN int ZEXPORT inflateInit OF((z_st read or consumed. The allocation of a sliding window will be deferred to the first call of inflate (if the decompression does not complete on the first call). If zalloc and zfree are set to Z_NULL, inflateInit updates - them to use default allocation functions. + them to use default allocation functions. total_in, total_out, adler, and + msg are initialized. inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_VERSION_ERROR if the zlib library version is incompatible with the @@ -397,7 +398,7 @@ ZEXTERN int ZEXPORT inflateInit OF((z_st */ -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +ZEXTERN int ZEXPORT inflate(z_streamp strm, int flush); /* inflate decompresses as much data as possible, and stops when the input buffer becomes empty or the output buffer becomes full. It may introduce @@ -517,7 +518,7 @@ ZEXTERN int ZEXPORT inflate OF((z_stream */ -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateEnd(z_streamp strm); /* All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending @@ -535,12 +536,12 @@ ZEXTERN int ZEXPORT inflateEnd OF((z_str */ /* -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy)); +ZEXTERN int ZEXPORT deflateInit2(z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy); This is another version of deflateInit with more compression options. The fields zalloc, zfree and opaque must be initialized before by the caller. @@ -607,9 +608,9 @@ ZEXTERN int ZEXPORT deflateInit2 OF((z_s compression: this will be done by deflate(). */ -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); +ZEXTERN int ZEXPORT deflateSetDictionary(z_streamp strm, + const Bytef *dictionary, + uInt dictLength); /* Initializes the compression dictionary from the given byte sequence without producing any compressed output. When using the zlib format, this @@ -651,9 +652,9 @@ ZEXTERN int ZEXPORT deflateSetDictionary not perform any compression: this will be done by deflate(). */ -ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, - Bytef *dictionary, - uInt *dictLength)); +ZEXTERN int ZEXPORT deflateGetDictionary(z_streamp strm, + Bytef *dictionary, + uInt *dictLength); /* Returns the sliding dictionary being maintained by deflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied @@ -673,8 +674,8 @@ ZEXTERN int ZEXPORT deflateGetDictionary stream state is inconsistent. */ -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, - z_streamp source)); +ZEXTERN int ZEXPORT deflateCopy(z_streamp dest, + z_streamp source); /* Sets the destination stream as a complete copy of the source stream. @@ -691,20 +692,20 @@ ZEXTERN int ZEXPORT deflateCopy OF((z_st destination. */ -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +ZEXTERN int ZEXPORT deflateReset(z_streamp strm); /* This function is equivalent to deflateEnd followed by deflateInit, but does not free and reallocate the internal compression state. The stream will leave the compression level and any other attributes that may have been - set unchanged. + set unchanged. total_in, total_out, adler, and msg are initialized. deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being Z_NULL). */ -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, - int level, - int strategy)); +ZEXTERN int ZEXPORT deflateParams(z_streamp strm, + int level, + int strategy); /* Dynamically update the compression level and compression strategy. The interpretation of level and strategy is as in deflateInit2(). This can be @@ -729,7 +730,7 @@ ZEXTERN int ZEXPORT deflateParams OF((z_ Then no more input data should be provided before the deflateParams() call. If this is done, the old level and strategy will be applied to the data compressed before deflateParams(), and the new level and strategy will be - applied to the the data compressed after deflateParams(). + applied to the data compressed after deflateParams(). deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if @@ -740,11 +741,11 @@ ZEXTERN int ZEXPORT deflateParams OF((z_ retried with more output space. */ -ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, - int good_length, - int max_lazy, - int nice_length, - int max_chain)); +ZEXTERN int ZEXPORT deflateTune(z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain); /* Fine tune deflate's internal compression parameters. This should only be used by someone who understands the algorithm used by zlib's deflate for @@ -757,8 +758,8 @@ ZEXTERN int ZEXPORT deflateTune OF((z_st returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. */ -ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, - uLong sourceLen)); +ZEXTERN uLong ZEXPORT deflateBound(z_streamp strm, + uLong sourceLen); /* deflateBound() returns an upper bound on the compressed size after deflation of sourceLen bytes. It must be called after deflateInit() or @@ -772,9 +773,9 @@ ZEXTERN uLong ZEXPORT deflateBound OF((z than Z_FINISH or Z_NO_FLUSH are used. */ -ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, - unsigned *pending, - int *bits)); +ZEXTERN int ZEXPORT deflatePending(z_streamp strm, + unsigned *pending, + int *bits); /* deflatePending() returns the number of bytes and bits of output that have been generated, but not yet provided in the available output. The bytes not @@ -787,9 +788,9 @@ ZEXTERN int ZEXPORT deflatePending OF((z stream state was inconsistent. */ -ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, - int bits, - int value)); +ZEXTERN int ZEXPORT deflatePrime(z_streamp strm, + int bits, + int value); /* deflatePrime() inserts bits in the deflate output stream. The intent is that this function is used to start off the deflate output with the bits @@ -804,8 +805,8 @@ ZEXTERN int ZEXPORT deflatePrime OF((z_s source stream state was inconsistent. */ -ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, - gz_headerp head)); +ZEXTERN int ZEXPORT deflateSetHeader(z_streamp strm, + gz_headerp head); /* deflateSetHeader() provides gzip header information for when a gzip stream is requested by deflateInit2(). deflateSetHeader() may be called @@ -821,16 +822,17 @@ ZEXTERN int ZEXPORT deflateSetHeader OF( gzip file" and give up. If deflateSetHeader is not used, the default gzip header has text false, - the time set to zero, and os set to 255, with no extra, name, or comment - fields. The gzip header is returned to the default state by deflateReset(). + the time set to zero, and os set to the current operating system, with no + extra, name, or comment fields. The gzip header is returned to the default + state by deflateReset(). deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent. */ /* -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); +ZEXTERN int ZEXPORT inflateInit2(z_streamp strm, + int windowBits); This is another version of inflateInit with an extra parameter. The fields next_in, avail_in, zalloc, zfree and opaque must be initialized @@ -883,9 +885,9 @@ ZEXTERN int ZEXPORT inflateInit2 OF((z_s deferred until inflate() is called. */ -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); +ZEXTERN int ZEXPORT inflateSetDictionary(z_streamp strm, + const Bytef *dictionary, + uInt dictLength); /* Initializes the decompression dictionary from the given uncompressed byte sequence. This function must be called immediately after a call of inflate, @@ -906,9 +908,9 @@ ZEXTERN int ZEXPORT inflateSetDictionary inflate(). */ -ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, - Bytef *dictionary, - uInt *dictLength)); +ZEXTERN int ZEXPORT inflateGetDictionary(z_streamp strm, + Bytef *dictionary, + uInt *dictLength); /* Returns the sliding dictionary being maintained by inflate. dictLength is set to the number of bytes in the dictionary, and that many bytes are copied @@ -921,7 +923,7 @@ ZEXTERN int ZEXPORT inflateGetDictionary stream state is inconsistent. */ -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateSync(z_streamp strm); /* Skips invalid compressed data until a possible full flush point (see above for the description of deflate with Z_FULL_FLUSH) can be found, or until all @@ -934,14 +936,14 @@ ZEXTERN int ZEXPORT inflateSync OF((z_st inflateSync returns Z_OK if a possible full flush point has been found, Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. - In the success case, the application may save the current current value of - total_in which indicates where valid compressed data was found. In the - error case, the application may repeatedly call inflateSync, providing more - input each time, until success or end of the input data. + In the success case, the application may save the current value of total_in + which indicates where valid compressed data was found. In the error case, + the application may repeatedly call inflateSync, providing more input each + time, until success or end of the input data. */ -ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, - z_streamp source)); +ZEXTERN int ZEXPORT inflateCopy(z_streamp dest, + z_streamp source); /* Sets the destination stream as a complete copy of the source stream. @@ -956,18 +958,19 @@ ZEXTERN int ZEXPORT inflateCopy OF((z_st destination. */ -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateReset(z_streamp strm); /* This function is equivalent to inflateEnd followed by inflateInit, but does not free and reallocate the internal decompression state. The stream will keep attributes that may have been set by inflateInit2. + total_in, total_out, adler, and msg are initialized. inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source stream state was inconsistent (such as zalloc or state being Z_NULL). */ -ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, - int windowBits)); +ZEXTERN int ZEXPORT inflateReset2(z_streamp strm, + int windowBits); /* This function is the same as inflateReset, but it also permits changing the wrap and window size requests. The windowBits parameter is interpreted @@ -980,9 +983,9 @@ ZEXTERN int ZEXPORT inflateReset2 OF((z_ the windowBits parameter is invalid. */ -ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, - int bits, - int value)); +ZEXTERN int ZEXPORT inflatePrime(z_streamp strm, + int bits, + int value); /* This function inserts bits in the inflate input stream. The intent is that this function is used to start inflating at a bit position in the @@ -1001,7 +1004,7 @@ ZEXTERN int ZEXPORT inflatePrime OF((z_s stream state was inconsistent. */ -ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +ZEXTERN long ZEXPORT inflateMark(z_streamp strm); /* This function returns two values, one in the lower 16 bits of the return value, and the other in the remaining upper bits, obtained by shifting the @@ -1029,8 +1032,8 @@ ZEXTERN long ZEXPORT inflateMark OF((z_s source stream state was inconsistent. */ -ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, - gz_headerp head)); +ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm, + gz_headerp head); /* inflateGetHeader() requests that gzip header information be stored in the provided gz_header structure. inflateGetHeader() may be called after @@ -1070,8 +1073,8 @@ ZEXTERN int ZEXPORT inflateGetHeader OF( */ /* -ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, - unsigned char FAR *window)); +ZEXTERN int ZEXPORT inflateBackInit(z_streamp strm, int windowBits, + unsigned char FAR *window); Initialize the internal stream state for decompression using inflateBack() calls. The fields zalloc, zfree and opaque in strm must be initialized @@ -1091,13 +1094,13 @@ ZEXTERN int ZEXPORT inflateBackInit OF(( the version of the header file. */ -typedef unsigned (*in_func) OF((void FAR *, - z_const unsigned char FAR * FAR *)); -typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); - -ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, - in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc)); +typedef unsigned (*in_func)(void FAR *, + z_const unsigned char FAR * FAR *); +typedef int (*out_func)(void FAR *, unsigned char FAR *, unsigned); + +ZEXTERN int ZEXPORT inflateBack(z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc); /* inflateBack() does a raw inflate with a single call using a call-back interface for input and output. This is potentially more efficient than @@ -1165,7 +1168,7 @@ ZEXTERN int ZEXPORT inflateBack OF((z_st cannot return Z_OK. */ -ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +ZEXTERN int ZEXPORT inflateBackEnd(z_streamp strm); /* All memory allocated by inflateBackInit() is freed. @@ -1173,7 +1176,7 @@ ZEXTERN int ZEXPORT inflateBackEnd OF((z state was inconsistent. */ -ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +ZEXTERN uLong ZEXPORT zlibCompileFlags(void); /* Return flags indicating compile-time options. Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: @@ -1226,8 +1229,8 @@ ZEXTERN uLong ZEXPORT zlibCompileFlags O you need special options. */ -ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); +ZEXTERN int ZEXPORT compress(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen); /* Compresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size @@ -1241,9 +1244,9 @@ ZEXTERN int ZEXPORT compress OF((Bytef * buffer. */ -ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen, - int level)); +ZEXTERN int ZEXPORT compress2(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level); /* Compresses the source buffer into the destination buffer. The level parameter has the same meaning as in deflateInit. sourceLen is the byte @@ -1257,15 +1260,15 @@ ZEXTERN int ZEXPORT compress2 OF((Bytef Z_STREAM_ERROR if the level parameter is invalid. */ -ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +ZEXTERN uLong ZEXPORT compressBound(uLong sourceLen); /* compressBound() returns an upper bound on the compressed size after compress() or compress2() on sourceLen bytes. It would be used before a compress() or compress2() call to allocate the destination buffer. */ -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); +ZEXTERN int ZEXPORT uncompress(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen); /* Decompresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size @@ -1282,8 +1285,8 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef buffer with the uncompressed data up to that point. */ -ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong *sourceLen)); +ZEXTERN int ZEXPORT uncompress2(Bytef *dest, uLongf *destLen, + const Bytef *source, uLong *sourceLen); /* Same as uncompress, except that sourceLen is a pointer, where the length of the source is *sourceLen. On return, *sourceLen is the number of @@ -1302,7 +1305,7 @@ ZEXTERN int ZEXPORT uncompress2 OF((Byte typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ /* -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); +ZEXTERN gzFile ZEXPORT gzopen(const char *path, const char *mode); Open the gzip (.gz) file at path for reading and decompressing, or compressing and writing. The mode parameter is as in fopen ("rb" or "wb") @@ -1339,7 +1342,7 @@ ZEXTERN gzFile ZEXPORT gzopen OF((const file could not be opened. */ -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +ZEXTERN gzFile ZEXPORT gzdopen(int fd, const char *mode); /* Associate a gzFile with the file descriptor fd. File descriptors are obtained from calls like open, dup, creat, pipe or fileno (if the file has @@ -1362,7 +1365,7 @@ ZEXTERN gzFile ZEXPORT gzdopen OF((int f will not detect if fd is invalid (unless fd is -1). */ -ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +ZEXTERN int ZEXPORT gzbuffer(gzFile file, unsigned size); /* Set the internal buffer size used by this library's functions for file to size. The default buffer size is 8192 bytes. This function must be called @@ -1378,7 +1381,7 @@ ZEXTERN int ZEXPORT gzbuffer OF((gzFile too late. */ -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +ZEXTERN int ZEXPORT gzsetparams(gzFile file, int level, int strategy); /* Dynamically update the compression level and strategy for file. See the description of deflateInit2 for the meaning of these parameters. Previously @@ -1389,7 +1392,7 @@ ZEXTERN int ZEXPORT gzsetparams OF((gzFi or Z_MEM_ERROR if there is a memory allocation error. */ -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +ZEXTERN int ZEXPORT gzread(gzFile file, voidp buf, unsigned len); /* Read and decompress up to len uncompressed bytes from file into buf. If the input file is not in gzip format, gzread copies the given number of @@ -1419,8 +1422,8 @@ ZEXTERN int ZEXPORT gzread OF((gzFile fi Z_STREAM_ERROR. */ -ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, - gzFile file)); +ZEXTERN z_size_t ZEXPORT gzfread(voidp buf, z_size_t size, z_size_t nitems, + gzFile file); /* Read and decompress up to nitems items of size size from file into buf, otherwise operating as gzread() does. This duplicates the interface of @@ -1445,14 +1448,14 @@ ZEXTERN z_size_t ZEXPORT gzfread OF((voi file, resetting and retrying on end-of-file, when size is not 1. */ -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, voidpc buf, unsigned len)); +ZEXTERN int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len); /* Compress and write the len uncompressed bytes at buf to file. gzwrite returns the number of uncompressed bytes written or 0 in case of error. */ -ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size, - z_size_t nitems, gzFile file)); +ZEXTERN z_size_t ZEXPORT gzfwrite(voidpc buf, z_size_t size, + z_size_t nitems, gzFile file); /* Compress and write nitems items of size size from buf to file, duplicating the interface of stdio's fwrite(), with size_t request and return types. If @@ -1465,7 +1468,7 @@ ZEXTERN z_size_t ZEXPORT gzfwrite OF((vo is returned, and the error state is set to Z_STREAM_ERROR. */ -ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); +ZEXTERN int ZEXPORTVA gzprintf(gzFile file, const char *format, ...); /* Convert, format, compress, and write the arguments (...) to file under control of the string format, as in fprintf. gzprintf returns the number of @@ -1480,7 +1483,7 @@ ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gz This can be determined using zlibCompileFlags(). */ -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +ZEXTERN int ZEXPORT gzputs(gzFile file, const char *s); /* Compress and write the given null-terminated string s to file, excluding the terminating null character. @@ -1488,7 +1491,7 @@ ZEXTERN int ZEXPORT gzputs OF((gzFile fi gzputs returns the number of characters written, or -1 in case of error. */ -ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +ZEXTERN char * ZEXPORT gzgets(gzFile file, char *buf, int len); /* Read and decompress bytes from file into buf, until len-1 characters are read, or until a newline character is read and transferred to buf, or an @@ -1502,13 +1505,13 @@ ZEXTERN char * ZEXPORT gzgets OF((gzFile buf are indeterminate. */ -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +ZEXTERN int ZEXPORT gzputc(gzFile file, int c); /* Compress and write c, converted to an unsigned char, into file. gzputc returns the value that was written, or -1 in case of error. */ -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +ZEXTERN int ZEXPORT gzgetc(gzFile file); /* Read and decompress one byte from file. gzgetc returns this byte or -1 in case of end of file or error. This is implemented as a macro for speed. @@ -1517,7 +1520,7 @@ ZEXTERN int ZEXPORT gzgetc OF((gzFile fi points to has been clobbered or not. */ -ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +ZEXTERN int ZEXPORT gzungetc(int c, gzFile file); /* Push c back onto the stream for file to be read as the first character on the next read. At least one character of push-back is always allowed. @@ -1529,7 +1532,7 @@ ZEXTERN int ZEXPORT gzungetc OF((int c, gzseek() or gzrewind(). */ -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +ZEXTERN int ZEXPORT gzflush(gzFile file, int flush); /* Flush all pending output to file. The parameter flush is as in the deflate() function. The return value is the zlib error number (see function @@ -1545,8 +1548,8 @@ ZEXTERN int ZEXPORT gzflush OF((gzFile f */ /* -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)); +ZEXTERN z_off_t ZEXPORT gzseek(gzFile file, + z_off_t offset, int whence); Set the starting position to offset relative to whence for the next gzread or gzwrite on file. The offset represents a number of bytes in the @@ -1564,7 +1567,7 @@ ZEXTERN z_off_t ZEXPORT gzseek OF((gzFil would be before the current position. */ -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +ZEXTERN int ZEXPORT gzrewind(gzFile file); /* Rewind file. This function is supported only for reading. @@ -1572,7 +1575,7 @@ ZEXTERN int ZEXPORT gzrewind OF((gzFi */ /* -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); +ZEXTERN z_off_t ZEXPORT gztell(gzFile file); Return the starting position for the next gzread or gzwrite on file. This position represents a number of bytes in the uncompressed data stream, @@ -1583,7 +1586,7 @@ ZEXTERN z_off_t ZEXPORT gztell OF((gz */ /* -ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); +ZEXTERN z_off_t ZEXPORT gzoffset(gzFile file); Return the current compressed (actual) read or write offset of file. This offset includes the count of bytes that precede the gzip stream, for example @@ -1592,7 +1595,7 @@ ZEXTERN z_off_t ZEXPORT gzoffset OF((gzF be used for a progress indicator. On error, gzoffset() returns -1. */ -ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +ZEXTERN int ZEXPORT gzeof(gzFile file); /* Return true (1) if the end-of-file indicator for file has been set while reading, false (0) otherwise. Note that the end-of-file indicator is set @@ -1607,7 +1610,7 @@ ZEXTERN int ZEXPORT gzeof OF((gzFile fil has grown since the previous end of file was detected. */ -ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +ZEXTERN int ZEXPORT gzdirect(gzFile file); /* Return true (1) if file is being copied directly while reading, or false (0) if file is a gzip stream being decompressed. @@ -1628,7 +1631,7 @@ ZEXTERN int ZEXPORT gzdirect OF((gzFile gzip file reading and decompression, which may not be desired.) */ -ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose(gzFile file); /* Flush all pending output for file, if necessary, close file and deallocate the (de)compression state. Note that once file is closed, you @@ -1641,8 +1644,8 @@ ZEXTERN int ZEXPORT gzclose OF((gzFil last read ended in the middle of a gzip stream, or Z_OK on success. */ -ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); -ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_r(gzFile file); +ZEXTERN int ZEXPORT gzclose_w(gzFile file); /* Same as gzclose(), but gzclose_r() is only for use when reading, and gzclose_w() is only for use when writing or appending. The advantage to @@ -1653,7 +1656,7 @@ ZEXTERN int ZEXPORT gzclose_w OF((gzFile zlib library. */ -ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +ZEXTERN const char * ZEXPORT gzerror(gzFile file, int *errnum); /* Return the error message for the last error which occurred on file. errnum is set to zlib error number. If an error occurred in the file system @@ -1669,7 +1672,7 @@ ZEXTERN const char * ZEXPORT gzerror OF( functions above that do not distinguish those cases in their return values. */ -ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +ZEXTERN void ZEXPORT gzclearerr(gzFile file); /* Clear the error and end-of-file flags for file. This is analogous to the clearerr() function in stdio. This is useful for continuing to read a gzip @@ -1686,7 +1689,7 @@ ZEXTERN void ZEXPORT gzclearerr OF((gzFi library. */ -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +ZEXTERN uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len); /* Update a running Adler-32 checksum with the bytes buf[0..len-1] and return the updated checksum. An Adler-32 value is in the range of a 32-bit @@ -1706,15 +1709,15 @@ ZEXTERN uLong ZEXPORT adler32 OF((uLong if (adler != original_adler) error(); */ -ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf, - z_size_t len)); +ZEXTERN uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, + z_size_t len); /* Same as adler32(), but with a size_t length. */ /* -ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, - z_off_t len2)); +ZEXTERN uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, + z_off_t len2); Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for @@ -1724,7 +1727,7 @@ ZEXTERN uLong ZEXPORT adler32_combine OF negative, the result has no meaning or utility. */ -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +ZEXTERN uLong ZEXPORT crc32(uLong crc, const Bytef *buf, uInt len); /* Update a running CRC-32 with the bytes buf[0..len-1] and return the updated CRC-32. A CRC-32 value is in the range of a 32-bit unsigned integer. @@ -1742,30 +1745,30 @@ ZEXTERN uLong ZEXPORT crc32 OF((uLong cr if (crc != original_crc) error(); */ -ZEXTERN uLong ZEXPORT crc32_z OF((uLong crc, const Bytef *buf, - z_size_t len)); +ZEXTERN uLong ZEXPORT crc32_z(uLong crc, const Bytef *buf, + z_size_t len); /* Same as crc32(), but with a size_t length. */ /* -ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); +ZEXTERN uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2); Combine two CRC-32 check values into one. For two sequences of bytes, seq1 and seq2 with lengths len1 and len2, CRC-32 check values were calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and - len2. + len2. len2 must be non-negative. */ /* -ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t len2)); +ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t len2); Return the operator corresponding to length len2, to be used with - crc32_combine_op(). + crc32_combine_op(). len2 must be non-negative. */ -ZEXTERN uLong ZEXPORT crc32_combine_op OF((uLong crc1, uLong crc2, uLong op)); +ZEXTERN uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op); /* Give the same result as crc32_combine(), using op in place of len2. op is is generated from len2 by crc32_combine_gen(). This will be faster than @@ -1778,20 +1781,20 @@ ZEXTERN uLong ZEXPORT crc32_combine_op O /* deflateInit and inflateInit are macros to allow checking the zlib version * and the compiler's view of z_stream: */ -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, - int windowBits, int memLevel, - int strategy, const char *version, - int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, - unsigned char FAR *window, - const char *version, - int stream_size)); +ZEXTERN int ZEXPORT deflateInit_(z_streamp strm, int level, + const char *version, int stream_size); +ZEXTERN int ZEXPORT inflateInit_(z_streamp strm, + const char *version, int stream_size); +ZEXTERN int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size); +ZEXTERN int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, + const char *version, int stream_size); +ZEXTERN int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size); #ifdef Z_PREFIX_SET # define Perl_crz_deflateInit(strm, level) \ deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) @@ -1836,7 +1839,7 @@ struct gzFile_s { unsigned char *next; z_off64_t pos; }; -ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ +ZEXTERN int ZEXPORT gzgetc_(gzFile file); /* backward compatibility */ #ifdef Z_PREFIX_SET # undef z_gzgetc # define Perl_crz_gzgetc(g) \ @@ -1853,13 +1856,13 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile f * without large file support, _LFS64_LARGEFILE must also be true */ #ifdef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off64_t)); + ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); + ZEXTERN z_off64_t ZEXPORT gzseek64(gzFile, z_off64_t, int); + ZEXTERN z_off64_t ZEXPORT gztell64(gzFile); + ZEXTERN z_off64_t ZEXPORT gzoffset64(gzFile); + ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off64_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off64_t); #endif #if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) @@ -1881,50 +1884,50 @@ ZEXTERN int ZEXPORT gzgetc_ OF((gzFile f # define crc32_combine_gen crc32_combine_gen64 # endif # ifndef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); + ZEXTERN gzFile ZEXPORT gzopen64(const char *, const char *); + ZEXTERN z_off_t ZEXPORT gzseek64(gzFile, z_off_t, int); + ZEXTERN z_off_t ZEXPORT gztell64(gzFile); + ZEXTERN z_off_t ZEXPORT gzoffset64(gzFile); + ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); # endif #else - ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); + ZEXTERN gzFile ZEXPORT gzopen(const char *, const char *); + ZEXTERN z_off_t ZEXPORT gzseek(gzFile, z_off_t, int); + ZEXTERN z_off_t ZEXPORT gztell(gzFile); + ZEXTERN z_off_t ZEXPORT gzoffset(gzFile); + ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); #endif #else /* Z_SOLO */ - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen OF((z_off_t)); + ZEXTERN uLong ZEXPORT adler32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen(z_off_t); #endif /* !Z_SOLO */ /* undocumented functions */ -ZEXTERN const char * ZEXPORT zError OF((int)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); -ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); -ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); -ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int)); -ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF((z_streamp)); -ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); -ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); +ZEXTERN const char * ZEXPORT zError(int); +ZEXTERN int ZEXPORT inflateSyncPoint(z_streamp); +ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table(void); +ZEXTERN int ZEXPORT inflateUndermine(z_streamp, int); +ZEXTERN int ZEXPORT inflateValidate(z_streamp, int); +ZEXTERN unsigned long ZEXPORT inflateCodesUsed(z_streamp); +ZEXTERN int ZEXPORT inflateResetKeep(z_streamp); +ZEXTERN int ZEXPORT deflateResetKeep(z_streamp); #if defined(_WIN32) && !defined(Z_SOLO) -ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, - const char *mode)); +ZEXTERN gzFile ZEXPORT gzopen_w(const wchar_t *path, + const char *mode); #endif #if defined(STDC) || defined(Z_HAVE_STDARG_H) # ifndef Z_SOLO -ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, - const char *format, - va_list va)); +ZEXTERN int ZEXPORTVA gzvprintf(gzFile file, + const char *format, + va_list va); # endif #endif Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zutil.c =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zutil.c,v diff -u -p -a -u -p -r1.8 zutil.c --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zutil.c 14 May 2024 19:38:54 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zutil.c 22 Jan 2025 00:37:42 -0000 @@ -24,13 +24,11 @@ z_const char * const z_errmsg[10] = { }; -const char * ZEXPORT zlibVersion() -{ +const char * ZEXPORT zlibVersion(void) { return ZLIB_VERSION; } -uLong ZEXPORT zlibCompileFlags() -{ +uLong ZEXPORT zlibCompileFlags(void) { uLong flags; flags = 0; @@ -121,9 +119,7 @@ uLong ZEXPORT zlibCompileFlags() # endif int ZLIB_INTERNAL z_verbose = verbose; -void ZLIB_INTERNAL z_error ( - char *m) -{ +void ZLIB_INTERNAL z_error(char *m) { fprintf(stderr, "%s\n", m); exit(1); } @@ -132,9 +128,7 @@ void ZLIB_INTERNAL z_error ( /* exported to allow conversion of error code to string for compress() and * uncompress() */ -const char * ZEXPORT zError( - int err) -{ +const char * ZEXPORT zError(int err) { return ERR_MSG(err); } @@ -148,22 +142,14 @@ const char * ZEXPORT zError( #ifndef HAVE_MEMCPY -void ZLIB_INTERNAL zmemcpy( - Bytef* dest, - const Bytef* source, - uInt len) -{ +void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len) { if (len == 0) return; do { *dest++ = *source++; /* ??? to be unrolled */ } while (--len != 0); } -int ZLIB_INTERNAL zmemcmp( - const Bytef* s1, - const Bytef* s2, - uInt len) -{ +int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len) { uInt j; for (j = 0; j < len; j++) { @@ -172,10 +158,7 @@ int ZLIB_INTERNAL zmemcmp( return 0; } -void ZLIB_INTERNAL zmemzero( - Bytef* dest, - uInt len) -{ +void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len) { if (len == 0) return; do { *dest++ = 0; /* ??? to be unrolled */ @@ -216,8 +199,7 @@ local ptr_table table[MAX_PTR]; * a protected system like OS/2. Use Microsoft C instead. */ -voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) -{ +voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) { voidpf buf; ulg bsize = (ulg)items*size; @@ -242,8 +224,7 @@ voidpf ZLIB_INTERNAL zcalloc(voidpf opaq return buf; } -void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) -{ +void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { int n; (void)opaque; @@ -279,14 +260,12 @@ void ZLIB_INTERNAL zcfree(voidpf opaque, # define _hfree hfree #endif -voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) -{ +voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, uInt items, uInt size) { (void)opaque; return _halloc((long)items, size); } -void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) -{ +void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { (void)opaque; _hfree(ptr); } @@ -299,25 +278,18 @@ void ZLIB_INTERNAL zcfree(voidpf opaque, #ifndef MY_ZCALLOC /* Any system without a special alloc function */ #ifndef STDC -extern voidp malloc OF((uInt size)); -extern voidp calloc OF((uInt items, uInt size)); -extern void free OF((voidpf ptr)); +extern voidp malloc(uInt size); +extern voidp calloc(uInt items, uInt size); +extern void free(voidpf ptr); #endif -voidpf ZLIB_INTERNAL zcalloc ( - voidpf opaque, - unsigned items, - unsigned size) -{ +voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) { (void)opaque; return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : (voidpf)calloc(items, size); } -void ZLIB_INTERNAL zcfree ( - voidpf opaque, - voidpf ptr) -{ +void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) { (void)opaque; free(ptr); } Index: gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zutil.h =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zutil.h,v diff -u -p -a -u -p -r1.8 zutil.h --- gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zutil.h 14 May 2024 19:38:54 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Compress-Raw-Zlib/zlib-src/zutil.h 22 Jan 2025 00:37:42 -0000 @@ -1,5 +1,5 @@ /* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-2022 Jean-loup Gailly, Mark Adler + * Copyright (C) 1995-2024 Jean-loup Gailly, Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -13,10 +13,6 @@ #ifndef ZUTIL_H #define ZUTIL_H -#ifdef __cplusplus -extern "C" { -#endif - #ifdef HAVE_HIDDEN # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) #else @@ -60,7 +56,7 @@ typedef unsigned long ulg; extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ /* (size given to avoid silly warnings with Visual C++) */ -#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] +#define ERR_MSG(err) z_errmsg[(err) < -6 || (err) > 2 ? 9 : 2 - (err)] #define ERR_RETURN(strm,err) \ return (strm->msg = ERR_MSG(err), (err)) @@ -141,17 +137,8 @@ extern z_const char * const z_errmsg[10] # endif #endif -#if defined(MACOS) || defined(TARGET_OS_MAC) +#if defined(MACOS) # define OS_CODE 7 -# ifndef Z_SOLO -# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -# include /* for fdopen */ -# else -# ifndef fdopen -# define fdopen(fd,mode) NULL /* No fdopen() */ -# endif -# endif -# endif #endif #ifdef __acorn @@ -174,18 +161,6 @@ extern z_const char * const z_errmsg[10] # define OS_CODE 19 #endif -#if defined(_BEOS_) || defined(RISCOS) -# define fdopen(fd,mode) NULL /* No fdopen() */ -#endif - -#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX -# if defined(_WIN32_WCE) -# define fdopen(fd,mode) NULL /* No fdopen() */ -# else -# define fdopen(fd,type) _fdopen(fd,type) -# endif -#endif - #if defined(__BORLANDC__) && !defined(MSDOS) #pragma warn -8004 #pragma warn -8008 @@ -195,9 +170,9 @@ extern z_const char * const z_errmsg[10] /* provide prototypes for these when building zlib without LFS */ #if !defined(_WIN32) && \ (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine_gen64 OF((z_off_t)); + ZEXTERN uLong ZEXPORT adler32_combine64(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine64(uLong, uLong, z_off_t); + ZEXTERN uLong ZEXPORT crc32_combine_gen64(z_off_t); #endif /* common defaults */ @@ -236,16 +211,16 @@ extern z_const char * const z_errmsg[10] # define zmemzero(dest, len) memset(dest, 0, len) # endif #else - void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); - int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); - void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); + void ZLIB_INTERNAL zmemcpy(Bytef* dest, const Bytef* source, uInt len); + int ZLIB_INTERNAL zmemcmp(const Bytef* s1, const Bytef* s2, uInt len); + void ZLIB_INTERNAL zmemzero(Bytef* dest, uInt len); #endif /* Diagnostic functions */ #ifdef ZLIB_DEBUG # include extern int ZLIB_INTERNAL z_verbose; - extern void ZLIB_INTERNAL z_error OF((char *m)); + extern void ZLIB_INTERNAL z_error(char *m); # define Assert(cond,msg) {if(!(cond)) z_error(msg);} # define Trace(x) {if (z_verbose>=0) fprintf x ;} # define Tracev(x) {if (z_verbose>0) fprintf x ;} @@ -262,9 +237,9 @@ extern z_const char * const z_errmsg[10] #endif #ifndef Z_SOLO - voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, - unsigned size)); - void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); + voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, + unsigned size); + void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr); #endif #define ZALLOC(strm, items, size) \ @@ -276,7 +251,4 @@ extern z_const char * const z_errmsg[10] #define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) -#ifdef __cplusplus -} -#endif #endif /* ZUTIL_H */ Index: gnu/usr.bin/perl/cpan/DB_File/DB_File.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/DB_File/DB_File.pm,v diff -u -p -a -u -p -r1.7 DB_File.pm --- gnu/usr.bin/perl/cpan/DB_File/DB_File.pm 14 May 2024 19:38:55 -0000 1.7 +++ gnu/usr.bin/perl/cpan/DB_File/DB_File.pm 22 Jan 2025 00:37:42 -0000 @@ -2,7 +2,7 @@ # # Written by Paul Marquess (pmqs@cpan.org) # -# Copyright (c) 1995-2022 Paul Marquess. All rights reserved. +# Copyright (c) 1995-2023 Paul Marquess. All rights reserved. # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. @@ -165,7 +165,7 @@ use Carp; # Module not thread safe, so don't clone sub CLONE_SKIP { 1 } -$VERSION = "1.858" ; +$VERSION = "1.859" ; $VERSION = eval $VERSION; # needed for dev releases { @@ -2325,7 +2325,7 @@ archive in F. =head1 COPYRIGHT -Copyright (c) 1995-2022 Paul Marquess. All rights reserved. This program +Copyright (c) 1995-2023 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/DB_File/DB_File.xs =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/DB_File/DB_File.xs,v diff -u -p -a -u -p -r1.6 DB_File.xs --- gnu/usr.bin/perl/cpan/DB_File/DB_File.xs 15 Feb 2023 01:36:16 -0000 1.6 +++ gnu/usr.bin/perl/cpan/DB_File/DB_File.xs 22 Jan 2025 00:37:42 -0000 @@ -6,7 +6,7 @@ All comments/suggestions/problems are welcome - Copyright (c) 1995-2022 Paul Marquess. All rights reserved. + Copyright (c) 1995-2023 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/DB_File/dbinfo =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/DB_File/dbinfo,v diff -u -p -a -u -p -r1.1.1.4 dbinfo --- gnu/usr.bin/perl/cpan/DB_File/dbinfo 15 Feb 2023 01:32:48 -0000 1.1.1.4 +++ gnu/usr.bin/perl/cpan/DB_File/dbinfo 22 Jan 2025 00:37:42 -0000 @@ -7,7 +7,7 @@ # Version: 1.07 # Date 2nd April 2011 # -# Copyright (c) 1998-2022 Paul Marquess. All rights reserved. +# Copyright (c) 1998-2023 Paul Marquess. All rights reserved. # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/Digest-MD5/Makefile.PL =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Digest-MD5/Makefile.PL,v diff -u -p -a -u -p -r1.4 Makefile.PL --- gnu/usr.bin/perl/cpan/Digest-MD5/Makefile.PL 15 Feb 2023 01:36:16 -0000 1.4 +++ gnu/usr.bin/perl/cpan/Digest-MD5/Makefile.PL 22 Jan 2025 00:37:42 -0000 @@ -20,16 +20,16 @@ if ($^O eq 'VMS') { WriteMakefile( - 'NAME' => 'Digest::MD5', + 'NAME' => 'Digest::MD5', 'VERSION_FROM' => 'MD5.pm', 'ABSTRACT' => 'Perl interface to the MD-5 algorithm', 'AUTHOR' => 'Gisle Aas ', 'LICENSE' => 'perl', 'MIN_PERL_VERSION' => 5.006, 'PREREQ_PM' => { - 'Digest::base' => '1.00', - 'XSLoader' => 0, - }, + 'Digest::base' => '1.00', + 'XSLoader' => 0, + }, 'META_MERGE' => { resources => { license => 'http://dev.perl.org/licenses/', Index: gnu/usr.bin/perl/cpan/Digest-MD5/t/bits.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Digest-MD5/t/bits.t,v diff -u -p -a -u -p -r1.1.1.2 bits.t --- gnu/usr.bin/perl/cpan/Digest-MD5/t/bits.t 15 Feb 2023 01:32:35 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/Digest-MD5/t/bits.t 22 Jan 2025 00:37:42 -0000 @@ -3,8 +3,7 @@ use strict; use warnings; -use Test qw(plan ok); -plan tests => 2; +use Test::More tests => 2; use Digest::MD5; @@ -12,18 +11,18 @@ my $md5 = Digest::MD5->new; if ($Digest::base::VERSION) { $md5->add_bits("01111111"); - ok($md5->hexdigest, "83acb6e67e50e31db6ed341dd2de1595"); + is($md5->hexdigest, "83acb6e67e50e31db6ed341dd2de1595"); eval { - $md5->add_bits("0111"); + $md5->add_bits("0111"); }; - ok($@ =~ /must be multiple of 8/); + like($@, qr/must be multiple of 8/); } else { print "# No Digest::base\n"; eval { - $md5->add_bits("foo"); + $md5->add_bits("foo"); }; - ok($@ =~ /^Can\'t locate Digest\/base\.pm in \@INC/); + like($@, qr/^Can\'t locate Digest\/base\.pm in \@INC/); ok(1); # dummy } Index: gnu/usr.bin/perl/cpan/Digest-MD5/t/md5-aaa.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Digest-MD5/t/md5-aaa.t,v diff -u -p -a -u -p -r1.1.1.2 md5-aaa.t --- gnu/usr.bin/perl/cpan/Digest-MD5/t/md5-aaa.t 15 Feb 2023 01:32:35 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/Digest-MD5/t/md5-aaa.t 22 Jan 2025 00:37:42 -0000 @@ -10,22 +10,22 @@ my $Is_EBCDIC = ord('A') == 193; my $testno = 0; while () { if (!$Is_EBCDIC) { - next if /^EBCDIC/; + next if /^EBCDIC/; } else { - next if !/^EBCDIC/; - s/^EBCDIC,\w+#//; - } - my($hexdigest, $message) = split; - $message =~ s/\"//g; + next if !/^EBCDIC/; + s/^EBCDIC,\w+#//; + } + my($hexdigest, $message) = split; + $message =~ s/\"//g; - my $failed; - $failed++ unless md5_hex($message) eq $hexdigest; - $failed++ unless Digest::MD5->new->add(split(//, $message))->digest - eq pack("H*", $hexdigest); + my $failed; + $failed++ unless md5_hex($message) eq $hexdigest; + $failed++ unless Digest::MD5->new->add(split(//, $message))->digest + eq pack("H*", $hexdigest); - print "not " if $failed; - print "ok ", ++$testno, "\n"; + print "not " if $failed; + print "ok ", ++$testno, "\n"; } Index: gnu/usr.bin/perl/cpan/Digest-MD5/t/utf8.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Digest-MD5/t/utf8.t,v diff -u -p -a -u -p -r1.1.1.3 utf8.t --- gnu/usr.bin/perl/cpan/Digest-MD5/t/utf8.t 15 Feb 2023 01:32:35 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/Digest-MD5/t/utf8.t 22 Jan 2025 00:37:42 -0000 @@ -1,12 +1,5 @@ #!perl -w -BEGIN { - if ($] < 5.006) { - print "1..0 # Skipped: your perl don't know unicode\n"; - exit; - } -} - use strict; use warnings; @@ -25,8 +18,8 @@ print "not " unless $@ && $@ =~ /^(Big b print "ok 1\n"; my $exp = ord "A" == 193 ? # EBCDIC - "c307ec81deba65e9a222ca81cd8f6ccd" : - "503debffe559537231ed24f25651ec20"; # Latin 1 + "c307ec81deba65e9a222ca81cd8f6ccd" : + "503debffe559537231ed24f25651ec20"; # Latin 1 chop($str); # only bytes left print "not " unless md5_hex($str) eq $exp; Index: gnu/usr.bin/perl/cpan/Encode/Encode.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/Encode.pm,v diff -u -p -a -u -p -r1.13 Encode.pm --- gnu/usr.bin/perl/cpan/Encode/Encode.pm 14 May 2024 19:38:55 -0000 1.13 +++ gnu/usr.bin/perl/cpan/Encode/Encode.pm 22 Jan 2025 00:37:42 -0000 @@ -1,5 +1,5 @@ # -# $Id: Encode.pm,v 3.19 2022/08/04 04:42:30 dankogai Exp $ +# $Id: Encode.pm,v 3.21 2024/02/25 22:17:32 dankogai Exp $ # package Encode; use strict; @@ -7,7 +7,7 @@ use warnings; use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG}; our $VERSION; BEGIN { - $VERSION = sprintf "%d.%02d", q$Revision: 3.19 $ =~ /(\d+)/g; + $VERSION = sprintf "%d.%02d", q$Revision: 3.21 $ =~ /(\d+)/g; require XSLoader; XSLoader::load( __PACKAGE__, $VERSION ); } @@ -431,10 +431,10 @@ same as C but C. So as opposite of C canonical names and aliases are not used when searching for object. - find_mime_encoding("utf8"); # returns undef because "utf8" is not valid I + find_mime_encoding("utf8"); # returns undef because "utf8" is not a valid MIME_ENCODING find_mime_encoding("utf-8"); # returns encode object "utf-8-strict" - find_mime_encoding("UTF-8"); # same as "utf-8" because I is case insensitive - find_mime_encoding("utf-8-strict"); returns undef because "utf-8-strict" is not valid I + find_mime_encoding("UTF-8"); # same as "utf-8" because MIME_ENCODING is case insensitive + find_mime_encoding("utf-8-strict"); returns undef because "utf-8-strict" is not a valid MIME_ENCODING =head3 from_to @@ -645,7 +645,7 @@ L ignores I and =head3 FB_DEFAULT - I = Encode::FB_DEFAULT ( == 0) + CHECK = Encode::FB_DEFAULT ( == 0) If I is 0, encoding and decoding replace any malformed character with a I. When you encode, I is used. @@ -655,7 +655,7 @@ warning category C<"utf8"> is given. =head3 FB_CROAK - I = Encode::FB_CROAK ( == 1) + CHECK = Encode::FB_CROAK ( == 1) If I is 1, methods immediately die with an error message. Therefore, when I is 1, you should trap @@ -663,7 +663,7 @@ exceptions with C, unless you re =head3 FB_QUIET - I = Encode::FB_QUIET + CHECK = Encode::FB_QUIET If I is set to C, encoding and decoding immediately return the portion of the data that has been processed so far when an @@ -682,7 +682,7 @@ code to do exactly that: =head3 FB_WARN - I = Encode::FB_WARN + CHECK = Encode::FB_WARN This is the same as C above, except that instead of being silent on errors, it issues a warning. This is handy for when you are debugging. @@ -780,7 +780,7 @@ See L for details. =head1 The UTF8 flag -Before the introduction of Unicode support in Perl, The C operator +Before the introduction of Unicode support in Perl, the C operator just compared the strings represented by two scalars. Beginning with Perl 5.8, C compares two strings with simultaneous consideration of I. To explain why we made it so, I quote from page 402 of Index: gnu/usr.bin/perl/cpan/Encode/bin/enc2xs =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/bin/enc2xs,v diff -u -p -a -u -p -r1.8 enc2xs --- gnu/usr.bin/perl/cpan/Encode/bin/enc2xs 15 Feb 2023 01:36:16 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Encode/bin/enc2xs 22 Jan 2025 00:37:42 -0000 @@ -3,7 +3,7 @@ BEGIN { # @INC poking no longer needed w/ new MakeMaker and Makefile.PL's # with $ENV{PERL_CORE} set # In case we need it in future... - require Config; import Config; + require Config; Config->import(); pop @INC if $INC[-1] eq '.'; } use strict; @@ -11,7 +11,7 @@ use warnings; use Getopt::Std; use Config; my @orig_ARGV = @ARGV; -our $VERSION = do { my @r = (q$Revision: 2.24 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +our $VERSION = do { my @r = (q$Revision: 2.25 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # These may get re-ordered. # RAW is a do_now as inserted by &enter @@ -213,7 +213,7 @@ if (exists $opt{f}) { } my $cname = $opt{o} ? $opt{o} : shift(@ARGV); -unless ($cname) { #debuging a win32 nmake error-only. works via cmdline +unless ($cname) { # Debugging a Win32 nmake error-only; works via cmdline. print "\nARGV:"; print "$_ " for @ARGV; print "\nopt:"; Index: gnu/usr.bin/perl/cpan/Encode/bin/encguess =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/bin/encguess,v diff -u -p -a -u -p -r1.3 encguess --- gnu/usr.bin/perl/cpan/Encode/bin/encguess 15 Feb 2023 01:36:16 -0000 1.3 +++ gnu/usr.bin/perl/cpan/Encode/bin/encguess 22 Jan 2025 00:37:42 -0000 @@ -61,7 +61,7 @@ encguess - guess character encodings of =head1 VERSION -$Id: encguess,v 0.3 2020/12/02 01:28:17 dankogai Exp $ +$Id: encguess,v 0.4 2023/11/10 01:10:50 dankogai Exp $ =head1 SYNOPSIS @@ -138,7 +138,7 @@ L, L Copyright 2015 Michael LaGrasta and Dan Kogai. This program is free software; you can redistribute it and/or modify it -under the terms of the the Artistic License (2.0). You may obtain a +under the terms of the Artistic License (2.0). You may obtain a copy of the full license at: L Index: gnu/usr.bin/perl/cpan/Encode/lib/Encode/Supported.pod =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/lib/Encode/Supported.pod,v diff -u -p -a -u -p -r1.3 Supported.pod --- gnu/usr.bin/perl/cpan/Encode/lib/Encode/Supported.pod 13 Feb 2019 21:15:10 -0000 1.3 +++ gnu/usr.bin/perl/cpan/Encode/lib/Encode/Supported.pod 22 Jan 2025 00:37:42 -0000 @@ -315,7 +315,7 @@ See L for details. posix-bc ---------------------------------------------------------------- -=item Encode::Symbols +=item Encode::Symbol For symbols and dingbats. Index: gnu/usr.bin/perl/cpan/Encode/t/Aliases.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/Aliases.t,v diff -u -p -a -u -p -r1.4 Aliases.t --- gnu/usr.bin/perl/cpan/Encode/t/Aliases.t 14 May 2024 19:38:55 -0000 1.4 +++ gnu/usr.bin/perl/cpan/Encode/t/Aliases.t 22 Jan 2025 00:37:42 -0000 @@ -5,7 +5,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/CJKT.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/CJKT.t,v diff -u -p -a -u -p -r1.1.1.2 CJKT.t --- gnu/usr.bin/perl/cpan/Encode/t/CJKT.t 13 Feb 2019 21:10:51 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/Encode/t/CJKT.t 22 Jan 2025 00:37:42 -0000 @@ -1,5 +1,5 @@ BEGIN { - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; @@ -46,7 +46,7 @@ for my $charset (sort keys %Charset){ my $src_enc = File::Spec->catfile($dir,"$charset.enc"); my $src_utf = File::Spec->catfile($dir,"$charset.utf"); my $dst_enc = File::Spec->catfile($dir,"$$.enc"); - my $dst_utf = File::Spec->catfile($dir,"$$.utf"); + my $dst_utf = File::Spec->catfile($dir,"$$.utf8"); open $src, "<$src_enc" or die "$src_enc : $!"; Index: gnu/usr.bin/perl/cpan/Encode/t/Encode.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/Encode.t,v diff -u -p -a -u -p -r1.1.1.5 Encode.t --- gnu/usr.bin/perl/cpan/Encode/t/Encode.t 15 Feb 2023 01:32:37 -0000 1.1.1.5 +++ gnu/usr.bin/perl/cpan/Encode/t/Encode.t 22 Jan 2025 00:37:42 -0000 @@ -7,7 +7,7 @@ BEGIN { print "1..0 # Skip: EBCDIC\n"; exit 0; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/Encoder.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/Encoder.t,v diff -u -p -a -u -p -r1.3 Encoder.t --- gnu/usr.bin/perl/cpan/Encode/t/Encoder.t 17 Nov 2014 20:56:59 -0000 1.3 +++ gnu/usr.bin/perl/cpan/Encode/t/Encoder.t 22 Jan 2025 00:37:42 -0000 @@ -1,9 +1,9 @@ # -# $Id: Encoder.t,v 2.1 2013/09/14 07:51:59 dankogai Exp $ +# $Id: Encoder.t,v 2.2 2023/11/10 01:10:50 dankogai Exp $ # BEGIN { - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/Unicode.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/Unicode.t,v diff -u -p -a -u -p -r1.4 Unicode.t --- gnu/usr.bin/perl/cpan/Encode/t/Unicode.t 15 Feb 2023 01:36:16 -0000 1.4 +++ gnu/usr.bin/perl/cpan/Encode/t/Unicode.t 22 Jan 2025 00:37:42 -0000 @@ -1,12 +1,12 @@ # -# $Id: Unicode.t,v 2.4 2021/07/23 02:26:54 dankogai Exp $ +# $Id: Unicode.t,v 2.5 2023/11/10 01:10:50 dankogai Exp $ # # This script is written entirely in ASCII, even though quoted literals # do include non-BMP unicode characters -- Are you happy, jhi? # BEGIN { - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/at-cn.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/at-cn.t,v diff -u -p -a -u -p -r1.1.1.2 at-cn.t --- gnu/usr.bin/perl/cpan/Encode/t/at-cn.t 13 Feb 2019 21:10:51 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/Encode/t/at-cn.t 22 Jan 2025 00:37:42 -0000 @@ -3,7 +3,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/at-tw.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/at-tw.t,v diff -u -p -a -u -p -r1.1.1.2 at-tw.t --- gnu/usr.bin/perl/cpan/Encode/t/at-tw.t 13 Feb 2019 21:10:51 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/Encode/t/at-tw.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,7 @@ BEGIN { if (! -d 'blib' and -d 't'){ chdir 't' }; unshift @INC, '../lib'; - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/enc_data.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/enc_data.t,v diff -u -p -a -u -p -r1.6 enc_data.t --- gnu/usr.bin/perl/cpan/Encode/t/enc_data.t 14 May 2024 19:38:55 -0000 1.6 +++ gnu/usr.bin/perl/cpan/Encode/t/enc_data.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,7 @@ -# $Id: enc_data.t,v 2.6 2022/04/07 03:06:40 dankogai Exp $ +# $Id: enc_data.t,v 2.7 2023/11/10 01:10:50 dankogai Exp $ BEGIN { - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/enc_eucjp.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/enc_eucjp.t,v diff -u -p -a -u -p -r1.5 enc_eucjp.t --- gnu/usr.bin/perl/cpan/Encode/t/enc_eucjp.t 30 Dec 2019 02:13:43 -0000 1.5 +++ gnu/usr.bin/perl/cpan/Encode/t/enc_eucjp.t 22 Jan 2025 00:37:42 -0000 @@ -1,8 +1,8 @@ -# $Id: enc_eucjp.t,v 2.6 2019/01/31 04:26:40 dankogai Exp $ +# $Id: enc_eucjp.t,v 2.7 2023/11/10 01:10:50 dankogai Exp $ # This is the twin of enc_utf8.t . BEGIN { - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/enc_module.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/enc_module.t,v diff -u -p -a -u -p -r1.6 enc_module.t --- gnu/usr.bin/perl/cpan/Encode/t/enc_module.t 14 May 2024 19:38:55 -0000 1.6 +++ gnu/usr.bin/perl/cpan/Encode/t/enc_module.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,7 @@ -# $Id: enc_module.t,v 2.6 2022/04/07 03:06:40 dankogai Exp $ +# $Id: enc_module.t,v 2.7 2023/11/10 01:10:50 dankogai Exp $ # This file is in euc-jp BEGIN { - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/enc_utf8.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/enc_utf8.t,v diff -u -p -a -u -p -r1.5 enc_utf8.t --- gnu/usr.bin/perl/cpan/Encode/t/enc_utf8.t 1 Mar 2021 23:19:45 -0000 1.5 +++ gnu/usr.bin/perl/cpan/Encode/t/enc_utf8.t 22 Jan 2025 00:37:42 -0000 @@ -1,8 +1,8 @@ -# $Id: enc_utf8.t,v 2.6 2019/12/25 09:23:21 dankogai Exp $ +# $Id: enc_utf8.t,v 2.7 2023/11/10 01:10:50 dankogai Exp $ # This is the twin of enc_eucjp.t . BEGIN { - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/encoding.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/encoding.t,v diff -u -p -a -u -p -r1.4 encoding.t --- gnu/usr.bin/perl/cpan/Encode/t/encoding.t 15 Feb 2023 01:36:16 -0000 1.4 +++ gnu/usr.bin/perl/cpan/Encode/t/encoding.t 22 Jan 2025 00:37:42 -0000 @@ -1,5 +1,5 @@ BEGIN { - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/fallback.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/fallback.t,v diff -u -p -a -u -p -r1.1.1.2 fallback.t --- gnu/usr.bin/perl/cpan/Encode/t/fallback.t 13 Feb 2019 21:10:51 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/Encode/t/fallback.t 22 Jan 2025 00:37:42 -0000 @@ -3,7 +3,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/grow.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/grow.t,v diff -u -p -a -u -p -r1.1.1.1 grow.t --- gnu/usr.bin/perl/cpan/Encode/t/grow.t 24 Sep 2010 14:49:00 -0000 1.1.1.1 +++ gnu/usr.bin/perl/cpan/Encode/t/grow.t 22 Jan 2025 00:37:42 -0000 @@ -5,7 +5,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/gsm0338.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/gsm0338.t,v diff -u -p -a -u -p -r1.1.1.3 gsm0338.t --- gnu/usr.bin/perl/cpan/Encode/t/gsm0338.t 15 Feb 2023 01:32:37 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/Encode/t/gsm0338.t 22 Jan 2025 00:37:42 -0000 @@ -3,7 +3,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; @@ -16,6 +16,10 @@ use utf8; use Test::More tests => 777; use Encode; use Encode::GSM0338; +use PerlIO::encoding; + +# perl < 5.8.8 didn't enable STOP_AT_PARTIAL by default +$PerlIO::encoding::fallback |= Encode::STOP_AT_PARTIAL; my $chk = Encode::LEAVE_SRC(); Index: gnu/usr.bin/perl/cpan/Encode/t/guess.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/guess.t,v diff -u -p -a -u -p -r1.1.1.3 guess.t --- gnu/usr.bin/perl/cpan/Encode/t/guess.t 13 Feb 2019 21:10:51 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/Encode/t/guess.t 22 Jan 2025 00:37:42 -0000 @@ -1,5 +1,5 @@ BEGIN { - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/jperl.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/jperl.t,v diff -u -p -a -u -p -r1.6 jperl.t --- gnu/usr.bin/perl/cpan/Encode/t/jperl.t 14 May 2024 19:38:55 -0000 1.6 +++ gnu/usr.bin/perl/cpan/Encode/t/jperl.t 22 Jan 2025 00:37:42 -0000 @@ -1,10 +1,10 @@ # -# $Id: jperl.t,v 2.6 2022/04/07 03:06:40 dankogai Exp $ +# $Id: jperl.t,v 2.7 2023/11/10 01:10:50 dankogai Exp $ # # This script is written in euc-jp BEGIN { - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/magic.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/magic.t,v diff -u -p -a -u -p -r1.1.1.1 magic.t --- gnu/usr.bin/perl/cpan/Encode/t/magic.t 13 Feb 2019 21:10:51 -0000 1.1.1.1 +++ gnu/usr.bin/perl/cpan/Encode/t/magic.t 22 Jan 2025 00:37:42 -0000 @@ -3,7 +3,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/mime-header.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/mime-header.t,v diff -u -p -a -u -p -r1.7 mime-header.t --- gnu/usr.bin/perl/cpan/Encode/t/mime-header.t 14 May 2024 19:38:55 -0000 1.7 +++ gnu/usr.bin/perl/cpan/Encode/t/mime-header.t 22 Jan 2025 00:37:42 -0000 @@ -1,5 +1,5 @@ # -# $Id: mime-header.t,v 2.16 2022/06/25 01:58:57 dankogai Exp $ +# $Id: mime-header.t,v 2.17 2023/11/10 01:10:50 dankogai Exp $ # This script is written in utf8 # BEGIN { @@ -7,7 +7,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/mime-name.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/mime-name.t,v diff -u -p -a -u -p -r1.3 mime-name.t --- gnu/usr.bin/perl/cpan/Encode/t/mime-name.t 13 Feb 2019 21:15:10 -0000 1.3 +++ gnu/usr.bin/perl/cpan/Encode/t/mime-name.t 22 Jan 2025 00:37:42 -0000 @@ -1,5 +1,5 @@ # -# $Id: mime-name.t,v 1.3 2017/10/06 22:21:53 dankogai Exp $ +# $Id: mime-name.t,v 1.4 2023/11/10 01:10:50 dankogai Exp $ # This script is written in utf8 # BEGIN { @@ -7,7 +7,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/perlio.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/perlio.t,v diff -u -p -a -u -p -r1.1.1.1 perlio.t --- gnu/usr.bin/perl/cpan/Encode/t/perlio.t 24 Sep 2010 14:49:00 -0000 1.1.1.1 +++ gnu/usr.bin/perl/cpan/Encode/t/perlio.t 22 Jan 2025 00:37:42 -0000 @@ -1,5 +1,5 @@ BEGIN { - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/rt.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/rt.pl,v diff -u -p -a -u -p -r1.2 rt.pl --- gnu/usr.bin/perl/cpan/Encode/t/rt.pl 24 Sep 2010 15:06:47 -0000 1.2 +++ gnu/usr.bin/perl/cpan/Encode/t/rt.pl 22 Jan 2025 00:37:42 -0000 @@ -1,6 +1,6 @@ #!/usr/local/bin/perl # -# $Id: rt.pl,v 2.1 2006/05/03 18:24:10 dankogai Exp $ +# $Id: rt.pl,v 2.2 2023/11/10 01:10:50 dankogai Exp $ # BEGIN { @@ -10,7 +10,7 @@ BEGIN { unshift @INC, '../lib'; $ucmdir = "../ext/Encode/ucm"; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/rt113164.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/rt113164.t,v diff -u -p -a -u -p -r1.1.1.1 rt113164.t --- gnu/usr.bin/perl/cpan/Encode/t/rt113164.t 13 Feb 2019 21:10:51 -0000 1.1.1.1 +++ gnu/usr.bin/perl/cpan/Encode/t/rt113164.t 22 Jan 2025 00:37:42 -0000 @@ -3,7 +3,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/rt65541.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/rt65541.t,v diff -u -p -a -u -p -r1.1.1.1 rt65541.t --- gnu/usr.bin/perl/cpan/Encode/t/rt65541.t 13 Feb 2019 21:10:51 -0000 1.1.1.1 +++ gnu/usr.bin/perl/cpan/Encode/t/rt65541.t 22 Jan 2025 00:37:42 -0000 @@ -3,7 +3,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/rt76824.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/rt76824.t,v diff -u -p -a -u -p -r1.1.1.1 rt76824.t --- gnu/usr.bin/perl/cpan/Encode/t/rt76824.t 13 Feb 2019 21:10:51 -0000 1.1.1.1 +++ gnu/usr.bin/perl/cpan/Encode/t/rt76824.t 22 Jan 2025 00:37:42 -0000 @@ -3,7 +3,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/rt85489.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/rt85489.t,v diff -u -p -a -u -p -r1.1.1.1 rt85489.t --- gnu/usr.bin/perl/cpan/Encode/t/rt85489.t 13 Feb 2019 21:10:51 -0000 1.1.1.1 +++ gnu/usr.bin/perl/cpan/Encode/t/rt85489.t 22 Jan 2025 00:37:42 -0000 @@ -3,7 +3,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/rt86327.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/rt86327.t,v diff -u -p -a -u -p -r1.1.1.1 rt86327.t --- gnu/usr.bin/perl/cpan/Encode/t/rt86327.t 13 Feb 2019 21:10:51 -0000 1.1.1.1 +++ gnu/usr.bin/perl/cpan/Encode/t/rt86327.t 22 Jan 2025 00:37:42 -0000 @@ -3,7 +3,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/truncated_utf8.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/truncated_utf8.t,v diff -u -p -a -u -p -r1.1.1.2 truncated_utf8.t --- gnu/usr.bin/perl/cpan/Encode/t/truncated_utf8.t 14 May 2024 19:36:31 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/Encode/t/truncated_utf8.t 22 Jan 2025 00:37:42 -0000 @@ -3,7 +3,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/Encode/t/utf8strict.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Encode/t/utf8strict.t,v diff -u -p -a -u -p -r1.1.1.3 utf8strict.t --- gnu/usr.bin/perl/cpan/Encode/t/utf8strict.t 13 Feb 2019 21:10:51 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/Encode/t/utf8strict.t 22 Jan 2025 00:37:42 -0000 @@ -6,7 +6,7 @@ BEGIN { chdir 't'; unshift @INC, '../lib'; } - require Config; import Config; + require Config; Config->import(); if ($Config{'extensions'} !~ /\bEncode\b/) { print "1..0 # Skip: Encode was not built\n"; exit 0; Index: gnu/usr.bin/perl/cpan/ExtUtils-Manifest/lib/ExtUtils/MANIFEST.SKIP =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/ExtUtils-Manifest/lib/ExtUtils/MANIFEST.SKIP,v diff -u -p -a -u -p -r1.5 MANIFEST.SKIP --- gnu/usr.bin/perl/cpan/ExtUtils-Manifest/lib/ExtUtils/MANIFEST.SKIP 15 Feb 2023 01:36:17 -0000 1.5 +++ gnu/usr.bin/perl/cpan/ExtUtils-Manifest/lib/ExtUtils/MANIFEST.SKIP 22 Jan 2025 00:37:42 -0000 @@ -9,6 +9,8 @@ \B\.gitignore\b \b_darcs\b \B\.cvsignore$ +\B\.bzr\b +\B\.bzrignore$ # Avoid VMS specific MakeMaker generated files \bDescrip.MMS$ @@ -46,6 +48,7 @@ \.# \.rej$ \..*\.sw.?$ +\.~\d+~$ # Avoid OS-specific files/dirs # Mac OSX metadata Index: gnu/usr.bin/perl/cpan/ExtUtils-Manifest/lib/ExtUtils/Manifest.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/ExtUtils-Manifest/lib/ExtUtils/Manifest.pm,v diff -u -p -a -u -p -r1.5 Manifest.pm --- gnu/usr.bin/perl/cpan/ExtUtils-Manifest/lib/ExtUtils/Manifest.pm 15 Feb 2023 01:36:17 -0000 1.5 +++ gnu/usr.bin/perl/cpan/ExtUtils-Manifest/lib/ExtUtils/Manifest.pm 22 Jan 2025 00:37:42 -0000 @@ -1,4 +1,4 @@ -package ExtUtils::Manifest; # git description: 1.72-7-g54209ce +package ExtUtils::Manifest; # git description: 1.74-10-g1bddbb0 require Exporter; use Config; @@ -10,7 +10,7 @@ use Carp; use strict; use warnings; -our $VERSION = '1.73'; +our $VERSION = '1.75'; our @ISA = ('Exporter'); our @EXPORT_OK = qw(mkmanifest manicheck filecheck fullcheck skipcheck @@ -18,7 +18,6 @@ our @EXPORT_OK = qw(mkmanifest maniskip ); -our $Is_MacOS = $^O eq 'MacOS'; our $Is_VMS = $^O eq 'VMS'; our $Is_VMS_mode = 0; our $Is_VMS_lc = 0; @@ -65,7 +64,7 @@ ExtUtils::Manifest - Utilities to write =head1 VERSION -version 1.73 +version 1.75 =head1 SYNOPSIS @@ -120,12 +119,11 @@ sub mkmanifest { my $manimiss = 0; my $read = (-r 'MANIFEST' && maniread()) or $manimiss++; $read = {} if $manimiss; - local *M; my $bakbase = $MANIFEST; $bakbase =~ s/\./_/g if $Is_VMS_nodot; # avoid double dots rename $MANIFEST, "$bakbase.bak" unless $manimiss; - open M, "> $MANIFEST" or die "Could not open $MANIFEST: $!"; - binmode M, ':raw'; + open my $fh, '>', $MANIFEST or die "Could not open $MANIFEST: $!"; + binmode $fh, ':raw'; my $skip = maniskip(); my $found = manifind(); my($key,$val,$file,%all); @@ -134,27 +132,25 @@ sub mkmanifest { 'This list of files' if $manimiss; # add new MANIFEST to known file list foreach $file (_sort keys %all) { - if ($skip->($file)) { - # Policy: only remove files if they're listed in MANIFEST.SKIP. - # Don't remove files just because they don't exist. - warn "Removed from $MANIFEST: $file\n" if $Verbose and exists $read->{$file}; - next; - } - if ($Verbose){ - warn "Added to $MANIFEST: $file\n" unless exists $read->{$file}; - } - my $text = $all{$file}; - $file = _unmacify($file); - my $tabs = (5 - (length($file)+1)/8); - $tabs = 1 if $tabs < 1; - $tabs = 0 unless $text; + if ($skip->($file)) { + # Policy: only remove files if they're listed in MANIFEST.SKIP. + # Don't remove files just because they don't exist. + warn "Removed from $MANIFEST: $file\n" if $Verbose and exists $read->{$file}; + next; + } + if ($Verbose){ + warn "Added to $MANIFEST: $file\n" unless exists $read->{$file}; + } + my $text = $all{$file}; + my $tabs = (5 - (length($file)+1)/8); + $tabs = 1 if $tabs < 1; + $tabs = 0 unless $text; if ($file =~ /\s/) { $file =~ s/([\\'])/\\$1/g; $file = "'$file'"; } - print M $file, "\t" x $tabs, $text, "\n"; + print $fh $file, "\t" x $tabs, $text, "\n"; } - close M; } # Geez, shouldn't this use File::Spec or File::Basename or something? @@ -162,7 +158,6 @@ sub mkmanifest { sub clean_up_filename { my $filename = shift; $filename =~ s|^\./||; - $filename =~ s/^:([^:]+)$/$1/ if $Is_MacOS; if ( $Is_VMS ) { $filename =~ s/\.$//; # trim trailing dot $filename = VMS::Filespec::unixify($filename); # unescape spaces, etc. @@ -189,18 +184,17 @@ sub manifind { my $found = {}; my $wanted = sub { - my $name = clean_up_filename($File::Find::name); - warn "Debug: diskfile $name\n" if $Debug; - return if -d $_; - $found->{$name} = ""; + my $name = clean_up_filename($File::Find::name); + warn "Debug: diskfile $name\n" if $Debug; + return if -d $_; + $found->{$name} = ""; }; # We have to use "$File::Find::dir/$_" in preprocess, because # $File::Find::name is unavailable. # Also, it's okay to use / here, because MANIFEST files use Unix-style # paths. - find({wanted => $wanted, follow_fast => 1}, - $Is_MacOS ? ":" : "."); + find({wanted => $wanted, follow_fast => 1}, "."); return $found; } @@ -318,8 +312,7 @@ sub _check_manifest { next if $skip->($file); warn "Debug: manicheck checking from disk $file\n" if $Debug; unless ( exists $read->{$file} ) { - my $canon = $Is_MacOS ? "\t" . _unmacify($file) : ''; - warn "Not in $MANIFEST: $file$canon\n" unless $Quiet; + warn "Not in $MANIFEST: $file\n" unless $Quiet; push @missentry, $file; } } @@ -344,13 +337,13 @@ sub maniread { my ($mfile) = @_; $mfile ||= $MANIFEST; my $read = {}; - local *M; - unless (open M, "< $mfile"){ + my $fh; + unless (open $fh, '<', $mfile){ warn "Problem opening $mfile: $!"; return $read; } local $_; - while (){ + while (<$fh>){ chomp; next if /^\s*#/; @@ -366,11 +359,7 @@ sub maniread { } next unless $file; - if ($Is_MacOS) { - $file = _macify($file); - $file =~ s/\\([0-3][0-7][0-7])/sprintf("%c", oct($1))/ge; - } - elsif ($Is_VMS_mode) { + if ($Is_VMS_mode) { require File::Basename; my($base,$dir) = File::Basename::fileparse($file); # Resolve illegal file specifications in the same way as tar @@ -391,7 +380,6 @@ sub maniread { $read->{$file} = $comment; } - close M; $read; } @@ -408,27 +396,39 @@ a given filename should be skipped. =cut +sub _process_skipline { + local $_ = shift; + chomp; + s/\r//; + $_ =~ qr{^\s*(?:(?:'([^\\']*(?:\\.[^\\']*)*)')|([^#\s]\S*))?(?:(?:\s*)|(?:\s+(.*?)\s*))$}; + #my $comment = $3; + my $filename = $2; + if ( defined($1) ) { + $filename = $1; + $filename =~ s/\\(['\\])/$1/g; + } + $filename; +} + # returns an anonymous sub that decides if an argument matches sub maniskip { my @skip ; my $mfile = shift || "$MANIFEST.SKIP"; _check_mskip_directives($mfile) if -f $mfile; - local(*M, $_); - open M, "< $mfile" or open M, "< $DEFAULT_MSKIP" or return sub {0}; - while (){ - chomp; - s/\r//; - $_ =~ qr{^\s*(?:(?:'([^\\']*(?:\\.[^\\']*)*)')|([^#\s]\S*))?(?:(?:\s*)|(?:\s+(.*?)\s*))$}; - #my $comment = $3; - my $filename = $2; - if ( defined($1) ) { - $filename = $1; - $filename =~ s/\\(['\\])/$1/g; - } - next if (not defined($filename) or not $filename); - push @skip, _macify($filename); + local $_; + my $fh; + open $fh, '<', $mfile or open $fh, '<', $DEFAULT_MSKIP or return sub {0}; + while (<$fh>){ + if (/^#!include_default\s*$/) { + if (my @default = _include_mskip_file()) { + warn "Debug: Including default MANIFEST.SKIP\n" if $Debug; + push @skip, grep $_, map _process_skipline($_), @default; + } + next; + } + next unless my $filename = _process_skipline($_); + push @skip, $filename; } - close M; return sub {0} unless (scalar @skip > 0); my $opts = $Is_VMS_mode ? '(?i)' : ''; @@ -440,6 +440,10 @@ sub maniskip { return sub { $_[0] =~ qr{$opts$regex} }; } +sub _get_homedir { + $^O eq 'MSWin32' && "$]" < 5.016 ? $ENV{HOME} || $ENV{USERPROFILE} : (glob('~'))[0]; +} + # checks for the special directives # #!include_default # #!include /path/to/some/manifest.skip @@ -448,46 +452,39 @@ sub maniskip { # and an external manifest.skip file sub _check_mskip_directives { my $mfile = shift; - local (*M, $_); + local $_; + my $fh; my @lines = (); my $flag = 0; - unless (open M, "< $mfile") { + unless (open $fh, '<', $mfile) { warn "Problem opening $mfile: $!"; return; } - while () { - if (/^#!include_default\s*$/) { - if (my @default = _include_mskip_file()) { - push @lines, @default; - warn "Debug: Including default MANIFEST.SKIP\n" if $Debug; - $flag++; - } - next; - } - if (/^#!include\s+(.*)\s*$/) { - my $external_file = $1; - if (my @external = _include_mskip_file($external_file)) { - push @lines, @external; - warn "Debug: Including external $external_file\n" if $Debug; - $flag++; - } + while (<$fh>) { + if (/^#!include\s+(.*)\s*$/) { + my $external_file = $1; + $external_file =~ s{^~/}{_get_homedir().'/'}e; + if (my @external = _include_mskip_file($external_file)) { + push @lines, @external; + warn "Debug: Including external $external_file\n" if $Debug; + $flag++; + } next; } push @lines, $_; } - close M; + close $fh; return unless $flag; my $bakbase = $mfile; $bakbase =~ s/\./_/g if $Is_VMS_nodot; # avoid double dots rename $mfile, "$bakbase.bak"; warn "Debug: Saving original $mfile as $bakbase.bak\n" if $Debug; - unless (open M, "> $mfile") { + unless (open $fh, '>', $mfile) { warn "Problem opening $mfile: $!"; return; } - binmode M, ':raw'; - print M $_ for (@lines); - close M; + binmode $fh, ':raw'; + print $fh $_ for (@lines); return; } @@ -499,15 +496,15 @@ sub _include_mskip_file { warn qq{Included file "$mskip" not found - skipping}; return; } - local (*M, $_); - unless (open M, "< $mskip") { + local $_; + my $fh; + unless (open $fh, '<', $mskip) { warn "Problem opening $mskip: $!"; return; } my @lines = (); push @lines, "\n#!start included $mskip\n"; - push @lines, $_ while ; - close M; + push @lines, $_ while <$fh>; push @lines, "#!end included $mskip\n\n"; return @lines; } @@ -543,22 +540,13 @@ sub manicopy { $target = VMS::Filespec::unixify($target) if $Is_VMS_mode; File::Path::mkpath([ $target ],! $Quiet,$Is_VMS ? undef : 0755); foreach my $file (keys %$read){ - if ($Is_MacOS) { - if ($file =~ m!:!) { - my $dir = _maccat($target, $file); - $dir =~ s/[^:]+$//; - File::Path::mkpath($dir,1,0755); - } - cp_if_diff($file, _maccat($target, $file), $how); - } else { - $file = VMS::Filespec::unixify($file) if $Is_VMS_mode; - if ($file =~ m!/!) { # Ilya, that hurts, I fear, or maybe not? - my $dir = File::Basename::dirname($file); - $dir = VMS::Filespec::unixify($dir) if $Is_VMS_mode; - File::Path::mkpath(["$target/$dir"],! $Quiet,$Is_VMS ? undef : 0755); - } - cp_if_diff($file, "$target/$file", $how); - } + $file = VMS::Filespec::unixify($file) if $Is_VMS_mode; + if ($file =~ m!/!) { # Ilya, that hurts, I fear, or maybe not? + my $dir = File::Basename::dirname($file); + $dir = VMS::Filespec::unixify($dir) if $Is_VMS_mode; + File::Path::mkpath(["$target/$dir"],! $Quiet,$Is_VMS ? undef : 0755); + } + cp_if_diff($file, "$target/$file", $how); } } @@ -569,28 +557,28 @@ sub cp_if_diff { return; } my($diff) = 0; - local(*F,*T); - open(F,"< $from\0") or die "Can't read $from: $!\n"; - if (open(T,"< $to\0")) { + my ($fromfh, $tofh); + open($fromfh, '<', $from) or die "Can't read $from: $!\n"; + if (open($tofh, '<', $to)) { local $_; - while () { $diff++,last if $_ ne ; } - $diff++ unless eof(T); - close T; + while (<$fromfh>) { $diff++,last if $_ ne <$tofh>; } + $diff++ unless eof($tofh); + close $tofh; } else { $diff++; } - close F; + close $fromfh; if ($diff) { - if (-e $to) { - unlink($to) or confess "unlink $to: $!"; - } + if (-e $to) { + unlink($to) or confess "unlink $to: $!"; + } STRICT_SWITCH: { - best($from,$to), last STRICT_SWITCH if $how eq 'best'; - cp($from,$to), last STRICT_SWITCH if $how eq 'cp'; - ln($from,$to), last STRICT_SWITCH if $how eq 'ln'; - croak("ExtUtils::Manifest::cp_if_diff " . - "called with illegal how argument [$how]. " . - "Legal values are 'best', 'cp', and 'ln'."); - } + best($from,$to), last STRICT_SWITCH if $how eq 'best'; + cp($from,$to), last STRICT_SWITCH if $how eq 'cp'; + ln($from,$to), last STRICT_SWITCH if $how eq 'ln'; + croak("ExtUtils::Manifest::cp_if_diff " . + "called with illegal how argument [$how]. " . + "Legal values are 'best', 'cp', and 'ln'."); + } } } @@ -634,49 +622,12 @@ sub best { my $is_exception = grep $srcFile =~ /$_/, @Exceptions; if ($is_exception or !$Config{d_link} or -l $srcFile) { - cp($srcFile, $dstFile); + cp($srcFile, $dstFile); } else { - ln($srcFile, $dstFile) or cp($srcFile, $dstFile); - } -} - -sub _macify { - my($file) = @_; - - return $file unless $Is_MacOS; - - $file =~ s|^\./||; - if ($file =~ m|/|) { - $file =~ s|/+|:|g; - $file = ":$file"; + ln($srcFile, $dstFile) or cp($srcFile, $dstFile); } - - $file; } -sub _maccat { - my($f1, $f2) = @_; - - return "$f1/$f2" unless $Is_MacOS; - - $f1 .= ":$f2"; - $f1 =~ s/([^:]:):/$1/g; - return $f1; -} - -sub _unmacify { - my($file) = @_; - - return $file unless $Is_MacOS; - - $file =~ s|^:||; - $file =~ s|([/ \n])|sprintf("\\%03o", unpack("c", $1))|ge; - $file =~ y|:|/|; - - $file; -} - - =head2 maniadd maniadd({ $file => $comment, ...}); @@ -697,9 +648,9 @@ sub maniadd { my @needed = grep !exists $manifest->{$_}, keys %$additions; return 1 unless @needed; - open(MANIFEST, ">>$MANIFEST") or + open(my $fh, '>>', $MANIFEST) or die "maniadd() could not open $MANIFEST: $!"; - binmode MANIFEST, ':raw'; + binmode $fh, ':raw'; foreach my $file (_sort @needed) { my $comment = $additions->{$file} || ''; @@ -707,9 +658,9 @@ sub maniadd { $file =~ s/([\\'])/\\$1/g; $file = "'$file'"; } - printf MANIFEST "%-40s %s\n", $file, $comment; + printf $fh "%-40s %s\n", $file, $comment; } - close MANIFEST or die "Error closing $MANIFEST: $!"; + close $fh or die "Error closing $MANIFEST: $!"; return 1; } @@ -720,10 +671,10 @@ sub maniadd { sub _fix_manifest { my $manifest_file = shift; - open MANIFEST, $MANIFEST or die "Could not open $MANIFEST: $!"; + open my $fh, '<', $MANIFEST or die "Could not open $MANIFEST: $!"; local $/; - my @manifest = split /(\015\012|\012|\015)/, , -1; - close MANIFEST; + my @manifest = split /(\015\012|\012|\015)/, <$fh>, -1; + close $fh; my $must_rewrite = ""; if ($manifest[-1] eq ""){ # sane case: last line had a terminal newline @@ -740,12 +691,12 @@ sub _fix_manifest { if ( $must_rewrite ) { 1 while unlink $MANIFEST; # avoid multiple versions on VMS - open MANIFEST, ">", $MANIFEST or die "(must_rewrite=$must_rewrite) Could not open >$MANIFEST: $!"; - binmode MANIFEST, ':raw'; + open $fh, ">", $MANIFEST or die "(must_rewrite=$must_rewrite) Could not open >$MANIFEST: $!"; + binmode $fh, ':raw'; for (my $i=0; $i<=$#manifest; $i+=2) { - print MANIFEST "$manifest[$i]\n"; + print $fh "$manifest[$i]\n"; } - close MANIFEST or die "could not write $MANIFEST: $!"; + close $fh or die "could not write $MANIFEST: $!"; } } @@ -813,11 +764,17 @@ files. At present two such directives ar =item #!include_default -This inserts the contents of the default MANIFEST.SKIP file +This tells ExtUtils::Manifest to read the default F +file and skip files accordingly, but I to include it in the local +F. This is intended to skip files according to a system +default, which can change over time without requiring further changes +to the distribution's F. =item #!include /Path/to/another/manifest.skip -This inserts the contents of the specified external file +This inserts the contents of the specified external file in the local +F. This is intended for authors to have a central +F file, and to include it with their various distributions. =back Index: gnu/usr.bin/perl/cpan/ExtUtils-Manifest/t/Manifest.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/ExtUtils-Manifest/t/Manifest.t,v diff -u -p -a -u -p -r1.4 Manifest.t --- gnu/usr.bin/perl/cpan/ExtUtils-Manifest/t/Manifest.t 30 Dec 2019 02:13:43 -0000 1.4 +++ gnu/usr.bin/perl/cpan/ExtUtils-Manifest/t/Manifest.t 22 Jan 2025 00:37:42 -0000 @@ -13,7 +13,7 @@ BEGIN { } chdir 't'; -use Test::More tests => 98; +use Test::More tests => 101; use Cwd; use File::Spec; @@ -132,14 +132,14 @@ like( $warn, qr/^Skipping MANIFEST\.SKIP my @skipped; catch_warning( sub { - @skipped = skipcheck() + @skipped = skipcheck() }); is( join( ' ', @skipped ), 'MANIFEST.SKIP', 'listed skipped files' ); { - local $ExtUtils::Manifest::Quiet = 1; - is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' ); + local $ExtUtils::Manifest::Quiet = 1; + is( join(' ', filecheck() ), 'bar', 'listing skipped with filecheck()' ); } # add a subdirectory and a file there that should be found @@ -185,7 +185,7 @@ is( ExtUtils::Manifest::maniread()->{non ok( mkdir( 'copy', 0777 ), 'made copy directory' ); $files = maniread(); eval { (undef, $warn) = catch_warning( sub { - manicopy( $files, 'copy', 'cp' ) }) + manicopy( $files, 'copy', 'cp' ) }) }; # a newline comes through, so get rid of it @@ -197,12 +197,12 @@ like($warn, qr/^Skipping MANIFEST.SKIP/i # tell ExtUtils::Manifest to use a different file { - local $ExtUtils::Manifest::MANIFEST = 'albatross'; - ($res, $warn) = catch_warning( \&mkmanifest ); - like( $warn, qr/Added to albatross: /, 'using a new manifest file' ); + local $ExtUtils::Manifest::MANIFEST = 'albatross'; + ($res, $warn) = catch_warning( \&mkmanifest ); + like( $warn, qr/Added to albatross: /, 'using a new manifest file' ); - # add the new file to the list of files to be deleted - $Files{'albatross'}++; + # add the new file to the list of files to be deleted + $Files{'albatross'}++; } @@ -233,10 +233,10 @@ is( $files->{yarrow}, 'hock',' is( $files->{foobar}, '', ' preserved old entries' ); my $manicontents = do { - local $/; - open my $fh, "MANIFEST" or die; - binmode $fh, ':raw'; - <$fh> + local $/; + open my $fh, "MANIFEST" or die; + binmode $fh, ':raw'; + <$fh> }; is index($manicontents, "\015\012"), -1, 'MANIFEST no CRLF'; @@ -291,11 +291,11 @@ SKIP: { local $ExtUtils::Manifest::MANIFEST = "albatross"; maniadd({ 'foo bar' => "contains space"}); is( maniread()->{'foo bar'}, "contains space", - 'spaced manifest filename' ); + 'spaced manifest filename' ); add_file( 'albatross.bak', '' ); ($res, $warn) = catch_warning( \&mkmanifest ); like( $warn, qr/\A(Added to.*\n)+\z/m, - 'no warnings about funky filename' ); + 'no warnings about funky filename' ); $funky_files{'space'} = 'foo bar'; } @@ -306,7 +306,7 @@ SKIP: { local $ExtUtils::Manifest::MANIFEST = "albatross"; maniadd({ 'foo\' baz\'quux' => "contains quote"}); is( maniread()->{'foo\' baz\'quux'}, "contains quote", - 'quoted manifest filename' ); + 'quoted manifest filename' ); $funky_files{'space_quote'} = 'foo\' baz\'quux'; } @@ -317,7 +317,7 @@ SKIP: { local $ExtUtils::Manifest::MANIFEST = "albatross"; maniadd({ 'foo bar\\baz' => "contains backslash"}); is( maniread()->{'foo bar\\baz'}, "contains backslash", - 'backslashed manifest filename' ); + 'backslashed manifest filename' ); $funky_files{'space_backslash'} = 'foo bar\\baz'; } @@ -328,7 +328,7 @@ SKIP: { local $ExtUtils::Manifest::MANIFEST = "albatross"; maniadd({ 'foo bar\\baz\'quux' => "backslash and quote"}); is( maniread()->{'foo bar\\baz\'quux'}, "backslash and quote", - 'backslashed and quoted manifest filename' ); + 'backslashed and quoted manifest filename' ); $funky_files{'space_quote_backslash'} = 'foo bar\\baz\'quux'; } @@ -342,14 +342,16 @@ SKIP: { local $ExtUtils::Manifest::MANIFEST = "albatross"; maniadd({ $quoted_filename => $description }); is( maniread()->{$quoted_filename}, $description, - 'file whose name starts and ends with quotes' ); + 'file whose name starts and ends with quotes' ); $funky_files{$description} = $quoted_filename; } my @funky_keys = qw(space space_quote space_backslash space_quote_backslash); # test including an external manifest.skip file in MANIFEST.SKIP { - maniadd({ foo => undef , albatross => undef, + local $ENV{HOME} = File::Spec->catdir($cwd, qw(mantest)); + + maniadd({ foo => undef, orange => undef, albatross => undef, 'mymanifest.skip' => undef, 'mydefault.skip' => undef}); for (@funky_keys) { maniadd( {$funky_files{$_} => $_} ) if defined $funky_files{$_}; @@ -360,8 +362,9 @@ my @funky_keys = qw(space space_quote sp local $ExtUtils::Manifest::DEFAULT_MSKIP = File::Spec->catfile($cwd, qw(mantest mydefault.skip)); my $skip = File::Spec->catfile($cwd, qw(mantest mymanifest.skip)); + add_file('global.skip' => "^orange\n"); add_file('MANIFEST.SKIP' => - "albatross\n#!include $skip\n#!include_default"); + "albatross\n#!include $skip\n#!include_default\n#!include ~/global.skip"); my ($res, $warn) = catch_warning( \&skipcheck ); for (qw(albatross foo foobar mymanifest.skip mydefault.skip)) { like( $warn, qr/Skipping \b$_\b/, @@ -370,23 +373,23 @@ my @funky_keys = qw(space space_quote sp for my $funky_key (@funky_keys) { SKIP: { my $funky_file = $funky_files{$funky_key}; - skip "'$funky_key' not created", 1 unless $funky_file; - like( $warn, qr/Skipping \b\Q$funky_file\E\b/, - "Skipping $funky_file"); - } + skip "'$funky_key' not created", 1 unless $funky_file; + like( $warn, qr/Skipping \b\Q$funky_file\E\b/, + "Skipping $funky_file"); + } } ($res, $warn) = catch_warning( \&mkmanifest ); - for (qw(albatross foo foobar mymanifest.skip mydefault.skip)) { + for (qw(albatross foo foobar mymanifest.skip mydefault.skip orange)) { like( $warn, qr/Removed from MANIFEST: \b$_\b/, "Removed $_ from MANIFEST" ); } for my $funky_key (@funky_keys) { SKIP: { my $funky_file = $funky_files{$funky_key}; - skip "'$funky_key' not created", 1 unless $funky_file; - like( $warn, qr/Removed from MANIFEST: \b\Q$funky_file\E\b/, - "Removed $funky_file from MANIFEST"); - } + skip "'$funky_key' not created", 1 unless $funky_file; + like( $warn, qr/Removed from MANIFEST: \b\Q$funky_file\E\b/, + "Removed $funky_file from MANIFEST"); + } } my $files = maniread; ok( ! exists $files->{albatross}, 'albatross excluded via MANIFEST.SKIP' ); @@ -394,6 +397,7 @@ my @funky_keys = qw(space space_quote sp ok( exists $files->{bar}, 'bar included in MANIFEST' ); ok( ! exists $files->{foobar}, 'foobar excluded via mymanifest.skip' ); ok( ! exists $files->{foo}, 'foo excluded via mymanifest.skip' ); + ok( ! exists $files->{orange}, 'orange excluded via global.skip' ); ok( ! exists $files->{'mymanifest.skip'}, 'mymanifest.skip excluded via mydefault.skip' ); ok( ! exists $files->{'mydefault.skip'}, @@ -403,34 +407,34 @@ my @funky_keys = qw(space space_quote sp for my $funky_key (@funky_keys) { SKIP: { my $funky_file = $funky_files{$funky_key}; - skip "'$funky_key' not created", 1 unless $funky_file; - ok( ! exists $files->{$funky_file}, - "'$funky_file' excluded via mymanifest.skip" ); - } + skip "'$funky_key' not created", 1 unless $funky_file; + ok( ! exists $files->{$funky_file}, + "'$funky_file' excluded via mymanifest.skip" ); + } } # tests for maniskip my $skipchk = maniskip(); is ( $skipchk->('albatross'), 1, - 'albatross excluded via MANIFEST.SKIP' ); + 'albatross excluded via MANIFEST.SKIP' ); is( $skipchk->('yarrow'), '', - 'yarrow included in MANIFEST' ); + 'yarrow included in MANIFEST' ); is( $skipchk->('bar'), '', - 'bar included in MANIFEST' ); + 'bar included in MANIFEST' ); $skipchk = maniskip('mymanifest.skip'); is( $skipchk->('foobar'), 1, - 'foobar excluded via mymanifest.skip' ); + 'foobar excluded via mymanifest.skip' ); is( $skipchk->('foo'), 1, - 'foo excluded via mymanifest.skip' ); + 'foo excluded via mymanifest.skip' ); is( $skipchk->('mymanifest.skip'), '', 'mymanifest.skip included via mydefault.skip' ); is( $skipchk->('mydefault.skip'), '', 'mydefault.skip included via mydefault.skip' ); $skipchk = maniskip('mydefault.skip'); is( $skipchk->('foobar'), '', - 'foobar included via mydefault.skip' ); + 'foobar included via mydefault.skip' ); is( $skipchk->('foo'), '', - 'foo included via mydefault.skip' ); + 'foo included via mydefault.skip' ); is( $skipchk->('mymanifest.skip'), 1, 'mymanifest.skip excluded via mydefault.skip' ); is( $skipchk->('mydefault.skip'), 1, @@ -438,6 +442,13 @@ my @funky_keys = qw(space space_quote sp my $extsep = $Is_VMS_noefs ? '_' : '.'; $Files{"$_.bak"}++ for ('MANIFEST', "MANIFEST${extsep}SKIP"); + + my $mskip_contents = do { + local $/; + open my $fh, '<', "MANIFEST${extsep}SKIP" or return; + <$fh>; + }; + unlike $mskip_contents, qr{^\Q^my\E}m, 'include_default memory-only'; } add_file('MANIFEST' => 'Makefile.PL'); @@ -473,11 +484,11 @@ SKIP: { END { - is( unlink( keys %Files ), keys %Files, 'remove all added files' ); - for my $file ( keys %Files ) { 1 while unlink $file; } # all versions - remove_dir( 'moretest', 'copy' ); - - # now get rid of the parent directory - ok( chdir( $cwd ), 'return to parent directory' ); - remove_dir( 'mantest' ); + is( unlink( keys %Files ), keys %Files, 'remove all added files' ); + for my $file ( keys %Files ) { 1 while unlink $file; } # all versions + remove_dir( 'moretest', 'copy' ); + + # now get rid of the parent directory + ok( chdir( $cwd ), 'return to parent directory' ); + remove_dir( 'mantest' ); } Index: gnu/usr.bin/perl/cpan/Getopt-Long/lib/Getopt/Long.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Getopt-Long/lib/Getopt/Long.pm,v diff -u -p -a -u -p -r1.9 Long.pm --- gnu/usr.bin/perl/cpan/Getopt-Long/lib/Getopt/Long.pm 14 May 2024 19:38:55 -0000 1.9 +++ gnu/usr.bin/perl/cpan/Getopt-Long/lib/Getopt/Long.pm 22 Jan 2025 00:37:42 -0000 @@ -3,31 +3,24 @@ # Getopt::Long.pm -- Universal options parsing # Author : Johan Vromans # Created On : Tue Sep 11 15:00:12 1990 -# Last Modified By: Johan Vromans -# Last Modified On: Thu Nov 17 17:45:27 2022 -# Update Count : 1777 +# Last Modified On: Sat Nov 11 17:48:41 2023 +# Update Count : 1808 # Status : Released ################ Module Preamble ################ -# There are no CPAN testers for very old versions of Perl. -# Getopt::Long is reported to run under 5.8. -use 5.004; +# Getopt::Long is reported to run under 5.6.1. Thanks Tux! +use 5.006001; use strict; use warnings; package Getopt::Long; -use vars qw($VERSION); -$VERSION = 2.54; -# For testing versions only. -use vars qw($VERSION_STRING); -$VERSION_STRING = "2.54"; +our $VERSION = 2.57; use Exporter; -use vars qw(@ISA @EXPORT @EXPORT_OK); -@ISA = qw(Exporter); +use base qw(Exporter); # Exported subroutines. sub GetOptions(@); # always @@ -37,21 +30,24 @@ sub Configure(@); # on demand sub HelpMessage(@); # on demand sub VersionMessage(@); # in demand +our @EXPORT; +our @EXPORT_OK; +# Values for $order. See GNU getopt.c for details. +our ($REQUIRE_ORDER, $PERMUTE, $RETURN_IN_ORDER); BEGIN { - # Init immediately so their contents can be used in the 'use vars' below. + ($REQUIRE_ORDER, $PERMUTE, $RETURN_IN_ORDER) = (0..2); @EXPORT = qw(&GetOptions $REQUIRE_ORDER $PERMUTE $RETURN_IN_ORDER); @EXPORT_OK = qw(&HelpMessage &VersionMessage &Configure &GetOptionsFromArray &GetOptionsFromString); } # User visible variables. -use vars @EXPORT, @EXPORT_OK; -use vars qw($error $debug $major_version $minor_version); +our ($error, $debug, $major_version, $minor_version); # Deprecated visible variables. -use vars qw($autoabbrev $getopt_compat $ignorecase $bundling $order - $passthrough); +our ($autoabbrev, $getopt_compat, $ignorecase, $bundling, $order, + $passthrough); # Official invisible variables. -use vars qw($genprefix $caller $gnu_compat $auto_help $auto_version $longprefix); +our ($genprefix, $caller, $gnu_compat, $auto_help, $auto_version, $longprefix); # Really invisible variables. my $bundling_values; @@ -125,97 +121,29 @@ sub import { ################ Initialization ################ -# Values for $order. See GNU getopt.c for details. -($REQUIRE_ORDER, $PERMUTE, $RETURN_IN_ORDER) = (0..2); # Version major/minor numbers. ($major_version, $minor_version) = $VERSION =~ /^(\d+)\.(\d+)/; ConfigDefaults(); -################ OO Interface ################ - -package Getopt::Long::Parser; - # Store a copy of the default configuration. Since ConfigDefaults has # just been called, what we get from Configure is the default. my $default_config = do { Getopt::Long::Configure () }; -sub new { - my $that = shift; - my $class = ref($that) || $that; - my %atts = @_; - - # Register the callers package. - my $self = { caller_pkg => (caller)[0] }; - - bless ($self, $class); - - # Process config attributes. - if ( defined $atts{config} ) { - my $save = Getopt::Long::Configure ($default_config, @{$atts{config}}); - $self->{settings} = Getopt::Long::Configure ($save); - delete ($atts{config}); - } - # Else use default config. - else { - $self->{settings} = $default_config; - } - - if ( %atts ) { # Oops - die(__PACKAGE__.": unhandled attributes: ". - join(" ", sort(keys(%atts)))."\n"); - } - - $self; -} - -sub configure { - my ($self) = shift; - - # Restore settings, merge new settings in. - my $save = Getopt::Long::Configure ($self->{settings}, @_); - - # Restore orig config and save the new config. - $self->{settings} = Getopt::Long::Configure ($save); -} - -sub getoptions { - my ($self) = shift; - - return $self->getoptionsfromarray(\@ARGV, @_); -} - -sub getoptionsfromarray { - my ($self) = shift; +# For the parser only. +sub _default_config { $default_config } - # Restore config settings. - my $save = Getopt::Long::Configure ($self->{settings}); - - # Call main routine. - my $ret = 0; - $Getopt::Long::caller = $self->{caller_pkg}; +################ Back to Normal ################ - eval { - # Locally set exception handler to default, otherwise it will - # be called implicitly here, and again explicitly when we try - # to deliver the messages. - local ($SIG{__DIE__}) = 'DEFAULT'; - $ret = Getopt::Long::GetOptionsFromArray (@_); - }; - - # Restore saved settings. - Getopt::Long::Configure ($save); - - # Handle errors and return value. - die ($@) if $@; - return $ret; +# The ooparser was traditionally part of the main package. +no warnings 'redefine'; +sub Getopt::Long::Parser::new { + require Getopt::Long::Parser; + goto &Getopt::Long::Parser::new; } - -package Getopt::Long; - -################ Back to Normal ################ +use warnings 'redefine'; # Indices in option control info. # Note that ParseOptions uses the fields directly. Search for 'hard-wired'. @@ -305,7 +233,7 @@ sub GetOptionsFromArray(@) { # Avoid some warnings if debugging. local ($^W) = 0; print STDERR - ("Getopt::Long $Getopt::Long::VERSION_STRING ", + ("Getopt::Long $VERSION ", "called from package \"$pkg\".", "\n ", "argv: ", @@ -806,11 +734,15 @@ sub OptCtl ($) { sub ParseOptionSpec ($$) { my ($opt, $opctl) = @_; + # Allow period in option name unless passing through, + my $op = $passthrough + ? qr/(?: \w+[-\w]* )/x : qr/(?: \w+[-.\w]* )/x; + # Match option spec. if ( $opt !~ m;^ ( # Option name - (?: \w+[-\w]* ) + $op # Aliases (?: \| (?: . [^|!+=:]* )? )* )? @@ -929,7 +861,8 @@ sub ParseOptionSpec ($$) { } } - if ( $dups && $^W ) { + if ( $dups ) { + # Warn now. Will become fatal in a future release. foreach ( split(/\n+/, $dups) ) { warn($_."\n"); } @@ -1495,9 +1428,7 @@ sub VersionMessage(@) { $0, defined $v ? " version $v" : (), "\n", "(", __PACKAGE__, "::", "GetOptions", - " version ", - defined($Getopt::Long::VERSION_STRING) - ? $Getopt::Long::VERSION_STRING : $VERSION, ";", + " version $VERSION,", " Perl version ", $] >= 5.006 ? sprintf("%vd", $^V) : $], ")\n"); @@ -1515,7 +1446,7 @@ sub VersionMessage(@) { sub HelpMessage(@) { eval { require Pod::Usage; - import Pod::Usage; + Pod::Usage->import; 1; } || die("Cannot provide help: cannot load Pod::Usage\n"); @@ -1941,7 +1872,9 @@ and the argument specification. The name specification contains the name of the option, optionally followed by a list of alternative names separated by vertical bar -characters. +characters. The name is made up of alphanumeric characters, hyphens, +underscores. If C is disabled, a period is also allowed in +option names. length option name is "length" length|size|l name is "length", aliases are "size" and "l" @@ -2048,18 +1981,7 @@ option will be incremented. =head2 Object oriented interface -Getopt::Long can be used in an object oriented way as well: - - use Getopt::Long; - $p = Getopt::Long::Parser->new; - $p->configure(...configuration options...); - if ($p->getoptions(...options descriptions...)) ... - if ($p->getoptionsfromarray( \@array, ...options descriptions...)) ... - -Configuration options can be passed to the constructor: - - $p = new Getopt::Long::Parser - config => [...configuration options...]; +See L. =head2 Callback object @@ -2389,11 +2311,12 @@ POSIXLY_CORRECT has been set, in which c C controls whether C<--opt=> is allowed, and what it should do. Without C, C<--opt=> gives an error. With C, -C<--opt=> will give option C and empty value. +C<--opt=> will give option C an empty value. This is the way GNU getopt_long() does it. -Note that C<--opt value> is still accepted, even though GNU -getopt_long() doesn't. +Note that for options with optional arguments, C<--opt value> is still +accepted, even though GNU getopt_long() requires writing C<--opt=value> +in this case. =item gnu_getopt @@ -2677,7 +2600,7 @@ When no destination is specified for an the resultant value in a global variable named CI, where I is the primary name of this option. When a program executes under C (recommended), these variables must be -pre-declared with our() or C. +pre-declared with our(). our $opt_length = 0; GetOptions ('length=i'); # will store in $opt_length @@ -2805,7 +2728,7 @@ Johan Vromans =head1 COPYRIGHT AND DISCLAIMER -This program is Copyright 1990,2015 by Johan Vromans. +This program is Copyright 1990,2015,2023 by Johan Vromans. This program is free software; you can redistribute it and/or modify it under the terms of the Perl Artistic License or the GNU General Public License as published by the Free Software Index: gnu/usr.bin/perl/cpan/Getopt-Long/lib/Getopt/Long/Parser.pm =================================================================== RCS file: gnu/usr.bin/perl/cpan/Getopt-Long/lib/Getopt/Long/Parser.pm diff -N gnu/usr.bin/perl/cpan/Getopt-Long/lib/Getopt/Long/Parser.pm --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Getopt-Long/lib/Getopt/Long/Parser.pm 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,177 @@ +#! perl + +# Parser.pm -- Getopt::Long object oriented interface +# Author : Johan Vromans +# Created On : Thu Nov 9 10:37:00 2023 +# Last Modified On: Sat Nov 11 17:48:49 2023 +# Update Count : 13 +# Status : Released + +package Getopt::Long::Parser; + +our $VERSION = 2.57; + +=head1 NAME + +Getopt::Long::Parser - Getopt::Long object oriented interface + +=head1 SYNOPSIS + + use Getopt::Long::Parser; + my $p = Getopt::Long::Parser->new; + $p->configure( ...configuration options... ); + if ( $p->getoptions( ...options descriptions... ) ) ... + if ( $p->getoptionsfromarray( \@array, ...options descriptions... ) ) ... + +Configuration options can be passed to the constructor: + + my $p = Getopt::Long::Parser->new + config => [...configuration options...]; + +=head1 DESCRIPTION + +Getopt::Long::Parser is an object oriented interface to +L. See its documentation for configuration and use. + +Note that Getopt::Long and Getopt::Long::Parser are not object +oriented. Getopt::Long::Parser emulates an object oriented interface, +which should be okay for most purposes. + +=head1 CONSTRUCTOR + + my $p = Getopt::Long::Parser->new( %options ); + +The constructor takes an optional hash with parameters. + +=over 4 + +=item config + +An array reference with configuration settings. +See L for all possible settings. + +=back + +=cut + +# Getopt::Long has a stub for Getopt::Long::Parser::new. +use Getopt::Long (); +no warnings 'redefine'; + +sub new { + my $that = shift; + my $class = ref($that) || $that; + my %atts = @_; + + # Register the callers package. + my $self = { caller_pkg => (caller)[0] }; + + bless ($self, $class); + + my $default_config = Getopt::Long::_default_config(); + + # Process config attributes. + if ( defined $atts{config} ) { + my $save = Getopt::Long::Configure ($default_config, @{$atts{config}}); + $self->{settings} = Getopt::Long::Configure ($save); + delete ($atts{config}); + } + # Else use default config. + else { + $self->{settings} = $default_config; + } + + if ( %atts ) { # Oops + die(__PACKAGE__.": unhandled attributes: ". + join(" ", sort(keys(%atts)))."\n"); + } + + $self; +} + +use warnings 'redefine'; + +=head1 METHODS + +In the examples, $p is assumed to be the result of a call to the constructor. + +=head2 configure + + $p->configure( %settings ); + +Update the current config settings. +See L for all possible settings. + +=cut + +sub configure { + my ($self) = shift; + + # Restore settings, merge new settings in. + my $save = Getopt::Long::Configure ($self->{settings}, @_); + + # Restore orig config and save the new config. + $self->{settings} = Getopt::Long::Configure ($save); +} + +=head2 getoptionsfromarray + + $res = $p->getoptionsfromarray( $aref, @opts ); + +=head2 getoptions + + $res = $p->getoptions( @opts ); + +The same as getoptionsfromarray( \@ARGV, @opts ). + +=cut + +sub getoptions { + my ($self) = shift; + + return $self->getoptionsfromarray(\@ARGV, @_); +} + +sub getoptionsfromarray { + my ($self) = shift; + + # Restore config settings. + my $save = Getopt::Long::Configure ($self->{settings}); + + # Call main routine. + my $ret = 0; + $Getopt::Long::caller = $self->{caller_pkg}; + + eval { + # Locally set exception handler to default, otherwise it will + # be called implicitly here, and again explicitly when we try + # to deliver the messages. + local ($SIG{__DIE__}) = 'DEFAULT'; + $ret = Getopt::Long::GetOptionsFromArray (@_); + }; + + # Restore saved settings. + Getopt::Long::Configure ($save); + + # Handle errors and return value. + die ($@) if $@; + return $ret; +} + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Johan Vromans + +=head1 COPYRIGHT AND DISCLAIMER + +This program is Copyright 1990,2015,2023 by Johan Vromans. +This program is free software; you can redistribute it and/or +modify it under the same terms as Perl. + +=cut + +1; Index: gnu/usr.bin/perl/cpan/Getopt-Long/t/gol-load1.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Getopt-Long/t/gol-load1.t diff -N gnu/usr.bin/perl/cpan/Getopt-Long/t/gol-load1.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Getopt-Long/t/gol-load1.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,37 @@ +#! perl + +# Verify that loading Getopt::Long does not load Getopt::Long::Parser +# until/unless used. + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = ('../lib', 'lib'); + } + else { + unshift @INC, 't/lib'; + } +} + +use strict; +use warnings; +use Test::More tests => 4; + +use_ok("Getopt::Long"); + +# Getopt::Long::Parser should not be loaded. +ok( !defined $Getopt::Long::Parser::VERSION, + "Getopt::Long did not load Parser" ); + +# Create a parser object. +my $p = Getopt::Long::Parser->new; + +# Getopt::Long::Parser should now be loaded. +ok( defined $Getopt::Long::Parser::VERSION, + "Parser $Getopt::Long::Parser::VERSION loaded" ); + +# Verify version match. +is( $Getopt::Long::VERSION, $Getopt::Long::Parser::VERSION, + "Parser version matches" ); + +diag( "Testing Getopt::Long $Getopt::Long::VERSION, Perl $], $^X" ); Index: gnu/usr.bin/perl/cpan/Getopt-Long/t/gol-load2.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Getopt-Long/t/gol-load2.t diff -N gnu/usr.bin/perl/cpan/Getopt-Long/t/gol-load2.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Getopt-Long/t/gol-load2.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,27 @@ +#! perl + +# Verify that loading Getopt::Long::Parser also loads Getopt::Long. + +BEGIN { + if( $ENV{PERL_CORE} ) { + chdir 't'; + @INC = ('../lib', 'lib'); + } + else { + unshift @INC, 't/lib'; + } +} + +use strict; +use warnings; +use Test::More tests => 3; + +use_ok("Getopt::Long::Parser"); + +# Getopt::Long should have been loaded as well. +ok( defined $Getopt::Long::VERSION, + "Getopt::Long::Parser loads Getopt::Long" ); + +# Verify version match. +is( $Getopt::Long::VERSION, $Getopt::Long::Parser::VERSION, + "Parser version matches" ); Index: gnu/usr.bin/perl/cpan/Getopt-Long/t/gol-oo.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Getopt-Long/t/gol-oo.t,v diff -u -p -a -u -p -r1.1.1.2 gol-oo.t --- gnu/usr.bin/perl/cpan/Getopt-Long/t/gol-oo.t 24 Mar 2014 14:58:52 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/Getopt-Long/t/gol-oo.t 22 Jan 2025 00:37:42 -0000 @@ -9,11 +9,11 @@ BEGIN { } } -use Getopt::Long; +use Getopt::Long::Parser; my $want_version="2.24"; die("Getopt::Long version $want_version required--this is only version ". - $Getopt::Long::VERSION) - unless $Getopt::Long::VERSION ge $want_version; + $Getopt::Long::Parser::VERSION) + unless $Getopt::Long::Parser::VERSION ge $want_version; print "1..14\n"; @ARGV = qw(-Foo -baR --foo bar); Index: gnu/usr.bin/perl/cpan/HTTP-Tiny/lib/HTTP/Tiny.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/HTTP-Tiny/lib/HTTP/Tiny.pm,v diff -u -p -a -u -p -r1.7 Tiny.pm --- gnu/usr.bin/perl/cpan/HTTP-Tiny/lib/HTTP/Tiny.pm 14 May 2024 19:38:55 -0000 1.7 +++ gnu/usr.bin/perl/cpan/HTTP-Tiny/lib/HTTP/Tiny.pm 22 Jan 2025 00:37:42 -0000 @@ -4,7 +4,7 @@ use strict; use warnings; # ABSTRACT: A small, simple, correct HTTP/1.1 client -our $VERSION = '0.086'; +our $VERSION = '0.088'; sub _croak { require Carp; Carp::croak(@_) } @@ -1727,7 +1727,7 @@ HTTP::Tiny - A small, simple, correct HT =head1 VERSION -version 0.086 +version 0.088 =head1 SYNOPSIS @@ -2351,7 +2351,7 @@ L - Required for SSL suppor =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker -at L. +at L. You will be notified automatically of any progress on your issue. =head2 Source Code @@ -2359,9 +2359,9 @@ You will be notified automatically of an This is open source software. The code repository is available for public review and contribution under the terms of the license. -L +L - git clone https://github.com/chansen/p5-http-tiny.git + git clone https://github.com/Perl-Toolchain-Gang/HTTP-Tiny.git =head1 AUTHORS Index: gnu/usr.bin/perl/cpan/IO-Compress/Makefile.PL =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/Makefile.PL,v diff -u -p -a -u -p -r1.8 Makefile.PL --- gnu/usr.bin/perl/cpan/IO-Compress/Makefile.PL 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/Makefile.PL 22 Jan 2025 00:37:42 -0000 @@ -3,8 +3,8 @@ use strict ; require 5.006 ; -$::VERSION = '2.204' ; -$::DEP_VERSION = '2.204'; +$::VERSION = '2.212' ; +$::DEP_VERSION = '2.212'; use lib '.'; use private::MakeUtil; Index: gnu/usr.bin/perl/cpan/IO-Compress/bin/streamzip =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/bin/streamzip,v diff -u -p -a -u -p -r1.1.1.3 streamzip --- gnu/usr.bin/perl/cpan/IO-Compress/bin/streamzip 14 May 2024 19:36:33 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/IO-Compress/bin/streamzip 22 Jan 2025 00:37:42 -0000 @@ -136,7 +136,7 @@ OPTIONS zstd Use LZMA compression [needs IO::Compress::Zstd] -version Display version number [$VERSION] -Copyright (c) 2019-2022 Paul Marquess. All rights reserved. +Copyright (c) 2019-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. @@ -292,7 +292,7 @@ Paul Marquess F. =head1 COPYRIGHT -Copyright (c) 2019-2022 Paul Marquess. All rights reserved. +Copyright (c) 2019-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/bin/zipdetails =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/bin/zipdetails,v diff -u -p -a -u -p -r1.6 zipdetails --- gnu/usr.bin/perl/cpan/IO-Compress/bin/zipdetails 15 Feb 2023 01:36:18 -0000 1.6 +++ gnu/usr.bin/perl/cpan/IO-Compress/bin/zipdetails 22 Jan 2025 00:37:42 -0000 @@ -7,6 +7,8 @@ use 5.010; # for unpack "Q<" +my $NESTING_DEBUG = 0 ; + BEGIN { # Check for a 32-bit Perl if (!eval { pack "Q", 1 }) { @@ -20,15 +22,30 @@ BEGIN { pop @INC if $INC[-1] eq '.' } use strict; use warnings ; no warnings 'portable'; # for unpacking > 2^32 -use feature 'state'; +use feature qw(state say); use IO::File; use Encode; use Getopt::Long; +use List::Util qw(min max); + +my $VERSION = '4.004' ; -my $VERSION = "2.104" ; +sub fatal_tryWalk; +sub fatal_truncated ; +sub info ; +sub warning ; +sub error ; +sub debug ; +sub fatal ; +sub topLevelFatal ; +sub internalFatal; +sub need ; +sub decimalHex; +use constant MAX64 => 0xFFFFFFFFFFFFFFFF ; use constant MAX32 => 0xFFFFFFFF ; +use constant MAX16 => 0xFFFF ; # Compression types use constant ZIP_CM_STORE => 0 ; @@ -45,6 +62,11 @@ use constant ZIP_GP_FLAG_PATCHED_MASK use constant ZIP_GP_FLAG_STRONG_ENCRYPTED_MASK => (1 << 6) ; use constant ZIP_GP_FLAG_LZMA_EOS_PRESENT => (1 << 1) ; use constant ZIP_GP_FLAG_LANGUAGE_ENCODING => (1 << 11) ; +use constant ZIP_GP_FLAG_PKWARE_ENHANCED_COMP => (1 << 12) ; +use constant ZIP_GP_FLAG_ENCRYPTED_CD => (1 << 13) ; + +# All the encryption flags +use constant ZIP_GP_FLAG_ALL_ENCRYPT => (ZIP_GP_FLAG_ENCRYPTED_MASK | ZIP_GP_FLAG_STRONG_ENCRYPTED_MASK | ZIP_GP_FLAG_ENCRYPTED_CD ); # Internal File Attributes use constant ZIP_IFA_TEXT_MASK => 1; @@ -56,10 +78,9 @@ use constant ZIP_CENTRAL_HDR_SIG use constant ZIP_END_CENTRAL_HDR_SIG => 0x06054b50; use constant ZIP64_END_CENTRAL_REC_HDR_SIG => 0x06064b50; use constant ZIP64_END_CENTRAL_LOC_HDR_SIG => 0x07064b50; -use constant ZIP_ARCHIVE_EXTRA_DATA_SIG => 0x08064b50; use constant ZIP_DIGITAL_SIGNATURE_SIG => 0x05054b50; - use constant ZIP_ARCHIVE_EXTRA_DATA_RECORD_SIG => 0x08064b50; +use constant ZIP_SINGLE_SEGMENT_MARKER => 0x30304b50; # APPNOTE 6.3.10, sec 8.5.4 # Extra sizes use constant ZIP_EXTRA_HEADER_SIZE => 2 ; @@ -71,6 +92,12 @@ use constant ZIP_EXTRA_SUBFIELD_HEADER_S use constant ZIP_EXTRA_SUBFIELD_MAX_SIZE => ZIP_EXTRA_MAX_SIZE - ZIP_EXTRA_SUBFIELD_HEADER_SIZE; +use constant ZIP_EOCD_MIN_SIZE => 22 ; + + +use constant ZIP_LD_FILENAME_OFFSET => 30; +use constant ZIP_CD_FILENAME_OFFSET => 46; + my %ZIP_CompressionMethods = ( 0 => 'Stored', @@ -82,7 +109,7 @@ my %ZIP_CompressionMethods = 6 => 'Imploded', 7 => 'Reserved for Tokenizing compression algorithm', 8 => 'Deflated', - 9 => 'Enhanced Deflating using Deflate64(tm)', + 9 => 'Deflate64', 10 => 'PKWARE Data Compression Library Imploding', 11 => 'Reserved by PKWARE', 12 => 'BZIP2', @@ -91,15 +118,17 @@ my %ZIP_CompressionMethods = 15 => 'Reserved by PKWARE', 16 => 'IBM z/OS CMPSC Compression', 17 => 'Reserved by PKWARE', - 18 => 'File is compressed using IBM TERSE (new)', + 18 => 'IBM/TERSE or Xceed BWT', # APPNOTE has IBM/TERSE. Xceed reuses it unofficially 19 => 'IBM LZ77 z Architecture (PFS)', + 20 => 'Ipaq8', # see https://encode.su/threads/1048-info-zip-lpaq8 + 92 => 'Reference', # Winzip Only from version 25 93 => 'Zstandard', 94 => 'MP3', 95 => 'XZ', 96 => 'WinZip JPEG Compression', 97 => 'WavPack compressed data', 98 => 'PPMd version I, Rev 1', - 99 => 'AES Encryption', + 99 => 'AES Encryption', # Apple also use this code for LZFSE compression in IPA files ); my %OS_Lookup = ( @@ -126,95 +155,264 @@ my %OS_Lookup = ( 30 => "AtheOS/Syllable", ); +{ + package Signatures ; + + my %Lookup = ( + # Map unpacked signature to + # decoder + # name + # central flag + + # Core Signatures + ::ZIP_LOCAL_HDR_SIG, [ \&::LocalHeader, "Local File Header", 0 ], + ::ZIP_DATA_HDR_SIG, [ \&::DataDescriptor, "Data Descriptor", 0 ], + ::ZIP_CENTRAL_HDR_SIG, [ \&::CentralHeader, "Central Directory Header", 1 ], + ::ZIP_END_CENTRAL_HDR_SIG, [ \&::EndCentralHeader, "End Central Directory Record", 1 ], + ::ZIP_SINGLE_SEGMENT_MARKER, [ \&::SingleSegmentMarker, "Split Archive Single Segment Marker", 0], + + # Zip64 + ::ZIP64_END_CENTRAL_REC_HDR_SIG, [ \&::Zip64EndCentralHeader, "Zip64 End of Central Directory Record", 1 ], + ::ZIP64_END_CENTRAL_LOC_HDR_SIG, [ \&::Zip64EndCentralLocator, "Zip64 End of Central Directory Locator", 1 ], + + # Digital signature (pkzip) + ::ZIP_DIGITAL_SIGNATURE_SIG, [ \&::DigitalSignature, "Digital Signature", 1 ], + + # Archive Encryption Headers (pkzip) - never seen this one + ::ZIP_ARCHIVE_EXTRA_DATA_RECORD_SIG, [ \&::ArchiveExtraDataRecord, "Archive Extra Record", 1 ], + ); + + sub decoder + { + my $signature = shift ; + + return undef + unless exists $Lookup{$signature}; + + return $Lookup{$signature}[0]; + } + + sub name + { + my $signature = shift ; + + return 'UNKNOWN' + unless exists $Lookup{$signature}; + + return $Lookup{$signature}[1]; + } + + sub titleName + { + my $signature = shift ; + + uc name($signature); + } + + sub hexValue + { + my $signature = shift ; + sprintf "0x%X", $signature ; + } + + sub hexValue32 + { + my $signature = shift ; + sprintf "0x%08X", $signature ; + } + + sub hexValue16 + { + my $signature = shift ; + sprintf "0x%04X", $signature ; + } + + sub nameAndHex + { + my $signature = shift ; + + return "'" . name($signature) . "' (" . hexValue32($signature) . ")" + } + + sub isCentralHeader + { + my $signature = shift ; + + return undef + unless exists $Lookup{$signature}; + + return $Lookup{$signature}[2]; + } + #sub isValidSignature + #{ + # my $signature = shift ; + # return exists $Lookup{$signature}} + #} + + sub getSigsForScan + { + my %sigs = + # map { $_ => 1 } + # map { substr($_->[0], 2, 2) => $_->[1] } # don't want the initial "PK" + map { substr(pack("V", $_), 2, 2) => $_ } + keys %Lookup ; + + return %sigs; + } -my %Lookup = ( - ZIP_LOCAL_HDR_SIG, \&LocalHeader, - ZIP_DATA_HDR_SIG, \&DataHeader, - ZIP_CENTRAL_HDR_SIG, \&CentralHeader, - ZIP_END_CENTRAL_HDR_SIG, \&EndCentralHeader, - ZIP64_END_CENTRAL_REC_HDR_SIG, \&Zip64EndCentralHeader, - ZIP64_END_CENTRAL_LOC_HDR_SIG, \&Zip64EndCentralLocator, - - # TODO - Archive Encryption Headers & digital signature - #ZIP_ARCHIVE_EXTRA_DATA_RECORD_SIG - #ZIP_DIGITAL_SIGNATURE_SIG - #ZIP_ARCHIVE_EXTRA_DATA_SIG -); +} my %Extras = ( - 0x0001, ['ZIP64', \&decode_Zip64], - 0x0007, ['AV Info', undef], - 0x0008, ['Extended Language Encoding', undef], - 0x0009, ['OS/2 extended attributes', undef], - 0x000a, ['NTFS FileTimes', \&decode_NTFS_Filetimes], - 0x000c, ['OpenVMS', undef], - 0x000d, ['Unix', undef], - 0x000e, ['Stream & Fork Descriptors', undef], - 0x000f, ['Patch Descriptor', undef], - 0x0014, ['PKCS#7 Store for X.509 Certificates', undef], - 0x0015, ['X.509 Certificate ID and Signature for individual file', undef], - 0x0016, ['X.509 Certificate ID for Central Directory', undef], - 0x0017, ['Strong Encryption Header', undef], - 0x0018, ['Record Management Controls', undef], - 0x0019, ['PKCS#7 Encryption Recipient Certificate List', undef], - 0x0020, ['Reserved for Timestamp record', undef], - 0x0021, ['Policy Decryption Key Record', undef], - 0x0022, ['Smartcrypt Key Provider Record', undef], - 0x0023, ['Smartcrypt Policy Key Data Record', undef], - # The Header ID mappings defined by Info-ZIP and third parties are: + # Local Central + # ID Name Handler min size max size min size max size + 0x0001, ['ZIP64', \&decode_Zip64, 0, 28, 0, 28], + 0x0007, ['AV Info', undef], # TODO + 0x0008, ['Extended Language Encoding', undef], # TODO + 0x0009, ['OS/2 extended attributes', undef], # TODO + 0x000a, ['NTFS FileTimes', \&decode_NTFS_Filetimes, 32, 32, 32, 32], + 0x000c, ['OpenVMS', \&decode_OpenVMS, 4, undef, 4, undef], + 0x000d, ['Unix', undef], + 0x000e, ['Stream & Fork Descriptors', undef], # TODO + 0x000f, ['Patch Descriptor', undef], + 0x0014, ['PKCS#7 Store for X.509 Certificates', undef], + 0x0015, ['X.509 Certificate ID and Signature for individual file', undef], + 0x0016, ['X.509 Certificate ID for Central Directory', undef], + 0x0017, ['Strong Encryption Header', \&decode_strong_encryption, 12, undef, 12, undef], + 0x0018, ['Record Management Controls', undef], + 0x0019, ['PKCS#7 Encryption Recipient Certificate List', undef], + 0x0020, ['Reserved for Timestamp record', undef], + 0x0021, ['Policy Decryption Key Record', undef], + 0x0022, ['Smartcrypt Key Provider Record', undef], + 0x0023, ['Smartcrypt Policy Key Data Record', undef], - 0x0065, ['IBM S/390 attributes - uncompressed', \&decodeMVS], - 0x0066, ['IBM S/390 attributes - compressed', undef], - 0x07c8, ['Info-ZIP Macintosh (old, J. Lee)', undef], - 0x2605, ['ZipIt Macintosh (first version)', undef], - 0x2705, ['ZipIt Macintosh v 1.3.5 and newer (w/o full filename)', undef], - 0x2805, ['ZipIt Macintosh v 1.3.5 and newer', undef], - 0x334d, ["Info-ZIP Macintosh (new, D. Haase's 'Mac3' field)", undef], - 0x4154, ['Tandem NSK', undef], - 0x4341, ['Acorn/SparkFS (David Pilling)', undef], - 0x4453, ['Windows NT security descriptor', \&decode_NT_security], - 0x4690, ['POSZIP 4690', undef], - 0x4704, ['VM/CMS', undef], - 0x470f, ['MVS', undef], - 0x4854, ['Theos, old inofficial port', undef], - 0x4b46, ['FWKCS MD5 (see below)', undef], - 0x4c41, ['OS/2 access control list (text ACL)', undef], - 0x4d49, ['Info-ZIP OpenVMS (obsolete)', undef], - 0x4d63, ['Macintosh SmartZIP, by Macro Bambini', undef], - 0x4f4c, ['Xceed original location extra field', undef], - 0x5356, ['AOS/VS (binary ACL)', undef], - 0x5455, ['Extended Timestamp', \&decode_UT], - 0x554e, ['Xceed unicode extra field', \&decode_Xceed_unicode], - 0x5855, ['Info-ZIP Unix (original; also OS/2, NT, etc.)', \&decode_UX], - 0x5a4c, ['ZipArchive Unicode Filename', undef], - 0x5a4d, ['ZipArchive Offsets Array', undef], - 0x6375, ['Info-ZIP Unicode Comment', \&decode_up ], - 0x6542, ['BeOS (BeBox, PowerMac, etc.)', undef], - 0x6854, ['Theos', undef], - 0x7075, ['Info-ZIP Unicode Path', \&decode_up ], - 0x756e, ['ASi Unix', undef], - 0x7441, ['AtheOS (AtheOS/Syllable attributes)', undef], - 0x7855, ['Unix Extra type 2', \&decode_Ux], - 0x7875, ['Unix Extra Type 3', \&decode_ux], - 0x9901, ['AES Encryption', \&decode_AES], - 0xa11e, ['Data Stream Alignment', \&decode_DataStreamAlignment], - 0xA220, ['Open Packaging Growth Hint', \&decode_GrowthHint ], - 0xCAFE, ['Java Executable', \&decode_Java_exe], - 0xfb4a, ['SMS/QDOS', undef], + # The Header ID mappings defined by Info-ZIP and third parties are: + 0x0065, ['IBM S/390 attributes - uncompressed', \&decode_MVS, 4, undef, 4, undef], + 0x0066, ['IBM S/390 attributes - compressed', undef], + 0x07c8, ['Info-ZIP Macintosh (old, J. Lee)', undef], + 0x10c5, ['Minizip CMS Signature', \&decode_Minizip_Signature, undef, undef, undef, undef], # https://github.com/zlib-ng/minizip-ng/blob/master/doc/mz_extrafield.md + 0x1986, ['Pixar USD', undef], # TODO + 0x1a51, ['Minizip Hash', \&decode_Minizip_Hash, 4, undef, 4, undef], # https://github.com/zlib-ng/minizip-ng/blob/master/doc/mz_extrafield.md + 0x2605, ['ZipIt Macintosh (first version)', undef], + 0x2705, ['ZipIt Macintosh v 1.3.5 and newer (w/o full filename)', undef], + 0x2805, ['ZipIt Macintosh v 1.3.5 and newer', undef], + 0x334d, ["Info-ZIP Macintosh (new, D. Haase's 'Mac3' field)", undef], # TODO + 0x4154, ['Tandem NSK [TA]', undef], # TODO + 0x4341, ['Acorn/SparkFS [AC]', undef], # TODO + 0x4453, ['Windows NT security descriptor [SD]', \&decode_NT_security, 11, undef, 4, 4], # TODO + 0x4690, ['POSZIP 4690', undef], + 0x4704, ['VM/CMS', undef], + 0x470f, ['MVS', undef], + 0x4854, ['Theos [TH]', undef], + 0x4b46, ['FWKCS MD5 [FK]', undef], + 0x4c41, ['OS/2 access control list [AL]', undef], + 0x4d49, ['Info-ZIP OpenVMS (obsolete) [IM]', undef], + 0x4d63, ['Macintosh SmartZIP [cM]', undef], # TODO + 0x4f4c, ['Xceed original location [LO]', undef], + 0x5356, ['AOS/VS (binary ACL) [VS]', undef], + 0x5455, ['Extended Timestamp [UT]', \&decode_UT, 1, 13, 1, 13], + 0x554e, ['Xceed unicode extra field [UN]', \&decode_Xceed_unicode, 6, undef, 8, undef], + 0x564B, ['Key-Value Pairs [KV]', \&decode_Key_Value_Pair, 13, undef, 13, undef],# TODO -- https://github.com/sozip/keyvaluepairs-spec/blob/master/zip_keyvalue_extra_field_specification.md + 0x5855, ['Unix Extra type 1 [UX]', \&decode_UX, 12, 12, 8, 8], + 0x5a4c, ['ZipArchive Unicode Filename [LZ]', undef], # https://www.artpol-software.com/ZipArchive + 0x5a4d, ['ZipArchive Offsets Array [MZ]', undef], # https://www.artpol-software.com/ZipArchive + 0x6375, ['Unicode Comment [uc]', \&decode_uc, 5, undef, 5, undef], + 0x6542, ['BeOS/Haiku [Be]', undef], # TODO + 0x6854, ['Theos [Th]', undef], + 0x7075, ['Unicode Path [up]', \&decode_up, 5, undef, 5, undef], + 0x756e, ['ASi Unix [un]', \&decode_ASi_Unix], # TODO + 0x7441, ['AtheOS [At]', undef], + 0x7855, ['Unix Extra type 2 [Ux]', \&decode_Ux, 4,4, 0, 0 ], + 0x7875, ['Unix Extra type 3 [ux]', \&decode_ux, 3, undef, 3, undef], + 0x9901, ['AES Encryption', \&decode_AES, 7, 7, 7, 7], + 0x9903, ['Reference', \&decode_Reference, 20, 20, 20, 20], # Added in WinZip ver 25 + 0xa11e, ['Data Stream Alignment', \&decode_DataStreamAlignment, 2, undef, 2, undef ], + 0xA220, ['Open Packaging Growth Hint', \&decode_GrowthHint, 4, undef, 4, undef ], + 0xCAFE, ['Java Executable', \&decode_Java_exe, 0, 0, 0, 0], + 0xCDCD, ['Minizip Central Directory', \&decode_Minizip_CD, 8, 8, 8, 8], # https://github.com/zlib-ng/minizip-ng/blob/master/doc/mz_extrafield.md + 0xd935, ['Android APK Alignment', undef], # TODO + 0xE57a, ['ALZip Codepage', undef], # TODO + 0xfb4a, ['SMS/QDOS', undef], # TODO ); + # Dummy entry only used in test harness, so only enable when ZIPDETAILS_TESTHARNESS is set + $Extras{0xFFFF} = + ['DUMMY', \&decode_DUMMY, undef, undef, undef, undef] + if $ENV{ZIPDETAILS_TESTHARNESS} ; + +sub extraFieldIdentifier +{ + my $id = shift ; + + my $name = $Extras{$id}[0] // "Unknown"; + + return "Extra Field '$name' (ID " . hexValue16($id) .")"; +} + +# Zip64EndCentralHeader version 2 +my %HashIDLookup = ( + 0x0000 => 'none', + 0x0001 => 'CRC32', + 0x8003 => 'MD5', + 0x8004 => 'SHA1', + 0x8007 => 'RIPEMD160', + 0x800C => 'SHA256', + 0x800D => 'SHA384', + 0x800E => 'SHA512', + ); + + +# Zip64EndCentralHeader version 2, Strong Encryption Header & DecryptionHeader +my %AlgIdLookup = ( + 0x6601 => "DES", + 0x6602 => "RC2 (version needed to extract < 5.2)", + 0x6603 => "3DES 168", + 0x6609 => "3DES 112", + 0x660E => "AES 128", + 0x660F => "AES 192", + 0x6610 => "AES 256", + 0x6702 => "RC2 (version needed to extract >= 5.2)", + 0x6720 => "Blowfish", + 0x6721 => "Twofish", + 0x6801 => "RC4", + 0xFFFF => "Unknown algorithm", + ); + +# Zip64EndCentralHeader version 2, Strong Encryption Header & DecryptionHeader +my %FlagsLookup = ( + 0x0001 => "Password required to decrypt", + 0x0002 => "Certificates only", + 0x0003 => "Password or certificate required to decrypt", + + # Values > 0x0003 reserved for certificate processing + ); + +# Strong Encryption Header & DecryptionHeader +my %HashAlgLookup = ( + 0x8004 => 'SHA1', + ); my $FH; my $ZIP64 = 0 ; my $NIBBLES = 8; + my $LocalHeaderCount = 0; my $CentralHeaderCount = 0; +my $InfoCount = 0; +my $WarningCount = 0; +my $ErrorCount = 0; +my $lastWasMessage = 0; + +my $fatalDisabled = 0; -my $START; my $OFFSET = 0 ; + +# Prefix data +my $POSSIBLE_PREFIX_DELTA = 0; +my $PREFIX_DELTA = 0; + my $TRAILING = 0 ; my $PAYLOADLIMIT = 256; my $ZERO = 0 ; @@ -222,7 +420,10 @@ my $APK = 0 ; my $START_APK = 0; my $APK_LEN = 0; -my $SEEN = Seen->new(); +my $CentralDirectory = CentralDirectory->new(); +my $LocalDirectory = LocalDirectory->new(); +my $HeaderOffsetIndex = HeaderOffsetIndex->new(); +my $EOCD_Present = 0; sub prOff { @@ -239,10 +440,11 @@ sub offset sprintf("%0${NIBBLES}X", $v); } -my ($OFF, $LENGTH, $CONTENT, $TEXT, $VALUE) ; +# Format variables +my ($OFF, $ENDS_AT, $LENGTH, $CONTENT, $TEXT, $VALUE) ; -my $FMT1 ; -my $FMT2 ; +my $FMT1 = 'STDOUT1'; +my $FMT2 = 'STDOUT2'; sub setupFormat { @@ -252,51 +454,58 @@ sub setupFormat my $width = '@' . ('>' x ($nibbles -1)); my $space = " " x length($width); + # See https://github.com/Perl/perl5/issues/14255 for issue with "^*" in perl < 5.22 + # my $rightColumn = "^*" ; + my $rightColumn = "^" . ("<" x 132); + + # Fill mode can split on space or newline chars + # Spliting on hyphen works differently from Perl 5.20 onwards + $: = " \n"; + my $fmt ; if ($wantVerbose) { - $FMT1 = " - format STDOUT = -$width $width ^<<<<<<<<<<<^<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -\$OFF, \$LENGTH, \$CONTENT, \$TEXT, \$VALUE -$space $space ^<<<<<<<<<<<^<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ - \$CONTENT, \$TEXT, \$VALUE + eval "format $FMT1 = +$width $width $width ^<<<<<<<<<<<^<<<<<<<<<<<<<<<<<<<< $rightColumn +\$OFF, \$ENDS_AT, \$LENGTH, \$CONTENT, \$TEXT, \$VALUE +$space $space $space ^<<<<<<<<<<<^<<<<<<<<<<<<<<<<<<<< $rightColumn~~ + \$CONTENT, \$TEXT, \$VALUE . "; - $FMT2 = " - format STDOUT = -$width $width ^<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -\$OFF, \$LENGTH, \$CONTENT, \$TEXT, \$VALUE -$space $space ^<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ + eval "format $FMT2 = +$width $width $width ^<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<< $rightColumn +\$OFF, \$ENDS_AT, \$LENGTH, \$CONTENT, \$TEXT, \$VALUE +$space $space $space ^<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<< $rightColumn~~ \$CONTENT, \$TEXT, \$VALUE -. " ; +. +"; } else { - - $FMT1 = " - format STDOUT = -$width ^<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + eval "format $FMT1 = +$width ^<<<<<<<<<<<<<<<<<<<< $rightColumn \$OFF, \$TEXT, \$VALUE -$space ^<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ +$space ^<<<<<<<<<<<<<<<<<<<< $rightColumn~~ \$TEXT, \$VALUE . "; - $FMT2 = " - format STDOUT = -$width ^<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + eval "format $FMT2 = +$width ^<<<<<<<<<<<<<<<<<< $rightColumn \$OFF, \$TEXT, \$VALUE -$space ^<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ +$space ^<<<<<<<<<<<<<<<<<< $rightColumn~~ \$TEXT, \$VALUE . -" ; +" } - eval "$FMT1"; + no strict 'refs'; + open($FMT1, ">&", \*STDOUT); select $FMT1; $| = 1 ; + open($FMT2, ">&", \*STDOUT); select $FMT2; $| = 1 ; + select 'STDOUT'; $| = 1; } @@ -310,23 +519,6 @@ sub mySpr return sprintf $format, @_ ; } -sub out0 -{ - my $size = shift; - my $text = shift; - my $format = shift; - - $OFF = prOff($size); - $LENGTH = offset($size) ; - $CONTENT = '...'; - $TEXT = $text; - $VALUE = mySpr $format, @_; - - write; - - skip($FH, $size); -} - sub xDump { my $input = shift; @@ -337,19 +529,81 @@ sub xDump sub hexDump { - my $input = shift; + return uc join ' ', unpack('(H2)*', $_[0]); +} + +sub hexDump16 +{ + return uc + join "\r", + map { join ' ', unpack('(H2)*', $_ ) } + unpack('(a16)*', $_[0]) ; +} - my $out = unpack('H*', $input) ; - $out =~ s#(..)# $1#g ; - $out =~ s/^ //; - $out = uc $out; +sub charDump2 +{ + sprintf "%v02X", $_[0]; +} - return $out; +sub charDump +{ + sprintf "%vX", $_[0]; } sub hexValue { - return sprintf("%X", $_[0]); + return sprintf("0x%X", $_[0]); +} + +sub hexValue32 +{ + return sprintf("0x%08X", $_[0]); +} + +sub hexValue16 +{ + return sprintf("0x%04X", $_[0]); +} + +sub outHexdump +{ + my $size = shift; + my $text = shift; + my $limit = shift ; + + return 0 + if $size == 0; + + # TODO - add a limit to data output + # if ($limit) + # { + # outSomeData($size, $text); + # } + # else + { + myRead(my $payload, $size); + out($payload, $text, hexDump16($payload)); + } + + return $size; +} + +sub decimalHex +{ + sprintf("%0*X (%u)", $_[1] // 0, $_[0], $_[0]) +} + +sub decimalHex0x +{ + sprintf("0x%0*X (%u)", $_[1] // 0, $_[0], $_[0]) +} + +sub decimalHex0xUndef +{ + return 'Unknown' + if ! defined $_[0]; + + return decimalHex0x @_; } sub out @@ -360,6 +614,7 @@ sub out my $size = length($data) ; + $ENDS_AT = offset($OFFSET + ($size ? $size - 1 : 0)) ; $OFF = prOff($size); $LENGTH = offset($size) ; $CONTENT = hexDump($data); @@ -368,7 +623,29 @@ sub out no warnings; - write; + write $FMT1 ; + + $lastWasMessage = 0; +} + +sub out0 +{ + my $size = shift; + my $text = shift; + my $format = shift; + + $ENDS_AT = offset($OFFSET + ($size ? $size - 1 : 0)) ; + $OFF = prOff($size); + $LENGTH = offset($size) ; + $CONTENT = '...'; + $TEXT = $text; + $VALUE = mySpr $format, @_; + + write $FMT1; + + skip($FH, $size); + + $lastWasMessage = 0; } sub out1 @@ -376,13 +653,16 @@ sub out1 my $text = shift; my $format = shift; + $ENDS_AT = '' ; $OFF = ''; $LENGTH = '' ; $CONTENT = ''; $TEXT = $text; $VALUE = mySpr $format, @_; - write; + write $FMT1; + + $lastWasMessage = 0; } sub out2 @@ -392,6 +672,7 @@ sub out2 my $format = shift; my $size = length($data) ; + $ENDS_AT = offset($OFFSET + ($size ? $size - 1 : 0)) ; $OFF = prOff($size); $LENGTH = offset($size); $CONTENT = hexDump($data); @@ -399,26 +680,26 @@ sub out2 $VALUE = mySpr $format, @_; no warnings; - eval "$FMT2"; - write ; - eval "$FMT1"; + write $FMT2; + + $lastWasMessage = 0; } + sub Value { my $letter = shift; - my @value = @_; if ($letter eq 'C') - { return Value_C(@value) } + { return decimalHex($_[0], 2) } elsif ($letter eq 'v') - { return Value_v(@value) } + { return decimalHex($_[0], 4) } elsif ($letter eq 'V') - { return Value_V(@value) } + { return decimalHex($_[0], 8) } elsif ($letter eq 'Q<') - { return Value_Q(@value) } + { return decimalHex($_[0], 16) } else - { die "here letter $letter"} + { internalFatal undef, "here letter $letter"} } sub outer @@ -498,6 +779,8 @@ sub outSomeData my $message = shift; my $redact = shift ; + # return if $size == 0; + if ($size > 0) { if ($size > $PAYLOADLIMIT) { my $before = $FH->tell(); @@ -511,6 +794,19 @@ sub outSomeData } } +sub outSomeDataParagraph +{ + my $size = shift; + my $message = shift; + my $redact = shift ; + + return if $size == 0; + + print "\n"; + outSomeData($size, $message, $redact); + +} + sub unpackValue_C { Value_v(unpack "C", $_[0]); @@ -518,7 +814,7 @@ sub unpackValue_C sub Value_C { - sprintf "%02X", $_[0]; + return decimalHex($_[0], 2); } @@ -529,7 +825,7 @@ sub unpackValue_v sub Value_v { - sprintf "%04X", $_[0]; + return decimalHex($_[0], 4); } sub unpackValue_V @@ -539,8 +835,7 @@ sub unpackValue_V sub Value_V { - my $v = defined $_[0] ? $_[0] : 0; - sprintf "%08X", $v; + return decimalHex($_[0] // 0, 8); } sub unpackValue_Q @@ -551,8 +846,7 @@ sub unpackValue_Q sub Value_Q { - my $v = shift ; - sprintf "%016X", $v; + return decimalHex($_[0], 16); } sub read_Q @@ -596,63 +890,95 @@ sub seekTo $OFFSET = $FH->tell(); } -sub scanForSignature +sub rewindRelative { - my %sigs = - map { $_ => 1 } - map { substr $_, 2, 2 } # don't want the initial "PK" - map { pack "V", $_ } - ( - ZIP_LOCAL_HDR_SIG , - ZIP_DATA_HDR_SIG , - ZIP_CENTRAL_HDR_SIG , - ZIP_END_CENTRAL_HDR_SIG , - ZIP64_END_CENTRAL_REC_HDR_SIG , - ZIP64_END_CENTRAL_LOC_HDR_SIG , - # ZIP_ARCHIVE_EXTRA_DATA_SIG , - # ZIP_DIGITAL_SIGNATURE_SIG , - # ZIP_ARCHIVE_EXTRA_DATA_RECORD_SIG , - ); + my $offset = shift ; + + $FH->seek(-$offset, SEEK_CUR); + # $OFFSET -= $offset; + $OFFSET = $FH->tell(); +} +sub deltaToNextSignature +{ my $start = $FH->tell(); - my $last = ''; - my $offset = 0; - my $buffer ; - BUFFER: - while ($FH->read($buffer, 1024 * 1000)) + my $got = scanForSignature(1); + + my $delta = $FH->tell() - $start ; + seekTo($start); + + if ($got) { - my $combine = $last . $buffer ; + return $delta ; + } - my $ix = 0; - while (1) + return 0 ; +} + +sub scanForSignature +{ + my $walk = shift // 0; + + # $count is only used to when 'walk' is enabled. + # Want to scan for a PK header at the start of the file. + # All other PK headers are should be directly after the previous PK record. + state $count = 0; + $count += $walk; + + my %sigs = Signatures::getSigsForScan(); + + my $start = $FH->tell(); + + # TODO -- Fix this? + if (1 || $count <= 1) { + + my $last = ''; + my $offset = 0; + my $buffer ; + + BUFFER: + while ($FH->read($buffer, 1024 * 1000)) { - $ix = index($combine, "PK", $ix) ; + my $combine = $last . $buffer ; - if ($ix == -1) + my $ix = 0; + while (1) { - $last = ''; - next BUFFER; - } + $ix = index($combine, "PK", $ix) ; - my $rest = substr($combine, $ix + 2, 2); + if ($ix == -1) + { + $last = ''; + next BUFFER; + } - if (! $sigs{$rest}) - { - $ix += 2; - next; - } + my $rest = substr($combine, $ix + 2, 2); - # possible match - my $here = $FH->tell(); - seekTo($here - length($combine) + $ix); + if (! $sigs{$rest}) + { + $ix += 2; + next; + } - return 1; - } + # possible match + my $here = $FH->tell(); + seekTo($here - length($combine) + $ix); + + my $name = Signatures::name($sigs{$rest}); + return $sigs{$rest}; + } - $last = substr($combine, $ix+4); + $last = substr($combine, $ix+4); + } + } + else { + die "FIX THIS"; + return ! $FH->eof(); } + # printf("scanForSignature %X\t%X (%X)\t%s\n", $start, $FH->tell(), $FH->tell() - $start, 'NO MATCH') ; + return 0; } @@ -660,733 +986,5076 @@ my $is64In32 = 0; my $opt_verbose = 0; my $opt_scan = 0; +my $opt_walk = 0; my $opt_Redact = 0; my $opt_utc = 0; - +my $opt_want_info_mesages = 1; +my $opt_want_warning_mesages = 1; +my $opt_want_error_mesages = 1; +my $opt_want_message_exit_status = 0; +my $exit_status_code = 0; +my $opt_help =0; $Getopt::Long::bundling = 1 ; -GetOptions("h" => \&Usage, - "v" => \$opt_verbose, - "scan" => \$opt_scan, - "redact" => \$opt_Redact, - "utc" => \$opt_utc, - "version" => sub { print "$VERSION\n"; exit }, +TextEncoding::setDefaults(); + +GetOptions("h|help" => \$opt_help, + "v" => \$opt_verbose, + "scan" => \$opt_scan, + "walk" => \$opt_walk, + "redact" => \$opt_Redact, + "utc" => \$opt_utc, + "version" => sub { print "$VERSION\n"; exit }, + + # Filename/comment encoding + "encoding=s" => \&TextEncoding::parseEncodingOption, + "no-encoding" => \&TextEncoding::NoEncoding, + "debug-encoding" => \&TextEncoding::debugEncoding, + "output-encoding=s" => \&TextEncoding::parseEncodingOption, + "language-encoding!" => \&TextEncoding::LanguageEncodingFlag, + + # Message control + "exit-bitmask!" => \$opt_want_message_exit_status, + "messages!" => sub { + my ($opt_name, $opt_value) = @_; + $opt_want_info_mesages = + $opt_want_warning_mesages = + $opt_want_error_mesages = $opt_value; + }, ) - or Usage("Invalid command line option\n"); + or exit 255 ; + +Usage() + if $opt_help; +die("No zipfile\n") + unless @ARGV == 1; -Usage("No zipfile") unless @ARGV == 1; +die("Cannot specify both '--walk' and '--scan'\n") + if $opt_walk && $opt_scan ; my $filename = shift @ARGV; -die "$filename does not exist\n" +topLevelFatal "No such file" unless -e $filename ; -die "$filename not a standard file\n" +topLevelFatal "'$filename' is a directory" + if -d $filename ; + +topLevelFatal "'$filename' is not a standard file" unless -f $filename ; $FH = IO::File->new( "<$filename" ) - or die "Cannot open $filename: $!\n"; + or topLevelFatal "Cannot open '$filename': $!"; +binmode($FH); +displayFileInfo($filename); +TextEncoding::encodingInfo(); my $FILELEN = -s $filename ; $TRAILING = -s $filename ; $NIBBLES = nibbles(-s $filename) ; -die "$filename too short to be a zip file\n" - if $FILELEN < 22 ; - -setupFormat($opt_verbose, $NIBBLES); +topLevelFatal "'$filename' is empty" + if $FILELEN == 0 ; -if(0) -{ - # Sanity check that this is a Zip file - my ($buffer, $signature) = read_V(); +topLevelFatal "file is too short to be a zip file" + if $FILELEN < ZIP_EOCD_MIN_SIZE ; - warn "$filename doesn't look like a zip file\n" - if $signature != ZIP_LOCAL_HDR_SIG ; - $FH->seek(0, SEEK_SET) ; -} +setupFormat($opt_verbose, $NIBBLES); my @Messages = (); -if ($opt_scan) +if ($opt_scan || $opt_walk) { + # Main loop for walk/scan processing + + my $foundZipRecords = 0; my $foundCentralHeader = 0; my $lastEndsAt = 0; + my $lastSignature = 0; + my $lastHeader = {}; - while(scanForSignature()) + $CentralDirectory->{alreadyScanned} = 1 ; + + my $output_encryptedCD = 0; + + reportPrefixData(); + while(my $s = scanForSignature($opt_walk)) { my $here = $FH->tell(); + my $delta = $here - $lastEndsAt ; - my ($buffer, $signature) = read_V(); - - # check for an APK header directly before the first central header - if ($signature == ZIP_CENTRAL_HDR_SIG && $foundCentralHeader == 0) + # delta can only be negative when '--scan' is used + if ($delta < 0 ) { - $foundCentralHeader = 1; + # nested or overlap + # check if nested + # remember & check if matching entry in CD + # printf("### WARNING: OVERLAP/NESTED Record found 0x%X 0x%X $delta\n", $here, $lastEndsAt) ; + } + elsif ($here != $lastEndsAt) + { + # scanForSignature had to skip bytes to find the next signature - ($START_APK, $APK, $APK_LEN) = chckForAPKSigningBlock($FH, $here) ; + # some special cases that don't have signatures need to be checked first - if ($START_APK) - { - seekTo($lastEndsAt+4); + seekTo($lastEndsAt); - scanApkBlock(); - seekTo($here); + if (! $output_encryptedCD && $CentralDirectory->isEncryptedCD()) + { + displayEncryptedCD(); + $output_encryptedCD = 1; + $lastEndsAt = $FH->tell(); next; } + elsif ($lastSignature == ZIP_LOCAL_HDR_SIG && $lastHeader->{'streamed'} ) + { + # Check for size of possibe malformed Data Descriptor before outputting payload + if (! $lastHeader->{'gotDataDescriptorSize'}) + { + my $hdrSize = checkForBadlyFormedDataDescriptor($lastHeader, $delta) ; - seekTo($here + 4); - } + if ($hdrSize) + { + # remove size of Data Descriptor from payload + $delta -= $hdrSize; + $lastHeader->{'gotDataDescriptorSize'} = $hdrSize; + } + } - my $handler = $Lookup{$signature}; - $handler->($signature, $buffer); + if(defined($lastHeader->{'payloadOutput'}) && ($lastEndsAt = BadlyFormedDataDescriptor($lastHeader, $delta))) + { + $HeaderOffsetIndex->rewindIndex(); + $lastHeader->{entry}->readDataDescriptor(1) ; + next; + } - $lastEndsAt = $FH->tell(); + # Assume we have the payload when streaming is enabled + outSomeData($delta, "PAYLOAD", $opt_Redact) ; + $lastHeader->{'payloadOutput'} = 1; + $lastEndsAt = $FH->tell(); - seekTo($here + 4) ; - } + next; + } + elsif (Signatures::isCentralHeader($s) && $foundCentralHeader == 0) + { + # check for an APK header directly before the first central header + $foundCentralHeader = 1; - dislayMessages(); - exit; + ($START_APK, $APK, $APK_LEN) = chckForAPKSigningBlock($FH, $here, 0) ; -} + if ($START_APK) + { + seekTo($lastEndsAt+4); + + scanApkBlock(); + $lastEndsAt = $FH->tell(); + next; + } + + seekTo($lastEndsAt); + } -our ($CdExists, $CdOffset, @CentralDirectory) = scanCentralDirectory($FH); + # Not a special case, so output generic padding message + if ($delta > 0) + { + reportPrefixData($delta) + if $lastEndsAt == 0 ; + outSomeDataParagraph($delta, "UNEXPECTED PADDING"); + info $FH->tell() - $delta, decimalHex0x($delta) . " Unexpected Padding bytes" + if $FH->tell() - $delta ; + $POSSIBLE_PREFIX_DELTA = $delta + if $lastEndsAt == 0; + $lastEndsAt = $FH->tell(); + next; + } + else + { + seekTo($here); + } -die "No Central Directory records found\n" - if ! $CdExists ; + } -$OFFSET = 0 ; -$FH->seek(0, SEEK_SET) ; + my ($buffer, $signature) = read_V(); -outSomeData($START, "PREFIX DATA") - if defined $START && $START > 0 ; + $lastSignature = $signature; -my $skippedFrom = 0 ; -my $skippedContent = 0 ; + my $handler = Signatures::decoder($signature); + if (!defined $handler) { + internalFatal undef, "xxx"; + } -while (1) -{ - last if $FH->eof(); + $foundZipRecords = 1; + $lastHeader = $handler->($signature, $buffer, $FH->tell() - 4) // {'streamed' => 0}; - my $here = $FH->tell(); - if ($here >= $TRAILING) { - print "\n" ; - outSomeData($FILELEN - $TRAILING, "TRAILING DATA"); - last; + $lastEndsAt = $FH->tell(); + seekTo($here + 4) + if $opt_scan; } - my ($buffer, $signature) = read_V(); + topLevelFatal "'$filename' is not a zip file" + unless $foundZipRecords ; - my $handler = $Lookup{$signature}; +} +else +{ + # Main loop for non-walk/scan processing - if (!defined $handler) + # check for prefix data + my $s = scanForSignature(); + if ($s && $FH->tell() != 0) { - if (@CentralDirectory) { - # Should be at offset that central directory says - my $locOffset = $CentralDirectory[0][0]; - my $delta = $locOffset - $here ; + $POSSIBLE_PREFIX_DELTA = $FH->tell(); + } - if ($here + 4 == $locOffset ) { - for (0 .. 3) { - $FH->ungetc(ord(substr($buffer, $_, 1))) - } - outSomeData($delta, "UNEXPECTED PADDING"); - next; + seekTo(0); + + scanCentralDirectory($FH); + + fatal_tryWalk undef, "No Zip metadata found at end of file" + if ! $CentralDirectory->exists() && ! $EOCD_Present ; + + $CentralDirectory->{alreadyScanned} = 1 ; + + Nesting::clearStack(); + + # $HeaderOffsetIndex->dump(); + + $OFFSET = 0 ; + $FH->seek(0, SEEK_SET) ; + + my $expectedOffset = 0; + my $expectedSignature = 0; + my $expectedBuffer = 0; + my $foundCentralHeader = 0; + my $processedAPK = 0; + my $processedECD = 0; + my $lastHeader ; + + # my $lastWasLocalHeader = 0; + # my $inCentralHeader = 0; + + while (1) + { + last if $FH->eof(); + + my $here = $FH->tell(); + + if ($here >= $TRAILING) { + my $delta = $FILELEN - $TRAILING; + outSomeDataParagraph($delta, "TRAILING DATA"); + info $FH->tell(), "Unexpected Trailing Data: " . decimalHex0x($delta) . " bytes"; + + last; + } + + my ($buffer, $signature) = read_V(); + + $expectedOffset = undef; + $expectedSignature = undef; + + # Check for split archive marker at start of file + if ($here == 0 && $signature == ZIP_SINGLE_SEGMENT_MARKER) + { + # let it drop through + $expectedSignature = ZIP_SINGLE_SEGMENT_MARKER; + $expectedOffset = 0; + } + else + { + my $expectedEntry = $HeaderOffsetIndex->getNextIndex() ; + if ($expectedEntry) + { + $expectedOffset = $expectedEntry->offset(); + $expectedSignature = $expectedEntry->signature(); + $expectedBuffer = pack "V", $expectedSignature ; } } + my $delta = $expectedOffset - $here ; - if ($here < $CdOffset) + # if ($here != $expectedOffset && $signature != ZIP_DATA_HDR_SIG) + # { + # rewindRelative(4); + # my $delta = $expectedOffset - $here ; + # outSomeDataParagraph($delta, "UNEXPECTED PADDING"); + # $HeaderOffsetIndex->rewindIndex(); + # next; + # } + + # Need to check for use-case where + # * there is a ZIP_DATA_HDR_SIG directly after a ZIP_LOCAL_HDR_SIG. + # The HeaderOffsetIndex object doesn't have visibility of it. + # * APK header directly before the CD + # * zipbomb + + if (defined $expectedOffset && $here != $expectedOffset && ( $CentralDirectory->exists() || $EOCD_Present) ) { - if ($APK) + if ($here > $expectedOffset) + { + # Probable zipbomb + + # Cursor $OFFSET need to rewind + $OFFSET = $expectedOffset; + $FH->seek($OFFSET + 4, SEEK_SET) ; + + $signature = $expectedSignature; + $buffer = $expectedBuffer ; + } + + # If get here then $here is less than $expectedOffset + + + # check for an APK header directly before the first central header + # Make sure not to miss a streaming data descriptor + if ($signature != ZIP_DATA_HDR_SIG && Signatures::isCentralHeader($expectedSignature) && $START_APK && ! $processedAPK ) { + seekTo($here+4); + # rewindRelative(4); scanApkBlock(); + $HeaderOffsetIndex->rewindIndex(); + $processedAPK = 1; next; } - # next - # if scanForSignature() ; + # Check Encrypted Central Directory + # if ($CentralHeaderSignatures{$expectedSignature} && $CentralDirectory->isEncryptedCD() && ! $processedECD) + # { + # # rewind the invalid signature + # seekTo($here); + # # rewindRelative(4); + # displayEncryptedCD(); + # $processedECD = 1; + # next; + # } - $skippedFrom = $FH->tell() ; - $skippedContent = $CdOffset - $skippedFrom ; + if ($signature != ZIP_DATA_HDR_SIG && $delta >= 0) + { + rewindRelative(4); + if($lastHeader->{'streamed'} && BadlyFormedDataDescriptor($lastHeader, $delta)) + { + $lastHeader->{entry}->readDataDescriptor(1) ; + $HeaderOffsetIndex->rewindIndex(); + next; + } - printf "\nWARNING!\nZip local header not found at offset 0x%X\n", $skippedFrom; - printf "Skipping 0x%x bytes to Central Directory...\n", $skippedContent; + reportPrefixData($delta) + if $here == 0; + outSomeDataParagraph($delta, "UNEXPECTED PADDING"); + info $FH->tell() - $delta, decimalHex0x($delta) . " Unexpected Padding bytes" + if $FH->tell() - $delta ; + $HeaderOffsetIndex->rewindIndex(); + next; + } - push @Messages, - sprintf("Expected Zip header not found at offset 0x%X, ", $skippedFrom) . - sprintf("skipped 0x%X bytes\n", $skippedContent); + # ZIP_DATA_HDR_SIG drops through + } - seekTo($CdOffset); + my $handler = Signatures::decoder($signature); - next; - } - else + if (!defined $handler) { - printf "\n\nUnexpected END at offset %08X, value %s\n", $here, Value_V($signature); + # if ($CentralDirectory->exists()) { - last; + # # Should be at offset that central directory says + # my $locOffset = $CentralDirectory->getNextLocalOffset(); + # my $delta = $locOffset - $here ; + + # if ($here + 4 == $locOffset ) { + # for (0 .. 3) { + # $FH->ungetc(ord(substr($buffer, $_, 1))) + # } + # outSomeData($delta, "UNEXPECTED PADDING"); + # next; + # } + # } + + + # if ($here == $CentralDirectory->{CentralDirectoryOffset} && $EOCD_Present && $CentralDirectory->isEncryptedCD()) + # { + # # rewind the invalid signature + # rewindRelative(4); + # displayEncryptedCD(); + # next; + # } + # elsif ($here < $CentralDirectory->{CentralDirectoryOffset}) + # { + # # next + # # if scanForSignature() ; + + # my $skippedFrom = $FH->tell() ; + # my $skippedContent = $CentralDirectory->{CentralDirectoryOffset} - $skippedFrom ; + + # printf "\nWARNING!\nExpected Zip header not found at offset 0x%X\n", $here; + # printf "Skipping 0x%X bytes to Central Directory...\n", $skippedContent; + + # push @Messages, + # sprintf("Expected Zip header not found at offset 0x%X, ", $skippedFrom) . + # sprintf("skipped 0x%X bytes\n", $skippedContent); + + # seekTo($CentralDirectory->{CentralDirectoryOffset}); + + # next; + # } + # else + { + fatal $here, sprintf "Unexpected Zip Signature '%s' at offset %s", Value_V($signature), decimalHex0x($here) ; + last; + } } - } - $ZIP64 = 0 if $signature != ZIP_DATA_HDR_SIG ; - $handler->($signature, $buffer); + $ZIP64 = 0 if $signature != ZIP_DATA_HDR_SIG ; + $lastHeader = $handler->($signature, $buffer, $FH->tell() - 4); + # $lastWasLocalHeader = $signature == ZIP_LOCAL_HDR_SIG ; + $HeaderOffsetIndex->rewindIndex() + if $signature == ZIP_DATA_HDR_SIG ; + } } -dislayMessages(); +dislayMessages() + if $opt_want_error_mesages ; -exit ; +exit $exit_status_code ; sub dislayMessages { - $SEEN->short_summary(); - - $SEEN->summary(); + # Compare Central & Local for discrepencies - if (@Messages) + if ($CentralDirectory->isMiniZipEncrypted) { - my $count = scalar @Messages ; - print "\nWARNINGS\n\n"; - print "* $_\n" for @Messages ; + # don't compare local & central entries when minizip-ng encryption is in play + info undef, "Zip file uses minizip-ng central directory encryption" } - print "Done\n"; -} - -sub compressionMethod -{ - my $id = shift ; - Value_v($id) . " '" . ($ZIP_CompressionMethods{$id} || "Unknown Method") . "'" ; -} - -sub LocalHeader -{ - my $signature = shift ; - my $data = shift ; - - my $from_offset = $FH->tell() - 4; + elsif ($CentralDirectory->exists() && $LocalDirectory->exists()) + { + # TODO check number of entries matches eocd + # TODO check header length matches reality - print "\n"; - ++ $LocalHeaderCount; - my $hexHdrCount = sprintf("%X", $LocalHeaderCount) ; - out $data, "LOCAL HEADER #$hexHdrCount" , Value_V($signature); + # Nesting::dump(); - my $buffer; + $LocalDirectory->sortByLocalOffset(); + my %cleanCentralEntries = %{ $CentralDirectory->{byCentralOffset} }; - my ($loc, $CDcompressedLength, $cdZip64, $zip64Sizes, $cdIndex, $cdEntryOffset) ; - if (! $opt_scan) - { - ($loc, $CDcompressedLength, $cdZip64, $zip64Sizes, $cdIndex, $cdEntryOffset) = @{ shift @CentralDirectory } ; - # my $cdi = sprintf("%X", $cdIndex) ; - # out1 "CENTRAL HEADER #$cdi", sprintf "Offset %s\n", Value_Q($cdEntryOffset); - } + if ($NESTING_DEBUG) + { + if (Nesting::encapsulationCount()) + { + say "# ENCAPSULATIONS"; - out_C "Extract Zip Spec", \&decodeZipVer; - out_C "Extract OS", \&decodeOS; + for my $index (sort { $a <=> $b } keys %{ Nesting::encapsulations() }) + { + my $outer = Nesting::entryByIndex($index) ; - my ($bgp, $gpFlag) = read_v(); - my ($bcm, $compressedMethod) = read_v(); + say "# Nesting " . $outer->outputFilename . " " . $outer->offsetStart . " " . $outer->offsetEnd ; - out $bgp, "General Purpose Flag", Value_v($gpFlag) ; - GeneralPurposeBits($compressedMethod, $gpFlag); + for my $inner (sort { $a <=> $b } @{ Nesting::encapsulations()->{$index} } ) + { + say "# " . $inner->outputFilename . " " . $inner->offsetStart . " " . $inner->offsetEnd ;; + } + } + } + } - out $bcm, "Compression Method", compressionMethod($compressedMethod) ; + { + # check for Local Directory orphans - out_V "Last Mod Time", sub { getTime(_dosToUnixTime($_[0])) }; + my %orphans = map { $_->localHeaderOffset => $_->outputFilename } + grep { $_->entryType == ZIP_LOCAL_HDR_SIG && # Want Local Headers + ! $_->encapsulated && + @{ $_->getCdEntries } == 0 + } + values %{ Nesting::getEntriesByOffset() }; - my $crc = out_V "CRC"; - my $compressedLength = out_V "Compressed Length"; - my $uncompressedLength = out_V "Uncompressed Length"; - my $filenameLength = out_v "Filename Length"; - my $extraLength = out_v "Extra Length"; - my $filename ; - myRead($filename, $filenameLength); - outputFilename($filename); + if (keys %orphans) + { + error undef, "Orphan Local Headers found: " . scalar(keys %orphans) ; - my $cl64 = $compressedLength; - my %ExtraContext = (); - if ($extraLength) - { - my @z64 = ($uncompressedLength, $compressedLength, 1, 1); - $ExtraContext{Zip64} = \@z64 ; - $ExtraContext{InCentralDir} = 0; - walkExtra($extraLength, \%ExtraContext); - } + my $table = new SimpleTable; + $table->addHeaderRow('Offset', 'Filename'); + $table->addDataRow(decimalHex0x($_), $orphans{$_}) + for sort { $a <=> $b } keys %orphans ; + $table->display(); + } + } - my @msg ; - # if ($cdZip64 && ! $ZIP64) - # { - # # Central directory said this was Zip64 - # # some zip files don't have the Zip64 field in the local header - # # seems to be a streaming issue. - # push @msg, "Missing Zip64 extra field in Local Header #$hexHdrCount\n"; + { + # check for Central Directory orphans + # probably only an issue with --walk & a zipbomb - # if (! $zip64Sizes) - # { - # # Central has a ZIP64 entry that doesn't have sizes - # # Local doesn't have a Zip 64 at all - # push @msg, "Unzip may complain about 'overlapped components' #$hexHdrCount\n"; - # } - # else - # { - # $ZIP64 = 1 - # } - # } + my %orphans = map { $_->centralHeaderOffset => $_ } + grep { $_->entryType == ZIP_CENTRAL_HDR_SIG # Want Central Headers + && ! $_->ldEntry # Filter out orphans + && ! $_->encapsulated # Not encapsulated + } + values %{ Nesting::getEntriesByOffset() }; + if (keys %orphans) + { + error undef, "Possible zipbomb -- Orphan Central Headers found: " . scalar(keys %orphans) ; + my $table = new SimpleTable; + $table->addHeaderRow('Offset', 'Filename'); + for (sort { $a <=> $b } keys %orphans ) + { + $table->addDataRow(decimalHex0x($_), $orphans{$_}{filename}); + delete $cleanCentralEntries{ $_ }; + } - my $size = 0; - $size = printAes(\%ExtraContext) - if $compressedMethod == 99 ; + $table->display(); + } + } - $size += printLzmaProperties() - if $compressedMethod == ZIP_CM_LZMA ; + if (Nesting::encapsulationCount()) + { + # Benign Nested zips + # This is the use-case where a zip file is "stored" in another zip file. + # NOT a zipbomb -- want the benign nested entries + + # Note: this is only active when scan is used + + my %outerEntries = map { $_->localHeaderOffset => $_->outputFilename } + grep { + $_->entryType == ZIP_CENTRAL_HDR_SIG && + ! $_->encapsulated && # not encapsulated + $_->ldEntry && # central header has a local sibling + $_->ldEntry->childrenCount && # local entry has embedded entries + ! Nesting::childrenInCentralDir($_->ldEntry) + } + values %{ Nesting::getEntriesByOffset() }; - $CDcompressedLength = $compressedLength - if $opt_scan ; + if (keys %outerEntries) + { + my $count = scalar keys %outerEntries; + info undef, "Nested Zip files found: $count"; - $CDcompressedLength -= $size; + my $table = new SimpleTable; + $table->addHeaderRow('Offset', 'Filename'); + $table->addDataRow(decimalHex0x($_), $outerEntries{$_}) + for sort { $a <=> $b } keys %outerEntries ; - if ($CDcompressedLength) { - outSomeData($CDcompressedLength, "PAYLOAD", $opt_Redact) ; - } + $table->display(); + } + } - if ($compressedMethod == 99) { - my $auth ; - myRead($auth, 10); - out $auth, "AES Auth", hexDump($auth); - } + if ($LocalDirectory->anyStreamedEntries) + { + # Check for a missing Data Descriptors - print "WARNING: $_" - for @msg; + my %missingDataDescriptor = map { $_->localHeaderOffset => $_->outputFilename } + grep { $_->entryType == ZIP_LOCAL_HDR_SIG && + $_->streamed && + ! $_->readDataDescriptor + } + values %{ Nesting::getEntriesByOffset() }; - push @Messages, @msg ; + for my $offset (sort keys %missingDataDescriptor) + { + my $filename = $missingDataDescriptor{$offset}; + error $offset, "Filename '$filename': Missing 'Data Descriptor'" ; + } + } - # $SEEN->save("LOCAL HEADER #" . sprintf("%X", $LocalHeaderCount), $filename, $from_offset, $from_offset + $CDcompressedLength); -} + { + # compare local & central for duplicate entries (CD entries point to same local header) -sub redactFilename -{ - my $filename = shift; + my %ByLocalOffset = map { $_->localHeaderOffset => $_ } + grep { + $_->entryType == ZIP_LOCAL_HDR_SIG # Want Local Headers + && ! $_->encapsulated # Not encapsulated + && @{ $_->getCdEntries } > 1 + } + values %{ Nesting::getEntriesByOffset() }; - # Redact everything apart from directory seperators - $filename =~ s([^/])(X)g - if $opt_Redact; + for my $offset (sort keys %ByLocalOffset) + { + my @entries = @{ $ByLocalOffset{$offset}->getCdEntries }; + if (@entries > 1) + { + # found duplicates + my $localEntry = $LocalDirectory->getByLocalOffset($offset) ; + if ($localEntry) + { + error undef, "Possible zipbomb -- Duplicate Central Headers referring to one Local header for '" . $localEntry->outputFilename . "' at offset " . decimalHex0x($offset); + } + else + { + error undef, "Possible zipbomb -- Duplicate Central Headers referring to one Local header at offset " . decimalHex0x($offset); + } + + my $table = new SimpleTable; + $table->addHeaderRow('Offset', 'Filename'); + for (sort { $a->centralHeaderOffset <=> $b->centralHeaderOffset } @entries) + { + $table->addDataRow(decimalHex0x($_->centralHeaderOffset), $_->outputFilename); + delete $cleanCentralEntries{ $_->centralHeaderOffset }; + } - return $filename; -} + $table->display(); + } + } + } -sub outputFilename -{ - my $filename = shift; + if (Nesting::encapsulationCount()) + { + # compare local & central for nested entries - $filename = redactFilename($filename) ; + # get the local offsets referenced in the CD + # this deliberately ignores any valid nested local entries + my @localOffsets = sort { $a <=> $b } keys %{ $CentralDirectory->{byLocalOffset} }; - if (length $filename > 256) - { - my $f = substr($filename, 0, 256) ; - out $f, "Filename", "'". $f . "' ..."; - } - else - { - out $filename, "Filename", "'". $filename . "'"; - } -} + # now check for nesting -sub CentralHeader -{ - my $signature = shift ; - my $data = shift ; + my %nested ; + my %bomb; - my $from_offset = $FH->tell() - 4; + for my $offset (@localOffsets) + { + my $innerEntry = $LocalDirectory->{byLocalOffset}{$offset}; + if ($innerEntry) + { + my $outerLocalEntry = Nesting::getOuterEncapsulation($innerEntry); + if (defined $outerLocalEntry) + { + my $outerOffset = $outerLocalEntry->localHeaderOffset(); + if ($CentralDirectory->{byLocalOffset}{ $offset }) + { + push @{ $bomb{ $outerOffset } }, $offset ; + } + else + { + push @{ $nested{ $outerOffset } }, $offset ; + } + } + } + } - ++ $CentralHeaderCount; - print "\n"; - out $data, "CENTRAL HEADER #" . sprintf("%X", $CentralHeaderCount) . "", Value_V($signature); - my $buffer; + if (keys %nested) + { + # The real central directory at eof does not know about these. + # likely to be a zip file stored in another zip file + warning undef, "Nested Local Entries found"; + for my $loc (sort keys %nested) + { + my $count = scalar @{ $nested{$loc} }; + my $outerEntry = $LocalDirectory->getByLocalOffset($loc); + say "Local Header for '" . $outerEntry->outputFilename . "' at offset " . decimalHex0x($loc) . " has $count nested Local Headers"; + for my $n ( @{ $nested{$loc} } ) + { + my $innerEntry = $LocalDirectory->getByLocalOffset($n); - out_C "Created Zip Spec", \&decodeZipVer; - out_C "Created OS", \&decodeOS; - out_C "Extract Zip Spec", \&decodeZipVer; - out_C "Extract OS", \&decodeOS; + say "# Nested Local Header for filename '" . $innerEntry->outputFilename . "' is at Offset " . decimalHex0x($n) ; + } + } + } - my ($bgp, $gpFlag) = read_v(); - my ($bcm, $compressedMethod) = read_v(); + if (keys %bomb) + { + # Central Directory knows about these, so this is a zipbomb - out $bgp, "General Purpose Flag", Value_v($gpFlag) ; - GeneralPurposeBits($compressedMethod, $gpFlag); + error undef, "Possible zipbomb -- Nested Local Entries found"; + for my $loc (sort keys %bomb) + { + my $count = scalar @{ $bomb{$loc} }; + my $outerEntry = $LocalDirectory->getByLocalOffset($loc); + say "# Local Header for '" . $outerEntry->outputFilename . "' at offset " . decimalHex0x($loc) . " has $count nested Local Headers"; + + my $table = new SimpleTable; + $table->addHeaderRow('Offset', 'Filename'); + $table->addDataRow(decimalHex0x($_), $LocalDirectory->getByLocalOffset($_)->outputFilename) + for sort @{ $bomb{$loc} } ; + + $table->display(); + + delete $cleanCentralEntries{ $_ } + for grep { defined $_ } + map { $CentralDirectory->{byLocalOffset}{$_}{centralHeaderOffset} } + @{ $bomb{$loc} } ; + } + } + } - out $bcm, "Compression Method", compressionMethod($compressedMethod) ; + # Check if contents of local headers match with central headers + # + # When central header encryption is used the local header values are masked (see APPNOTE 6.3.10, sec 4) + # In this usecase the central header will appear to be absent + # + # key fields + # filename, compressed/uncompessed lengths, crc, compression method + { + for my $centralEntry ( sort { $a->centralHeaderOffset() <=> $b->centralHeaderOffset() } values %cleanCentralEntries ) + { + my $localOffset = $centralEntry->localHeaderOffset; + my $localEntry = $LocalDirectory->getByLocalOffset($localOffset); - out_V "Last Mod Time", sub { getTime(_dosToUnixTime($_[0])) }; + next + unless $localEntry; - my $crc = out_V "CRC"; - my $compressedLength = out_V "Compressed Length"; - my $uncompressedLength = out_V "Uncompressed Length"; - my $filenameLength = out_v "Filename Length"; - my $extraLength = out_v "Extra Length"; - my $comment_length = out_v "Comment Length"; - my $disk_start = out_v "Disk Start"; - my $int_file_attrib = out_v "Int File Attributes"; + state $fields = [ + # field name offset display name stringify + ['filename', ZIP_CD_FILENAME_OFFSET, + 'Filename', undef, ], + ['extractVersion', 7, 'Extract Zip Spec', sub { decimalHex0xUndef($_[0]) . " " . decodeZipVer($_[0]) }, ], + ['generalPurposeFlags', 8, 'General Purpose Flag', \&decimalHex0xUndef, ], + ['compressedMethod', 10, 'Compression Method', sub { decimalHex0xUndef($_[0]) . " " . getcompressionMethodName($_[0]) }, ], + ['lastModDateTime', 12, 'Modification Time', sub { decimalHex0xUndef($_[0]) . " " . LastModTime($_[0]) }, ], + ['crc32', 16, 'CRC32', \&decimalHex0xUndef, ], + ['compressedSize', 20, 'Compressed Size', \&decimalHex0xUndef, ], + ['uncompressedSize', 24, 'Uncompressed Size', \&decimalHex0xUndef, ], - out1 "[Bit 0]", $int_file_attrib & 1 ? "1 Text Data" : "0 'Binary Data'"; + ] ; - my $ext_file_attrib = out_V "Ext File Attributes"; - out1 "[Bit 0]", "Read-Only" - if $ext_file_attrib & 0x01 ; - out1 "[Bit 1]", "Hidden" - if $ext_file_attrib & 0x02 ; - out1 "[Bit 2]", "System" - if $ext_file_attrib & 0x04 ; - out1 "[Bit 3]", "Label" - if $ext_file_attrib & 0x08 ; - out1 "[Bit 4]", "Directory" - if $ext_file_attrib & 0x10 ; - out1 "[Bit 5]", "Archive" - if $ext_file_attrib & 0x20 ; + my $table = new SimpleTable; + $table->addHeaderRow('Field Name', 'Central Offset', 'Central Value', 'Local Offset', 'Local Value'); - my $lcl_hdr_offset = out_V "Local Header Offset"; + for my $data (@$fields) + { + my ($field, $offset, $name, $stringify) = @$data; + # if the local header uses streaming and we are running a scan/walk, the compressed/uncompressed sizes will not be known + my $localValue = $localEntry->{$field} ; + my $centralValue = $centralEntry->{$field}; + + if (($localValue // '-1') ne ($centralValue // '-2')) + { + if ($stringify) + { + $localValue = $stringify->($localValue); + $centralValue = $stringify->($centralValue); + } + + $table->addDataRow($name, + decimalHex0xUndef($centralEntry->centralHeaderOffset() + $offset), + $centralValue, + decimalHex0xUndef($localOffset+$offset), + $localValue); + } + } - my $filename ; - myRead($filename, $filenameLength); - outputFilename($filename); + my $badFields = $table->hasData; + if ($badFields) + { + error undef, "Found $badFields Field Mismatch for Filename '". $centralEntry->outputFilename . "'"; + $table->display(); + } + } + } + } + elsif ($CentralDirectory->exists()) + { + my @messages = "Central Directory exists, but Local Directory not found" ; + push @messages , "Try running with --walk' or '--scan' options" + unless $opt_scan || $opt_walk ; + error undef, @messages; + } + elsif ($LocalDirectory->exists()) + { + if ($CentralDirectory->isEncryptedCD()) + { + warning undef, "Local Directory exists, but Central Directory is encrypted" + } + else + { + error undef, "Local Directory exists, but Central Directory not found" + } - my %ExtraContext = ( CRC => $crc, - LocalHdrOffset => $lcl_hdr_offset, - CompressedLength => $compressedLength); + } - if ($extraLength) + if ($ErrorCount ||$WarningCount || $InfoCount ) { - my @z64 = ($uncompressedLength, $compressedLength, $lcl_hdr_offset, $disk_start); - $ExtraContext{Zip64} = \@z64 ; - $ExtraContext{InCentralDir} = 1; - walkExtra($extraLength, \%ExtraContext); + say "#" + unless $lastWasMessage ; + + say "# Error Count: $ErrorCount" + if $ErrorCount; + say "# Warning Count: $WarningCount" + if $WarningCount; + say "# Info Count: $InfoCount" + if $InfoCount; } - if ($comment_length) + if (@Messages) { - my $comment ; - myRead($comment, $comment_length); - out $comment, "Comment", "'". $comment . "'"; + my $count = scalar @Messages ; + say "#\nWARNINGS"; + say "# * $_\n" for @Messages ; } - - $SEEN->save("CENTRAL HEADER ref Local #" . sprintf("%X", $CentralHeaderCount), $filename, \%ExtraContext) ; + say "#\n# Done"; } -sub decodeZipVer +sub checkForBadlyFormedDataDescriptor { - my $ver = shift ; - - my $sHi = int($ver /10) ; - my $sLo = $ver % 10 ; + my $lastHeader = shift; + my $delta = shift // 0; - #out1 "Zip Spec", "$sHi.$sLo"; - "$sHi.$sLo"; -} + # check size of delta - a DATA HDR without a signature can only be + # 12 bytes for 32-bit + # 20 bytes for 64-bit -sub decodeOS -{ - my $ver = shift ; + my $here = $FH->tell(); - $OS_Lookup{$ver} || "Unknown" ; -} + my $localEntry = $lastHeader->{entry}; -sub Zip64EndCentralHeader -{ - my $signature = shift ; - my $data = shift ; + return 0 + unless $opt_scan || $opt_walk ; - print "\n"; - out $data, "ZIP64 END CENTRAL DIR RECORD", Value_V($signature); + # delta can be the actual payload + a data descriptor without a sig - my $buff; - myRead($buff, 8); + my $signature = unpack "V", peekAtOffset($here + $delta, 4); - out $buff, "Size of record", unpackValue_Q($buff); + if ($signature == ZIP_DATA_HDR_SIG) + { + return 0; + } - my $size = unpack "Q<", $buff; + my $cl32 = unpack "V", peekAtOffset($here + $delta - 8, 4); + my $cl64 = unpack "Q<", peekAtOffset($here + $delta - 16, 8); - out_C "Created Zip Spec", \&decodeZipVer; - out_C "Created OS", \&decodeOS; - out_C "Extract Zip Spec", \&decodeZipVer; - out_C "Extract OS", \&decodeOS; - out_V "Number of this disk"; - out_V "Central Dir Disk no"; - out_Q "Entries in this disk"; - out_Q "Total Entries"; - out_Q "Size of Central Dir"; - out_Q "Offset to Central dir"; + if ($cl32 == $delta - 12) + { + return 12; + } - # TODO - - if ($size != 44) + if ($cl64 == $delta - 20) { - push @Messages, "Unsupported Size field in Zip64EndCentralHeader: should be 44, got $size\n" + return 20 ; } + + return 0; } -sub Zip64EndCentralLocator +sub BadlyFormedDataDescriptor { - my $signature = shift ; - my $data = shift ; + my $lastHeader= shift; + my $delta = shift; - print "\n"; - out $data, "ZIP64 END CENTRAL DIR LOCATOR", Value_V($signature); + # check size of delta - a DATA HDR without a signature can only be + # 12 bytes for 32-bit + # 20 bytes for 64-bit - out_V "Central Dir Disk no"; - out_Q "Offset to Central dir"; - out_V "Total no of Disks"; -} + my $here = $FH->tell(); -sub EndCentralHeader -{ - my $signature = shift ; - my $data = shift ; + my $localEntry = $lastHeader->{entry}; + my $compressedSize = $lastHeader->{payloadLength} ; - print "\n"; - out $data, "END CENTRAL HEADER", Value_V($signature); + my $sigName = Signatures::titleName(ZIP_DATA_HDR_SIG); - out_v "Number of this disk"; - out_v "Central Dir Disk no"; - out_v "Entries in this disk"; - out_v "Total Entries"; - out_V "Size of Central Dir"; - out_V "Offset to Central Dir"; - my $comment_length = out_v "Comment Length"; + if ($opt_scan || $opt_walk) + { + # delta can be the actual payload + a data descriptor without a sig - if ($comment_length) + if ($lastHeader->{'gotDataDescriptorSize'} == 12) + { + # seekTo($FH->tell() + $delta - 12) ; + + # outSomeData($delta - 12, "PAYLOAD", $opt_Redact) ; + + print "\n"; + out1 "Missing $sigName Signature", Value_V(ZIP_DATA_HDR_SIG); + + error $FH->tell(), "Missimg $sigName Signature"; + $localEntry->crc32( out_V "CRC"); + $localEntry->compressedSize( out_V "Compressed Size"); + $localEntry->uncompressedSize( out_V "Uncompressed Size"); + + if ($localEntry->zip64) + { + error $here, "'$sigName': expected 64-bit values, got 32-bit"; + } + + return $FH->tell(); + } + + if ($lastHeader->{'gotDataDescriptorSize'} == 20) + { + # seekTo($FH->tell() + $delta - 20) ; + + # outSomeData($delta - 20, "PAYLOAD", $opt_Redact) ; + + print "\n"; + out1 "Missing $sigName Signature", Value_V(ZIP_DATA_HDR_SIG); + + error $FH->tell(), "Missimg $sigName Signature"; + $localEntry->crc32( out_V "CRC"); + $localEntry->compressedSize( out_Q "Compressed Size"); + $localEntry->uncompressedSize( out_Q "Uncompressed Size"); + + if (! $localEntry->zip64) + { + error $here, "'$sigName': expected 32-bit values, got 64-bit"; + } + + return $FH->tell(); + } + + error 0, "MISSING $sigName"; + + seekTo($here); + return 0; + } + + my $cdEntry = $localEntry->getCdEntry; + + if ($delta == 12) { - my $comment ; - myRead($comment, $comment_length); - out $comment, "Comment", "'$comment'"; + $FH->seek($lastHeader->{payloadOffset} + $lastHeader->{payloadLength}, SEEK_SET) ; + + my $cl = unpack "V", peekAtOffset($FH->tell() + 4, 4); + if ($cl == $compressedSize) + { + print "\n"; + out1 "Missing $sigName Signature", Value_V(ZIP_DATA_HDR_SIG); + + error $FH->tell(), "Missimg $sigName Signature"; + $localEntry->crc32( out_V "CRC"); + $localEntry->compressedSize( out_V "Compressed Size"); + $localEntry->uncompressedSize( out_V "Uncompressed Size"); + + if ($localEntry->zip64) + { + error $here, "'$sigName': expected 64-bit values, got 32-bit"; + } + + return $FH->tell(); + } + } + + if ($delta == 20) + { + $FH->seek($lastHeader->{payloadOffset} + $lastHeader->{payloadLength}, SEEK_SET) ; + + my $cl = unpack "Q<", peekAtOffset($FH->tell() + 4, 8); + + if ($cl == $compressedSize) + { + print "\n"; + out1 "Missing $sigName Signature", Value_V(ZIP_DATA_HDR_SIG); + + error $FH->tell(), "Missimg $sigName Signature"; + $localEntry->crc32( out_V "CRC"); + $localEntry->compressedSize( out_Q "Compressed Size"); + $localEntry->uncompressedSize( out_Q "Uncompressed Size"); + + if (! $localEntry->zip64 && ( $cdEntry && ! $cdEntry->zip64)) + { + error $here, "'$sigName': expected 32-bit values, got 64-bit"; + } + + return $FH->tell(); + } } + + seekTo($here); + + error $here, "Missing $sigName"; + return 0; +} + +sub getcompressionMethodName +{ + my $id = shift ; + " '" . ($ZIP_CompressionMethods{$id} || "Unknown Method") . "'" ; +} + +sub compressionMethod +{ + my $id = shift ; + Value_v($id) . getcompressionMethodName($id); } -sub DataHeader +sub LocalHeader { my $signature = shift ; my $data = shift ; + my $startRecordOffset = shift ; + my $locHeaderOffset = $FH->tell() -4 ; + + ++ $LocalHeaderCount; print "\n"; - out $data, "STREAMING DATA HEADER", Value_V($signature); + out $data, "LOCAL HEADER #$LocalHeaderCount" , Value_V($signature); + + need 26, Signatures::name($signature); + + my $buffer; + my $orphan = 0; + + my ($loc, $CDcompressedSize, $cdZip64, $zip64Sizes, $cdIndex, $cdEntryOffset) ; + my $CentralEntryExists = $CentralDirectory->localOffset($startRecordOffset); + my $localEntry = LocalDirectoryEntry->new(); - out_V "CRC"; + my $cdEntry; - if ($ZIP64) + if (! $opt_scan && ! $opt_walk && $CentralEntryExists) { - out_Q "Compressed Length" ; - out_Q "Uncompressed Length" ; + $cdEntry = $CentralDirectory->getByLocalOffset($startRecordOffset); + + if (! $cdEntry) + { + out1 "Orphan Entry: No matching central directory" ; + $orphan = 1 ; + } + + $cdZip64 = $cdEntry->zip64ExtraPresent; + $zip64Sizes = $cdEntry->zip64SizesPresent; + $cdEntryOffset = $cdEntry->centralHeaderOffset ; + $localEntry->addCdEntry($cdEntry) ; + + if ($cdIndex && $cdIndex != $LocalHeaderCount) + { + # fatal undef, "$cdIndex != $LocalHeaderCount" + } } - else + + my $extractVer = out_C "Extract Zip Spec", \&decodeZipVer; + out_C "Extract OS", \&decodeOS; + + my ($bgp, $gpFlag) = read_v(); + my ($bcm, $compressedMethod) = read_v(); + + out $bgp, "General Purpose Flag", Value_v($gpFlag) ; + GeneralPurposeBits($compressedMethod, $gpFlag); + my $LanguageEncodingFlag = $gpFlag & ZIP_GP_FLAG_LANGUAGE_ENCODING ; + my $streaming = $gpFlag & ZIP_GP_FLAG_STREAMING_MASK ; + $localEntry->languageEncodingFlag($LanguageEncodingFlag) ; + + out $bcm, "Compression Method", compressionMethod($compressedMethod) ; + info $FH->tell() - 2, "Unknown 'Compression Method' ID " . decimalHex0x($compressedMethod, 2) + if ! defined $ZIP_CompressionMethods{$compressedMethod} ; + + my $lastMod = out_V "Modification Time", sub { LastModTime($_[0]) }; + + my $crc = out_V "CRC"; + warning $FH->tell() - 4, "CRC field should be zero when streaming is enabled" + if $streaming && $crc != 0 ; + + my $compressedSize = out_V "Compressed Size"; + # warning $FH->tell(), "Compressed Size should be zero when streaming is enabled"; + + my $uncompressedSize = out_V "Uncompressed Size"; + # warning $FH->tell(), "Uncompressed Size should be zero when streaming is enabled"; + + my $filenameLength = out_v "Filename Length"; + + if ($filenameLength == 0) { - out_V "Compressed Length" ; - out_V "Uncompressed Length" ; + info $FH->tell()- 2, "Zero Length filename"; } -} + my $extraLength = out_v "Extra Length"; + + my $filename = ''; + if ($filenameLength) + { + need $filenameLength, Signatures::name($signature), 'Filename'; -sub GeneralPurposeBits -{ - my $method = shift; - my $gp = shift; + myRead(my $raw_filename, $filenameLength); + $localEntry->filename($raw_filename) ; + $filename = outputFilename($raw_filename, $LanguageEncodingFlag); + $localEntry->outputFilename($filename); + } + + $localEntry->localHeaderOffset($locHeaderOffset) ; + $localEntry->offsetStart($locHeaderOffset) ; + $localEntry->compressedSize($compressedSize) ; + $localEntry->uncompressedSize($uncompressedSize) ; + $localEntry->extractVersion($extractVer); + $localEntry->generalPurposeFlags($gpFlag); + $localEntry->lastModDateTime($lastMod); + $localEntry->crc32($crc) ; + $localEntry->zip64ExtraPresent($cdZip64) ; + $localEntry->zip64SizesPresent($zip64Sizes) ; + + $localEntry->compressedMethod($compressedMethod) ; + $localEntry->streamed($gpFlag & ZIP_GP_FLAG_STREAMING_MASK) ; + + $localEntry->std_localHeaderOffset($locHeaderOffset + $PREFIX_DELTA) ; + $localEntry->std_compressedSize($compressedSize) ; + $localEntry->std_uncompressedSize($uncompressedSize) ; + $localEntry->std_diskNumber(0) ; - out1 "[Bit 0]", "1 'Encryption'" if $gp & ZIP_GP_FLAG_ENCRYPTED_MASK; + if ($extraLength) + { + need $extraLength, Signatures::name($signature), 'Extra'; + walkExtra($extraLength, $localEntry); + } - my %lookup = ( - 0 => "Normal Compression", - 1 => "Maximum Compression", - 2 => "Fast Compression", - 3 => "Super Fast Compression"); + # APPNOTE 6.3.10, sec 4.3.8 + warning $FH->tell - $filenameLength, "Directory '$filename' must not have a payload" + if ! $streaming && $filename =~ m#/$# && $localEntry->uncompressedSize ; + my @msg ; + # if ($cdZip64 && ! $ZIP64) + # { + # # Central directory said this was Zip64 + # # some zip files don't have the Zip64 field in the local header + # # seems to be a streaming issue. + # push @msg, "Missing Zip64 extra field in Local Header #$hexHdrCount\n"; - if ($method == ZIP_CM_DEFLATE) + # if (! $zip64Sizes) + # { + # # Central has a ZIP64 entry that doesn't have sizes + # # Local doesn't have a Zip 64 at all + # push @msg, "Unzip may complain about 'overlapped components' #$hexHdrCount\n"; + # } + # else + # { + # $ZIP64 = 1 + # } + # } + + + my $minizip_encrypted = $localEntry->minizip_secure; + my $pk_encrypted = ($gpFlag & ZIP_GP_FLAG_STRONG_ENCRYPTED_MASK) && $compressedMethod != 99 && ! $minizip_encrypted; + + # Detecting PK strong encryption from a local header is a bit convoluted. + # Cannot just use ZIP_GP_FLAG_ENCRYPTED_CD because minizip also uses this bit. + # so jump through some hoops + # extract ver is >= 5.0' + # all the encryption flags are set in gpflags + # TODO - add zero lengths for crc, compresssed & uncompressed + + if (($gpFlag & ZIP_GP_FLAG_ALL_ENCRYPT) == ZIP_GP_FLAG_ALL_ENCRYPT && $extractVer >= 0x32 ) { - my $mid = ($gp >> 1) & 0x03 ; + $CentralDirectory->setPkEncryptedCD() + } - out1 "[Bits 1-2]", "$mid '$lookup{$mid}'"; + my $size = 0; + + # If no CD scanned, get compressed Size from local header. + # Zip64 extra field takes priority + my $cdl = defined $cdEntry + ? $cdEntry->compressedSize() + : undef; + + $CDcompressedSize = $localEntry->compressedSize ; + $CDcompressedSize = $cdl + if defined $cdl && $gpFlag & ZIP_GP_FLAG_STREAMING_MASK; + + my $cdu = defined $CentralDirectory->{byLocalOffset}{$locHeaderOffset} + ? $CentralDirectory->{byLocalOffset}{$locHeaderOffset}{uncompressedSize} + : undef; + my $CDuncompressedSize = $localEntry->uncompressedSize ; + + $CDuncompressedSize = $cdu + if defined $cdu && $gpFlag & ZIP_GP_FLAG_STREAMING_MASK; + + my $fullCompressedSize = $CDcompressedSize; + + my $payloadOffset = $FH->tell(); + $localEntry->payloadOffset($payloadOffset) ; + $localEntry->offsetEnd($payloadOffset + $fullCompressedSize -1) ; + + if ($CDcompressedSize) + { + # check if enough left in file for the payload + my $available = $FILELEN - $FH->tell; + if ($available < $CDcompressedSize ) + { + error $FH->tell, + "file truncated while reading 'PAYLOAD'", + expectedMessage($CDcompressedSize, $available); + + $CDcompressedSize = $available; + } } - if ($method == ZIP_CM_LZMA) + # Next block can decrement the CDcompressedSize + # possiblty to zero. Need to remember if it started out + # as a non-zero value + my $haveCDcompressedSize = $CDcompressedSize; + + if ($compressedMethod == 99 && $localEntry->aesValid) # AES Encryption { - if ($gp & ZIP_GP_FLAG_LZMA_EOS_PRESENT) { - out1 "[Bit 1]", "1 'LZMA EOS Marker Present'" ; + $CDcompressedSize -= printAes($localEntry) + } + elsif (($gpFlag & ZIP_GP_FLAG_ALL_ENCRYPT) == 0) + { + if ($compressedMethod == ZIP_CM_LZMA) + { + + $size = printLzmaProperties() + } + + $CDcompressedSize -= $size; + } + elsif ($pk_encrypted) + { + $CDcompressedSize -= DecryptionHeader(); + } + + if ($haveCDcompressedSize) { + + if ($compressedMethod == 92 && $CDcompressedSize == 20) { + # Payload for a Reference is the SHA-1 hash of the uncompressed content + myRead(my $sha1, 20); + out $sha1, "PAYLOAD", "SHA-1 Hash: " . hexDump($sha1); + } + elsif ($compressedMethod == 99 && $localEntry->aesValid ) { + outSomeData($CDcompressedSize, "PAYLOAD", $opt_Redact) ; + my $auth ; + myRead($auth, 10); + out $auth, "AES Auth", hexDump16($auth); } else { - out1 "[Bit 1]", "0 'LZMA EOS Marker Not Present'" ; + outSomeData($CDcompressedSize, "PAYLOAD", $opt_Redact) ; } } - if ($method == ZIP_CM_IMPLODE) # Imploding + print "WARNING: $_" + for @msg; + + push @Messages, @msg ; + + $LocalDirectory->addEntry($localEntry); + + return { + 'localHeader' => 1, + 'streamed' => $gpFlag & ZIP_GP_FLAG_STREAMING_MASK, + 'offset' => $startRecordOffset, + 'length' => $FH->tell() - $startRecordOffset, + 'payloadLength' => $fullCompressedSize, + 'payloadOffset' => $payloadOffset, + 'entry' => $localEntry, + } ; +} + +use constant Pack_ZIP_DIGITAL_SIGNATURE_SIG => pack("V", ZIP_DIGITAL_SIGNATURE_SIG); + +sub findDigitalSignature +{ + my $cdSize = shift; + + my $here = $FH->tell(); + + my $data ; + myRead($data, $cdSize); + + seekTo($here); + + # find SIG + my $ix = index($data, Pack_ZIP_DIGITAL_SIGNATURE_SIG); + if ($ix > -1) { - out1 "[Bit 1]", ($gp & (1 << 1) ? "1 '8k" : "0 '4k") . " Sliding Dictionary'" ; - out1 "[Bit 2]", ($gp & (2 << 1) ? "1 '3" : "0 '2" ) . " Shannon-Fano Trees'" ; + # check size of signature meaans it is directly after the encrypted CD + my $sigSize = unpack "v", substr($data, $ix+4, 2); + if ($ix + 4 + 2 + $sigSize == $cdSize) + { + # return size of digital signature record + return 4 + 2 + $sigSize ; + } } - out1 "[Bit 3]", "1 'Streamed'" if $gp & ZIP_GP_FLAG_STREAMING_MASK; - out1 "[Bit 4]", "1 'Enhanced Deflating'" if $gp & 1 << 4; - out1 "[Bit 5]", "1 'Compressed Patched'" if $gp & 1 << 5 ; - out1 "[Bit 6]", "1 'Strong Encryption'" if $gp & ZIP_GP_FLAG_STRONG_ENCRYPTED_MASK; - out1 "[Bit 11]", "1 'Language Encoding'" if $gp & ZIP_GP_FLAG_LANGUAGE_ENCODING; - out1 "[Bit 12]", "1 'Pkware Enhanced Compression'" if $gp & 1 <<12 ; - out1 "[Bit 13]", "1 'Encrypted Central Dir'" if $gp & 1 <<13 ; + return 0; +} - return (); +sub displayEncryptedCD +{ + # First thing in the encrypted CD is the Decryption Header + my $decryptHeaderSize = DecryptionHeader(1); + + # Check for digital signature record in the CD + # It needs to be the very last thing in the CD + + my $delta = deltaToNextSignature(); + print "\n"; + outSomeData($delta, "ENCRYPTED CENTRAL DIRECTORY") + if $delta; } +sub DecryptionHeader +{ + # APPNOTE 6.3.10, sec 7.2.4 + + # -Decryption Header: + # Value Size Description + # ----- ---- ----------- + # IVSize 2 bytes Size of initialization vector (IV) + # IVData IVSize Initialization vector for this file + # Size 4 bytes Size of remaining decryption header data + # Format 2 bytes Format definition for this record + # AlgID 2 bytes Encryption algorithm identifier + # Bitlen 2 bytes Bit length of encryption key + # Flags 2 bytes Processing flags + # ErdSize 2 bytes Size of Encrypted Random Data + # ErdData ErdSize Encrypted Random Data + # Reserved1 4 bytes Reserved certificate processing data + # Reserved2 (var) Reserved for certificate processing data + # VSize 2 bytes Size of password validation data + # VData VSize-4 Password validation data + # VCRC32 4 bytes Standard ZIP CRC32 of password validation data -sub seekSet + my $central = shift ; + + if ($central) + { + print "\n"; + out "", "CENTRAL HEADER DECRYPTION RECORD"; + + } + else + { + print "\n"; + out "", "DECRYPTION HEADER RECORD"; + } + + my $bytecount = 2; + + my $IVSize = out_v "IVSize"; + outHexdump($IVSize, "IVData"); + $bytecount += $IVSize; + + my $Size = out_V "Size"; + $bytecount += $Size + 4; + + out_v "Format"; + out_v "AlgId", sub { $AlgIdLookup{ $_[0] } // "Unknown algorithm" } ; + out_v "BitLen"; + out_v "Flags", sub { $FlagsLookup{ $_[0] } // "Reserved for certificate processing" } ; + + my $ErdSize = out_v "ErdSize"; + outHexdump($ErdSize, "ErdData"); + + my $Reserved1_RCount = out_V "RCount"; + Reserved2($Reserved1_RCount); + + my $VSize = out_v "VSize"; + outHexdump($VSize-4, "VData"); + + out_V "VCRC32"; + + return $bytecount ; +} + +sub Reserved2 { - my $fh = $_[0] ; - my $size = $_[1]; + # APPNOTE 6.3.10, sec 7.4.3 & 7.4.4 - use Fcntl qw(SEEK_SET); - seek($fh, $size, SEEK_SET); + my $recipients = shift; + + return 0 + if $recipients == 0; + + out_v "HashAlg", sub { $HashAlgLookup{ $_[0] } // "Unknown algorithm" } ; + my $HSize = out_v "HSize" ; + + my $ix = 1; + for (0 .. $recipients-1) + { + my $hex = sprintf("Key #%X", $ix) ; + my $RESize = out_v "RESize $hex"; + + outHexdump($HSize, "REHData $hex"); + outHexdump($RESize - $HSize, "REKData $hex"); + ++ $ix; + } } -sub skip +sub redactData { - my $fh = $_[0] ; - my $size = $_[1]; + my $data = shift; - use Fcntl qw(SEEK_CUR); - seek($fh, $size, SEEK_CUR); + # Redact everything apart from directory seperators + $data =~ s(.)(X)g + if $opt_Redact; + + return $data; +} + +sub redactFilename +{ + my $filename = shift; + + # Redact everything apart from directory seperators + $filename =~ s(.)(X)g + if $opt_Redact; + return $filename; } +sub validateDirectory +{ + # Check that Directries are stored correctly + # + # 1. Filename MUST end with a "/" + # see APPNOTE 6.3.10, sec 4.3.8 + # 2. Uncompressed size == 0 + # see APPNOTE 6.3.10, sec 4.3.8 + # 3. warn if compressed size > 0 and Uncompressed size == 0 + # 4. check for presence of DOS directory attrib in External Attributes + # 5. Check for Unix extrnal attribute S_IFDIR + + my $offset = shift ; + my $filename = shift ; + my $extractVersion = shift; + my $versionMadeBy = shift; + my $compressedSize = shift; + my $uncompressedSize = shift; + my $externalAttributes = shift; + + my $dosAttributes = $externalAttributes & 0xFFFF; + my $otherAttributes = ($externalAttributes >> 16 ) & 0xFFFF; + + my $probablyDirectory = 0; + my $filenameOK = 0; + my $attributesSet = 0; + my $dosAttributeSet = 0; + my $unixAttributeSet = 0; + + if ($filename =~ m#/$#) + { + # filename claims it is a directory. + $probablyDirectory = 1; + $filenameOK = 1; + } + + if ($dosAttributes & 0x0010) # ATTR_DIRECTORY + { + $probablyDirectory = 1; + $attributesSet = 1 ; + $dosAttributeSet = 1 ; + } + + if ($versionMadeBy == 3 && $otherAttributes & 0x4000) # Unix & S_IFDIR + { + $probablyDirectory = 1; + $attributesSet = 1; + $unixAttributeSet = 1; + } + + return + unless $probablyDirectory ; + + error $offset + CentralDirectoryEntry::Offset_Filename(), + "Directory '$filename' must end in a '/'", + "'External Attributes' flag this as a directory" + if ! $filenameOK && $uncompressedSize == 0; + + info $offset + CentralDirectoryEntry::Offset_ExternalAttributes(), + "DOS Directory flag not set in 'External Attributes' for Directory '$filename'" + if $filenameOK && ! $dosAttributeSet; + + info $offset + CentralDirectoryEntry::Offset_ExternalAttributes(), + "Unix Directory flag not set in 'External Attributes' for Directory '$filename'" + if $filenameOK && $versionMadeBy == 3 && ! $unixAttributeSet; + + if ($uncompressedSize != 0) + { + # APPNOTE 6.3.10, sec 4.3.8 + error $offset + CentralDirectoryEntry::Offset_UncompressedSize(), + "Directory '$filename' must not have a payload" + } + elsif ($compressedSize != 0) + { + + info $offset + CentralDirectoryEntry::Offset_CompressedSize(), + "Directory '$filename' has compressed payload that uncompresses to nothing" + } + + if ($extractVersion < 20) + { + # APPNOTE 6.3.10, sec 4.4.3.2 + my $got = decodeZipVer($extractVersion); + warning $offset + CentralDirectoryEntry::Offset_VersionNeededToExtract(), + "'Extract Zip Spec' is '$got'. Need value >= '2.0' for Directory '$filename'" + } +} + +sub validateFilename +{ + my $filename = shift ; + + return "Zero length filename" + if $filename eq '' ; + + # TODO + # - check length of filename + # getconf NAME_MAX . and getconf PATH_MAX . on Linux + + # Start with APPNOTE restrictions + + # APPNOTE 6.3.10, sec 4.4.17.1 + # + # No absolute path + # No backslash delimeters + # No drive letters + + return "Filename must not be an absolute path" + if $filename =~ m#^/#; + + return ["Backslash detected in filename", "Possible Windows path."] + if $filename =~ m#\\#; + + return "Windows Drive Letter '$1' not allowed in filename" + if $filename =~ /^([a-z]:)/i ; + + # Slip Vulnerability with use of ".." in a relative path + # https://security.snyk.io/research/zip-slip-vulnerability + return ["Use of '..' in filename is a Zip Slip Vulnerability", + "See https://security.snyk.io/research/zip-slip-vulnerability" ] + if $filename =~ m#^\.\./# || $filename =~ m#/\.\./# || $filename =~ m#/\.\.# ; + + # Cannot have "." or ".." as the full filename + return "Use of current-directory filename '.' may not unzip correctly" + if $filename eq '.' ; + + return "Use of parent-directory filename '..' may not unzip correctly" + if $filename eq '..' ; + + # Portability (mostly with Windows) + + { + # see https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file + state $badDosFilename = join '|', map { quotemeta } + qw(CON PRN AUX NUL + COM1 COM2 COM3 COM4 COM5 COM6 COM7 COM8 COM9 + LPT1 LPT2 LPT3 LPT4 LPT5 LPT6 LPT7 LPT8 LPT9 + ) ; + + # if $filename contains any invalid codepoints, we will get a warning like this + # + # Operation "pattern match (m//)" returns its argument for non-Unicode code point + # + # so silence it for now. + + no warnings; + + return "Portability Issue: '$1' is a reserved Windows device name" + if $filename =~ /^($badDosFilename)$/io ; + + # Can't have the device name with an extension either + return "Portability Issue: '$1' is a reserved Windows device name" + if $filename =~ /^($badDosFilename)\./io ; + } + + state $illegal_windows_chars = join '|', map { quotemeta } qw( < > : " | ? * ); + return "Portability Issue: Windows filename cannot contain '$1'" + if $filename =~ /($illegal_windows_chars)/o ; + + return "Portability Issue: Null character '\\x00' is not allowed in a Windows or Linux filename" + if $filename =~ /\x00/ ; + + return sprintf "Portability Issue: Control character '\\x%02X' is not allowed in a Windows filename", ord($1) + if $filename =~ /([\x00-\x1F])/ ; + + return undef; +} + +sub getOutputFilename +{ + my $raw_filename = shift; + my $LanguageEncodingFlag = shift; + my $message = shift // "Filename"; + + my $filename ; + my $decoded_filename; + + if ($raw_filename eq '') + { + if ($message eq 'Filename') + { + warning $FH->tell() , + "Filename ''", + "Zero Length Filename" ; + } + + return '', '', 0; + } + elsif ($opt_Redact) + { + return redactFilename($raw_filename), '', 0 ; + } + else + { + $decoded_filename = TextEncoding::decode($raw_filename, $message, $LanguageEncodingFlag) ; + $filename = TextEncoding::encode($decoded_filename, $message, $LanguageEncodingFlag) ; + } + + return $filename, $decoded_filename, $filename ne $raw_filename ; +} + +sub outputFilename +{ + my $raw_filename = shift; + my $LanguageEncodingFlag = shift; + my $message = shift // "Filename"; + + my ($filename, $decoded_filename, $modified) = getOutputFilename($raw_filename, $LanguageEncodingFlag); + + out $raw_filename, $message, "'". $filename . "'"; + + if (! $opt_Redact && TextEncoding::debugEncoding()) + { + # use Devel::Peek; + # print "READ " ; Dump($raw_filename); + # print "INTERNAL " ; Dump($decoded_filename); + # print "OUTPUT " ; Dump($filename); + + debug $FH->tell() - length($raw_filename), + "$message Encoding Change" + if $modified ; + + # use Unicode::Normalize; + # my $NormaizedForm ; + # if (defined $decoded_filename) + # { + # $NormaizedForm .= Unicode::Normalize::checkNFD $decoded_filename ? 'NFD ' : ''; + # $NormaizedForm .= Unicode::Normalize::checkNFC $decoded_filename ? 'NFC ' : ''; + # $NormaizedForm .= Unicode::Normalize::checkNFKD $decoded_filename ? 'NFKD ' : ''; + # $NormaizedForm .= Unicode::Normalize::checkNFKC $decoded_filename ? 'NFKC ' : ''; + # $NormaizedForm .= Unicode::Normalize::checkFCD $decoded_filename ? 'FCD ' : ''; + # $NormaizedForm .= Unicode::Normalize::checkFCC $decoded_filename ? 'FCC ' : ''; + # } + + debug $FH->tell() - length($raw_filename), + "Encoding Debug for $message", + "Octets Read from File [$raw_filename][" . length($raw_filename). "] [" . charDump2($raw_filename) . "]", + "Via Unicode Codepoints [$decoded_filename][" . length($decoded_filename) . "] [" . charDump($decoded_filename) . "]", + # "Unicode Normalization $NormaizedForm", + "Octets Written [$filename][" . length($filename). "] [" . charDump2($filename) . "]"; + } + + if ($message eq 'Filename' && $opt_want_warning_mesages) + { + # Check for bad, unsafe & not portable filenames + my $v = validateFilename($decoded_filename); + + if ($v) + { + my @v = ref $v eq 'ARRAY' + ? @$v + : $v; + + warning $FH->tell() - length($raw_filename), + "Filename '$filename'", + @v + } + } + + return $filename; +} + +sub CentralHeader +{ + my $signature = shift ; + my $data = shift ; + my $startRecordOffset = shift ; + + my $cdEntryOffset = $FH->tell() - 4 ; + + ++ $CentralHeaderCount; + + print "\n"; + out $data, "CENTRAL HEADER #$CentralHeaderCount", Value_V($signature); + my $buffer; + + need 42, Signatures::name($signature); + + out_C "Created Zip Spec", \&decodeZipVer; + my $made_by = out_C "Created OS", \&decodeOS; + my $extractVer = out_C "Extract Zip Spec", \&decodeZipVer; + out_C "Extract OS", \&decodeOS; + + my ($bgp, $gpFlag) = read_v(); + my ($bcm, $compressedMethod) = read_v(); + + my $cdEntry = CentralDirectoryEntry->new($cdEntryOffset); + + out $bgp, "General Purpose Flag", Value_v($gpFlag) ; + GeneralPurposeBits($compressedMethod, $gpFlag); + my $LanguageEncodingFlag = $gpFlag & ZIP_GP_FLAG_LANGUAGE_ENCODING ; + $cdEntry->languageEncodingFlag($LanguageEncodingFlag) ; + + out $bcm, "Compression Method", compressionMethod($compressedMethod) ; + info $FH->tell() - 2, "Unknown 'Compression Method' ID " . decimalHex0x($compressedMethod, 2) + if ! defined $ZIP_CompressionMethods{$compressedMethod} ; + + my $lastMod = out_V "Modification Time", sub { LastModTime($_[0]) }; + + my $crc = out_V "CRC"; + my $compressedSize = out_V "Compressed Size"; + my $std_compressedSize = $compressedSize; + my $uncompressedSize = out_V "Uncompressed Size"; + my $std_uncompressedSize = $uncompressedSize; + my $filenameLength = out_v "Filename Length"; + if ($filenameLength == 0) + { + info $FH->tell()- 2, "Zero Length filename"; + } + my $extraLength = out_v "Extra Length"; + my $comment_length = out_v "Comment Length"; + my $disk_start = out_v "Disk Start"; + my $std_disk_start = $disk_start; + + my $int_file_attrib = out_v "Int File Attributes"; + out1 "[Bit 0]", $int_file_attrib & 1 ? "1 'Text Data'" : "0 'Binary Data'"; + out1 "[Bits 1-15]", Value_v($int_file_attrib & 0xFE) . " 'Unknown'" + if $int_file_attrib & 0xFE ; + + my $ext_file_attrib = out_V "Ext File Attributes"; + + { + # MS-DOS Attributes are bottom two bytes + my $dos_attrib = $ext_file_attrib & 0xFFFF; + + # See https://learn.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants + # and https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-smb/65e0c225-5925-44b0-8104-6b91339c709f + + out1 "[Bit 0]", "Read-Only" if $dos_attrib & 0x0001 ; + out1 "[Bit 1]", "Hidden" if $dos_attrib & 0x0002 ; + out1 "[Bit 2]", "System" if $dos_attrib & 0x0004 ; + out1 "[Bit 3]", "Label" if $dos_attrib & 0x0008 ; + out1 "[Bit 4]", "Directory" if $dos_attrib & 0x0010 ; + out1 "[Bit 5]", "Archive" if $dos_attrib & 0x0020 ; + out1 "[Bit 6]", "Device" if $dos_attrib & 0x0040 ; + out1 "[Bit 7]", "Normal" if $dos_attrib & 0x0080 ; + out1 "[Bit 8]", "Temporary" if $dos_attrib & 0x0100 ; + out1 "[Bit 9]", "Sparse" if $dos_attrib & 0x0200 ; + out1 "[Bit 10]", "Reparse Point" if $dos_attrib & 0x0400 ; + out1 "[Bit 11]", "Compressed" if $dos_attrib & 0x0800 ; + + out1 "[Bit 12]", "Offline" if $dos_attrib & 0x1000 ; + out1 "[Bit 13]", "Not Indexed" if $dos_attrib & 0x2000 ; + + # Zip files created on Mac seem to set this bit. Not clear why. + out1 "[Bit 14]", "Possible Mac Flag" if $dos_attrib & 0x4000 ; + + # p7Zip & 7z set this bit to flag that the high 16-bits are Unix attributes + out1 "[Bit 15]", "Possible p7zip/7z Unix Flag" if $dos_attrib & 0x8000 ; + + } + + my $native_attrib = ($ext_file_attrib >> 16 ) & 0xFFFF; + + if ($made_by == 3) # Unix + { + + state $mask = { + 0 => '---', + 1 => '--x', + 2 => '-w-', + 3 => '-wx', + 4 => 'r--', + 5 => 'r-x', + 6 => 'rw-', + 7 => 'rwx', + } ; + + my $rwx = ($native_attrib & 0777); + + if ($rwx) + { + my $output = ''; + $output .= $mask->{ ($rwx >> 6) & 07 } ; + $output .= $mask->{ ($rwx >> 3) & 07 } ; + $output .= $mask->{ ($rwx >> 0) & 07 } ; + + out1 "[Bits 16-24]", Value_v($rwx) . " 'Unix attrib: $output'" ; + out1 "[Bit 25]", "1 'Sticky'" + if $rwx & 0x200 ; + out1 "[Bit 26]", "1 'Set GID'" + if $rwx & 0x400 ; + out1 "[Bit 27]", "1 'Set UID'" + if $rwx & 0x800 ; + + my $not_rwx = (($native_attrib >> 12) & 0xF); + if ($not_rwx) + { + state $masks = { + 0x0C => 'Socket', # 0x0C 0b1100 + 0x0A => 'Symbolic Link', # 0x0A 0b1010 + 0x08 => 'Regular File', # 0x08 0b1000 + 0x06 => 'Block Device', # 0x06 0b0110 + 0x04 => 'Directory', # 0x04 0b0100 + 0x02 => 'Character Device', # 0x02 0b0010 + 0x01 => 'FIFO', # 0x01 0b0001 + }; + + my $got = $masks->{$not_rwx} // 'Unknown Unix attrib' ; + out1 "[Bits 28-31]", Value_C($not_rwx) . " '$got'" + } + } + } + elsif ($native_attrib) + { + out1 "[Bits 24-31]", Value_v($native_attrib) . " 'Unknown attributes for OS ID $made_by'" + } + + my ($d, $locHeaderOffset) = read_V(); + my $out = Value_V($locHeaderOffset); + my $std_localHeaderOffset = $locHeaderOffset; + + if ($locHeaderOffset != MAX32) + { + testPossiblePrefix($locHeaderOffset, ZIP_LOCAL_HDR_SIG); + if ($PREFIX_DELTA) + { + $out .= " [Actual Offset is " . Value_V($locHeaderOffset + $PREFIX_DELTA) . "]" + } + } + + out $d, "Local Header Offset", $out; + + if ($locHeaderOffset != MAX32) + { + my $commonMessage = "'Local Header Offset' field in '" . Signatures::name($signature) . "' is invalid"; + $locHeaderOffset = checkOffsetValue($locHeaderOffset, $startRecordOffset, 0, $commonMessage, $startRecordOffset + CentralDirectoryEntry::Offset_RelativeOffsetToLocal(), ZIP_LOCAL_HDR_SIG) ; + } + + my $filename = ''; + if ($filenameLength) + { + need $filenameLength, Signatures::name($signature), 'Filename'; + + myRead(my $raw_filename, $filenameLength); + $cdEntry->filename($raw_filename) ; + $filename = outputFilename($raw_filename, $LanguageEncodingFlag); + $cdEntry->outputFilename($filename); + } + + $cdEntry->centralHeaderOffset($cdEntryOffset) ; + $cdEntry->localHeaderOffset($locHeaderOffset) ; + $cdEntry->compressedSize($compressedSize) ; + $cdEntry->uncompressedSize($uncompressedSize) ; + $cdEntry->zip64ExtraPresent(undef) ; #$cdZip64; ### FIX ME + $cdEntry->zip64SizesPresent(undef) ; # $zip64Sizes; ### FIX ME + $cdEntry->extractVersion($extractVer); + $cdEntry->generalPurposeFlags($gpFlag); + $cdEntry->compressedMethod($compressedMethod) ; + $cdEntry->lastModDateTime($lastMod); + $cdEntry->crc32($crc) ; + $cdEntry->inCentralDir(1) ; + + $cdEntry->std_localHeaderOffset($std_localHeaderOffset) ; + $cdEntry->std_compressedSize($std_compressedSize) ; + $cdEntry->std_uncompressedSize($std_uncompressedSize) ; + $cdEntry->std_diskNumber($std_disk_start) ; + + if ($extraLength) + { + need $extraLength, Signatures::name($signature), 'Extra'; + + walkExtra($extraLength, $cdEntry); + } + + # $cdEntry->endCentralHeaderOffset($FH->tell() - 1); + + # Can only validate for directory after zip64 data is read + validateDirectory($cdEntryOffset, $filename, $extractVer, $made_by, + $cdEntry->compressedSize, $cdEntry->uncompressedSize, $ext_file_attrib); + + if ($comment_length) + { + need $comment_length, Signatures::name($signature), 'Comment'; + + my $comment ; + myRead($comment, $comment_length); + outputFilename $comment, $LanguageEncodingFlag, "Comment"; + $cdEntry->comment($comment); + } + + $cdEntry->offsetStart($cdEntryOffset) ; + $cdEntry->offsetEnd($FH->tell() - 1) ; + + $CentralDirectory->addEntry($cdEntry); + + return { 'encapsulated' => $cdEntry ? $cdEntry->encapsulated() : 0}; +} + +sub decodeZipVer +{ + my $ver = shift ; + + return "" + if ! defined $ver; + + my $sHi = int($ver /10) ; + my $sLo = $ver % 10 ; + + "$sHi.$sLo"; +} + +sub decodeOS +{ + my $ver = shift ; + + $OS_Lookup{$ver} || "Unknown" ; +} + +sub Zip64EndCentralHeader +{ + # Extra ID is 0x0001 + + # APPNOTE 6.3.10, section 4.3.14, 7.3.3, 7.3.4 & APPENDIX C + + # TODO - APPNOTE allows an extensible data sector at end of this record (see APPNOTE 6.3.10, section 4.3.14.4) + # The code below does NOT take this into account. + + my $signature = shift ; + my $data = shift ; + my $startRecordOffset = shift ; + + print "\n"; + out $data, "ZIP64 END CENTRAL DIR RECORD", Value_V($signature); + + need 8, Signatures::name($signature); + + my $size = out_Q "Size of record"; + + need $size, Signatures::name($signature); + + out_C "Created Zip Spec", \&decodeZipVer; + out_C "Created OS", \&decodeOS; + my $extractSpec = out_C "Extract Zip Spec", \&decodeZipVer; + out_C "Extract OS", \&decodeOS; + my $diskNumber = out_V "Number of this disk"; + my $cdDiskNumber = out_V "Central Dir Disk no"; + my $entriesOnThisDisk = out_Q "Entries in this disk"; + my $totalEntries = out_Q "Total Entries"; + my $centralDirSize = out_Q "Size of Central Dir"; + + my ($d, $centralDirOffset) = read_Q(); + my $out = Value_Q($centralDirOffset); + testPossiblePrefix($centralDirOffset, ZIP_CENTRAL_HDR_SIG); + + $out .= " [Actual Offset is " . Value_Q($centralDirOffset + $PREFIX_DELTA) . "]" + if $PREFIX_DELTA ; + out $d, "Offset to Central dir", $out; + + if (! emptyArchive($startRecordOffset, $diskNumber, $cdDiskNumber, $entriesOnThisDisk, $totalEntries, $centralDirSize, $centralDirOffset)) + { + my $commonMessage = "'Offset to Central Directory' field in '" . Signatures::name($signature) . "' is invalid"; + $centralDirOffset = checkOffsetValue($centralDirOffset, $startRecordOffset, $centralDirSize, $commonMessage, $startRecordOffset + 48, ZIP_CENTRAL_HDR_SIG, 0, $extractSpec < 0x3E) ; + } + + # Length of 44 means typical version 1 header + return + if $size == 44 ; + + my $remaining = $size - 44; + + # pkzip sets the extract zip spec to 6.2 (0x3E) to signal a v2 record + # See APPNOTE 6.3.10, section, 7.3.3 + + if ($extractSpec >= 0x3E) + { + # Version 2 header (see APPNOTE 6.3.7, section 7.3.4, ) + # Can use version 2 header to infer presence of encrypted CD + $CentralDirectory->setPkEncryptedCD(); + + + # Compression Method 2 bytes Method used to compress the + # Central Directory + # Compressed Size 8 bytes Size of the compressed data + # Original Size 8 bytes Original uncompressed size + # AlgId 2 bytes Encryption algorithm ID + # BitLen 2 bytes Encryption key length + # Flags 2 bytes Encryption flags + # HashID 2 bytes Hash algorithm identifier + # Hash Length 2 bytes Length of hash data + # Hash Data (variable) Hash data + + my ($bcm, $compressedMethod) = read_v(); + out $bcm, "Compression Method", compressionMethod($compressedMethod) ; + info $FH->tell() - 2, "Unknown 'Compression Method' ID " . decimalHex0x($compressedMethod, 2) + if ! defined $ZIP_CompressionMethods{$compressedMethod} ; + out_Q "Compressed Size"; + out_Q "Uncompressed Size"; + out_v "AlgId", sub { $AlgIdLookup{ $_[0] } // "Unknown algorithm" } ; + out_v "BitLen"; + out_v "Flags", sub { $FlagsLookup{ $_[0] } // "reserved for certificate processing" } ; + out_v "HashID", sub { $HashIDLookup{ $_[0] } // "Unknown ID" } ; + + my $hashLen = out_v "Hash Length "; + outHexdump($hashLen, "Hash Data"); + + $remaining -= $hashLen + 28; + } + + my $entry = Zip64EndCentralHeaderEntry->new(); + + if ($remaining) + { + # Handle 'zip64 extensible data sector' here + # See APPNOTE 6.3.10, section 4.3.14.3, 4.3.14.4 & APPENDIX C + # Not seen a real example of this. Tested with hand crafted files. + walkExtra($remaining, $entry); + } + + return {}; +} + + +sub Zip64EndCentralLocator +{ + # APPNOTE 6.3.10, sec 4.3.15 + + my $signature = shift ; + my $data = shift ; + my $startRecordOffset = shift ; + + print "\n"; + out $data, "ZIP64 END CENTRAL DIR LOCATOR", Value_V($signature); + + need 16, Signatures::name($signature); + + # my ($nextRecord, $deltaActuallyAvailable) = $HeaderOffsetIndex->checkForOverlap(16); + + # if ($deltaActuallyAvailable) + # { + # fatal_truncated_record( + # sprintf("ZIP64 END CENTRAL DIR LOCATOR \@%X truncated", $FH->tell() - 4), + # sprintf("Need 0x%X bytes, have 0x%X available", 16, $deltaActuallyAvailable), + # sprintf("Next Record is %s \@0x%X", $nextRecord->name(), $nextRecord->offset()) + # ) + # } + + # TODO - check values for traces of multi-part + crazy offsets + out_V "Central Dir Disk no"; + + my ($d, $zip64EndCentralDirOffset) = read_Q(); + my $out = Value_Q($zip64EndCentralDirOffset); + testPossiblePrefix($zip64EndCentralDirOffset, ZIP64_END_CENTRAL_REC_HDR_SIG); + + $out .= " [Actual Offset is " . Value_Q($zip64EndCentralDirOffset + $PREFIX_DELTA) . "]" + if $PREFIX_DELTA ; + out $d, "Offset to Zip64 EOCD", $out; + + my $totalDisks = out_V "Total no of Disks"; + + if ($totalDisks > 0) + { + my $commonMessage = "'Offset to Zip64 End of Central Directory Record' field in '" . Signatures::name($signature) . "' is invalid"; + $zip64EndCentralDirOffset = checkOffsetValue($zip64EndCentralDirOffset, $startRecordOffset, 0, $commonMessage, $FH->tell() - 12, ZIP64_END_CENTRAL_REC_HDR_SIG) ; + } + + return {}; +} + +sub needZip64EOCDLocator +{ + # zip64 end of central directory field needed if any of the fields + # in the End Central Header record are maxed out + + my $diskNumber = shift ; + my $cdDiskNumber = shift ; + my $entriesOnThisDisk = shift ; + my $totalEntries = shift ; + my $centralDirSize = shift ; + my $centralDirOffset = shift ; + + return (full16($diskNumber) || # 4.4.19 + full16($cdDiskNumber) || # 4.4.20 + full16($entriesOnThisDisk) || # 4.4.21 + full16($totalEntries) || # 4.4.22 + full32($centralDirSize) || # 4.4.23 + full32($centralDirOffset) # 4.4.24 + ) ; +} + +sub emptyArchive +{ + my $offset = shift; + my $diskNumber = shift ; + my $cdDiskNumber = shift ; + my $entriesOnThisDisk = shift ; + my $totalEntries = shift ; + my $centralDirSize = shift ; + my $centralDirOffset = shift ; + + return (#$offset == 0 && + $diskNumber == 0 && + $cdDiskNumber == 0 && + $entriesOnThisDisk == 0 && + $totalEntries == 0 && + $centralDirSize == 0 && + $centralDirOffset== 0 + ) ; +} + +sub EndCentralHeader +{ + # APPNOTE 6.3.10, sec 4.3.16 + + my $signature = shift ; + my $data = shift ; + my $startRecordOffset = shift ; + + print "\n"; + out $data, "END CENTRAL HEADER", Value_V($signature); + + need 18, Signatures::name($signature); + + # TODO - check values for traces of multi-part + crazy values + my $diskNumber = out_v "Number of this disk"; + my $cdDiskNumber = out_v "Central Dir Disk no"; + my $entriesOnThisDisk = out_v "Entries in this disk"; + my $totalEntries = out_v "Total Entries"; + my $centralDirSize = out_V "Size of Central Dir"; + + my ($d, $centralDirOffset) = read_V(); + my $out = Value_V($centralDirOffset); + testPossiblePrefix($centralDirOffset, ZIP_CENTRAL_HDR_SIG); + + $out .= " [Actual Offset is " . Value_V($centralDirOffset + $PREFIX_DELTA) . "]" + if $PREFIX_DELTA && $centralDirOffset != MAX32 ; + out $d, "Offset to Central Dir", $out; + + my $comment_length = out_v "Comment Length"; + + if ($comment_length) + { + my $here = $FH->tell() ; + my $available = $FILELEN - $here ; + if ($available < $comment_length) + { + error $here, + "file truncated while reading 'Comment' field in '" . Signatures::name($signature) . "'", + expectedMessage($comment_length, $available); + $comment_length = $available; + } + + if ($comment_length) + { + my $comment ; + myRead($comment, $comment_length); + outputFilename $comment, 0, "Comment"; + } + } + + if ( ! Nesting::isNested($startRecordOffset, $FH->tell() -1)) + { + # Not nested + if (! needZip64EOCDLocator($diskNumber, $cdDiskNumber, $entriesOnThisDisk, $totalEntries, $centralDirSize, $centralDirOffset) && + ! emptyArchive($startRecordOffset, $diskNumber, $cdDiskNumber, $entriesOnThisDisk, $totalEntries, $centralDirSize, $centralDirOffset)) + { + my $commonMessage = "'Offset to Central Directory' field in '" . Signatures::name($signature) . "' is invalid"; + $centralDirOffset = checkOffsetValue($centralDirOffset, $startRecordOffset, $centralDirSize, $commonMessage, $startRecordOffset + 16, ZIP_CENTRAL_HDR_SIG) ; + } + } + # else do nothing + + return {}; +} + +sub DataDescriptor +{ + + # Data header record or Spanned archive marker. + # + + # ZIP_DATA_HDR_SIG at start of file flags a spanned zip file. + # If it is a true marker, the next four bytes MUST be a ZIP_LOCAL_HDR_SIG + # See APPNOTE 6.3.10, sec 8.5.3, 8.5.4 & 8.5.5 + + # If not at start of file, assume a Data Header Record + # See APPNOTE 6.3.10, sec 4.3.9 & 4.3.9.3 + + my $signature = shift ; + my $data = shift ; + my $startRecordOffset = shift ; + + my $here = $FH->tell(); + + if ($here == 4) + { + # Spanned Archive Marker + out $data, "SPLIT ARCHIVE MULTI-SEGMENT MARKER", Value_V($signature); + return; + + # my (undef, $next_sig) = read_V(); + # seekTo(0); + + # if ($next_sig == ZIP_LOCAL_HDR_SIG) + # { + # print "\n"; + # out $data, "SPLIT ARCHIVE MULTI-SEGMENT MARKER", Value_V($signature); + # seekTo($here); + # return; + # } + } + + my $sigName = Signatures::titleName(ZIP_DATA_HDR_SIG); + + print "\n"; + out $data, $sigName, Value_V($signature); + + need 24, Signatures::name($signature); + + # Ignore header payload if nested (assume 64-bit descriptor) + if (Nesting::isNested( $here - 4, $here - 4 + 24 - 1)) + { + out "", "Skipping Nested Payload"; + return {}; + } + + my $compressedSize; + my $uncompressedSize; + + my $localEntry = $LocalDirectory->lastStreamedEntryAdded(); + my $centralEntry = $localEntry && $localEntry->getCdEntry ; + + if (!$localEntry) + { + # found a Data Descriptor without a local header + out "", "Skipping Data Descriptor", "No matching Local header with streaming bit set"; + error $here - 4, "Orphan '$sigName' found", "No matching Local header with streaming bit set"; + return {}; + } + + my $crc = out_V "CRC"; + my $payloadLength = $here - 4 - $localEntry->payloadOffset; + + my $deltaToNext = deltaToNextSignature(); + my $cl32 = unpack "V", peekAtOffset($here + 4, 4); + my $cl64 = unpack "Q<", peekAtOffset($here + 4, 8); + + # use delta to next header & payload length + # deals with use case where the payload length < 32 bit + # will use a 32-bit value rather than the 64-bit value + + # see if delta & payload size match + if ($deltaToNext == 16 && $cl64 == $payloadLength) + { + if (! $localEntry->zip64 && ($centralEntry && ! $centralEntry->zip64)) + { + error $here, "'$sigName': expected 32-bit values, got 64-bit"; + } + + $compressedSize = out_Q "Compressed Size" ; + $uncompressedSize = out_Q "Uncompressed Size" ; + } + elsif ($deltaToNext == 8 && $cl32 == $payloadLength) + { + if ($localEntry->zip64) + { + error $here, "'$sigName': expected 64-bit values, got 32-bit"; + } + + $compressedSize = out_V "Compressed Size" ; + $uncompressedSize = out_V "Uncompressed Size" ; + } + + # Try matching juast payload lengths + elsif ($cl32 == $payloadLength) + { + if ($localEntry->zip64) + { + error $here, "'$sigName': expected 64-bit values, got 32-bit"; + } + + $compressedSize = out_V "Compressed Size" ; + $uncompressedSize = out_V "Uncompressed Size" ; + + warning $here, "'$sigName': Zip Header not directly after Data Descriptor"; + } + elsif ($cl64 == $payloadLength) + { + if (! $localEntry->zip64 && ($centralEntry && ! $centralEntry->zip64)) + { + error $here, "'$sigName': expected 32-bit values, got 64-bit"; + } + + $compressedSize = out_Q "Compressed Size" ; + $uncompressedSize = out_Q "Uncompressed Size" ; + + warning $here, "'$sigName': Zip Header not directly after Data Descriptor"; + } + + # payloads don't match, so try delta + elsif ($deltaToNext == 16) + { + if (! $localEntry->zip64 && ($centralEntry && ! $centralEntry->zip64)) + { + error $here, "'$sigName': expected 32-bit values, got 64-bit"; + } + + $compressedSize = out_Q "Compressed Size" ; + # compressed size is wrong + error $here, "'$sigName': Compressed size" . decimalHex0x($compressedSize) . " doesn't match with payload size " . decimalHex0x($payloadLength); + + $uncompressedSize = out_Q "Uncompressed Size" ; + } + elsif ($deltaToNext == 8 ) + { + if ($localEntry->zip64) + { + error $here, "'$sigName': expected 64-bit values, got 32-bit"; + } + + $compressedSize = out_V "Compressed Size" ; + # compressed size is wrong + error $here, "'$sigName': Compressed Size " . decimalHex0x($compressedSize) . " doesn't match with payload size " . decimalHex0x($payloadLength); + + $uncompressedSize = out_V "Uncompressed Size" ; + } + + # no payoad or delta match at all, so likely a false positive or data corruption + else + { + warning $here, "Cannot determine size of Data Descriptor record"; + } + + # TODO - neither payload size or delta to next signature match + + if ($localEntry) + { + $localEntry->readDataDescriptor(1) ; + $localEntry->crc32($crc) ; + $localEntry->compressedSize($compressedSize) ; + $localEntry->uncompressedSize($uncompressedSize) ; + } + + # APPNOTE 6.3.10, sec 4.3.8 + my $filename = $localEntry->filename; + warning undef, "Directory '$filename' must not have a payload" + if $filename =~ m#/$# && $uncompressedSize ; + + return { + crc => $crc, + compressedSize => $compressedSize, + uncompressedSize => $uncompressedSize, + }; +} + +sub SingleSegmentMarker +{ + # ZIP_SINGLE_SEGMENT_MARKER at start of file flags a spanned zip file. + # If this ia a true marker, the next four bytes MUST be a ZIP_LOCAL_HDR_SIG + # See APPNOTE 6.3.10, sec 8.5.3, 8.5.4 & 8.5.5 + + my $signature = shift ; + my $data = shift ; + my $startRecordOffset = shift ; + + my $here = $FH->tell(); + + if ($here == 4) + { + my (undef, $next_sig) = read_V(); + if ($next_sig == ZIP_LOCAL_HDR_SIG) + { + print "\n"; + out $data, "SPLIT ARCHIVE SINGLE-SEGMENT MARKER", Value_V($signature); + } + seekTo($here); + } + + return {}; +} + +sub ArchiveExtraDataRecord +{ + # TODO - not seen an example of this record + + # APPNOTE 6.3.10, sec 4.3.11 + + my $signature = shift ; + my $data = shift ; + my $startRecordOffset = shift ; + + out $data, "ARCHIVE EXTRA DATA RECORD", Value_V($signature); + + need 2, Signatures::name($signature); + + my $size = out_v "Size of record"; + + need $size, Signatures::name($signature); + + outHexdump($size, "Field data", 1); + + return {}; +} + +sub DigitalSignature +{ + my $signature = shift ; + my $data = shift ; + my $startRecordOffset = shift ; + + print "\n"; + out $data, "DIGITAL SIGNATURE RECORD", Value_V($signature); + + need 2, Signatures::name($signature); + my $Size = out_v "Size of record"; + + need $Size, Signatures::name($signature); + + + myRead(my $payload, $Size); + out $payload, "Signature", hexDump16($payload); + + return {}; +} + +sub GeneralPurposeBits +{ + my $method = shift; + my $gp = shift; + + out1 "[Bit 0]", "1 'Encryption'" if $gp & ZIP_GP_FLAG_ENCRYPTED_MASK; + + my %lookup = ( + 0 => "Normal Compression", + 1 => "Maximum Compression", + 2 => "Fast Compression", + 3 => "Super Fast Compression"); + + + if ($method == ZIP_CM_DEFLATE) + { + my $mid = ($gp >> 1) & 0x03 ; + + out1 "[Bits 1-2]", "$mid '$lookup{$mid}'"; + } + + if ($method == ZIP_CM_LZMA) + { + if ($gp & ZIP_GP_FLAG_LZMA_EOS_PRESENT) { + out1 "[Bit 1]", "1 'LZMA EOS Marker Present'" ; + } + else { + out1 "[Bit 1]", "0 'LZMA EOS Marker Not Present'" ; + } + } + + if ($method == ZIP_CM_IMPLODE) # Imploding + { + out1 "[Bit 1]", ($gp & (1 << 1) ? "1 '8k" : "0 '4k") . " Sliding Dictionary'" ; + out1 "[Bit 2]", ($gp & (2 << 1) ? "1 '3" : "0 '2" ) . " Shannon-Fano Trees'" ; + } + + out1 "[Bit 3]", "1 'Streamed'" if $gp & ZIP_GP_FLAG_STREAMING_MASK; + out1 "[Bit 4]", "1 'Enhanced Deflating'" if $gp & 1 << 4; + out1 "[Bit 5]", "1 'Compressed Patched'" if $gp & ZIP_GP_FLAG_PATCHED_MASK ; + out1 "[Bit 6]", "1 'Strong Encryption'" if $gp & ZIP_GP_FLAG_STRONG_ENCRYPTED_MASK; + out1 "[Bit 11]", "1 'Language Encoding'" if $gp & ZIP_GP_FLAG_LANGUAGE_ENCODING; + out1 "[Bit 12]", "1 'Pkware Enhanced Compression'" if $gp & ZIP_GP_FLAG_PKWARE_ENHANCED_COMP ; + out1 "[Bit 13]", "1 'Encrypted Central Dir'" if $gp & ZIP_GP_FLAG_ENCRYPTED_CD ; + + return (); +} + + +sub seekSet +{ + my $fh = $_[0] ; + my $size = $_[1]; + + use Fcntl qw(SEEK_SET); + seek($fh, $size, SEEK_SET); + +} + +sub skip +{ + my $fh = $_[0] ; + my $size = $_[1]; + + use Fcntl qw(SEEK_CUR); + seek($fh, $size, SEEK_CUR); + +} + + +sub myRead +{ + my $got = \$_[0] ; + my $size = $_[1]; + + my $wantSize = $size; + $$got = ''; + + if ($size == 0) + { + return ; + } + + if ($size > 0) + { + my $buff ; + my $status = $FH->read($buff, $size); + return $status + if $status < 0; + $$got .= $buff ; + } + + my $len = length $$got; + # fatal undef, "Truncated file (got $len, wanted $wantSize): $!" + fatal undef, "Unexpected zip file truncation", + expectedMessage($wantSize, $len) + if length $$got != $wantSize; +} + +sub expectedMessage +{ + my $expected = shift; + my $got = shift; + return "Expected " . decimalHex0x($expected) . " bytes, but only " . decimalHex0x($got) . " available" +} + +sub need +{ + my $byteCount = shift ; + my $message = shift ; + my $field = shift // ''; + + # return $FILELEN - $FH->tell() >= $byteCount; + my $here = $FH->tell() ; + my $available = $FILELEN - $here ; + if ($available < $byteCount) + { + my @message ; + + if ($field) + { + push @message, "Unexpected zip file truncation while reading '$field' field in '$message'"; + } + else + { + push @message, "Unexpected zip file truncation while reading '$message'"; + } + + + push @message, expectedMessage($byteCount, $available); + # push @message, sprintf("Expected 0x%X bytes, but only 0x%X available", $byteCount, $available); + push @message, "Try running with --walk' or '--scan' options" + if ! $opt_scan && ! $opt_walk ; + + fatal $here, @message; + } +} + +sub testPossiblePrefix +{ + my $offset = shift; + my $expectedSignature = shift ; + + if (testPossiblePrefixNoPREFIX_DELTA($offset, $expectedSignature)) + { + $PREFIX_DELTA = $POSSIBLE_PREFIX_DELTA; + $POSSIBLE_PREFIX_DELTA = 0; + + reportPrefixData(); + + return 1 + } + + return 0 +} + +sub testPossiblePrefixNoPREFIX_DELTA +{ + my $offset = shift; + my $expectedSignature = shift ; + + return 0 + if $offset + 4 > $FILELEN || ! $POSSIBLE_PREFIX_DELTA || $PREFIX_DELTA; + + my $currentOFFSET = $OFFSET; + my $gotSig = readSignatureFromOffset($offset); + + if ($gotSig == $expectedSignature) + { + # do have possible prefix data, but the offset is correct + $POSSIBLE_PREFIX_DELTA = $PREFIX_DELTA = 0; + $OFFSET = $currentOFFSET; + + return 0; + } + + $gotSig = readSignatureFromOffset($offset + $POSSIBLE_PREFIX_DELTA); + + $OFFSET = $currentOFFSET; + + return ($gotSig == $expectedSignature) ; +} + +sub offsetIsValid +{ + my $offset = shift; + my $headerStart = shift; + my $centralDirSize = shift; + my $commonMessage = shift ; + my $expectedSignature = shift ; + my $dereferencePointer = shift; + + my $must_point_back = 1; + + my $delta = $offset - $FILELEN + 1 ; + + $offset += $PREFIX_DELTA + if $PREFIX_DELTA ; + + return sprintf("value %s is %s bytes past EOF", decimalHex0x($offset), decimalHex0x($delta)) + if $delta > 0 ; + + return sprintf "value %s must be less that %s", decimalHex0x($offset), decimalHex0x($headerStart) + if $must_point_back && $offset >= $headerStart; + + if ($dereferencePointer) + { + my $actual = $headerStart - $centralDirSize; + my $cdSizeOK = ($actual == $offset); + my $possibleDelta = $actual - $offset; + + if ($centralDirSize && ! $cdSizeOK && $possibleDelta > 0 && readSignatureFromOffset($possibleDelta) == ZIP_LOCAL_HDR_SIG) + { + # If testing end of central dir, check if the location of the first CD header + # is consistent with the central dir size. + # Common use case is a SFX zip file + + my $gotSig = readSignatureFromOffset($actual); + my $v = hexValue32($gotSig); + return 'value @ ' . hexValue($actual) . " should decode to signature for " . Signatures::nameAndHex($expectedSignature) . ". Got $v" # . hexValue32($gotSig) + if $gotSig != $expectedSignature ; + + $PREFIX_DELTA = $possibleDelta; + reportPrefixData(); + + return undef; + } + else + { + my $gotSig = readSignatureFromOffset($offset); + my $v = hexValue32($gotSig); + return 'value @ ' . hexValue($offset) . " should decode to signature for " . Signatures::nameAndHex($expectedSignature) . ". Got $v" # . hexValue32($gotSig) + if $gotSig != $expectedSignature ; + } + } + + return undef ; +} + +sub checkOffsetValue +{ + my $offset = shift; + my $headerStart = shift; + my $centralDirSize = shift; + my $commonMessage = shift ; + my $messageOffset = shift; + my $expectedSignature = shift ; + my $fatal = shift // 0; + my $dereferencePointer = shift // 1; + + my $keepOFFSET = $OFFSET ; + + my $message = offsetIsValid($offset, $headerStart, $centralDirSize, $commonMessage, $expectedSignature, $dereferencePointer); + if ($message) + { + fatal_tryWalk($messageOffset, $commonMessage, $message) + if $fatal; + + error $messageOffset, $commonMessage, $message + if ! $fatal; + } + + $OFFSET = $keepOFFSET; + + return $offset + $PREFIX_DELTA; + +} + +sub fatal_tryWalk +{ + my $offset = shift ; + my $message = shift; + + fatal($offset, $message, @_, "Try running with --walk' or '--scan' options"); +} + +sub fatal +{ + my $offset = shift ; + my $message = shift; + + return if $fatalDisabled; + + if (defined $offset) + { + warn "#\n# FATAL: Offset " . hexValue($offset) . ": $message\n"; + } + else + { + warn "#\n# FATAL: $message\n"; + } + + warn "# $_ . \n" + for @_; + warn "#\n" ; + + exit 1; +} + +sub disableFatal +{ + $fatalDisabled = 1 ; +} + +sub enableFatal +{ + $fatalDisabled = 0 ; +} + +sub topLevelFatal +{ + my $message = shift ; + + no warnings 'utf8'; + + warn "FATAL: $message\n"; + + warn "$_ . \n" + for @_; + + exit 1; +} + +sub internalFatal +{ + my $offset = shift ; + my $message = shift; + + no warnings 'utf8'; + + if (defined $offset) + { + warn "# FATAL: Offset " . hexValue($offset) . ": Internal Error: $message\n"; + } + else + { + warn "# FATAL: Internal Error: $message\n"; + } + + warn "# $_ \n" + for @_; + + warn "# Please report error at https://github.com/pmqs/zipdetails/issues\n"; + exit 1; +} + +sub warning +{ + my $offset = shift ; + my $message = shift; + + no warnings 'utf8'; + + return + unless $opt_want_warning_mesages ; + + say "#" + unless $lastWasMessage ++ ; + + if (defined $offset) + { + say "# WARNING: Offset " . hexValue($offset) . ": $message"; + } + else + { + say "# WARNING: $message"; + } + + + say "# $_" for @_ ; + say "#"; + ++ $WarningCount ; + + $exit_status_code |= 2 + if $opt_want_message_exit_status ; +} + +sub error +{ + my $offset = shift ; + my $message = shift; + + no warnings 'utf8'; + + return + unless $opt_want_error_mesages ; + + say "#" + unless $lastWasMessage ++ ; + + if (defined $offset) + { + say "# ERROR: Offset " . hexValue($offset) . ": $message"; + } + else + { + say "# ERROR: $message"; + } + + + say "# $_" for @_ ; + say "#"; + + ++ $ErrorCount ; + + $exit_status_code |= 4 + if $opt_want_message_exit_status ; +} + +sub debug +{ + my $offset = shift ; + my $message = shift; + + no warnings 'utf8'; + + say "#" + unless $lastWasMessage ++ ; + + if (defined $offset) + { + say "# DEBUG: Offset " . hexValue($offset) . ": $message"; + } + else + { + say "# DEBUG: $message"; + } + + + say "# $_" for @_ ; + say "#"; +} + +sub internalError +{ + my $message = shift; + + no warnings 'utf8'; + + say "#"; + say "# ERROR: $message"; + say "# $_" for @_ ; + say "# Please report error at https://github.com/pmqs/zipdetails/issues"; + say "#"; + + ++ $ErrorCount ; +} + +sub reportPrefixData +{ + my $delta = shift // $PREFIX_DELTA ; + state $reported = 0; + return if $reported || $delta == 0; + + info 0, "found " . decimalHex0x($delta) . " bytes before beginning of zipfile" ; + $reported = 1; +} + +sub info +{ + my $offset = shift; + my $message = shift; + + no warnings 'utf8'; + + return + unless $opt_want_info_mesages ; + + say "#" + unless $lastWasMessage ++ ; + + if (defined $offset) + { + say "# INFO: Offset " . hexValue($offset) . ": $message"; + } + else + { + say "# INFO: $message"; + } + + say "# $_" for @_ ; + say "#"; + + ++ $InfoCount ; + + $exit_status_code |= 1 + if $opt_want_message_exit_status ; +} + +sub walkExtra +{ + # APPNOTE 6.3.10, sec 4.4.11, 4.4.28, 4.5 + my $XLEN = shift; + my $entry = shift; + + # Caller has determined that there are $XLEN bytes available to read + + my $buff ; + my $offset = 0 ; + + my $id; + my $subLen; + my $payload ; + + my $count = 0 ; + my $endExtraOffset = $FH->tell() + $XLEN ; + + while ($offset < $XLEN) { + + ++ $count; + + # Detect if there is not enough data for an extra ID and length. + # Android zipalign and zipflinger are prime candidates for these + # non-standard extra sub-fields. + my $remaining = $XLEN - $offset; + if ($remaining < ZIP_EXTRA_SUBFIELD_HEADER_SIZE) { + # There is not enough left. + # Consume whatever is there and return so parsing + # can continue. + + myRead($payload, $remaining); + my $data = hexDump($payload); + + if ($payload =~ /^\x00+$/) + { + # All nulls + out $payload, "Null Padding in Extra"; + info $FH->tell() - length($payload), decimalHex0x(length $payload) . " Null Padding Bytes in Extra Field" ; + } + else + { + out $payload, "Extra Data", $data; + error $FH->tell() - length($payload), "'Extra Data' Malformed"; + } + + return undef; + } + + myRead($id, ZIP_EXTRA_SUBFIELD_ID_SIZE); + $offset += ZIP_EXTRA_SUBFIELD_ID_SIZE; + my $lookID = unpack "v", $id ; + if ($lookID == 0) + { + # check for null padding at end of extra + my $here = $FH->tell(); + my $rest; + myRead($rest, $XLEN - $offset); + if ($rest =~ /^\x00+$/) + { + my $len = length ($id . $rest) ; + out $id . $rest, "Null Padding in Extra"; + info $FH->tell() - $len, decimalHex0x($len) . " Null Padding Bytes in Extra Field"; + return undef; + } + + seekTo($here); + } + + my ($who, $decoder, $local_min, $local_max, $central_min, $central_max) = @{ $Extras{$lookID} // ['', undef, undef, undef, undef, undef ] }; + + my $idString = Value_v($lookID) ; + $idString .= " '$who'" + if $who; + + out $id, "Extra ID #$count", $idString ; + info $FH->tell() - 2, "Unknown Extra ID $idString" + if ! exists $Extras{$lookID} ; + + myRead($buff, ZIP_EXTRA_SUBFIELD_LEN_SIZE); + $offset += ZIP_EXTRA_SUBFIELD_LEN_SIZE; + + $subLen = unpack("v", $buff); + out2 $buff, "Length", Value_v($subLen) ; + + $remaining = $XLEN - $offset; + if ($subLen > $remaining ) + { + error $FH->tell() -2, + extraFieldIdentifier($lookID) . ": 'Length' field invalid", + sprintf("value %s > %s bytes remaining", decimalHex0x($subLen), decimalHex0x($remaining)); + outSomeData $remaining, " Extra Payload"; + return undef; + } + + if (! defined $decoder) + { + if ($subLen) + { + myRead($payload, $subLen); + my $data = hexDump16($payload); + + out2 $payload, "Extra Payload", $data; + } + } + else + { + if (testExtraLimits($lookID, $subLen, $entry->inCentralDir)) + { + my $endExtraOffset = $FH->tell() + $subLen; + $decoder->($lookID, $subLen, $entry) ; + + # Belt & Braces - should now be at $endExtraOffset + # error here means issue in an extra handler + # should noy happen, but just in case + # TODO -- need tests for this + my $here = $FH->tell() ; + if ($here > $endExtraOffset) + { + # gone too far, so need to bomb out now + internalFatal $here, "Overflow processing " . extraFieldIdentifier($lookID) . ".", + sprintf("Should be at offset %s, actually at %s", decimalHex0x($endExtraOffset), decimalHex0x($here)); + } + elsif ($here < $endExtraOffset) + { + # not gone far enough, can recover + error $here, + sprintf("Expected to be at offset %s after processing %s, actually at %s", decimalHex0x($endExtraOffset), extraFieldIdentifier($lookID), decimalHex0x($here)), + "Skipping " . decimalHex0x($endExtraOffset - $here) . " bytes"; + outSomeData $endExtraOffset - $here, " Extra Data"; + } + } + } + + $offset += $subLen ; + } + + return undef ; +} + +sub testExtraLimits +{ + my $lookID = shift; + my $size = shift; + my $inCentralDir = shift; + + my ($who, undef, $local_min, $local_max, $central_min, $central_max) = @{ $Extras{$lookID} // ['', undef, undef, undef, undef, undef ] }; + + my ($min, $max) = $inCentralDir + ? ($central_min, $central_max) + : ($local_min, $local_max) ; + + return 1 + if ! defined $min && ! defined $max ; + + if (defined $min && defined $max) + { + # both the same + if ($min == $max) + { + if ($size != $min) + { + error $FH->tell() -2, sprintf "%s: 'Length' field invalid: expected %s, got %s", extraFieldIdentifier($lookID), decimalHex0x($min), decimalHex0x($size); + outSomeData $size, " Extra Payload" if $size; + return 0; + } + } + else # min != max + { + if ($size < $min || $size > $max) + { + error $FH->tell() -2, sprintf "%s: 'Length' field invalid: value must be betweem %s and %s, got %s", extraFieldIdentifier($lookID), decimalHex0x($min), decimalHex0x($max), decimalHex0x($size); + outSomeData $size, " Extra Payload" if $size ; + return 0; + } + } + + } + else # must be defined $min & undefined max + { + if ($size < $min) + { + error $FH->tell() -2, sprintf "%s: 'Length' field invalid: value must be at least %s, got %s", extraFieldIdentifier($lookID), decimalHex0x($min), decimalHex0x($size); + outSomeData $size, " Extra Payload" if $size; + return 0; + } + } + + return 1; + +} + +sub full32 +{ + return ($_[0] // 0) == MAX32 ; +} + +sub full16 +{ + return ($_[0] // 0) == MAX16 ; +} + +sub decode_Zip64 +{ + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + myRead(my $payload, $len); + if ($entry->inCentralDir() ) + { + walk_Zip64_in_CD($extraID, $payload, $entry, 1) ; + } + else + { + walk_Zip64_in_LD($extraID, $payload, $entry, 1) ; + + } +} + +sub walk_Zip64_in_LD +{ + my $extraID = shift ; + my $zip64Extended = shift; + my $entry = shift; + my $display = shift // 1 ; + + my $fieldStart = $FH->tell() - length $zip64Extended; + my $fieldOffset = $fieldStart ; + + $ZIP64 = 1; + $entry->zip64(1); + + if (length $zip64Extended == 0) + { + info $fieldOffset, extraFieldIdentifier($extraID) . ": Length is Zero"; + return; + } + + my $assumeLengthsPresent = (length($zip64Extended) == 16) ; + my $assumeAllFieldsPresent = (length($zip64Extended) == 28) ; + + if ($assumeLengthsPresent || $assumeAllFieldsPresent || full32 $entry->std_uncompressedSize ) + { + # TODO defer a warning if in local header & central/local don't have std_uncompressedSizeset to 0xffffffff + if (length $zip64Extended < 8) + { + my $message = extraFieldIdentifier($extraID) . ": Expected " . decimalHex0x(8) . " bytes for 'Uncompressed Size': only " . decimalHex0x(length $zip64Extended) . " bytes present"; + error $fieldOffset, $message; + out2 $zip64Extended, $message; + return; + } + + $fieldOffset += 8; + my $data = substr($zip64Extended, 0, 8, "") ; + $entry->uncompressedSize(unpack "Q<", $data); + out2 $data, "Uncompressed Size", Value_Q($entry->uncompressedSize) + if $display; + } + + if ($assumeLengthsPresent || $assumeAllFieldsPresent || full32 $entry->std_compressedSize) + { + if (length $zip64Extended < 8) + { + my $message = extraFieldIdentifier($extraID) . ": Expected " . decimalHex0x(8) . " bytes for 'Compressed Size': only " . decimalHex0x(length $zip64Extended) . " bytes present"; + error $fieldOffset, $message; + out2 $zip64Extended, $message; + return; + } + + $fieldOffset += 8; + + my $data = substr($zip64Extended, 0, 8, "") ; + $entry->compressedSize( unpack "Q<", $data); + out2 $data, "Compressed Size", Value_Q($entry->compressedSize) + if $display; + } + + # Zip64 in local header should not have localHeaderOffset or disk number + # but some zip files do + + if ($assumeAllFieldsPresent) + { + $fieldOffset += 8; + + my $data = substr($zip64Extended, 0, 8, "") ; + my $localHeaderOffset = unpack "Q<", $data; + out2 $data, "Offset to Local Dir", Value_Q($localHeaderOffset) + if $display; + } + + if ($assumeAllFieldsPresent) + { + $fieldOffset += 4; + + my $data = substr($zip64Extended, 0, 4, "") ; + my $diskNumber = unpack "v", $data; + out2 $data, "Disk Number", Value_V($diskNumber) + if $display; + } + + if (length $zip64Extended) + { + if ($display) + { + out2 $zip64Extended, "Unexpected Data", hexDump16 $zip64Extended ; + info $fieldOffset, extraFieldIdentifier($extraID) . ": Unexpected Data: " . decimalHex0x(length $zip64Extended) . " bytes"; + } + } + +} + +sub walk_Zip64_in_CD +{ + my $extraID = shift ; + my $zip64Extended = shift; + my $entry = shift; + my $display = shift // 1 ; + + my $fieldStart = $FH->tell() - length $zip64Extended; + my $fieldOffset = $fieldStart ; + + $ZIP64 = 1; + $entry->zip64(1); + + if (length $zip64Extended == 0) + { + info $fieldOffset, extraFieldIdentifier($extraID) . ": Length is Zero"; + return; + } + + my $assumeAllFieldsPresent = (length($zip64Extended) == 28) ; + + if ($assumeAllFieldsPresent || full32 $entry->std_uncompressedSize ) + { + if (length $zip64Extended < 8) + { + my $message = extraFieldIdentifier($extraID) . ": Expected " . decimalHex0x(8) . " bytes for 'Uncompressed Size': only " . decimalHex0x(length $zip64Extended) . " bytes present"; + error $fieldOffset, $message; + out2 $zip64Extended, $message; + return; + } + + $fieldOffset += 8; + my $data = substr($zip64Extended, 0, 8, "") ; + $entry->uncompressedSize(unpack "Q<", $data); + out2 $data, "Uncompressed Size", Value_Q($entry->uncompressedSize) + if $display; + } + + if ($assumeAllFieldsPresent || full32 $entry->std_compressedSize) + { + if (length $zip64Extended < 8) + { + my $message = extraFieldIdentifier($extraID) . ": Expected " . decimalHex0x(8) . " bytes for 'Compressed Size': only " . decimalHex0x(length $zip64Extended) . " bytes present"; + error $fieldOffset, $message; + out2 $zip64Extended, $message; + return; + } + + $fieldOffset += 8; + + my $data = substr($zip64Extended, 0, 8, "") ; + $entry->compressedSize(unpack "Q<", $data); + out2 $data, "Compressed Size", Value_Q($entry->compressedSize) + if $display; + } + + if ($assumeAllFieldsPresent || full32 $entry->std_localHeaderOffset) + { + if (length $zip64Extended < 8) + { + my $message = extraFieldIdentifier($extraID) . ": Expected " . decimalHex0x(8) . " bytes for 'Offset to Local Dir': only " . decimalHex0x(length $zip64Extended) . " bytes present"; + error $fieldOffset, $message; + out2 $zip64Extended, $message; + return; + } + + $fieldOffset += 8; + + my $here = $FH->tell(); + my $data = substr($zip64Extended, 0, 8, "") ; + $entry->localHeaderOffset(unpack "Q<", $data); + out2 $data, "Offset to Local Dir", Value_Q($entry->localHeaderOffset) + if $display; + + my $commonMessage = "'Offset to Local Dir' field in 'Zip64 Extra Field' is invalid"; + $entry->localHeaderOffset(checkOffsetValue($entry->localHeaderOffset, $fieldStart, 0, $commonMessage, $fieldStart, ZIP_LOCAL_HDR_SIG, 0) ); + } + + if ($assumeAllFieldsPresent || full16 $entry->std_diskNumber) + { + if (length $zip64Extended < 4) + { + my $message = extraFieldIdentifier($extraID) . ": Expected " . decimalHex0x(4) . " bytes for 'Disk Number': only " . decimalHex0x(length $zip64Extended) . " bytes present"; + error $fieldOffset, $message; + out2 $zip64Extended, $message; + return; + } + + $fieldOffset += 4; + + my $here = $FH->tell(); + my $data = substr($zip64Extended, 0, 4, "") ; + $entry->diskNumber(unpack "v", $data); + out2 $data, "Disk Number", Value_V($entry->diskNumber) + if $display; + $entry->zip64_diskNumberPresent(1); + } + + if (length $zip64Extended) + { + if ($display) + { + out2 $zip64Extended, "Unexpected Data", hexDump16 $zip64Extended ; + info $fieldOffset, extraFieldIdentifier($extraID) . ": Unexpected Data: " . decimalHex0x(length $zip64Extended) . " bytes"; + } + } +} + +sub Ntfs2Unix +{ + my $m = shift; + my $v = shift; + + # NTFS offset is 19DB1DED53E8000 + + my $hex = Value_Q($v) ; + + # Treat empty value as special case + # Could decode to 1 Jan 1601 + return "$hex 'No Date/Time'" + if $v == 0; + + $v -= 0x19DB1DED53E8000 ; + my $ns = ($v % 10000000) * 100; + my $elapse = int ($v/10000000); + return "$hex '" . getT($elapse) . + " " . sprintf("%0dns'", $ns); +} + +sub decode_NTFS_Filetimes +{ + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + out_V " Reserved"; + out_v " Tag1"; + out_v " Size1" ; + + my ($m, $s1) = read_Q; + out $m, " Mtime", Ntfs2Unix($m, $s1); + + my ($a, $s3) = read_Q; + out $a, " Atime", Ntfs2Unix($a, $s3); + + my ($c, $s2) = read_Q; + out $c, " Ctime", Ntfs2Unix($c, $s2); +} + +sub OpenVMS_DateTime +{ + my $ix = shift; + my $tag = shift; + my $size = shift; + + # VMS epoch is 17 Nov 1858 + # Offset to Unix Epoch is -0x7C95674C3DA5C0 (-35067168005400000) + + my ($data, $value) = read_Q(); + + my $datetime = "No Date Time'"; + if ($value != 0) + { + my $v = $value - 0x007C95674C3DA5C0 ; + my $ns = ($v % 10000000) * 100 ; + my $seconds = int($v / 10000000) ; + $datetime = getT($seconds) . + " " . sprintf("%0dns'", $ns); + } + + out2 $data, " Attribute", Value_Q($value) . " '$datetime"; +} + +sub OpenVMS_DumpBytes +{ + my $ix = shift; + my $tag = shift; + my $size = shift; + + myRead(my $data, $size); + + out($data, " Attribute", hexDump16($data)); + +} + +sub OpenVMS_4ByteValue +{ + my $ix = shift; + my $tag = shift; + my $size = shift; + + my ($data, $value) = read_V(); + + out2 $data, " Attribute", Value_V($value); +} + +sub OpenVMS_UCHAR +{ + my $ix = shift; + my $tag = shift; + my $size = shift; + + state $FCH = { + 0 => 'FCH$M_WASCONTIG', + 1 => 'FCH$M_NOBACKUP', + 2 => 'FCH$M_WRITEBACK', + 3 => 'FCH$M_READCHECK', + 4 => 'FCH$M_WRITCHECK', + 5 => 'FCH$M_CONTIGB', + 6 => 'FCH$M_LOCKED', + 6 => 'FCH$M_CONTIG', + 11 => 'FCH$M_BADACL', + 12 => 'FCH$M_SPOOL', + 13 => 'FCH$M_DIRECTORY', + 14 => 'FCH$M_BADBLOCK', + 15 => 'FCH$M_MARKDEL', + 16 => 'FCH$M_NOCHARGE', + 17 => 'FCH$M_ERASE', + 18 => 'FCH$M_SHELVED', + 20 => 'FCH$M_SCRATCH', + 21 => 'FCH$M_NOMOVE', + 22 => 'FCH$M_NOSHELVABLE', + } ; + + my ($data, $value) = read_V(); + + out2 $data, " Attribute", Value_V($value); + + for my $bit ( sort { $a <=> $b } keys %{ $FCH } ) + { + # print "$bit\n"; + if ($value & (1 << $bit) ) + { + out1 " [Bit $bit]", $FCH->{$bit} ; + } + } +} + +sub OpenVMS_2ByteValue +{ + my $ix = shift; + my $tag = shift; + my $size = shift; + + my ($data, $value) = read_v(); + + out2 $data, " Attribute", Value_v($value); +} + +sub OpenVMS_revision +{ + my $ix = shift; + my $tag = shift; + my $size = shift; + + my ($data, $value) = read_v(); + + out2 $data, " Attribute", Value_v($value) . "'Revision Count " . Value_v($value) . "'"; +} + +sub decode_OpenVMS +{ + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + state $openVMS_tags = { + 0x04 => [ 'ATR$C_RECATTR', \&OpenVMS_DumpBytes ], + 0x03 => [ 'ATR$C_UCHAR', \&OpenVMS_UCHAR ], + 0x11 => [ 'ATR$C_CREDATE', \&OpenVMS_DateTime ], + 0x12 => [ 'ATR$C_REVDATE', \&OpenVMS_DateTime ], + 0x13 => [ 'ATR$C_EXPDATE', \&OpenVMS_DateTime ], + 0x14 => [ 'ATR$C_BAKDATE', \&OpenVMS_DateTime ], + 0x0D => [ 'ATR$C_ASCDATES', \&OpenVMS_revision ], + 0x15 => [ 'ATR$C_UIC', \&OpenVMS_4ByteValue ], + 0x16 => [ 'ATR$C_FPRO', \&OpenVMS_DumpBytes ], + 0x17 => [ 'ATR$C_RPRO', \&OpenVMS_2ByteValue ], + 0x1D => [ 'ATR$C_JOURNAL', \&OpenVMS_DumpBytes ], + 0x1F => [ 'ATR$C_ADDACLENT', \&OpenVMS_DumpBytes ], + } ; + + out_V " CRC"; + $len -= 4; + + my $ix = 1; + while ($len) + { + my ($data, $tag) = read_v(); + my $tagname = 'Unknown Tag'; + my $decoder = undef; + + if ($openVMS_tags->{$tag}) + { + ($tagname, $decoder) = @{ $openVMS_tags->{$tag} } ; + } + + out2 $data, "Tag #$ix", Value_v($tag) . " '" . $tagname . "'" ; + my $size = out_v " Size"; + + if (defined $decoder) + { + $decoder->($ix, $tag, $size) ; + } + else + { + outSomeData($size, " Attribute"); + } + + ++ $ix; + $len -= $size + 2 + 2; + } + +} + +sub getT +{ + my $time = shift ; + + if ($opt_utc) + { return scalar gmtime($time) // 'Unknown'} + else + { return scalar localtime($time) // 'Unknown' } +} + +sub getTime +{ + my $time = shift ; + + return "'Invalid Date or Time'" + if ! defined $time; + + return "'" . getT($time) . "'"; +} + +sub LastModTime +{ + my $value = shift ; + + return "'No Date/Time'" + if $value == 0; + + return getTime(_dosToUnixTime($value)) +} + +sub _dosToUnixTime +{ + my $dt = shift; + + # Mozilla xpi files have empty datetime + # This is not a valid Dos datetime value + return 0 if $dt == 0 ; + + my $year = ( ( $dt >> 25 ) & 0x7f ) + 80; + my $mon = ( ( $dt >> 21 ) & 0x0f ) - 1; + my $mday = ( ( $dt >> 16 ) & 0x1f ); + + my $hour = ( ( $dt >> 11 ) & 0x1f ); + my $min = ( ( $dt >> 5 ) & 0x3f ); + my $sec = ( ( $dt << 1 ) & 0x3e ); + + use Time::Local ; + my $time_t; + eval + { + # Use eval to catch crazy dates + $time_t = Time::Local::timegm( $sec, $min, $hour, $mday, $mon, $year); + } + or do + { + my $dosDecode = $year+1900 . sprintf "-%02u-%02u %02u:%02u:%02u", $mon, $mday, $hour, $min, $sec; + warning $FH->tell(), "'Modification Time' value " . decimalHex0x($dt, 4) . " decodes to '$dosDecode': not a valid DOS date/time" ; + return undef + }; + + return $time_t; + +} + +sub decode_UT +{ + # 0x5455 'UT: Extended Timestamp' + + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + # Definition in IZ APPNOTE + + # NOTE: Although the IZ appnote says that the central directory + # doesn't store the Acces & Creation times, there are + # some implementations that do poopulate the CD incorrectly. + + # Caller has determined that at least one byte is available + + # When $full is true assume all timestamps are present + my $full = ($len == 13) ; + + my $remaining = $len; + + my ($data, $flags) = read_C(); + + my $v = Value_C $flags; + my @f ; + push @f, "Modification" if $flags & 1; + push @f, "Access" if $flags & 2; + push @f, "Creation" if $flags & 4; + $v .= " '" . join(' ', @f) . "'" + if @f; + + out $data, " Flags", $v; + + info $FH->tell() - 1, extraFieldIdentifier($extraID) . ": Reserved bits set in 'Flags' field" + if $flags & ~0x7; + + -- $remaining; + + if ($flags & 1 || $full) + { + if ($remaining == 0 ) + { + # Central Dir only has Modification Time + error $FH->tell(), extraFieldIdentifier($extraID) . ": Missing field 'Modification Time'" ; + return; + } + else + { + info $FH->tell(), extraFieldIdentifier($extraID) . ": Unexpected 'Modification Time' present" + if ! ($flags & 1) ; + + if ($remaining < 4) + { + outSomeData $remaining, " Extra Data"; + error $FH->tell() - $remaining, + extraFieldIdentifier($extraID) . ": Truncated reading 'Modification Time'", + expectedMessage(4, $remaining); + return; + } + + my ($data, $time) = read_V(); + + out2 $data, "Modification Time", Value_V($time) . " " . getTime($time) ; + + $remaining -= 4 ; + } + } + + # The remaining sub-fields are only present in the Local Header + + if ($flags & 2 || $full) + { + if ($remaining == 0 && $entry->inCentralDir) + { + # Central Dir doesn't have access time + } + else + { + info $FH->tell(), extraFieldIdentifier($extraID) . ": Unexpected 'Access Time' present" + if ! ($flags & 2) || $entry->inCentralDir ; + + if ($remaining < 4) + { + outSomeData $remaining, " Extra Data"; + error $FH->tell() - $remaining, + extraFieldIdentifier($extraID) . ": Truncated reading 'Access Time'" , + expectedMessage(4, $remaining); + + return; + } + + my ($data, $time) = read_V(); + + out2 $data, "Access Time", Value_V($time) . " " . getTime($time) ; + $remaining -= 4 ; + } + } + + if ($flags & 4 || $full) + { + if ($remaining == 0 && $entry->inCentralDir) + { + # Central Dir doesn't have creation time + } + else + { + info $FH->tell(), extraFieldIdentifier($extraID) . ": Unexpected 'Creation Time' present" + if ! ($flags & 4) || $entry->inCentralDir ; + + if ($remaining < 4) + { + outSomeData $remaining, " Extra Data"; + + error $FH->tell() - $remaining, + extraFieldIdentifier($extraID) . ": Truncated reading 'Creation Time'" , + expectedMessage(4, $remaining); + + return; + } + + my ($data, $time) = read_V(); + + out2 $data, "Creation Time", Value_V($time) . " " . getTime($time) ; + } + } +} + + +sub decode_Minizip_Signature +{ + # 0x10c5 Minizip CMS Signature + + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + # Definition in https://github.com/zlib-ng/minizip-ng/blob/master/doc/mz_extrafield.md#cms-signature-0x10c5 + + $CentralDirectory->setMiniZipEncrypted(); + + if ($len == 0) + { + info $FH->tell() - 2, extraFieldIdentifier($extraID) . ": Zero length Signature"; + return; + } + + outHexdump($len, " Signature"); + +} + +sub decode_Minizip_Hash +{ + # 0x1a51 Minizip Hash + # Definition in https://github.com/zlib-ng/minizip-ng/blob/master/doc/mz_extrafield.md#hash-0x1a51 + + # caller ckecks there are at least 4 bytes available + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + state $Algorithm = { + 10 => 'MD5', + 20 => 'SHA1', + 23 => 'SHA256', + }; + + my $remaining = $len; + + $CentralDirectory->setMiniZipEncrypted(); + + my ($data, $alg) = read_v(); + my $algorithm = $Algorithm->{$alg} // "Unknown"; + + out $data, " Algorithm", Value_v($alg) . " '$algorithm'"; + if (! exists $Algorithm->{$alg}) + { + info $FH->tell() - 2, extraFieldIdentifier($extraID) . ": Unknown algorithm ID " .Value_v($alg); + } + + my ($d, $digestSize) = read_v(); + out $d, " Digest Size", Value_v($digestSize); + + $remaining -= 4; + + if ($digestSize == 0) + { + info $FH->tell() - 2, extraFieldIdentifier($extraID) . ": Zero length Digest"; + } + elsif ($digestSize > $remaining) + { + error $FH->tell() - 2, extraFieldIdentifier($extraID) . ": Digest Size " . decimalHex0x($digestSize) . " > " . decimalHex0x($remaining) . " bytes remaining in extra field" ; + $digestSize = $remaining ; + } + + outHexdump($digestSize, " Digest"); + + $remaining -= $digestSize; + + if ($remaining) + { + outHexdump($remaining, " Unexpected Data"); + error $FH->tell() - $remaining, extraFieldIdentifier($extraID) . ": " . decimalHex0x($remaining) . " unexpected trailing bytes" ; + } +} + +sub decode_Minizip_CD +{ + # 0xcdcd Minizip Central Directory + # Definition in https://github.com/zlib-ng/minizip-ng/blob/master/doc/mz_extrafield.md#central-directory-0xcdcd + + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + $entry->minizip_secure(1); + $CentralDirectory->setMiniZipEncrypted(); + + my $size = out_Q " Entries"; + + } + +sub decode_AES +{ + # ref https://www.winzip.com/en/support/aes-encryption/ + # Document version: 1.04 + # Last modified: January 30, 2009 + + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + return if $len == 0 ; + + my $validAES = 1; + + state $lookup = { 1 => "AE-1", 2 => "AE-2" }; + my $vendorVersion = out_v " Vendor Version", sub { $lookup->{$_[0]} || "Unknown" } ; + if (! $lookup->{$vendorVersion}) + { + $validAES = 0; + warning $FH->tell() - 2, extraFieldIdentifier($extraID) . ": Unknown 'Vendor Version' $vendorVersion. Valid values are 1,2" + } + + my $id ; + myRead($id, 2); + my $idValue = out $id, " Vendor ID", unpackValue_v($id) . " '$id'"; + + if ($id ne 'AE') + { + $validAES = 0; + warning $FH->tell() - 2, extraFieldIdentifier($extraID) . ": Unknown 'Vendor ID' '$idValue'. Valid value is 'AE'" + } + + state $strengths = {1 => "128-bit encryption key", + 2 => "192-bit encryption key", + 3 => "256-bit encryption key", + }; + + my $strength = out_C " Encryption Strength", sub {$strengths->{$_[0]} || "Unknown" } ; + + if (! $strengths->{$strength}) + { + $validAES = 0; + warning $FH->tell() - 1, extraFieldIdentifier($extraID) . ": Unknown 'Encryption Strength' $strength. Valid values are 1,2,3" + } + + my ($bmethod, $method) = read_v(); + out $bmethod, " Compression Method", compressionMethod($method) ; + if (! defined $ZIP_CompressionMethods{$method}) + { + $validAES = 0; + warning $FH->tell() - 2, extraFieldIdentifier($extraID) . ": Unknown 'Compression Method' ID " . decimalHex0x($method, 2) + } + + $entry->aesStrength($strength) ; + $entry->aesValid($validAES) ; +} + +sub decode_Reference +{ + # ref https://www.winzip.com/en/support/compression-methods/ + + my $len = shift; + my $entry = shift; + + out_V " CRC"; + myRead(my $uuid, 16); + # UUID is big endian + out2 $uuid, "UUID", + unpack('H*', substr($uuid, 0, 4)) . '-' . + unpack('H*', substr($uuid, 4, 2)) . '-' . + unpack('H*', substr($uuid, 6, 2)) . '-' . + unpack('H*', substr($uuid, 8, 2)) . '-' . + unpack('H*', substr($uuid, 10, 6)) ; +} + +sub decode_DUMMY +{ + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + out_V " Data"; +} + +sub decode_GrowthHint +{ + # APPNOTE 6.3.10, sec 4.6.10 + + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + # caller has checked that 4 bytes are available, + # so can output values without checking available space + out_v " Signature" ; + out_v " Initial Value"; + + my $padding; + myRead($padding, $len - 4); + + out2 $padding, "Padding", hexDump16($padding); + + if ($padding !~ /^\x00+$/) + { + info $FH->tell(), extraFieldIdentifier($extraID) . ": 'Padding' is not all NULL bytes"; + } +} + +sub decode_DataStreamAlignment +{ + # APPNOTE 6.3.10, sec 4.6.11 + + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + my $inCentralHdr = $entry->inCentralDir ; + + return if $len == 0 ; + + my ($data, $alignment) = read_v(); + + out $data, " Alignment", Value_v($alignment) ; + + my $recompress_value = $alignment & 0x8000 ? 1 : 0; + + my $recompressing = $recompress_value ? "True" : "False"; + $alignment &= 0x7FFF ; + my $hexAl = sprintf("%X", $alignment); + + out1 " [Bit 15]", "$recompress_value 'Recompress $recompressing'"; + out1 " [Bits 0-14]", "$hexAl 'Minimal Alignment $alignment'"; + + if (! $inCentralHdr && $len - 2 > 0) + { + my $padding; + myRead($padding, $len - 2); + + out2 $padding, "Padding", hexDump16($padding); + } +} + + +sub decode_UX +{ + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + my $inCentralHdr = $entry->inCentralDir ; + + return if $len == 0 ; + + my ($data, $time) = read_V(); + out2 $data, "Access Time", Value_V($time) . " " . getTime($time) ; + + ($data, $time) = read_V(); + out2 $data, "Modification Time", Value_V($time) . " " . getTime($time) ; + + if (! $inCentralHdr ) { + out_v " UID" ; + out_v " GID"; + } +} + +sub decode_Ux +{ + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + return if $len == 0 ; + out_v " UID" ; + out_v " GID"; +} + +sub decodeLitteEndian +{ + my $value = shift ; + + if (length $value == 8) + { + return unpackValueQ ($value) + } + elsif (length $value == 4) + { + return unpackValue_V ($value) + } + elsif (length $value == 2) + { + return unpackValue_v ($value) + } + elsif (length $value == 1) + { + return unpackValue_C ($value) + } + else { + # TODO - fix this + internalFatal undef, "unsupported decodeLitteEndian length '" . length ($value) . "'"; + } +} + +sub decode_ux +{ + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + # caller has checked that 3 bytes are available + + return if $len == 0 ; + + my $version = out_C " Version" ; + info $FH->tell() - 1, extraFieldIdentifier($extraID) . ": 'Version' should be " . decimalHex0x(1) . ", got " . decimalHex0x($version, 1) + if $version != 1 ; + + my $available = $len - 1 ; + + my $uidSize = out_C " UID Size"; + $available -= 1; + + if ($uidSize) + { + if ($available < $uidSize) + { + outSomeData($available, " Bad Extra Data"); + error $FH->tell() - $available, + extraFieldIdentifier($extraID) . ": truncated reading 'UID'", + expectedMessage($uidSize, $available); + return; + } + + myRead(my $data, $uidSize); + out2 $data, "UID", decodeLitteEndian($data); + $available -= $uidSize ; + } + + if ($available < 1) + { + error $FH->tell(), + extraFieldIdentifier($extraID) . ": truncated reading 'GID Size'", + expectedMessage($uidSize, $available); + return ; + } + + my $gidSize = out_C " GID Size"; + $available -= 1 ; + if ($gidSize) + { + if ($available < $gidSize) + { + outSomeData($available, " Bad Extra Data"); + error $FH->tell() - $available, + extraFieldIdentifier($extraID) . ": truncated reading 'GID'", + expectedMessage($gidSize, $available); + return; + } + + myRead(my $data, $gidSize); + out2 $data, "GID", decodeLitteEndian($data); + $available -= $gidSize ; + } + +} + +sub decode_Java_exe +{ + my $extraID = shift ; + my $len = shift; + my $entry = shift; + +} + +sub decode_up +{ + # APPNOTE 6.3.10, sec 4.6.9 + + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + out_C " Version"; + out_V " NameCRC32"; + + if ($len - 5 > 0) + { + myRead(my $data, $len - 5); + + outputFilename($data, 1, " UnicodeName"); + } +} + +sub decode_ASi_Unix +{ + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + # https://stackoverflow.com/questions/76581811/why-does-unzip-ignore-my-zip64-end-of-central-directory-record + + out_V " CRC"; + my $native_attrib = out_v " Mode"; + + # TODO - move to separate sub & tidy + if (1) # Unix + { + + state $mask = { + 0 => '---', + 1 => '--x', + 2 => '-w-', + 3 => '-wx', + 4 => 'r--', + 5 => 'r-x', + 6 => 'rw-', + 7 => 'rwx', + } ; + + my $rwx = ($native_attrib & 0777); + + if ($rwx) + { + my $output = ''; + $output .= $mask->{ ($rwx >> 6) & 07 } ; + $output .= $mask->{ ($rwx >> 3) & 07 } ; + $output .= $mask->{ ($rwx >> 0) & 07 } ; + + out1 " [Bits 0-8]", Value_v($rwx) . " 'Unix attrib: $output'" ; + out1 " [Bit 9]", "1 'Sticky'" + if $rwx & 0x200 ; + out1 " [Bit 10]", "1 'Set GID'" + if $rwx & 0x400 ; + out1 " [Bit 11]", "1 'Set UID'" + if $rwx & 0x800 ; + + my $not_rwx = (($native_attrib >> 12) & 0xF); + if ($not_rwx) + { + state $masks = { + 0x0C => 'Socket', # 0x0C 0b1100 + 0x0A => 'Symbolic Link', # 0x0A 0b1010 + 0x08 => 'Regular File', # 0x08 0b1000 + 0x06 => 'Block Device', # 0x06 0b0110 + 0x04 => 'Directory', # 0x04 0b0100 + 0x02 => 'Character Device', # 0x02 0b0010 + 0x01 => 'FIFO', # 0x01 0b0001 + }; + + my $got = $masks->{$not_rwx} // 'Unknown Unix attrib' ; + out1 " [Bits 12-15]", Value_C($not_rwx) . " '$got'" + } + } + } + + + my $s = out_V " SizDev"; + out_v " UID"; + out_v " GID"; + +} + +sub decode_uc +{ + # APPNOTE 6.3.10, sec 4.6.8 + + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + out_C " Version"; + out_V " ComCRC32"; + + if ($len - 5 > 0) + { + myRead(my $data, $len - 5); + + outputFilename($data, 1, " UnicodeCom"); + } +} + +sub decode_Xceed_unicode +{ + # 0x554e + + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + my $data ; + my $remaining = $len; + + # No public definition available, so reverse engineer the content. + + # See https://github.com/pmqs/zipdetails/issues/13 for C# source that populates + # this field. + + # Fiddler https://www.telerik.com/fiddler) creates this field. + + # Local Header only has UTF16LE filename + # + # Field definition + # 4 bytes Signature always XCUN + # 2 bytes Filename Length (divided by 2) + # Filename + + # Central has UTF16LE filename & comment + # + # Field definition + # 4 bytes Signature always XCUN + # 2 bytes Filename Length (divided by 2) + # 2 bytes Comment Length (divided by 2) + # Filename + # Comment + + # First 4 bytes appear to be little-endian "XCUN" all the time + # Just double check + my ($idb, $id) = read_V(); + $remaining -= 4; + + my $outid = decimalHex0x($id); + $outid .= " 'XCUN'" + if $idb eq 'NUCX'; + + out $idb, " ID", $outid; + + # Next 2 bytes contains a count of the filename length divided by 2 + # Dividing by 2 gives the number of UTF-16 characters. + my $filenameLength = out_v " Filename Length"; + $filenameLength *= 2; # Double to get number of bytes to read + $remaining -= 2; + + my $commentLength = 0; + + if ($entry->inCentralDir) + { + # Comment length only in Central Directory + # Again stored divided by 2. + $commentLength = out_v " Comment Length"; + $commentLength *= 2; # Double to get number of bytes to read + $remaining -= 2; + } + + # next is a UTF16 encoded filename + + if ($filenameLength) + { + if ($filenameLength > $remaining ) + { + myRead($data, $remaining); + out redactData($data), " UTF16LE Filename", "'" . redactFilename(decode("UTF16LE", $data)) . "'"; + + error $FH->tell() - $remaining, + extraFieldIdentifier($extraID) . ": Truncated reading 'UTF16LE Filename'", + expectedMessage($filenameLength, $remaining); + return undef; + } + + myRead($data, $filenameLength); + out redactData($data), " UTF16LE Filename", "'" . redactFilename(decode("UTF16LE", $data)) . "'"; + $remaining -= $filenameLength; + } + + # next is a UTF16 encoded comment + + if ($commentLength) + { + if ($commentLength > $remaining ) + { + myRead($data, $remaining); + out redactData($data), " UTF16LE Comment", "'" . redactFilename(decode("UTF16LE", $data)) . "'"; + + error $FH->tell() - $remaining, + extraFieldIdentifier($extraID) . ": Truncated reading 'UTF16LE Comment'", + expectedMessage($filenameLength, $remaining); + return undef; + } + + myRead($data, $commentLength); + out redactData($data), " UTF16LE Comment", "'" . redactFilename(decode("UTF16LE", $data)) . "'"; + $remaining -= $commentLength; + } + + if ($remaining) + { + outHexdump($remaining, " Unexpected Data"); + error $FH->tell() - $remaining, extraFieldIdentifier($extraID) . ": " . decimalHex0x($remaining) . " unexpected trailing bytes" ; + } +} + +sub decode_Key_Value_Pair +{ + # 0x564B 'KV' + # https://github.com/sozip/keyvaluepairs-spec/blob/master/zip_keyvalue_extra_field_specification.md + + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + my $remaining = $len; + + myRead(my $signature, 13); + $remaining -= 13; + + if ($signature ne 'KeyValuePairs') + { + error $FH->tell() - 13, extraFieldIdentifier($extraID) . ": 'Signature' field not 'KeyValuePairs'" ; + myRead(my $payload, $remaining); + my $data = hexDump16($signature . $payload); + + out2 $signature . $payload, "Extra Payload", $data; + + return ; + } + + out $signature, ' Signature', "'KeyValuePairs'"; + my $kvPairs = out_C " KV Count"; + $remaining -= 1; + + for my $index (1 .. $kvPairs) + { + my $key; + my $klen = out_v " Key size #$index"; + $remaining -= 4; + + myRead($key, $klen); + outputFilename $key, 1, " Key #$index"; + $remaining -= $klen; + + my $value; + my $vlen = out_v " Value size #$index"; + $remaining -= 4; + + myRead($value, $vlen); + outputFilename $value, 1, " Value #$index"; + $remaining -= $vlen; + } + + # TODO check that + # * count of kv pairs is accurate + # * no truncation in middle of kv data + # * no trailing data +} + +sub decode_NT_security +{ + # IZ Appnote + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + my $inCentralHdr = $entry->inCentralDir ; + + out_V " Uncompressed Size" ; + + if (! $inCentralHdr) { + + out_C " Version" ; + + out_v " CType", sub { "'" . ($ZIP_CompressionMethods{$_[0]} || "Unknown Method") . "'" }; + + out_V " CRC" ; + + my $plen = $len - 4 - 1 - 2 - 4; + outHexdump $plen, " Extra Payload"; + } +} + +sub decode_MVS +{ + # APPNOTE 6.3.10, Appendix + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + # data in Big-Endian + myRead(my $data, $len); + my $ID = unpack("N", $data); + + if ($ID == 0xE9F3F9F0) # EBCDIC for "Z390" + { + my $d = substr($data, 0, 4, '') ; + out($d, " ID", "'Z390'"); + } + + out($data, " Extra Payload", hexDump16($data)); +} + +sub decode_strong_encryption +{ + # APPNOTE 6.3.10, sec 4.5.12 & 7.4.2 + + my $extraID = shift ; + my $len = shift; + my $entry = shift; + + # TODO check for overflow is contents > $len + out_v " Format"; + out_v " AlgId", sub { $AlgIdLookup{ $_[0] } // "Unknown algorithm" } ; + out_v " BitLen"; + out_v " Flags", sub { $FlagsLookup{ $_[0] } // "reserved for certificate processing" } ; + + # see APPNOTE 6.3.10, sec 7.4.2 for this part + my $recipients = out_V " Recipients"; + + my $available = $len - 12; + + if ($recipients) + { + if ($available < 2) + { + outSomeData($available, " Badly formed extra data"); + # TODO - need warning + return; + } + + out_v " HashAlg", sub { $HashAlgLookup{ $_[0] } // "Unknown algorithm" } ; + $available -= 2; + + if ($available < 2) + { + outSomeData($available, " Badly formed extra data"); + # TODO - need warning + return; + } + + my $HSize = out_v " HSize" ; + $available -= 2; + + # should have $recipients * $HSize bytes available + if ($recipients * $HSize != $available) + { + outSomeData($available, " Badly formed extra data"); + # TODO - need warning + return; + } + + my $ix = 1; + for (0 .. $recipients-1) + { + myRead(my $payload, $HSize); + my $data = hexDump16($payload); + + out2 $payload, sprintf("Key #%X", $ix), $data; + ++ $ix; + } + } +} + + +sub printAes +{ + # ref https://www.winzip.com/en/support/aes-encryption/ + + my $entry = shift; + + return 0 + if ! $entry->aesValid; + + my %saltSize = ( + 1 => 8, + 2 => 12, + 3 => 16, + ); + + myRead(my $salt, $saltSize{$entry->aesStrength } // 0); + out $salt, "AES Salt", hexDump16($salt); + myRead(my $pwv, 2); + out $pwv, "AES Pwd Ver", hexDump16($pwv); + + return $saltSize{$entry->aesStrength} + 2 + 10; +} + +sub printLzmaProperties +{ + my $len = 0; + + my $b1; + my $b2; + my $buffer; + + myRead($b1, 2); + my ($verHi, $verLow) = unpack ("CC", $b1); + + out $b1, "LZMA Version", sprintf("%02X%02X", $verHi, $verLow) . " '$verHi.$verLow'"; + my $LzmaPropertiesSize = out_v "LZMA Properties Size"; + $len += 4; + + my $LzmaInfo = out_C "LZMA Info", sub { $_[0] == 93 ? "(Default)" : ""}; + + my $PosStateBits = 0; + my $LiteralPosStateBits = 0; + my $LiteralContextBits = 0; + $PosStateBits = int($LzmaInfo / (9 * 5)); + $LzmaInfo -= $PosStateBits * 9 * 5; + $LiteralPosStateBits = int($LzmaInfo / 9); + $LiteralContextBits = $LzmaInfo - $LiteralPosStateBits * 9; + + out1 " PosStateBits", $PosStateBits; + out1 " LiteralPosStateBits", $LiteralPosStateBits; + out1 " LiteralContextBits", $LiteralContextBits; + + out_V "LZMA Dictionary Size"; + + # TODO - assumption that this is 5 + $len += $LzmaPropertiesSize; + + skip($FH, $LzmaPropertiesSize - 5) + if $LzmaPropertiesSize != 5 ; + + return $len; +} + +sub peekAtOffset +{ + # my $fh = shift; + my $offset = shift; + my $len = shift; + + my $here = $FH->tell(); + + seekTo($offset) ; + + my $buffer; + myRead($buffer, $len); + seekTo($here); + + length $buffer == $len + or return ''; + + return $buffer; +} + +sub readFromOffset +{ + # my $fh = shift; + my $offset = shift; + my $len = shift; + + seekTo($offset) ; + + my $buffer; + myRead($buffer, $len); + + length $buffer == $len + or return ''; + + return $buffer; +} + +sub readSignatureFromOffset +{ + my $offset = shift ; + + # catch use case where attempting to read past EOF + # sub is expecting to return a 32-bit value so return 54-bit out-of-bound value + return MAX64 + if $offset + 4 > $FILELEN ; + + my $here = $FH->tell(); + my $buffer = readFromOffset($offset, 4); + my $gotSig = unpack("V", $buffer) ; + seekTo($here); + + return $gotSig; +} + + +sub chckForAPKSigningBlock +{ + my $fh = shift; + my $cdOffset = shift; + my $cdSize = shift; + + # APK Signing Block comes directy before the Central directory + # See https://source.android.com/security/apksigning/v2 + + # If offset available is less than 44, it isn't an APK signing block + # + # len1 8 + # id 4 + # kv with zero len 8 + # len1 8 + # magic 16 + # ---------- + # 44 + + return (0, 0, '') + if $cdOffset < 44 || $FILELEN - $cdSize < 44 ; + + # Step 1 - 16 bytes before CD is literal string "APK Sig Block 42" + my $magicOffset = $cdOffset - 16; + my $buffer = readFromOffset($magicOffset, 16); + + return (0, 0, '') + if $buffer ne "APK Sig Block 42" ; + + # Step 2 - read the second length field + # and check that it looks ok + $buffer = readFromOffset($cdOffset - 16 - 8, 8); + my $len2 = unpack("Q<", $buffer); + + return (0, 0, '') + if $len2 == 0 || $len2 > $FILELEN; + + # Step 3 - read the first length field. + # It should be identical to the second one. + + my $startApkOffset = $cdOffset - 8 - $len2 ; + + $buffer = readFromOffset($startApkOffset, 8); + my $len1 = unpack("Q<", $buffer); + + return (0, 0, '') + if $len1 != $len2; + + return ($startApkOffset, $cdOffset - 16 - 8, $buffer); +} + +sub scanApkBlock +{ + state $IDs = { + 0x7109871a => "APK Signature v2", + 0xf05368c0 => "APK Signature v3", + 0x42726577 => "Verity Padding Block", # from https://android.googlesource.com/platform/tools/apksig/+/master/src/main/java/com/android/apksig/internal/apk/ApkSigningBlockUtils.java + 0x6dff800d => "Source Stamp", + 0x504b4453 => "Dependency Info", + 0x71777777 => "APK Channel Block", + 0xff3b5998 => "Zero Block", + 0x2146444e => "Play Metadata", + } ; + + + seekTo($FH->tell() - 4) ; + print "\n"; + out "", "APK SIGNING BLOCK"; + + scanApkPadding(); + out_Q "Block Length Copy #1"; + my $ix = 1; + + while ($FH->tell() < $APK - 8) + { + my ($bytes, $id, $len); + ($bytes, $len) = read_Q ; + out $bytes, "ID/Value Length #" . sprintf("%X", $ix), Value_Q($len); + + ($bytes, $id) = read_V; + + out $bytes, " ID", Value_V($id) . " '" . ($IDs->{$id} // 'Unknown ID') . "'"; + + outSomeData($len-4, " Value"); + ++ $ix; + } + + out_Q "Block Length Copy #2"; + + my $magic ; + myRead($magic, 16); + + out $magic, "Magic", qq['$magic']; +} + +sub scanApkPadding +{ + my $here = $FH->tell(); + + return + if $here == $START_APK; + + # found some padding + + my $delta = $START_APK - $here; + my $padding = peekAtOffset($here, $delta); + + if ($padding =~ /^\x00+$/) + { + outSomeData($delta, "Null Padding"); + } + else + { + outHexdump($delta, "Unexpected Padding"); + } +} + +sub scanCentralDirectory +{ + my $fh = shift; + + my $here = $fh->tell(); + + # Use cases + # 1 32-bit CD + # 2 64-bit CD + + my ($offset, $size) = findCentralDirectoryOffset($fh); + $CentralDirectory->{CentralDirectoryOffset} = $offset; + $CentralDirectory->{CentralDirectorySize} = $size; + + return () + if ! defined $offset; + + $fh->seek($offset, SEEK_SET) ; + + # Now walk the Central Directory Records + my $buffer ; + my $cdIndex = 0; + my $cdEntryOffset = 0; + + while ($fh->read($buffer, ZIP_CD_FILENAME_OFFSET) == ZIP_CD_FILENAME_OFFSET && + unpack("V", $buffer) == ZIP_CENTRAL_HDR_SIG) { + + my $startHeader = $fh->tell() - ZIP_CD_FILENAME_OFFSET; + + my $cdEntryOffset = $fh->tell() - ZIP_CD_FILENAME_OFFSET; + $HeaderOffsetIndex->addOffsetNoPrefix($cdEntryOffset, ZIP_CENTRAL_HDR_SIG) ; + + ++ $cdIndex ; + + my $extractVer = unpack("v", substr($buffer, 6, 1)); + my $gpFlag = unpack("v", substr($buffer, 8, 2)); + my $lastMod = unpack("V", substr($buffer, 10, 4)); + my $crc = unpack("V", substr($buffer, 16, 4)); + my $compressedSize = unpack("V", substr($buffer, 20, 4)); + my $uncompressedSize = unpack("V", substr($buffer, 24, 4)); + my $filename_length = unpack("v", substr($buffer, 28, 2)); + my $extra_length = unpack("v", substr($buffer, 30, 2)); + my $comment_length = unpack("v", substr($buffer, 32, 2)); + my $diskNumber = unpack("v", substr($buffer, 34, 2)); + my $locHeaderOffset = unpack("V", substr($buffer, 42, 4)); + + my $cdZip64 = 0; + my $zip64Sizes = 0; + + if (! full32 $locHeaderOffset) + { + # Check for corrupt offset + # 1. ponting paset EOF + # 2. offset points forward in the file + # 3. value at offset is not a CD record signature + + my $commonMessage = "'Local Header Offset' field in '" . Signatures::name(ZIP_CENTRAL_HDR_SIG) . "' is invalid"; + checkOffsetValue($locHeaderOffset, $startHeader, 0, $commonMessage, + $startHeader + CentralDirectoryEntry::Offset_RelativeOffsetToLocal(), + ZIP_LOCAL_HDR_SIG, 1) ; + } + + $fh->read(my $filename, $filename_length) ; + + my $cdEntry = CentralDirectoryEntry->new(); + + $cdEntry->centralHeaderOffset($startHeader) ; + $cdEntry->localHeaderOffset($locHeaderOffset) ; + $cdEntry->compressedSize($compressedSize) ; + $cdEntry->uncompressedSize($uncompressedSize) ; + $cdEntry->extractVersion($extractVer); + $cdEntry->generalPurposeFlags($gpFlag); + $cdEntry->filename($filename) ; + $cdEntry->lastModDateTime($lastMod); + $cdEntry->languageEncodingFlag($gpFlag & ZIP_GP_FLAG_LANGUAGE_ENCODING) ; + $cdEntry->diskNumber($diskNumber) ; + $cdEntry->crc32($crc) ; + $cdEntry->zip64ExtraPresent($cdZip64) ; + + $cdEntry->std_localHeaderOffset($locHeaderOffset) ; + $cdEntry->std_compressedSize($compressedSize) ; + $cdEntry->std_uncompressedSize($uncompressedSize) ; + $cdEntry->std_diskNumber($diskNumber) ; + + + if ($extra_length) + { + $fh->read(my $extraField, $extra_length) ; + + # Check for Zip64 + my $zip64Extended = findID(0x0001, $extraField); + + if ($zip64Extended) + { + $cdZip64 = 1; + walk_Zip64_in_CD(1, $zip64Extended, $cdEntry, 0); + } + } + + $cdEntry->offsetStart($startHeader) ; + $cdEntry->offsetEnd($FH->tell() - 1); + + # don't call addEntry until after the extra fields have been scanned + # the localheader offset value may be updated in th ezip64 extra field. + $CentralDirectory->addEntry($cdEntry); + $HeaderOffsetIndex->addOffset($cdEntry->localHeaderOffset, ZIP_LOCAL_HDR_SIG) ; + + skip($fh, $comment_length ) ; + } + + $FH->seek($fh->tell() - ZIP_CD_FILENAME_OFFSET, SEEK_SET); + + # Check for Digital Signature + $HeaderOffsetIndex->addOffset($fh->tell() - 4, ZIP_DIGITAL_SIGNATURE_SIG) + if $fh->read($buffer, 4) == 4 && + unpack("V", $buffer) == ZIP_DIGITAL_SIGNATURE_SIG ; + + $CentralDirectory->sortByLocalOffset(); + $HeaderOffsetIndex->sortOffsets(); + + $fh->seek($here, SEEK_SET) ; + +} + +use constant ZIP64_END_CENTRAL_LOC_HDR_SIZE => 20; +use constant ZIP64_END_CENTRAL_REC_HDR_MIN_SIZE => 56; + +sub offsetFromZip64 +{ + my $fh = shift ; + my $here = shift; + my $eocdSize = shift; + + #### Zip64 end of central directory locator + + # check enough bytes available for zip64 locator record + fatal_tryWalk undef, "Cannot find signature for " . Signatures::nameAndHex(ZIP64_END_CENTRAL_LOC_HDR_SIG), # 'Zip64 end of central directory locator': 0x07064b50" + "Possible truncated or corrupt zip file" + if $here < ZIP64_END_CENTRAL_LOC_HDR_SIZE ; + + $fh->seek($here - ZIP64_END_CENTRAL_LOC_HDR_SIZE, SEEK_SET) ; + $here = $FH->tell(); + + my $buffer; + my $got = 0; + $fh->read($buffer, ZIP64_END_CENTRAL_LOC_HDR_SIZE); + + my $gotSig = unpack("V", $buffer); + fatal_tryWalk $here - 4, sprintf("Expected signature for " . Signatures::nameAndHex(ZIP64_END_CENTRAL_LOC_HDR_SIG) . " not found, got 0x%X", $gotSig) + if $gotSig != ZIP64_END_CENTRAL_LOC_HDR_SIG ; + + $HeaderOffsetIndex->addOffset($fh->tell() - ZIP64_END_CENTRAL_LOC_HDR_SIZE, ZIP64_END_CENTRAL_LOC_HDR_SIG) ; + + + my $cd64 = unpack "Q<", substr($buffer, 8, 8); + my $totalDisks = unpack "V", substr($buffer, 16, 4); + + testPossiblePrefix($cd64, ZIP64_END_CENTRAL_REC_HDR_SIG); + + if ($totalDisks > 0) + { + my $commonMessage = "'Offset to Zip64 End of Central Directory Record' field in '" . Signatures::name(ZIP64_END_CENTRAL_LOC_HDR_SIG) . "' is invalid"; + $cd64 = checkOffsetValue($cd64, $here, 0, $commonMessage, $here + 8, ZIP64_END_CENTRAL_REC_HDR_SIG, 1) ; + } + + my $delta = $here - $cd64; + + #### Zip64 end of central directory record + + my $zip64eocd_name = "'" . Signatures::name(ZIP64_END_CENTRAL_REC_HDR_SIG) . "'"; + my $zip64eocd_name_value = Signatures::nameAndHex(ZIP64_END_CENTRAL_REC_HDR_SIG); + my $zip64eocd_value = Signatures::hexValue(ZIP64_END_CENTRAL_REC_HDR_SIG); + + # check enough bytes available + # fatal_tryWalk sprintf "Size of 'Zip64 End of Central Directory Record' 0x%X too small", $cd64 + fatal_tryWalk undef, sprintf "Size of $zip64eocd_name 0x%X too small", $cd64 + if $delta < ZIP64_END_CENTRAL_REC_HDR_MIN_SIZE; + + # Seek to Zip64 End of Central Directory Record + $fh->seek($cd64, SEEK_SET) ; + $HeaderOffsetIndex->addOffsetNoPrefix($fh->tell(), ZIP64_END_CENTRAL_REC_HDR_SIG) ; + + $fh->read($buffer, ZIP64_END_CENTRAL_REC_HDR_MIN_SIZE) ; + + my $sig = unpack("V", substr($buffer, 0, 4)) ; + fatal_tryWalk undef, sprintf "Cannot find $zip64eocd_name: expected $zip64eocd_value but got 0x%X", $sig + if $sig != ZIP64_END_CENTRAL_REC_HDR_SIG ; + + # pkzip sets the extract zip spec to 6.2 (0x3E) to signal a v2 record + # See APPNOTE 6.3.10, section, 7.3.3 + + # Version 1 header is 44 bytes (assuming no extensible data sector) + # Version 2 header (see APPNOTE 6.3.7, section) is > 44 bytes + + my $extractSpec = unpack "C", substr($buffer, 14, 1); + my $diskNumber = unpack "V", substr($buffer, 16, 4); + my $cdDiskNumber = unpack "V", substr($buffer, 20, 4); + my $entriesOnThisDisk = unpack "Q<", substr($buffer, 24, 8); + my $totalEntries = unpack "Q<", substr($buffer, 32, 8); + my $centralDirSize = unpack "Q<", substr($buffer, 40, 8); + my $centralDirOffset = unpack "Q<", substr($buffer, 48, 8); + + if ($extractSpec >= 0x3E) + { + $opt_walk = 1; + $CentralDirectory->setPkEncryptedCD(); + } + + if (! emptyArchive($here, $diskNumber, $cdDiskNumber, $entriesOnThisDisk, $totalEntries, $centralDirSize, $centralDirOffset)) + { + my $commonMessage = "'Offset to Central Directory' field in $zip64eocd_name is invalid"; + $centralDirOffset = checkOffsetValue($centralDirOffset, $here, 0, $commonMessage, $here + 48, ZIP_CENTRAL_HDR_SIG, 1, $extractSpec < 0x3E) ; + } + + # TODO - APPNOTE allows an extensible data sector here (see APPNOTE 6.3.10, section 4.3.14.2) -- need to take this into account + + return ($centralDirOffset, $centralDirSize) ; +} + +use constant Pack_ZIP_END_CENTRAL_HDR_SIG => pack("V", ZIP_END_CENTRAL_HDR_SIG); + +sub findCentralDirectoryOffset +{ + my $fh = shift ; + + # Most common use-case is where there is no comment, so + # know exactly where the end of central directory record + # should be. + + need ZIP_EOCD_MIN_SIZE, Signatures::name(ZIP_END_CENTRAL_HDR_SIG); + + $fh->seek(-ZIP_EOCD_MIN_SIZE(), SEEK_END) ; + my $here = $fh->tell(); + + my $is64bit = $here > MAX32; + my $over64bit = $here & (~ MAX32); + + my $buffer; + $fh->read($buffer, ZIP_EOCD_MIN_SIZE); + + my $zip64 = 0; + my $diskNumber ; + my $cdDiskNumber ; + my $entriesOnThisDisk ; + my $totalEntries ; + my $centralDirSize ; + my $centralDirOffset ; + my $commentLength = 0; + my $trailingBytes = 0; + + if ( unpack("V", $buffer) == ZIP_END_CENTRAL_HDR_SIG ) { + + $HeaderOffsetIndex->addOffset($here + $PREFIX_DELTA, ZIP_END_CENTRAL_HDR_SIG) ; + + $diskNumber = unpack("v", substr($buffer, 4, 2)); + $cdDiskNumber = unpack("v", substr($buffer, 6, 2)); + $entriesOnThisDisk= unpack("v", substr($buffer, 8, 2)); + $totalEntries = unpack("v", substr($buffer, 10, 2)); + $centralDirSize = unpack("V", substr($buffer, 12, 4)); + $centralDirOffset = unpack("V", substr($buffer, 16, 4)); + $commentLength = unpack("v", substr($buffer, 20, 2)); + } + else { + $fh->seek(0, SEEK_END) ; + + my $fileLen = $fh->tell(); + my $want = 0 ; + + while(1) { + $want += 1024 * 32; + my $seekTo = $fileLen - $want; + if ($seekTo < 0 ) { + $seekTo = 0; + $want = $fileLen ; + } + $fh->seek( $seekTo, SEEK_SET); + $fh->read($buffer, $want) ; + my $pos = rindex( $buffer, Pack_ZIP_END_CENTRAL_HDR_SIG); + + if ($pos >= 0 && $want - $pos > ZIP_EOCD_MIN_SIZE) { + $here = $seekTo + $pos ; + $HeaderOffsetIndex->addOffset($here + $PREFIX_DELTA, ZIP_END_CENTRAL_HDR_SIG) ; + + $diskNumber = unpack("v", substr($buffer, $pos + 4, 2)); + $cdDiskNumber = unpack("v", substr($buffer, $pos + 6, 2)); + $entriesOnThisDisk= unpack("v", substr($buffer, $pos + 8, 2)); + $totalEntries = unpack("v", substr($buffer, $pos + 10, 2)); + $centralDirSize = unpack("V", substr($buffer, $pos + 12, 4)); + $centralDirOffset = unpack("V", substr($buffer, $pos + 16, 4)); + $commentLength = unpack("v", substr($buffer, $pos + 20, 2)) // 0; + + my $expectedEof = $fileLen - $want + $pos + ZIP_EOCD_MIN_SIZE + $commentLength ; + # check for trailing data after end of zip + if ($expectedEof < $fileLen ) { + $TRAILING = $expectedEof ; + $trailingBytes = $FILELEN - $expectedEof ; + } + last ; + } + + return undef + if $want == $fileLen; + + } + } -sub myRead -{ - my $got = \$_[0] ; - my $size = $_[1]; + $EOCD_Present = 1; - my $wantSize = $size; - $$got = ''; + # Empty zip file can just contain an EOCD record + return (0, 0) + if ZIP_EOCD_MIN_SIZE + $commentLength + $trailingBytes == $FILELEN ; - if ($size == 0) + if (needZip64EOCDLocator($diskNumber, $cdDiskNumber, $entriesOnThisDisk, $totalEntries, $centralDirOffset, $centralDirSize) && + ! emptyArchive($here, $diskNumber, $cdDiskNumber, $entriesOnThisDisk, $totalEntries, $centralDirOffset, $centralDirSize)) { - return ; + ($centralDirOffset, $centralDirSize) = offsetFromZip64($fh, $here, ZIP_EOCD_MIN_SIZE + $commentLength + $trailingBytes) } + elsif ($is64bit) + { + # use-case is where a 64-bit zip file doesn't use the 64-bit + # extensions. + # print "EOCD not 64-bit $centralDirOffset ($here)\n" ; - if ($size > 0) + fatal_tryWalk $here, "Zip file > 4Gig. Expected 'Offset to Central Dir' to be 0xFFFFFFFF, got " . hexValue($centralDirOffset); + + $centralDirOffset += $over64bit; + $is64In32 = 1; + } + else { - my $buff ; - my $status = $FH->read($buff, $size); - return $status - if $status < 0; - $$got .= $buff ; + if ($centralDirSize) + { + my $commonMessage = "'Offset to Central Directory' field in '" . Signatures::name(ZIP_END_CENTRAL_HDR_SIG) . "' is invalid"; + $centralDirOffset = checkOffsetValue($centralDirOffset, $here, $centralDirSize, $commonMessage, $here + 16, ZIP_CENTRAL_HDR_SIG, 1) ; + } } - my $len = length $$got; - die "Truncated file (got $len, wanted $wantSize): $!\n" - if length $$got != $wantSize; -} - + return (0, 0) + if $totalEntries == 0 && $entriesOnThisDisk == 0; + # APK Signing Block is directly before the first CD entry + # Check if it is present + ($START_APK, $APK, $APK_LEN) = chckForAPKSigningBlock($fh, $centralDirOffset, ZIP_EOCD_MIN_SIZE + $commentLength); + return ($centralDirOffset, $centralDirSize) ; +} -sub walkExtra +sub findID { - my $XLEN = shift; - my $context = shift; - - my $buff ; - my $offset = 0 ; - - my $id; - my $subLen; - my $payload ; + my $id_want = shift ; + my $data = shift; - my $count = 0 ; + my $XLEN = length $data ; + my $offset = 0 ; while ($offset < $XLEN) { - ++ $count; - - # Detect if there is not enough data for an extra ID and length. - # Android zipalign and zipflinger are prime candidates for these - # non-standard extra sub-fields. - my $remaining = $XLEN - $offset; - if ($remaining < ZIP_EXTRA_SUBFIELD_HEADER_SIZE) { - # There is not enough left. - # Consume whatever is there and return so parsing - # can continue. - myRead($payload, $remaining); - my $data = hexDump($payload); - - if ($payload =~ /^\x00+$/) - { - out $payload, "Null Padding in Extra"; - } - else - { - out $payload, "Malformed Extra Data", $data; - } - - return undef; - } + return undef + if $offset + ZIP_EXTRA_SUBFIELD_HEADER_SIZE > $XLEN ; - myRead($id, ZIP_EXTRA_SUBFIELD_ID_SIZE); + my $id = substr($data, $offset, ZIP_EXTRA_SUBFIELD_ID_SIZE); + $id = unpack("v", $id); $offset += ZIP_EXTRA_SUBFIELD_ID_SIZE; - my $lookID = unpack "v", $id ; - if ($lookID == 0) - { - # check for null padding at end of extra - my $here = $FH->tell(); - my $rest; - myRead($rest, $XLEN - $offset); - if ($rest =~ /^\x00+$/) - { - out $id . $rest, "Null Padding in Extra"; - return undef; - } - - seekTo($here); - } - - my ($who, $decoder) = @{ $Extras{$lookID} // ['', undef ] }; - - $who = "$id: $who" - if $id =~ /\w\w/ ; - - $who = "'$who'"; - out $id, "Extra ID #" . Value_v($count), unpackValue_v($id) . " $who" ; - - myRead($buff, ZIP_EXTRA_SUBFIELD_LEN_SIZE); - $offset += ZIP_EXTRA_SUBFIELD_LEN_SIZE; - $subLen = unpack("v", $buff); - out2 $buff, "Length", Value_v($subLen) ; + my $subLen = unpack("v", substr($data, $offset, + ZIP_EXTRA_SUBFIELD_LEN_SIZE)); + $offset += ZIP_EXTRA_SUBFIELD_LEN_SIZE ; return undef if $offset + $subLen > $XLEN ; - if (! defined $decoder) - { - if ($subLen) - { - myRead($payload, $subLen); - my $data = hexDump($payload); - - out2 $payload, "Extra Payload", $data; - } - } - else - { - $decoder->($subLen, $context) ; - } + return substr($data, $offset, $subLen) + if $id eq $id_want ; $offset += $subLen ; } @@ -1395,1026 +6064,1452 @@ sub walkExtra } -sub full32 +sub nibbles { - return $_[0] == MAX32 ; + my @nibbles = ( + [ 16 => 0x1000000000000000 ], + [ 15 => 0x100000000000000 ], + [ 14 => 0x10000000000000 ], + [ 13 => 0x1000000000000 ], + [ 12 => 0x100000000000 ], + [ 11 => 0x10000000000 ], + [ 10 => 0x1000000000 ], + [ 9 => 0x100000000 ], + [ 8 => 0x10000000 ], + [ 7 => 0x1000000 ], + [ 6 => 0x100000 ], + [ 5 => 0x10000 ], + [ 4 => 0x1000 ], + [ 4 => 0x100 ], + [ 4 => 0x10 ], + [ 4 => 0x1 ], + ); + my $value = shift ; + + for my $pair (@nibbles) + { + my ($count, $limit) = @{ $pair }; + + return $count + if $value >= $limit ; + } } -sub decode_Zip64 { - my $len = shift; - my $context = shift; + package HeaderOffsetEntry; - my $z64Data = $context->{Zip64}; - my $inCentralHdr = $context->{InCentralDir} ; - my $inLocalHdr = ! $inCentralHdr ; + sub new + { + my $class = shift ; + my $offset = shift ; + my $signature = shift; - $ZIP64 = 1; + bless [ $offset, $signature, Signatures::name($signature)] , $class; - if ($inLocalHdr || full32 $z64Data->[0]) { - out_Q " Uncompressed Size"; } - if ($inLocalHdr || full32 $z64Data->[1]) { - $context->{CompressedLength} = out_Q " Compressed Size"; + sub offset + { + my $self = shift; + return $self->[0]; } - if (full32 $z64Data->[2] ) { - $context->{LocalHdrOffset} = out_Q " Offset to Local Dir"; + sub signature + { + my $self = shift; + return $self->[1]; } - if ($z64Data->[3] == 0xFFFF ) { - out_V " Disk Number"; + sub name + { + my $self = shift; + return $self->[2]; } + } -sub Ntfs2Unix { - my $m = shift; - my $v = shift; + package HeaderOffsetIndex; - # NTFS offset is 19DB1DED53E8000 + # Store a list of header offsets recorded when scannning the central directory - my $hex = Value_Q($v) ; - $v -= 0x19DB1DED53E8000 ; - my $ns = ($v % 10000000) * 100; - my $elapse = int ($v/10000000); - return "$hex '" . getT($elapse) . - " " . sprintf("%0dns'", $ns); -} + sub new + { + my $class = shift ; -sub decode_NTFS_Filetimes -{ - my $len = shift; - my $context = shift; + my %object = ( + 'offsetIndex' => [], + 'offset2Index' => {}, + 'offset2Signature' => {}, + 'currentIndex' => -1, + 'currentSignature' => 0, + # 'sigNames' => $sigNames, + ) ; - out_V " Reserved"; - out_v " Tag1"; - out_v " Size1" ; + bless \%object, $class; + } - my ($m, $s1) = read_Q; - out $m, " Mtime", Ntfs2Unix($m, $s1); + sub sortOffsets + { + my $self = shift ; - my ($a, $s3) = read_Q; - out $m, " Atime", Ntfs2Unix($m, $s3); + @{ $self->{offsetIndex} } = sort { $a->[0] <=> $b->[0] } + @{ $self->{offsetIndex} }; + my $ix = 0; + $self->{offset2Index}{$_} = $ix++ + for @{ $self->{offsetIndex} } ; + } - my ($c, $s2) = read_Q; - out $c, " Ctime", Ntfs2Unix($m, $s2); -} + sub addOffset + { + my $self = shift ; + my $offset = shift ; + my $signature = shift ; -sub getT -{ - my $time = shift ; + $offset += $PREFIX_DELTA ; + $self->addOffsetNoPrefix($offset, $signature); + } - if ($opt_utc) - { return scalar gmtime($time) } - else - { return scalar localtime($time) } -} + sub addOffsetNoPrefix + { + my $self = shift ; + my $offset = shift ; + my $signature = shift ; -sub getTime -{ - my $time = shift ; + my $name = Signatures::name($signature); - return "'" . getT($time) . "'"; -} + if (! defined $self->{offset2Signature}{$offset}) + { + push @{ $self->{offsetIndex} }, HeaderOffsetEntry->new($offset, $signature) ; + $self->{offset2Signature}{$offset} = $signature; + } + } -sub decode_UT -{ - my $len = shift; - my $context = shift; + sub getNextIndex + { + my $self = shift ; + my $offset = shift ; - my ($data, $flags) = read_C(); + $self->{currentIndex} ++; - my $f = Value_C $flags; - $f .= " mod" if $flags & 1; - $f .= " access" if $flags & 2; - $f .= " change" if $flags & 4; + return ${ $self->{offsetIndex} }[$self->{currentIndex}] // undef + } - out $data, " Flags", "'$f'"; + sub rewindIndex + { + my $self = shift ; + my $offset = shift ; - -- $len; + $self->{currentIndex} --; + } - if ($flags & 1) + sub dump { - my ($data, $time) = read_V(); - - out2 $data, "Mod Time", Value_V($time) . " " . getTime($time) ; + my $self = shift; - $len -= 4 ; + say "### HeaderOffsetIndex"; + say "### Offset\tSignature"; + for my $x ( @{ $self->{offsetIndex} } ) + { + my ($offset, $sig) = @$x; + printf "### %X %d\t\t" . $x->name() . "\n", $x->offset(), $x->offset(); + } } + sub checkForOverlap + { + my $self = shift ; + my $need = shift; - if ($flags & 2 && $len > 0 ) - { - my ($data, $time) = read_V(); + my $needOffset = $FH->tell() + $need; - out2 $data, "Access Time", Value_V($time) . " " . getTime($time) ; - $len -= 4 ; - } + for my $hdrOffset (@{ $self->{offsetIndex} }) + { + my $delta = $hdrOffset - $needOffset; + return [$self->{offsetIndex}{$hdrOffset}, $needOffset - $hdrOffset] + if $delta <= 0 ; + } - if ($flags & 4 && $len > 0) - { - my ($data, $time) = read_V(); + return [undef, undef]; + } - out2 $data, "Change Time", Value_V($time) . " " . getTime($time) ; - } } +{ + package FieldsAndAccessors; + sub Add + { + use Data::Dumper ; -sub decode_AES -{ - # ref https://www.winzip.com/win/es/aes_info.html + my $classname = shift; + my $object = shift; + my $fields = shift ; + my $no_handler = shift // {}; - my $len = shift; - my $context = shift; + state $done = {}; - return if $len == 0 ; - my %lookup = ( 1 => "AE-1", 2 => "AE-2"); - out_v " Vendor Version", sub { $lookup{$_[0]} || "Unknown" } ; + while (my ($name, $value) = each %$fields) + { + my $method = "${classname}::$name"; - my $id ; - myRead($id, 2); - out $id, " Vendor ID", unpackValue_v($id) . " '$id'"; + $object->{$name} = $value; - my %strengths = (1 => "128-bit encryption key", - 2 => "192-bit encryption key", - 3 => "256-bit encryption key", - ); + # don't auto-create a handler + next + if $no_handler->{$name}; + + no strict 'refs'; + + # Don't use lvalue sub for now - vscode debugger breaks with it enabled. + # https://github.com/richterger/Perl-LanguageServer/issues/194 + # *$method = sub : lvalue { + # $_[0]->{$name} ; + # } + # unless defined $done->{$method}; + + # Auto-generate getter/setter + *$method = sub { + $_[0]->{$name} = $_[1] + if @_ == 2; + return $_[0]->{$name} ; + } + unless defined $done->{$method}; - my $strength = out_C " Encryption Strength", sub {$strengths{$_[0]} || "Unknown" } ; + ++ $done->{$method}; - my ($bmethod, $method) = read_v(); - out $bmethod, " Compression Method", compressionMethod($method) ; - $context->{AesStrength} = $strength ; + } + } } -sub decode_GrowthHint { - my $len = shift; - my $context = shift; - my $inCentralHdr = $context->{InCentralDir} ; + package BaseEntry ; - return if $len == 0 ; + sub new + { + my $class = shift ; - out_v " Signature" ; - out_v " Initial Value"; + state $index = 0; + + my %fields = ( + 'index' => $index ++, + 'zip64' => 0, + 'offsetStart' => 0, + 'offsetEnd' => 0, + 'inCentralDir' => 0, + 'encapsulated' => 0, # enclosed in outer zip + 'childrenCount' => 0, # this entry is a zip with enclosed children + 'streamed' => 0, + 'languageEncodingFlag' => 0, + 'entryType' => 0, + ) ; + + my $self = bless {}, $class; + + FieldsAndAccessors::Add($class, $self, \%fields) ; - my $padding; - myRead($padding, $len - 4); - my $data = hexDump($padding); + return $self; + } - out2 $padding, "Padding", $data; + sub increment_childrenCount + { + my $self = shift; + $self->{childrenCount} ++; + } } -sub decode_DataStreamAlignment { - my $len = shift; - my $context = shift; - my $inCentralHdr = $context->{InCentralDir} ; + package LocalCentralEntryBase ; - return if $len == 0 ; + use parent -norequire , 'BaseEntry' ; - my ($data, $alignment) = read_v(); + sub new + { + my $class = shift ; - out $data, " Alignment", Value_v($alignment) ; + my $self = $class->SUPER::new(); - my $recompress_value = $alignment & 0x8000 ? 1 : 0; - my $recompressing = $recompress_value ? "True" : "False"; - $alignment &= 0x7FFF ; - my $hexAl = sprintf("%X", $alignment); + my %fields = ( + # fields from the header + 'centralHeaderOffset' => 0, + 'localHeaderOffset' => 0, + + 'extractVersion' => 0, + 'generalPurposeFlags' => 0, + 'compressedMethod' => 0, + 'lastModDateTime' => 0, + 'crc32' => 0, + 'compressedSize' => 0, + 'uncompressedSize' => 0, + 'filename' => '', + 'outputFilename' => '', + # inferred data + # 'InCentralDir' => 0, + # 'zip64' => 0, + + 'zip64ExtraPresent' => 0, + 'zip64SizesPresent' => 0, + 'payloadOffset' => 0, + + # zip64 extra + 'zip64_compressedSize' => undef, + 'zip64_uncompressedSize' => undef, + 'zip64_localHeaderOffset' => undef, + 'zip64_diskNumber' => undef, + 'zip64_diskNumberPresent' => 0, + + # Values direct from the header before merging any Zip64 values + 'std_compressedSize' => undef, + 'std_uncompressedSize' => undef, + 'std_localHeaderOffset' => undef, + 'std_diskNumber' => undef, + + # AES + 'aesStrength' => 0, + 'aesValid' => 0, - out1 " [Bit 15]", "$recompress_value 'Recompress $recompressing'"; - out1 " [Bits 0-14]", "$hexAl 'Minimal Alignment $alignment'"; + # Minizip CD encryption + 'minizip_secure' => 0, - if (! $inCentralHdr && $len - 2 > 0) - { - my $padding; - myRead($padding, $len - 2); + ) ; + + FieldsAndAccessors::Add($class, $self, \%fields) ; - out2 $padding, "Padding", hexDump($padding); + return $self; } } - -sub decode_UX { - my $len = shift; - my $context = shift; - my $inCentralHdr = $context->{InCentralDir} ; + package Zip64EndCentralHeaderEntry ; - return if $len == 0 ; + use parent -norequire , 'LocalCentralEntryBase' ; - my ($data, $time) = read_V(); - out2 $data, "Access Time", Value_V($time) . " " . getTime($time) ; + sub new + { + my $class = shift ; - ($data, $time) = read_V(); - out2 $data, "Mod Time", Value_V($time) . " " . getTime($time) ; + my $self = $class->SUPER::new(); - if (! $inCentralHdr ) { - out_v " UID" ; - out_v " GID"; + + my %fields = ( + 'inCentralDir' => 1, + ) ; + + FieldsAndAccessors::Add($class, $self, \%fields) ; + + return $self; } + } -sub decode_Ux { - my $len = shift; - my $context = shift; + package CentralDirectoryEntry; - return if $len == 0 ; - out_v " UID" ; - out_v " GID"; -} + use parent -norequire , 'LocalCentralEntryBase' ; -sub decodeLitteEndian -{ - my $value = shift ; + use constant Offset_VersionMadeBy => 4; + use constant Offset_VersionNeededToExtract => 6; + use constant Offset_GeneralPurposeFlags => 8; + use constant Offset_CompressionMethod => 10; + use constant Offset_ModificationTime => 12; + use constant Offset_ModificationDate => 14; + use constant Offset_CRC32 => 16; + use constant Offset_CompressedSize => 20; + use constant Offset_UncompressedSize => 24; + use constant Offset_FilenameLength => 28; + use constant Offset_ExtraFieldLength => 30; + use constant Offset_FileCommentLength => 32; + use constant Offset_DiskNumber => 34; + use constant Offset_InternalAttributes => 36; + use constant Offset_ExternalAttributes => 38; + use constant Offset_RelativeOffsetToLocal => 42; + use constant Offset_Filename => 46; - if (length $value == 4) + sub new { - return Value_V unpack ("V", $value) - } - else { - # TODO - fix this - die "unsupported\n"; - } + my $class = shift ; + my $offset = shift; - my $got = 0 ; - my $shift = 0; + # check for existing entry + return $CentralDirectory->{byCentralOffset}{$offset} + if defined $offset && defined $CentralDirectory->{byCentralOffset}{$offset} ; + + my $self = $class->SUPER::new(); + + my %fields = ( + 'diskNumber' => 0, + 'comment' => "", + 'ldEntry' => undef, + ) ; - #hexDump - #reverse - #my @a =unpack "C*", $value; - #@a = reverse @a; - #hexDump(@a); + FieldsAndAccessors::Add($class, $self, \%fields) ; - for (reverse unpack "C*", $value) - { - $got = ($got << 8) + $_ ; - } + $self->inCentralDir(1) ; + $self->entryType(::ZIP_CENTRAL_HDR_SIG) ; - return $got ; + return $self; + } } -sub decode_ux { - my $len = shift; - my $context = shift; + package CentralDirectory; - return if $len == 0 ; - out_C " Version" ; - my $uidSize = out_C " UID Size"; - myRead(my $data, $uidSize); - out2 $data, "UID", decodeLitteEndian($data); + sub new + { + my $class = shift ; - my $gidSize = out_C " GID Size"; - myRead($data, $gidSize); - out2 $data, "GID", decodeLitteEndian($data); + my %object = ( + 'entries' => [], + 'count' => 0, + 'byLocalOffset' => {}, + 'byCentralOffset' => {}, + 'byName' => {}, + 'offset2Index' => {}, + 'normalized_filenames' => {}, + 'CentralDirectoryOffset' => 0, + 'CentralDirectorySize' => 0, + 'zip64' => 0, + 'encryptedCD' => 0, + 'minizip_secure' => 0, + 'alreadyScanned' => 0, + ) ; -} + bless \%object, $class; + } -sub decode_Java_exe -{ - my $len = shift; - my $context = shift; + sub addEntry + { + my $self = shift ; + my $entry = shift ; -} + my $localHeaderOffset = $entry->localHeaderOffset ; + my $CentralDirectoryOffset = $entry->centralHeaderOffset ; + my $filename = $entry->filename ; -sub decode_up -{ - my $len = shift; - my $context = shift; + Nesting::add($entry); + # Create a reference from Central to Local header entries + my $ldEntry = Nesting::getLdEntryByOffset($localHeaderOffset); + if ($ldEntry) + { + $entry->ldEntry($ldEntry) ; - out_C " Version"; - out_V " NameCRC32"; + # LD -> CD + # can have multiple LD entries point to same CD + # so need to keep a list + $ldEntry->addCdEntry($entry); + } - myRead(my $data, $len - 5); + # only check for duplicate in real CD scan + if ($self->{alreadyScanned} && ! $entry->encapsulated ) + { + my $existing = $self->{byName}{$filename} ; + if ($existing && $existing->centralHeaderOffset != $entry->centralHeaderOffset) + { + ::error $CentralDirectoryOffset, + "Duplicate Central Directory entries for filename '$filename'", + "Current Central Directory entry at offset " . ::decimalHex0x($CentralDirectoryOffset), + "Duplicate Central Directory entry at offset " . ::decimalHex0x($self->{byName}{$filename}{centralHeaderOffset}); - out $data, " UnicodeName", $data; -} + # not strictly illegal to have duplicate filename, so save this one + } + else + { + my $existingNormalizedEntry = $self->normalize_filename($entry, $filename); + if ($existingNormalizedEntry) + { + ::warning $CentralDirectoryOffset, + "Portability Issue: Found case-insensitive duplicate for filename '$filename'", + "Current Central Directory entry at offset " . ::decimalHex0x($CentralDirectoryOffset), + "Duplicate Central Directory entry for filename '" . $existingNormalizedEntry->outputFilename . "' at offset " . ::decimalHex0x($existingNormalizedEntry->centralHeaderOffset); + } + } + } -sub decode_Xceed_unicode -{ - my $len = shift; - my $context = shift; + # CD can get processed twice, so return if already processed + return + if $self->{byCentralOffset}{$CentralDirectoryOffset} ; - my $data ; + if (! $entry->encapsulated ) + { + push @{ $self->{entries} }, $entry; + + $self->{byLocalOffset}{$localHeaderOffset} = $entry; + $self->{byCentralOffset}{$CentralDirectoryOffset} = $entry; + $self->{byName}{ $filename } = $entry; + $self->{offset2Index} = $self->{count} ++; + } - # No public definition available, so guess the fields used for this one - # Data analysis based on output from Fiddler (https://www.telerik.com/fiddler), - # which uses this field + } - # First 4 bytes appear to be "NUCX" all the time - myRead($data, 4); - out $data, " ID", $data; + sub exists + { + my $self = shift ; - # Next 2 bytes contains a count of the remaining bytes/2 - # Probably the number of UTF-16 characters, including the - # optional NULL prefix - out_v " Length"; + return scalar @{ $self->{entries} }; + } - # next is a UTF16 encode filename - # sometimes preceeded by a two Null bytes + sub sortByLocalOffset + { + my $self = shift ; - myRead($data, $len - 6); + @{ $self->{entries} } = sort { $a->localHeaderOffset() <=> $b->localHeaderOffset() } + @{ $self->{entries} }; + } - my $prefix = substr($data, 0, 2); - if ($prefix eq "\x00\x00") + sub getByLocalOffset { - # Found the Null prefix - out $prefix, " Null", '0000'; - substr($data, 0, 2) = ''; + my $self = shift ; + my $offset = shift ; + + # TODO - what happens if none exists? + my $entry = $self->{byLocalOffset}{$offset - $PREFIX_DELTA} ; + return $entry ; } - out $data, " UTF16LE Name", decode("UTF16LE", $data); -} + sub localOffset + { + my $self = shift ; + my $offset = shift ; + # TODO - what happens if none exists? + return $self->{byLocalOffset}{$offset - $PREFIX_DELTA} ; + } -sub decode_NT_security -{ - my $len = shift; - my $context = shift; - my $inCentralHdr = $context->{InCentralDir} ; + sub getNextLocalOffset + { + my $self = shift ; + my $offset = shift ; - out_V " Uncompressed Size" ; + my $index = $self->{offset2Index} ; - if (! $inCentralHdr) { + if ($index + 1 >= $self->{count}) + { + return 0; + } - out_C " Version" ; + return ${ $self->{entries} }[$index+1]->localHeaderOffset() ; + } - out_v " Type"; + sub inCD + { + my $self = shift ; + $FH->tell() >= $self->{CentralDirectoryOffset}; + } + + sub setPkEncryptedCD + { + my $self = shift ; - out_V " NameCRC32" ; + $self->{encryptedCD} = 1 ; - my $plen = $len - 4 - 1 - 2 - 4; - myRead(my $payload, $plen); - out $plen, " Extra Payload", hexDump($payload); } -} -sub decodeMVS -{ - my $len = shift; - my $context = shift; + sub setMiniZipEncrypted + { + my $self = shift ; - # data in Big-Endian - myRead(my $data, $len); - my $ID = unpack("N", $data); + $self->{minizip_secure} = 1 ; + } - if ($ID == 0xE9F3F9F0) + sub isMiniZipEncrypted { - out($data, " ID", "'Z390'"); - substr($data, 0, 4) = ''; + my $self = shift ; + return $self->{minizip_secure}; } - out($data, " Extra Payload", hexDump($data)); -} + sub isEncryptedCD + { + my $self = shift ; + return $self->{encryptedCD} && ! $self->{minizip_secure}; + } -sub printAes -{ - # ref https://www.winzip.com/win/es/aes_info.html + sub normalize_filename + { + # check if there is a filename that already exists + # with the same name when normalized to lower case - my $context = shift ; + my $self = shift ; + my $entry = shift; + my $filename = shift; - my %saltSize = ( - 1 => 8, - 2 => 12, - 3 => 16, - ); + my $nFilename = lc $filename; - myRead(my $salt, $saltSize{$context->{AesStrength} }); - out $salt, "AES Salt", hexDump($salt); - myRead(my $pwv, 2); - out $pwv, "AES Pwd Ver", hexDump($pwv); + my $lookup = $self->{normalized_filenames}{$nFilename}; + # if ($lookup && $lookup ne $filename) + if ($lookup) + { + return $lookup, + } + + $self->{normalized_filenames}{$nFilename} = $entry; - return $saltSize{$context->{AesStrength}} + 2 + 10; + return undef; + } } -sub printLzmaProperties { - my $len = 0; + package LocalDirectoryEntry; - my $b1; - my $b2; - my $buffer; + use parent -norequire , 'LocalCentralEntryBase' ; - myRead($b1, 2); - my ($verHi, $verLow) = unpack ("CC", $b1); + use constant Offset_VersionNeededToExtract => 4; + use constant Offset_GeneralPurposeFlags => 6; + use constant Offset_CompressionMethod => 8; + use constant Offset_ModificationTime => 10; + use constant Offset_ModificationDate => 12; + use constant Offset_CRC32 => 14; + use constant Offset_CompressedSize => 18; + use constant Offset_UncompressedSize => 22; + use constant Offset_FilenameLength => 26; + use constant Offset_ExtraFieldLength => 27; + use constant Offset_Filename => 30; - out $b1, "LZMA Version", sprintf("%02X%02X", $verHi, $verLow) . " '$verHi.$verLow'"; - my $LzmaPropertiesSize = out_v "LZMA Properties Size"; - $len += 4; + sub new + { + my $class = shift ; - my $LzmaInfo = out_C "LZMA Info", sub { $_[0] == 93 ? "(Default)" : ""}; + my $self = $class->SUPER::new(); - my $PosStateBits = 0; - my $LiteralPosStateBits = 0; - my $LiteralContextBits = 0; - $PosStateBits = int($LzmaInfo / (9 * 5)); - $LzmaInfo -= $PosStateBits * 9 * 5; - $LiteralPosStateBits = int($LzmaInfo / 9); - $LiteralContextBits = $LzmaInfo - $LiteralPosStateBits * 9; + my %fields = ( + 'streamedMatch' => 0, + 'readDataDescriptor' => 0, + 'cdEntryIndex' => {}, + 'cdEntryList' => [], + ) ; - out1 " PosStateBits", $PosStateBits; - out1 " LiteralPosStateBits", $LiteralPosStateBits; - out1 " LiteralContextBits", $LiteralContextBits; + FieldsAndAccessors::Add($class, $self, \%fields) ; - out_V "LZMA Dictionary Size"; + $self->inCentralDir(0) ; + $self->entryType(::ZIP_LOCAL_HDR_SIG) ; - # TODO - assumption that this is 5 - $len += $LzmaPropertiesSize; + return $self; + } - skip($FH, $LzmaPropertiesSize - 5) - if $LzmaPropertiesSize != 5 ; + sub addCdEntry + { + my $self = shift ; + my $entry = shift; - return $len; -} + # don't want encapsulated entries + # and protect against duplicates + return + if $entry->encapsulated || + $self->{cdEntryIndex}{$entry->index} ++ >= 1; -sub readFromOffset -{ - # my $fh = shift; - my $offset = shift; - my $len = shift; + push @{ $self->{cdEntryList} }, $entry ; + } - seekTo($offset) ; + sub getCdEntry + { + my $self = shift ; - my $buffer; - myRead($buffer, $len); - # $fh->read($buffer, $len) == $len - length $buffer == $len - or return ''; + return [] + if ! $self->{cdEntryList} ; - return $buffer; + return $self->{cdEntryList}[0] ; + } + + sub getCdEntries + { + my $self = shift ; + return $self->{cdEntryList} ; + } } -sub chckForAPKSigningBlock { - my $fh = shift; - my $cdOffset = shift; + package LocalDirectory; - # APK Signing Block comes directy before the Central directory + sub new + { + my $class = shift ; - # If offset less than - # - # len1 8 - # id 4 - # kv with zero len 8 - # len1 8 - # magic 16 - # ---------- - # 44 + my %object = ( + 'entries' => [], + 'count' => 0, + 'byLocalOffset' => {}, + 'byName' => {}, + 'offset2Index' => {}, + 'normalized_filenames' => {}, + 'CentralDirectoryOffset' => 0, + 'CentralDirectorySize' => 0, + 'zip64' => 0, + 'encryptedCD' => 0, + 'streamedPresent' => 0, + ) ; - return (0, 0, '') - if $cdOffset < 44; + bless \%object, $class; + } + + sub isLocalEntryNested + { + my $self = shift ; + my $localEntry = shift; + + return Nesting::getFirstEncapsulation($localEntry); + + } + + sub addEntry + { + my $self = shift ; + my $localEntry = shift ; + + my $filename = $localEntry->filename ; + my $localHeaderOffset = $localEntry->localHeaderOffset; + my $payloadOffset = $localEntry->payloadOffset ; + + my $existingEntry = $self->{byName}{$filename} ; + + my $endSurfaceArea = $payloadOffset + ($localEntry->compressedSize // 0) ; + + if ($existingEntry) + { + ::error $localHeaderOffset, + "Duplicate Local Directory entry for filename '$filename'", + "Current Local Directory entry at offset " . ::decimalHex0x($localHeaderOffset), + "Duplicate Local Directory entry at offset " . ::decimalHex0x($existingEntry->localHeaderOffset), + } + else + { + + my ($existing_filename, $offset) = $self->normalize_filename($filename); + if ($existing_filename) + { + ::warning $localHeaderOffset, + "Portability Issue: Found case-insensitive duplicate for filename '$filename'", + "Current Local Directory entry at offset " . ::decimalHex0x($localHeaderOffset), + "Duplicate Local Directory entry for filename '$existing_filename' at offset " . ::decimalHex0x($offset); + } + } - # Step 1 - 16 bytes before CD is literal string "APK Sig Block 42" - my $magicOffset = $cdOffset - 16; - my $buffer = readFromOffset($magicOffset, 16); + # keep nested local entries for zipbomb deteection + push @{ $self->{entries} }, $localEntry; - return (0, 0, '') - if $buffer ne "APK Sig Block 42" ; + $self->{byLocalOffset}{$localHeaderOffset} = $localEntry; + $self->{byName}{ $filename } = $localEntry; - # Step 2 - read the two length fields - # and check they are identical - $buffer = readFromOffset($cdOffset - 16 - 8, 8); - my $len2 = unpack("Q<", $buffer); + $self->{streamedPresent} ++ + if $localEntry->streamed; - return (0, 0, '') - if $len2 == 0 ; + Nesting::add($localEntry); + } - my $startApkOffset = $cdOffset - 8 - $len2 ; + sub exists + { + my $self = shift ; - $buffer = readFromOffset($startApkOffset, 8); - my $len1 = unpack("Q<", $buffer); + return scalar @{ $self->{entries} }; + } - return (0, 0, '') - if $len1 != $len2; + sub sortByLocalOffset + { + my $self = shift ; - return ($startApkOffset, $cdOffset - 16 - 8, $buffer); -} + @{ $self->{entries} } = sort { $a->localHeaderOffset() <=> $b->localHeaderOffset() } + @{ $self->{entries} }; + } -sub scanApkBlock -{ - state $IDs = { - 0x7109871a => "APK Signature v2", - 0xf05368c0 => "APK Signature v3", - 0x42726577 => "Verity Padding Block", # from https://android.googlesource.com/platform/tools/apksig/+/master/src/main/java/com/android/apksig/internal/apk/ApkSigningBlockUtils.java - 0x6dff800d => "Source Stamp", - 0x504b4453 => "Dependency Info", - 0x71777777 => "APK Channel Block", - 0xff3b5998 => "Zero Block", - 0x2146444e => "Play Metadata", - } ; + sub localOffset + { + my $self = shift ; + my $offset = shift ; + return $self->{byLocalOffset}{$offset} ; + } - seekTo($FH->tell() - 4) ; - print "\nAPK SIGNING BLOCK\n"; + sub getByLocalOffset + { + my $self = shift ; + my $offset = shift ; - scanApkPadding(''); - out_Q "Block Length Copy #1"; - my $ix = 1; + # TODO - what happens if none exists? + my $entry = $self->{byLocalOffset}{$offset} ; + return $entry ; + } - while ($FH->tell() < $APK - 8) + sub getNextLocalOffset { - my ($bytes, $id, $len); - ($bytes, $len) = read_Q ; - out $bytes, "ID/Value Length #" . sprintf("%X", $ix), Value_Q($len); + my $self = shift ; + my $offset = shift ; - ($bytes, $id) = read_V; + my $index = $self->{offset2Index} ; - out $bytes, " ID", Value_V($id) . " '" . ($IDs->{$id} // 'Unknown ID') . "'"; + if ($index + 1 >= $self->{count}) + { + return 0; + } - outSomeData($len-4, " Value"); - ++ $ix; + return ${ $self->{entries} }[$index+1]->localHeaderOffset ; } - out_Q "Block Length Copy #2"; + sub lastStreamedEntryAdded + { + my $self = shift ; + my $offset = shift ; - my $magic ; - myRead($magic, 16); + for my $entry ( reverse @{ $self->{entries} } ) + { + if ($entry->streamed)# && ! $entry->streamedMatch) + { + $entry->streamedMatch($entry->streamedMatch + 1) ; + return $entry; + } + } - out $magic, "Magic", qq['$magic']; -} + return undef; + } -sub scanApkPadding -{ - my $bytes = shift ; + sub inCD + { + my $self = shift ; + $FH->tell() >= $self->{CentralDirectoryOffset}; + } + + sub setPkEncryptedCD + { + my $self = shift ; + + $self->{encryptedCD} = 1 ; - # padding - my $here = $FH->tell(); - my $got; - myRead($got, $APK - $here); - $got = $bytes . $got; - if ($got =~ /^(\x00+)($APK_LEN)?/) - { - my $len = length $1 ; - seekTo($here - length($bytes)); - outSomeData($len, "Null Padding"); } - else + + sub isEncryptedCD { - seekTo($here); + my $self = shift ; + return $self->{encryptedCD} ; + } + + sub anyStreamedEntries + { + my $self = shift ; + return $self->{streamedPresent} ; } + sub normalize_filename + { + # check if there is a filename that already exists + # with the same name when normalized to lower case + + my $self = shift ; + my $filename = shift; + + my $nFilename = lc $filename; + + my $lookup = $self->{normalized_filenames}{$nFilename}; + if ($lookup && $lookup ne $filename) + { + return $self->{byName}{$lookup}{outputFilename}, + $self->{byName}{$lookup}{localHeaderOffset} + } + + $self->{normalized_filenames}{$nFilename} = $filename; + + return undef, undef; + } } -sub scanCentralDirectory { - my $fh = shift; - - my $here = $fh->tell(); + package Eocd ; - # Use cases - # 1 32-bit CD - # 2 64-bit CD + sub new + { + my $class = shift ; - my @CD = (); - my $offset = findCentralDirectoryOffset($fh); + my %object = ( + 'zip64' => 0, + ) ; - return () - if ! defined $offset; + bless \%object, $class; + } +} - $fh->seek($offset, SEEK_SET) ; +sub displayFileInfo +{ + return; - # Now walk the Central Directory Records - my $buffer ; - my $cdIndex = 0; - while ($fh->read($buffer, 46) == 46 && - unpack("V", $buffer) == ZIP_CENTRAL_HDR_SIG) { + my $filename = shift; - my $cdEntryOffset = $fh->tell() - 46; - ++ $cdIndex ; + info undef, + "Filename : '$filename'", + "Size : " . (-s $filename) . " (" . decimalHex0x(-s $filename) . ")", + # "Native Encoding: '" . TextEncoding::getNativeLocaleName() . "'", +} - my $compressedLength = unpack("V", substr($buffer, 20, 4)); - my $uncompressedLength = unpack("V", substr($buffer, 24, 4)); - my $filename_length = unpack("v", substr($buffer, 28, 2)); - my $extra_length = unpack("v", substr($buffer, 30, 2)); - my $comment_length = unpack("v", substr($buffer, 32, 2)); - my $locHeaderOffset = unpack("V", substr($buffer, 42, 4)); - my $cdZip64 = 0; - my $zip64Sizes = 0; +{ + package TextEncoding; - skip($fh, $filename_length ) ; + my $nativeLocaleEncoding = getNativeLocale(); + my $opt_EncodingFrom = $nativeLocaleEncoding; + my $opt_EncodingTo = $nativeLocaleEncoding ; + my $opt_Encoding_Enabled; + my $opt_Debug_Encoding; + my $opt_use_LanguageEncodingFlag; - if ($extra_length) - { - $fh->read(my $extraField, $extra_length) ; - # $self->smartReadExact(\$extraField, $extra_length); + sub setDefaults + { + $nativeLocaleEncoding = getNativeLocale(); + $opt_EncodingFrom = $nativeLocaleEncoding; + $opt_EncodingTo = $nativeLocaleEncoding ; + $opt_Encoding_Enabled = 1; + $opt_Debug_Encoding = 0; + $opt_use_LanguageEncodingFlag = 1; + } - # Check for Zip64 - # my SizesExtended = findID("\x01\x00", $extraField); - my $zip64Extended = findID(0x0001, $extraField); + sub getNativeLocale + { + state $enc; - if ($zip64Extended) + if (! defined $enc) + { + eval { - $cdZip64 = 1; - - if ($uncompressedLength == MAX32) + require encoding ; + my $encoding = encoding::_get_locale_encoding() ; + if (! $encoding) { - $uncompressedLength = unpack "Q<", substr($zip64Extended, 0, 8, ""); - $zip64Sizes = 1; + # CP437 is the legacy default for zip files + $encoding = 'cp437'; + # ::warning undef, "Cannot determine system charset: defaulting to '$encoding'" } - if ($compressedLength == MAX32) - { - $compressedLength = unpack "Q<", substr($zip64Extended, 0, 8, ""); - $zip64Sizes = 1; + $enc = Encode::find_encoding($encoding) ; + } ; + } - } - if ($locHeaderOffset == MAX32) - { - $locHeaderOffset = unpack "Q<", substr($zip64Extended, 0, 8, ""); - } + return $enc; + } + + sub getNativeLocaleName + { + state $name; + + return $name + if defined $name ; + + if (! defined $name) + { + my $enc = getNativeLocale(); + if ($enc) + { + $name = $enc->name() + } + else + { + $name = 'unknown' } } - my $got = [$locHeaderOffset, $compressedLength, $cdZip64, $zip64Sizes, $cdIndex, $cdEntryOffset] ; + return $name ; + } - skip($fh, $comment_length ) ; + sub parseEncodingOption + { + my $opt_name = shift; + my $opt_value = shift; + + my $enc = Encode::find_encoding($opt_value) ; + die "Encoding '$opt_value' not found for option '$opt_name'\n" + unless ref $enc; - push @CD, $got ; + if ($opt_name eq 'encoding') + { + $opt_EncodingFrom = $enc; + } + elsif ($opt_name eq 'output-encoding') + { + $opt_EncodingTo = $enc; + } + else + { + die "Unknown option $opt_name\n" + } } - $fh->seek($here, SEEK_SET) ; + sub NoEncoding + { + my $opt_name = shift; + my $opt_value = shift; - # @CD = sort { $a->[0]->cmp($b->[0]) } @CD ; - @CD = sort { $a->[0] <=> $b->[0] } @CD ; + $opt_Encoding_Enabled = 0 ; + } - # Set the first Local File Header offset. - $START = $CD[0]->[0] - if @CD ; + sub LanguageEncodingFlag + { + my $opt_name = shift; + my $opt_value = shift; - return (1, $offset, @CD); -} + $opt_use_LanguageEncodingFlag = $opt_value ; + } + sub debugEncoding + { + if (@_) + { + $opt_Debug_Encoding = 1 ; + } -sub offsetFromZip64 -{ - my $fh = shift ; - my $here = shift; + return $opt_Debug_Encoding ; + } - $fh->seek($here - 20, SEEK_SET) - # TODO - fix this - or die "xx $!" ; + sub encodingInfo + { + return + unless $opt_Encoding_Enabled && $opt_Debug_Encoding ; - my $buffer; - my $got = 0; - ($got = $fh->read($buffer, 20)) == 20 - # TODO - fix this - or die "xxx + my $enc = TextEncoding::getNativeLocaleName(); + my $from = $opt_EncodingFrom->name(); + my $to = $opt_EncodingTo->name(); + ::debug undef, "Debug Encoding Enabled", + "System Default Encoding: '$enc'", + "Encoding used when reading from zip file: '$from'", + "Encoding used for display output: '$to'"; + } - $here $got $!" ; + sub cleanEval + { + chomp $_[0] ; + $_[0] =~ s/ at .+ line \d+\.$// ; + return $_[0]; + } - if ( unpack("V", $buffer) == ZIP64_END_CENTRAL_LOC_HDR_SIG ) { - my $cd64 = unpack "Q<", substr($buffer, 8, 8); + sub decode + { + my $name = shift ; + my $type = shift ; + my $LanguageEncodingFlag = shift ; - $fh->seek($cd64, SEEK_SET) ; + return $name + if ! $opt_Encoding_Enabled ; - $fh->read($buffer, 4) == 4 - # TODO - fix this - or die "xxx" ; + # TODO - check for badly formed content + if ($LanguageEncodingFlag && $opt_use_LanguageEncodingFlag) + { + # use "utf-8-strict" to catch invalid codepoints + eval { $name = Encode::decode('utf-8-strict', $name, Encode::FB_CROAK ) } ; + ::warning $FH->tell() - length $name, "Could not decode 'UTF-8' $type: " . cleanEval $@ + if $@ ; + } + else + { + eval { $name = $opt_EncodingFrom->decode($name, Encode::FB_CROAK ) } ; + ::warning $FH->tell() - length $name, "Could not decode '" . $opt_EncodingFrom->name() . "' $type: " . cleanEval $@ + if $@; + } - if ( unpack("V", $buffer) == ZIP64_END_CENTRAL_REC_HDR_SIG ) { + # remove any BOM + $name =~ s/^\x{FEFF}//; - $fh->read($buffer, 8) == 8 - # TODO - fix this - or die "xxx" ; - my $size = unpack "Q<", $buffer; - $fh->read($buffer, $size) == $size - # TODO - fix this - or die "xxx" ; + return $name ; + } + + sub encode + { + my $name = shift ; + my $type = shift ; + my $LanguageEncodingFlag = shift ; - my $cd64 = unpack "Q<", substr($buffer, 36, 8); + return $name + if ! $opt_Encoding_Enabled; - return $cd64 ; + if ($LanguageEncodingFlag && $opt_use_LanguageEncodingFlag) + { + eval { $name = Encode::encode('utf8', $name, Encode::FB_CROAK ) } ; + ::warning $FH->tell() - length $name, "Could not encode 'utf8' $type: " . cleanEval $@ + if $@ ; + } + else + { + eval { $name = $opt_EncodingTo->encode($name, Encode::FB_CROAK ) } ; + ::warning $FH->tell() - length $name, "Could not encode '" . $opt_EncodingTo->name() . "' $type: " . cleanEval $@ + if $@; } - die "Cannot find 'Zip64 end of central directory record': 0x06054b50\nTry running with --scan option.\n" ; + return $name; } - - die "Cannot find signature for 'Zip64 end of central directory locator': 0x07064b50 \nTry running with --scan option.\n" ; } -use constant Pack_ZIP_END_CENTRAL_HDR_SIG => pack("V", ZIP_END_CENTRAL_HDR_SIG); - -sub findCentralDirectoryOffset { - my $fh = shift ; - - # Most common use-case is where there is no comment, so - # know exactly where the end of central directory record - # should be. + package Nesting; - $fh->seek(-22, SEEK_END) ; - my $here = $fh->tell(); - - my $is64bit = $here > MAX32; - my $over64bit = $here & (~ MAX32); + use Data::Dumper; - my $buffer; - $fh->read($buffer, 22) == 22 - # TODO - fix this - or die "xxx" ; + my @nestingStack = (); + my %encapsulations; + my %inner2outer; + my $encapsulationCount = 0; + my %index2entry ; + my %offset2entry ; - my $zip64 = 0; - my $centralDirOffset ; + # my %localOffset2cdEntry; - if ( unpack("V", $buffer) == ZIP_END_CENTRAL_HDR_SIG ) { - $centralDirOffset = unpack("V", substr($buffer, 16, 4)); + sub clearStack + { + @nestingStack = (); + %encapsulations = (); + %inner2outer = (); + %index2entry = (); + %offset2entry = (); + $encapsulationCount = 0; } - else { - $fh->seek(0, SEEK_END) ; - - my $fileLen = $fh->tell(); - my $want = 0 ; - - while(1) { - $want += 1024 * 32; - my $seekTo = $fileLen - $want; - if ($seekTo < 0 ) { - $seekTo = 0; - $want = $fileLen ; - } - $fh->seek( $seekTo, SEEK_SET) - # TODO - fix this - or die "xxx $!" ; - my $got; - ($got = $fh->read($buffer, $want)) == $want - # TODO - fix this - or die "xxx $got $!" ; - my $pos = rindex( $buffer, Pack_ZIP_END_CENTRAL_HDR_SIG); - if ($pos >= 0 && $want - $pos > 22) { - $here = $seekTo + $pos ; - $centralDirOffset = unpack("V", substr($buffer, $pos + 16, 4)); - my $commentLength = unpack("V", substr($buffer, $pos + 20, 2)); - $commentLength = 0 if ! defined $commentLength ; - - my $expectedEof = $fileLen - $want + $pos + 22 + $commentLength ; - # check for trailing data after end of zip - if ($expectedEof < $fileLen ) { - $TRAILING = $expectedEof ; - } - last ; - } + sub dump + { + my $indent = shift // 0; - return undef - if $want == $fileLen; + for my $offset (sort {$a <=> $b} keys %offset2entry) + { + my $leading = " " x $indent ; + say $leading . "\nOffset $offset" ; + say Dumper($offset2entry{$offset}) } } - if (full32 $centralDirOffset) + sub add { - $centralDirOffset = offsetFromZip64($fh, $here) + my $entry = shift; + + getEnclosingEntry($entry); + push @nestingStack, $entry; + $index2entry{ $entry->index } = $entry; + $offset2entry{ $entry->offsetStart } = $entry; } - elsif ($is64bit) + + sub getEnclosingEntry { - # use-case is where a 64-bit zip file doesn't use the 64-bit - # extensions. - print "EOCD not 64-bit $centralDirOffset ($here)\n" ; + my $entry = shift; + + my $filename = $entry->filename; + + pop @nestingStack + while @nestingStack && $entry->offsetStart > $nestingStack[-1]->offsetEnd ; + + my $match = undef; + + if (@nestingStack && + $entry->offsetStart >= $nestingStack[-1]->offsetStart && + $entry->offsetEnd <= $nestingStack[-1]->offsetEnd && + $entry->index != $nestingStack[-1]->index) + { + # Nested entry found + $match = $nestingStack[-1]; + push @{ $encapsulations{ $match->index } }, $entry; + $inner2outer{ $entry->index} = $match->index; + ++ $encapsulationCount; + + $entry->encapsulated(1) ; + $match->increment_childrenCount(); - push @Messages, - sprintf "Zip file > 4Gig. Expected 'Offset to Central Dir' to be 0xFFFFFFFF, got 0x%X\n", $centralDirOffset; + if ($NESTING_DEBUG) + { + say "#### nesting " . (caller(1))[3] . " index #" . $entry->index . ' "' . + $entry->outputFilename . '" [' . $entry->offsetStart . "->" . $entry->offsetEnd . "]" . + " in #" . $match->index . ' "' . + $match->outputFilename . '" [' . $match->offsetStart . "->" . $match->offsetEnd . "]" ; + } + } - $centralDirOffset += $over64bit; - $is64In32 = 1; + return $match; } - ($START_APK, $APK, $APK_LEN) = chckForAPKSigningBlock($fh, $centralDirOffset); + sub isNested + { + my $offsetStart = shift; + my $offsetEnd = shift; - return $centralDirOffset ; -} + if ($NESTING_DEBUG) + { + say "### Want: offsetStart " . ::decimalHex0x($offsetStart) . " offsetEnd " . ::decimalHex0x($offsetEnd); + for my $entry (@nestingStack) + { + say "### Have: offsetStart " . ::decimalHex0x($entry->offsetStart) . " offsetEnd " . ::decimalHex0x($entry->offsetEnd); + } + } -sub findID -{ - my $id_want = shift ; - my $data = shift; + return 0 + unless @nestingStack ; - my $XLEN = length $data ; + my @copy = @nestingStack ; - my $offset = 0 ; - while ($offset < $XLEN) { + pop @copy + while @copy && $offsetStart > $copy[-1]->offsetEnd ; - return undef - if $offset + ZIP_EXTRA_SUBFIELD_HEADER_SIZE > $XLEN ; + return @copy && + $offsetStart >= $copy[-1]->offsetStart && + $offsetEnd <= $copy[-1]->offsetEnd ; + } - my $id = substr($data, $offset, ZIP_EXTRA_SUBFIELD_ID_SIZE); - $id = unpack("v", $id); - $offset += ZIP_EXTRA_SUBFIELD_ID_SIZE; + sub getOuterEncapsulation + { + my $entry = shift; - my $subLen = unpack("v", substr($data, $offset, - ZIP_EXTRA_SUBFIELD_LEN_SIZE)); - $offset += ZIP_EXTRA_SUBFIELD_LEN_SIZE ; + my $outerIndex = $inner2outer{ $entry->index } ; return undef - if $offset + $subLen > $XLEN ; + if ! defined $outerIndex ; - return substr($data, $offset, $subLen) - if $id eq $id_want ; + return $index2entry{$outerIndex} // undef; + } - $offset += $subLen ; + sub getEncapsulations + { + my $entry = shift; + + return $encapsulations{ $entry->index } ; } - return undef ; -} + sub getFirstEncapsulation + { + my $entry = shift; + my $got = $encapsulations{ $entry->index } ; -sub _dosToUnixTime -{ - my $dt = shift; + return defined $got ? $$got[0] : undef; + } - my $year = ( ( $dt >> 25 ) & 0x7f ) + 80; - my $mon = ( ( $dt >> 21 ) & 0x0f ) - 1; - my $mday = ( ( $dt >> 16 ) & 0x1f ); + sub encapsulations + { + return \%encapsulations; + } - my $hour = ( ( $dt >> 11 ) & 0x1f ); - my $min = ( ( $dt >> 5 ) & 0x3f ); - my $sec = ( ( $dt << 1 ) & 0x3e ); + sub encapsulationCount + { + return $encapsulationCount; + } + sub childrenInCentralDir + { + # find local header entries that have children that are not referenced in the CD + # tis means it is likely a benign nextd zip file + my $entry = shift; - use POSIX 'mktime'; + for my $child (@{ $encapsulations{$entry->index} } ) + { + next + unless $child->entryType == ::ZIP_LOCAL_HDR_SIG ; - # Force mktime to return a UTC time - local $ENV{TZ} = "UTC"; + return 1 + if @{ $child->cdEntryList }; + } - my $time_t = mktime( $sec, $min, $hour, $mday, $mon, $year, 0, 0, -1 ); - return 0 if ! defined $time_t; - return $time_t; -} + return 0; + } -sub nibbles -{ - my @nibbles = ( - [ 16 => 0x1000000000000000 ], - [ 15 => 0x100000000000000 ], - [ 14 => 0x10000000000000 ], - [ 13 => 0x1000000000000 ], - [ 12 => 0x100000000000 ], - [ 11 => 0x10000000000 ], - [ 10 => 0x1000000000 ], - [ 9 => 0x100000000 ], - [ 8 => 0x10000000 ], - [ 7 => 0x1000000 ], - [ 6 => 0x100000 ], - [ 5 => 0x10000 ], - [ 4 => 0x1000 ], - [ 4 => 0x100 ], - [ 4 => 0x10 ], - [ 4 => 0x1 ], - ); - my $value = shift ; + sub entryByIndex + { + my $index = shift; + return $index2entry{$index}; + } - for my $pair (@nibbles) + sub getEntryByOffset { - my ($count, $limit) = @{ $pair }; + my $offset = shift; + return $offset2entry{$offset}; + } - return $count - if $value >= $limit ; + sub getLdEntryByOffset + { + my $offset = shift; + my $entry = $offset2entry{$offset}; + + return $entry + if $entry && $entry->entryType == ::ZIP_LOCAL_HDR_SIG; + + return undef; } -} + sub getEntriesByOffset + { + return \%offset2entry ; + } +} { - package Seen; + package SimpleTable ; + + use List::Util qw(max sum); sub new { - my $class = shift ; - - my %object = ( overlaps => [], - duplicates => [], - detail => [], - duplicate_count => 0, - overlap_count => 0, - ) ; + my $class = shift; + my %object = ( + header => [], + data => [], + columns => 0, + prefix => '# ', + ); bless \%object, $class; } - sub save + sub addHeaderRow { - my $self = shift ; - my $hdrId = shift; - my $name = shift; - my $extras = shift; + my $self = shift; + push @{ $self->{header} }, [ @_ ] ; + $self->{columns} = max($self->{columns}, scalar @_ ) ; + } + + sub addDataRow + { + my $self = shift; - my $from_offset = $extras->{LocalHdrOffset}; - my $to_offset = $from_offset ; - $to_offset += $extras->{CompressedLength} - 1 ; + push @{ $self->{data} }, [ @_ ] ; + $self->{columns} = max($self->{columns}, scalar @_ ) ; + } + + sub hasData + { + my $self = shift; - my $crc = $extras->{CRC}; + return scalar @{ $self->{data} } ; + } - $name = ::redactFilename($name) ; + sub display + { + my $self = shift; - for my $entry ( @{ $self->{detail} } ) + # work out the column widths + my @colW = (0) x $self->{columns} ; + for my $row (@{ $self->{data} }, @{ $self->{header} }) { - if ( $from_offset == $entry->{from} && $to_offset == $entry->{to} && $crc == $entry->{crc}) - { - $self->{duplicate_count} ++; - print "$hdrId: '$name' matches with $entry->{str}\n" - } - elsif ( ($from_offset >= $entry->{from} && $from_offset <= $entry->{to} ) || - ($to_offset >= $entry->{from} && $to_offset <= $entry->{to} ) - ) + my @r = @$row; + for my $ix (0 .. $self->{columns} -1) { - # die "overlap!" - # push @{ $self->{overlap} }, - $self->{overlap_count} ++; - - print "$hdrId: '$name' overlaps with $entry->{str}\n"; + $colW[$ix] = max($colW[$ix], + 3 + length( $r[$ix] ) + ); } } - # warn "ADD $from_offset $to_offset $hdrId: $name\n"; - push @{ $self->{detail} }, - { - from => $from_offset, - to => $to_offset, - length => $extras->{CompressedLength}, - id => $hdrId, - crc => $crc, - name => $name, - str => "$hdrId: '$name'", - } ; - } - - sub short_summary - { - my $self = shift; + my $width = sum(@colW) ; #+ @colW ; + my @template ; + for my $w (@colW) + { + push @template, ' ' x ($w - 3); + } - my $duplicates = $self->{duplicate_count}; - push @Messages, "$duplicates duplicate entries" - if $duplicates; + print $self->{prefix} . '-' x ($width + 1) . "\n"; - my $overlaps = $self->{overlap_count}; - push @Messages, "$overlaps overlap entries" - if $overlaps; - } + for my $row (@{ $self->{header} }) + { + my @outputRow = @template; - sub summary - { - my $self = shift ; + print $self->{prefix} . '| '; + for my $ix (0 .. $self->{columns} -1) + { + my $field = $template[$ix] ; + substr($field, 0, length($row->[$ix]), $row->[$ix]); + print $field . ' | '; + } + print "\n"; - # disable for now - return; + } - print "\n"; - for my $entry ( sort { $a->{from}->cmp($b->{from}) } @{ $self->{detail} } ) + print $self->{prefix} . '-' x ($width + 1) . "\n"; + for my $row (@{ $self->{data} }) { - my $from_offset = $entry->{from}; - my $to_offset = $entry->{to}; - my $hdrId = $entry->{id}; - my $name = $entry->{name}; - print "$hdrId\t" . $entry->{from} . "\n"; - + my @outputRow = @template; + print $self->{prefix} . '| '; + for my $ix (0 .. $self->{columns} -1) + { + my $field = $template[$ix] ; + substr($field, 0, length($row->[$ix]), $row->[$ix]); + print $field . ' | '; + } + print "\n"; } - } + print $self->{prefix} . '-' x ($width + 1) . "\n"; + print "#\n"; + } } sub Usage { - if (@_) - { - warn "$_\n" - for @_ ; - warn "\n"; - } + my $enc = TextEncoding::getNativeLocaleName(); - die < file +files. You should have a copy of the zip file definition, +L, at hand to help understand the output from this program. =head2 Default Behaviour By default the program expects to be given a well-formed zip file. It will -navigate the Zip file by first parsing the zip central directory at the end -of the file. If that is found, it will then walk through the zip records -starting at the beginning of the file. Any badly formed zip data structures -encountered are likely to terminate the program. - -If the program finds any structural problems with the zip file it will -print a summary at the end of the output report. The set of error cases -reported is very much a work in progress, so don't rely on this feature to -find all the possible errors in a zip file. If you have suggestions for -use-cases where this could be enhanced please consider creating an -enhancement request (see L<"SUPPORT">). - -Date/time fields are found in zip files are displayed in local time. Use -the C<--utc> option to display these fields in Coordinated Universal Time -(UTC). - -=head2 Scan-Mode - -If you do have a potentially corrupt zip file, particulatly where the -central directory at the end of the file is absent/incomplete, you can try -usng the C<--scan> option to search for zip records that are still present. - -When Scan-mode is enabled, the program will walk the zip file from the -start, blindly looking for the 4-byte signatures that preceed each of the -zip data structures. If it finds any of the recognised signatures it will -attempt to dump the associated zip record. For very large zip files, this -operation can take a long time to run. - -Note that the 4-byte signatures used in zip files can sometimes match with -random data stored in the zip file, so care is needed interpreting the -results. +navigate the zip file by first parsing the zip C at the end +of the file. If the C is found, it will then walk +sequentally through the zip records starting at the beginning of the file. +See L for other processing options. + +If the program finds any structural or portability issues with the zip file +it will print a message at the point it finds the issue and/or in a summary +at the end of the output report. Whilst the set of issues that can be +detected it exhaustive, don't assume that this program can find I the +possible issues in a zip file - there are likely edge conditions that need +to be addressed. + +If you have suggestions for use-cases where this could be enhanced please +consider creating an enhancement request (see L<"SUPPORT">). + +=head3 Date & Time fields + +Date/time fields found in zip files are displayed in local time. Use the +C<--utc> option to display these fields in Coordinated Universal Time (UTC). + +=head3 Filenames & Comments + +Filenames and comments are decoded/encoded using the default system +encoding of the host running C. When the sytem encoding cannot +be determined C will be used. + +The exceptions are + +=over 5 + +=item * + +when the C is set in the zip file, the +filename/comment fields are assumed to be encoded in UTF-8. + +=item * + +the definition for the metadata field implies UTF-8 charset encoding + +=back + +See L<"Filename Encoding Issues"> and L for ways to control the encoding of filename/comment fields. =head2 OPTIONS +=head3 General Options + =over 5 -=item -h +=item C<-h>, C<--help> Display help -=item --redact +=item C<--redact> -Obscure filenames in the output. Handy for the use case where the zip files -contains sensitive data that cannot be shared. +Obscure filenames and payload data in the output. Handy for the use case +where the zip files contains sensitive data that cannot be shared. -=item --scan +=item C<--scan> -Walk the zip file loking for possible zip records. Can be error-prone. -See L<"Scan-Mode"> +Pessimistically scan the zip file loking for possible zip records. Can be +error-prone. For very large zip files this option is slow. Consider using +the C<--walk> option first. See L<"Advanced Analysis Options"> -=item --utc +=item C<--utc> -By default, date/time fields are displayed in local time. Use this option -to display them in in Coordinated Universal Time (UTC). +By default, date/time fields are displayed in local time. Use this option to +display them in in Coordinated Universal Time (UTC). -=item -v +=item C<-v> Enable Verbose mode. See L<"Verbose Output">. -=item --version +=item C<--version> Display version number of the program and exit. +=item C<--walk> + +Optimistically walk the zip file looking for possible zip records. +See L<"Advanced Analysis Options"> + +=back + +=head3 Filename & Comment Encoding Options + +See L<"Filename Encoding Issues"> + +=over 5 + +=item C<--encoding name> + +Use encoding "name" when reading filenames/comments from the zip file. + +When this option is not specified the default the system encoding is used. + +=item C< --no-encoding> + +Disable all filename & comment encoding/decoding. Filenames/comments are +processed as byte streams. + +This option is not enabled by default. + +=item C<--output-encoding name> + +Use encoding "name" when writing filename/comments to the display. By +default the system encoding will be used. + +=item C<--language-encoding>, C<--no-language-encoding> + +Modern zip files set a metadata entry in zip files, called the "Language +encoding flag", when they write filenames/comments encoded in UTF-8. + +Occasionally some applications set the C but write +data that is not UTF-8 in the filename/comment fields of the zip file. This +will usually result in garbled text being output for the +filenames/comments. + +To deal with this use-case, set the C<--no-language-encoding> option and, +if needed, set the C<--encoding name> option to encoding actually used. + +Default is C<--language-encoding>. + +=item C<--debug-encoding> + +Display extra debugging info when a filename/comment encoding has changed. + +=back + +=head3 Message Control Options + +=over 5 + +=item C<--messages>, C<--no-messages> + +Enable/disable the output of all info/warning/error messages. + +Disabling messages means that no checks are carried out to check that the +zip file is well-formed. + +Default is enabled. + +=item C<--exit-bitmask>, C<--no-exit-bitmask> + +Enable/disable exit status bitmask for messages. Default disabled. +Bitmask values are: 1 for info, 2 for warning and 4 for error. + =back + =head2 Default Output -By default zipdetails will output the details of the zip file in three -columns. +By default C will output each metadata field from the zip file +in three columns. + +=over 5 + +=item 1 + +The offset, in hex, to the start of the field relative to the beginning of +the file. + +=item 2 + +The name of the field. + +=item 3 + +Detailed information about the contents of the field. The format depends on +the type of data: =over 5 -=item Column 1 +=item * Numeric Values + +If the field contains an 8-bit, 16-bit, 32-bit or 64-bit numeric value, it +will be displayed in both hex and decimal -- for example "C<002A (42)>". -This contains the offset from the start of the file in hex. +Note that Zip files store most numeric values in I encoding +(there area few rare instances where I is used). The value read +from the zip file will have the I encoding removed before being +displayed. -=item Column 2 +Next, is an optional description of what the numeric value means. -This contains a textual description of the field. +=item * String -=item Column 3 +If the field corresponds to a printable string, it will be output enclosed +in single quotes. -If the field contains a numeric value it will be displayed in hex. Zip -stores most numbers in little-endian format - the value displayed will have -the little-endian encoding removed. +=item * Binary Data -Next, is an optional description of what the value means. +The term I is just a catch-all for all other metadata in the +zip file. This data is displayed as a series of ascii-hex byte values in +the same order they are stored in the zip file. =back -For example, assuming you have a zip file with two entries, like this +=back + +For example, assuming you have a zip file, C, with one entry - $ unzip -l test.zip - Archive: setup/test.zip + $ unzip -l test.zip + Archive: test.zip Length Date Time Name --------- ---------- ----- ---- - 6 2021-03-23 18:52 latters.txt - 6 2021-03-23 18:52 numbers.txt + 446 2023-03-22 20:03 lorem.txt --------- ------- - 12 2 files + 446 1 file Running C will gives this output $ zipdetails test.zip - 0000 LOCAL HEADER #1 04034B50 - 0004 Extract Zip Spec 0A '1.0' - 0005 Extract OS 00 'MS-DOS' - 0006 General Purpose Flag 0000 - 0008 Compression Method 0000 'Stored' - 000A Last Mod Time 5277983D 'Tue Mar 23 19:01:58 2021' - 000E CRC 0F8A149C - 0012 Compressed Length 00000006 - 0016 Uncompressed Length 00000006 - 001A Filename Length 000B - 001C Extra Length 0000 - 001E Filename 'letters.txt' - 0029 PAYLOAD abcde. - - 002F LOCAL HEADER #2 04034B50 - 0033 Extract Zip Spec 0A '1.0' - 0034 Extract OS 00 'MS-DOS' - 0035 General Purpose Flag 0000 - 0037 Compression Method 0000 'Stored' - 0039 Last Mod Time 5277983D 'Tue Mar 23 19:01:58 2021' - 003D CRC 261DAFE6 - 0041 Compressed Length 00000006 - 0045 Uncompressed Length 00000006 - 0049 Filename Length 000B - 004B Extra Length 0000 - 004D Filename 'numbers.txt' - 0058 PAYLOAD 12345. - - 005E CENTRAL HEADER #1 02014B50 - 0062 Created Zip Spec 1E '3.0' - 0063 Created OS 03 'Unix' - 0064 Extract Zip Spec 0A '1.0' - 0065 Extract OS 00 'MS-DOS' - 0066 General Purpose Flag 0000 - 0068 Compression Method 0000 'Stored' - 006A Last Mod Time 5277983D 'Tue Mar 23 19:01:58 2021' - 006E CRC 0F8A149C - 0072 Compressed Length 00000006 - 0076 Uncompressed Length 00000006 - 007A Filename Length 000B - 007C Extra Length 0000 - 007E Comment Length 0000 - 0080 Disk Start 0000 - 0082 Int File Attributes 0001 - [Bit 0] 1 Text Data - 0084 Ext File Attributes 81B40000 - 0088 Local Header Offset 00000000 - 008C Filename 'letters.txt' - - 0097 CENTRAL HEADER #2 02014B50 - 009B Created Zip Spec 1E '3.0' - 009C Created OS 03 'Unix' - 009D Extract Zip Spec 0A '1.0' - 009E Extract OS 00 'MS-DOS' - 009F General Purpose Flag 0000 - 00A1 Compression Method 0000 'Stored' - 00A3 Last Mod Time 5277983D 'Tue Mar 23 19:01:58 2021' - 00A7 CRC 261DAFE6 - 00AB Compressed Length 00000006 - 00AF Uncompressed Length 00000006 - 00B3 Filename Length 000B - 00B5 Extra Length 0000 - 00B7 Comment Length 0000 - 00B9 Disk Start 0000 - 00BB Int File Attributes 0001 - [Bit 0] 1 Text Data - 00BD Ext File Attributes 81B40000 - 00C1 Local Header Offset 0000002F - 00C5 Filename 'numbers.txt' - - 00D0 END CENTRAL HEADER 06054B50 - 00D4 Number of this disk 0000 - 00D6 Central Dir Disk no 0000 - 00D8 Entries in this disk 0002 - 00DA Total Entries 0002 - 00DC Size of Central Dir 00000072 - 00E0 Offset to Central Dir 0000005E - 00E4 Comment Length 0000 - Done + 0000 LOCAL HEADER #1 04034B50 (67324752) + 0004 Extract Zip Spec 14 (20) '2.0' + 0005 Extract OS 00 (0) 'MS-DOS' + 0006 General Purpose Flag 0000 (0) + [Bits 1-2] 0 'Normal Compression' + 0008 Compression Method 0008 (8) 'Deflated' + 000A Modification Time 5676A072 (1450614898) 'Wed Mar 22 20:03:36 2023' + 000E CRC F90EE7FF (4178503679) + 0012 Compressed Size 0000010E (270) + 0016 Uncompressed Size 000001BE (446) + 001A Filename Length 0009 (9) + 001C Extra Length 0000 (0) + 001E Filename 'lorem.txt' + 0027 PAYLOAD + + 0135 CENTRAL HEADER #1 02014B50 (33639248) + 0139 Created Zip Spec 1E (30) '3.0' + 013A Created OS 03 (3) 'Unix' + 013B Extract Zip Spec 14 (20) '2.0' + 013C Extract OS 00 (0) 'MS-DOS' + 013D General Purpose Flag 0000 (0) + [Bits 1-2] 0 'Normal Compression' + 013F Compression Method 0008 (8) 'Deflated' + 0141 Modification Time 5676A072 (1450614898) 'Wed Mar 22 20:03:36 2023' + 0145 CRC F90EE7FF (4178503679) + 0149 Compressed Size 0000010E (270) + 014D Uncompressed Size 000001BE (446) + 0151 Filename Length 0009 (9) + 0153 Extra Length 0000 (0) + 0155 Comment Length 0000 (0) + 0157 Disk Start 0000 (0) + 0159 Int File Attributes 0001 (1) + [Bit 0] 1 'Text Data' + 015B Ext File Attributes 81ED0000 (2179792896) + [Bits 16-24] 01ED (493) 'Unix attrib: rwxr-xr-x' + [Bits 28-31] 08 (8) 'Regular File' + 015F Local Header Offset 00000000 (0) + 0163 Filename 'lorem.txt' + + 016C END CENTRAL HEADER 06054B50 (101010256) + 0170 Number of this disk 0000 (0) + 0172 Central Dir Disk no 0000 (0) + 0174 Entries in this disk 0001 (1) + 0176 Total Entries 0001 (1) + 0178 Size of Central Dir 00000037 (55) + 017C Offset to Central Dir 00000135 (309) + 0180 Comment Length 0000 (0) + # + # Done =head2 Verbose Output -If the C<-v> option is present, column 1 is expanded to include +If the C<-v> option is present, the metadata output is split into the +following columns: =over 5 -=item * +=item 1 -The offset from the start of the file in hex. +The offset, in hex, to the start of the field relative to the beginning of +the file. -=item * +=item 2 -The length of the field in hex. +The offset, in hex, to the end of the field relative to the beginning of +the file. -=item * +=item 3 -A hex dump of the bytes in field in the order they are stored in the zip -file. +The length, in hex, of the field. + +=item 4 + +A hex dump of the bytes in field in the order they are stored in the zip file. + +=item 5 + +A textual description of the field. + +=item 6 + +Information about the contents of the field. See the description in the +L for more details. =back -Here is the same zip file dumped using the C C<-v> option: +Here is the same zip file, C, dumped using the C +C<-v> option: $ zipdetails -v test.zip - 0000 0004 50 4B 03 04 LOCAL HEADER #1 04034B50 - 0004 0001 0A Extract Zip Spec 0A '1.0' - 0005 0001 00 Extract OS 00 'MS-DOS' - 0006 0002 00 00 General Purpose Flag 0000 - 0008 0002 00 00 Compression Method 0000 'Stored' - 000A 0004 3D 98 77 52 Last Mod Time 5277983D 'Tue Mar 23 19:01:58 2021' - 000E 0004 9C 14 8A 0F CRC 0F8A149C - 0012 0004 06 00 00 00 Compressed Length 00000006 - 0016 0004 06 00 00 00 Uncompressed Length 00000006 - 001A 0002 0B 00 Filename Length 000B - 001C 0002 00 00 Extra Length 0000 - 001E 000B 6C 65 74 74 Filename 'letters.txt' - 65 72 73 2E - 74 78 74 - 0029 0006 61 62 63 64 PAYLOAD abcde. - 65 0A - - 002F 0004 50 4B 03 04 LOCAL HEADER #2 04034B50 - 0033 0001 0A Extract Zip Spec 0A '1.0' - 0034 0001 00 Extract OS 00 'MS-DOS' - 0035 0002 00 00 General Purpose Flag 0000 - 0037 0002 00 00 Compression Method 0000 'Stored' - 0039 0004 3D 98 77 52 Last Mod Time 5277983D 'Tue Mar 23 19:01:58 2021' - 003D 0004 E6 AF 1D 26 CRC 261DAFE6 - 0041 0004 06 00 00 00 Compressed Length 00000006 - 0045 0004 06 00 00 00 Uncompressed Length 00000006 - 0049 0002 0B 00 Filename Length 000B - 004B 0002 00 00 Extra Length 0000 - 004D 000B 6E 75 6D 62 Filename 'numbers.txt' - 65 72 73 2E - 74 78 74 - 0058 0006 31 32 33 34 PAYLOAD 12345. - 35 0A - - 005E 0004 50 4B 01 02 CENTRAL HEADER #1 02014B50 - 0062 0001 1E Created Zip Spec 1E '3.0' - 0063 0001 03 Created OS 03 'Unix' - 0064 0001 0A Extract Zip Spec 0A '1.0' - 0065 0001 00 Extract OS 00 'MS-DOS' - 0066 0002 00 00 General Purpose Flag 0000 - 0068 0002 00 00 Compression Method 0000 'Stored' - 006A 0004 3D 98 77 52 Last Mod Time 5277983D 'Tue Mar 23 19:01:58 2021' - 006E 0004 9C 14 8A 0F CRC 0F8A149C - 0072 0004 06 00 00 00 Compressed Length 00000006 - 0076 0004 06 00 00 00 Uncompressed Length 00000006 - 007A 0002 0B 00 Filename Length 000B - 007C 0002 00 00 Extra Length 0000 - 007E 0002 00 00 Comment Length 0000 - 0080 0002 00 00 Disk Start 0000 - 0082 0002 01 00 Int File Attributes 0001 - [Bit 0] 1 Text Data - 0084 0004 00 00 B4 81 Ext File Attributes 81B40000 - 0088 0004 00 00 00 00 Local Header Offset 00000000 - 008C 000B 6C 65 74 74 Filename 'letters.txt' - 65 72 73 2E - 74 78 74 - - 0097 0004 50 4B 01 02 CENTRAL HEADER #2 02014B50 - 009B 0001 1E Created Zip Spec 1E '3.0' - 009C 0001 03 Created OS 03 'Unix' - 009D 0001 0A Extract Zip Spec 0A '1.0' - 009E 0001 00 Extract OS 00 'MS-DOS' - 009F 0002 00 00 General Purpose Flag 0000 - 00A1 0002 00 00 Compression Method 0000 'Stored' - 00A3 0004 3D 98 77 52 Last Mod Time 5277983D 'Tue Mar 23 19:01:58 2021' - 00A7 0004 E6 AF 1D 26 CRC 261DAFE6 - 00AB 0004 06 00 00 00 Compressed Length 00000006 - 00AF 0004 06 00 00 00 Uncompressed Length 00000006 - 00B3 0002 0B 00 Filename Length 000B - 00B5 0002 00 00 Extra Length 0000 - 00B7 0002 00 00 Comment Length 0000 - 00B9 0002 00 00 Disk Start 0000 - 00BB 0002 01 00 Int File Attributes 0001 - [Bit 0] 1 Text Data - 00BD 0004 00 00 B4 81 Ext File Attributes 81B40000 - 00C1 0004 2F 00 00 00 Local Header Offset 0000002F - 00C5 000B 6E 75 6D 62 Filename 'numbers.txt' - 65 72 73 2E - 74 78 74 - - 00D0 0004 50 4B 05 06 END CENTRAL HEADER 06054B50 - 00D4 0002 00 00 Number of this disk 0000 - 00D6 0002 00 00 Central Dir Disk no 0000 - 00D8 0002 02 00 Entries in this disk 0002 - 00DA 0002 02 00 Total Entries 0002 - 00DC 0004 72 00 00 00 Size of Central Dir 00000072 - 00E0 0004 5E 00 00 00 Offset to Central Dir 0000005E - 00E4 0002 00 00 Comment Length 0000 - Done + 0000 0003 0004 50 4B 03 04 LOCAL HEADER #1 04034B50 (67324752) + 0004 0004 0001 14 Extract Zip Spec 14 (20) '2.0' + 0005 0005 0001 00 Extract OS 00 (0) 'MS-DOS' + 0006 0007 0002 00 00 General Purpose Flag 0000 (0) + [Bits 1-2] 0 'Normal Compression' + 0008 0009 0002 08 00 Compression Method 0008 (8) 'Deflated' + 000A 000D 0004 72 A0 76 56 Modification Time 5676A072 (1450614898) 'Wed Mar 22 20:03:36 2023' + 000E 0011 0004 FF E7 0E F9 CRC F90EE7FF (4178503679) + 0012 0015 0004 0E 01 00 00 Compressed Size 0000010E (270) + 0016 0019 0004 BE 01 00 00 Uncompressed Size 000001BE (446) + 001A 001B 0002 09 00 Filename Length 0009 (9) + 001C 001D 0002 00 00 Extra Length 0000 (0) + 001E 0026 0009 6C 6F 72 65 Filename 'lorem.txt' + 6D 2E 74 78 + 74 + 0027 0134 010E ... PAYLOAD + + 0135 0138 0004 50 4B 01 02 CENTRAL HEADER #1 02014B50 (33639248) + 0139 0139 0001 1E Created Zip Spec 1E (30) '3.0' + 013A 013A 0001 03 Created OS 03 (3) 'Unix' + 013B 013B 0001 14 Extract Zip Spec 14 (20) '2.0' + 013C 013C 0001 00 Extract OS 00 (0) 'MS-DOS' + 013D 013E 0002 00 00 General Purpose Flag 0000 (0) + [Bits 1-2] 0 'Normal Compression' + 013F 0140 0002 08 00 Compression Method 0008 (8) 'Deflated' + 0141 0144 0004 72 A0 76 56 Modification Time 5676A072 (1450614898) 'Wed Mar 22 20:03:36 2023' + 0145 0148 0004 FF E7 0E F9 CRC F90EE7FF (4178503679) + 0149 014C 0004 0E 01 00 00 Compressed Size 0000010E (270) + 014D 0150 0004 BE 01 00 00 Uncompressed Size 000001BE (446) + 0151 0152 0002 09 00 Filename Length 0009 (9) + 0153 0154 0002 00 00 Extra Length 0000 (0) + 0155 0156 0002 00 00 Comment Length 0000 (0) + 0157 0158 0002 00 00 Disk Start 0000 (0) + 0159 015A 0002 01 00 Int File Attributes 0001 (1) + [Bit 0] 1 'Text Data' + 015B 015E 0004 00 00 ED 81 Ext File Attributes 81ED0000 (2179792896) + [Bits 16-24] 01ED (493) 'Unix attrib: rwxr-xr-x' + [Bits 28-31] 08 (8) 'Regular File' + 015F 0162 0004 00 00 00 00 Local Header Offset 00000000 (0) + 0163 016B 0009 6C 6F 72 65 Filename 'lorem.txt' + 6D 2E 74 78 + 74 + + 016C 016F 0004 50 4B 05 06 END CENTRAL HEADER 06054B50 (101010256) + 0170 0171 0002 00 00 Number of this disk 0000 (0) + 0172 0173 0002 00 00 Central Dir Disk no 0000 (0) + 0174 0175 0002 01 00 Entries in this disk 0001 (1) + 0176 0177 0002 01 00 Total Entries 0001 (1) + 0178 017B 0004 37 00 00 00 Size of Central Dir 00000037 (55) + 017C 017F 0004 35 01 00 00 Offset to Central Dir 00000135 (309) + 0180 0181 0002 00 00 Comment Length 0000 (0) + # + # Done + +=head2 Advanced Analysis + +If you have a corrupt or non-standard zip file, particulatly one where the +C metadata at the end of the file is absent/incomplete, you +can use either the C<--walk> option or the C<--scan> option to search for +any zip metadata that is still present in the file. + +When either of these options is enabled, this program will bypass the +initial step of reading the C at the end of the file and +simply scan the zip file sequentially from the start of the file looking +for zip metedata records. Although this can be error prone, for the most +part it will find any zip file metadata that is still present in the file. + +The difference between the two options is how aggressive the sequential +scan is: C<--walk> is optimistic, while C<--scan> is pessimistic. + +To understand the difference in more detail you need to know a bit about +how zip file metadata is structured. Under the hood, a zip file uses a +series of 4-byte signatures to flag the start of a each of the metadata +records it uses. When the C<--walk> or the C<--scan> option is enabled both +work identically by scanning the file from the beginning looking for any +the of these valid 4-byte metadata signatures. When a 4-byte signature is +found both options will blindly assume that it has found a vald metadata +record and display it. + +=head3 C<--walk> + +The C<--walk> option optimistically assumes that it has found a real zip +metatada record and so starts the scan for the next record directly after +the record it has just output. + +=head3 C<--scan> + +The C<--scan> option is pessimistic and assumes the 4-byte signature +sequence may have been a false-positive, so before starting the scan for +the next resord, it will rewind to the location in the file directly after +the 4-byte sequecce it just processed. This means it will rescan data that +has already been processed. For very lage zip files the C<--scan> option +can be really realy slow, so trying the C<--walk> option first. + +B: If the zip file being processed contains one or more +nested zip files, and the outer zip file uses the C compression +method, the C<--scan> option will display the zip metadata for both the +outer & inner zip files. + +=head2 Filename Encoding Issues + +Sometimes when displaying the contents of a zip file the filenames (or +comments) appear to be garbled. This section walks through the reasons and +mitigations that can be applied to work around these issues. + +=head3 Background + +When zip files were first created in the 1980's, there was no Unicode or +UTF-8. Issues around character set encoding interoperability were not a +major concern. + +Initially, the only official encoding supported in zip files was IBM Code +Page 437 (AKA C). As time went on users in locales where C +wasn't appropriate stored filenames in the encoding native to their locale. +If you were running a system that matched the locale of the zip file, all +was well. If not, you had to post-process the filenames after unzipping the +zip file. + +Fast forward to the introduction of Unicode and UTF-8 encoding. The +approach now used by all major zip implementations is to set the C (also known as C) in the zip file metadata to signal +that a filename/comment is encoded in UTF-8. + +To ensure maximum interoperability when sharing zip files store 7-bit +filenames as-is in the zip file. For anything else the C bit needs to +be set and the filename is encoded in UTF-8. Although this rule is kept to +for the most part, there are exceptions out in the wild. + +=head3 Dealing with Encoding Errors + +The most common filename encoding issue is where the C bit is not set and +the filename is stored in a character set that doesnt't match the system +encoding. This mostly impacts legacy zip files that predate the +introduction of Unicode. + +To deal with this issue you first need to know what encoding was used in +the zip file. For example, if the filename is encoded in C you +can display the filenames using the C<--encoding> option + + zipdetails --encoding ISO-8859-1 myfile.zip + +A less common variation of this is where the C bit is set, signalling +that the filename will be encoded in UTF-8, but the filename is not encoded +in UTF-8. To deal with this scenarion, use the C<--no-language-encoding> +option along with the C<--encoding> option. + =head1 LIMITATIONS @@ -2760,19 +8006,67 @@ The following zip file features are not =item * -Multi-part archives. +Multi-part/Split/Spanned Zip Archives. + +This program cannot give an overall report on the combined parts of a +multi-part zip file. + +The best you can do is run with either the C<--scan> or C<--walk> options +against individual parts. Some will contains zipfile metadata which will be +detected and some will only contain compressed payload data. + + +=item * + +Encrypted Central Directory + +When pkzip I is enabled in a zip file this program can +still parse most of the metadata in the zip file. The exception is when the +C of a zip file is also encrypted. This program cannot +parse any metadata from an encrypted C. + +=item * + +Corrupt Zip files + +When C encounters a corrupt zip file, it will do one or more of +the following + +=over 5 + +=item * + +Display details of the corruption and carry on + +=item * + +Display details of the corruption and terminate =item * -The strong encryption features defined in the L document. +Terminate with a generic message + +=back + +Which of the above is output is dependent in the severity of the +corruption. =back =head1 TODO -Error handling is a work in progress. If the program encounters a problem -reading a zip file it is likely to terminate with an unhelpful error -message. +=head2 JSON/YML Output + +Output some of the zip file metadata as a JSON or YML document. + +=head2 Corrupt Zip files + +Although the detection and reporting of most of the common corruption use-cases is +present in C, there are likely to be other edge cases that need +to be supported. + +If you have a corrupt Zip file that isn't being processed properly, please +report it (see L<"SUPPORT">). =head1 SUPPORT @@ -2783,17 +8077,18 @@ L. +L. An alternative reference is the Info-Zip appnote. This is available from L For details of WinZip AES encryption see L. +Encryption Specification AE-1 and +AE-2|https://www.winzip.com/en/support/aes-encryption/>. The C program that comes with the info-zip distribution -(L) can also display details of the structure of -a zip file. +(L) can also display details of the structure of a zip +file. =head1 AUTHOR @@ -2802,7 +8097,7 @@ Paul Marquess F. =head1 COPYRIGHT -Copyright (c) 2011-2022 Paul Marquess. All rights reserved. +Copyright (c) 2011-2024 Paul Marquess. All rights reserved. -This program is free software; you can redistribute it and/or modify it -under the same terms as Perl itself. +This program is free software; you can redistribute it and/or modify it under +the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/Compress/Zlib.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/Compress/Zlib.pm,v diff -u -p -a -u -p -r1.8 Zlib.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/Compress/Zlib.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/Compress/Zlib.pm 22 Jan 2025 00:37:42 -0000 @@ -7,17 +7,17 @@ use Carp ; use IO::Handle ; use Scalar::Util qw(dualvar); -use IO::Compress::Base::Common 2.204 ; -use Compress::Raw::Zlib 2.204 ; -use IO::Compress::Gzip 2.204 ; -use IO::Uncompress::Gunzip 2.204 ; +use IO::Compress::Base::Common 2.212 ; +use Compress::Raw::Zlib 2.212 ; +use IO::Compress::Gzip 2.212 ; +use IO::Uncompress::Gunzip 2.212 ; use strict ; use warnings ; use bytes ; our ($VERSION, $XS_VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); -$VERSION = '2.204'; +$VERSION = '2.212'; $XS_VERSION = $VERSION; $VERSION = eval $VERSION; @@ -461,7 +461,7 @@ sub inflate package Compress::Zlib ; -use IO::Compress::Gzip::Constants 2.204 ; +use IO::Compress::Gzip::Constants 2.212 ; sub memGzip($) { @@ -1509,7 +1509,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 1995-2023 Paul Marquess. All rights reserved. +Copyright (c) 1995-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/File/GlobMapper.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/File/GlobMapper.pm,v diff -u -p -a -u -p -r1.6 GlobMapper.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/File/GlobMapper.pm 15 Feb 2023 01:36:18 -0000 1.6 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/File/GlobMapper.pm 22 Jan 2025 00:37:42 -0000 @@ -10,14 +10,14 @@ BEGIN { if ($] < 5.006) { - require File::BSDGlob; import File::BSDGlob qw(:glob) ; - $CSH_GLOB = File::BSDGlob::GLOB_CSH() ; + require File::BSDGlob; File::BSDGlob->import(':glob'); + $CSH_GLOB = File::BSDGlob::GLOB_CSH(); *globber = \&File::BSDGlob::csh_glob; } else { - require File::Glob; import File::Glob qw(:glob) ; - $CSH_GLOB = File::Glob::GLOB_CSH() ; + require File::Glob; File::Glob->import(':glob'); + $CSH_GLOB = File::Glob::GLOB_CSH(); #*globber = \&File::Glob::bsd_glob; *globber = \&File::Glob::csh_glob; } Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Base.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Base.pm,v diff -u -p -a -u -p -r1.8 Base.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Base.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Base.pm 22 Jan 2025 00:37:42 -0000 @@ -6,7 +6,7 @@ require 5.006 ; use strict ; use warnings; -use IO::Compress::Base::Common 2.204 ; +use IO::Compress::Base::Common 2.212 ; use IO::File (); ; use Scalar::Util (); @@ -20,7 +20,7 @@ use Symbol(); our (@ISA, $VERSION); @ISA = qw(IO::File Exporter); -$VERSION = '2.204'; +$VERSION = '2.212'; #Can't locate object method "SWASHNEW" via package "utf8" (perhaps you forgot to load "utf8"?) at .../ext/Compress-Zlib/Gzip/blib/lib/Compress/Zlib/Common.pm line 16. @@ -1051,7 +1051,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Bzip2.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Bzip2.pm,v diff -u -p -a -u -p -r1.8 Bzip2.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Bzip2.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Bzip2.pm 22 Jan 2025 00:37:42 -0000 @@ -5,16 +5,16 @@ use warnings; use bytes; require Exporter ; -use IO::Compress::Base 2.204 ; +use IO::Compress::Base 2.212 ; -use IO::Compress::Base::Common 2.204 qw(); -use IO::Compress::Adapter::Bzip2 2.204 ; +use IO::Compress::Base::Common 2.212 qw(); +use IO::Compress::Adapter::Bzip2 2.212 ; our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $Bzip2Error); -$VERSION = '2.204'; +$VERSION = '2.212'; $Bzip2Error = ''; @ISA = qw(IO::Compress::Base Exporter); @@ -51,7 +51,7 @@ sub getExtraParams { my $self = shift ; - use IO::Compress::Base::Common 2.204 qw(:Parse); + use IO::Compress::Base::Common 2.212 qw(:Parse); return ( 'blocksize100k' => [IO::Compress::Base::Common::Parse_unsigned, 1], @@ -387,7 +387,7 @@ Defaults to 0. =back -=head2 Examples +=head2 Oneshot Examples Here are a few example that show the capabilities of the module. @@ -466,7 +466,10 @@ The format of the constructor for Cnew( $output [,OPTS] ) or die "IO::Compress::Bzip2 failed: $Bzip2Error\n"; -It returns an C object on success and undef on failure. +The constructor takes one mandatory parameter, C<$output>, defined below and +zero or more C, defined in L. + +It returns an C object on success and C on failure. The variable C<$Bzip2Error> will contain an error message on failure. If you are running Perl 5.005 or better the object, C<$z>, returned from @@ -479,6 +482,18 @@ these forms $z->print("hello world\n"); print $z "hello world\n"; +Below is a simple exaple of using the OO interface to create an output file +C and write some data to it. + + my $filename = "myfile.bz2"; + my $z = IO::Compress::Bzip2->new($filename) + or die "IO::Compress::Bzip2 failed: $Bzip2Error\n"; + + $z->print("abcde"); + $z->close(); + +See the L for more. + The mandatory parameter C<$output> is used to control the destination of the compressed data. This parameter can take one of these forms. @@ -576,7 +591,52 @@ This is a placeholder option. =head2 Examples -TODO +=head3 Streaming + +This very simple command line example demonstrates the streaming capabilities +of the module. The code reads data from STDIN or all the files given on the +commandline, compresses it, and writes the compressed data to STDOUT. + + use strict ; + use warnings ; + use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ; + + my $z = IO::Compress::Bzip2->new("-", Stream => 1) + or die "IO::Compress::Bzip2 failed: $Bzip2Error\n"; + + while (<>) { + $z->print("abcde"); + } + $z->close(); + +Note the use of C<"-"> to means C. Alternatively you can use C<\*STDOUT>. + +=head3 Compressing a file from the filesystem + +To read the contents of the file C and write the compressed +data to the file C there are a few options + +Start by creating the compression object and opening the input file + + use strict ; + use warnings ; + use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ; + + my $input = "file1.txt"; + my $z = IO::Compress::Bzip2->new("file1.txt.bz2") + or die "IO::Compress::Bzip2 failed: $Bzip2Error\n"; + + # open the input file + open my $fh, "<", "file1.txt" + or die "Cannot open file1.txt: $!\n"; + + # loop through the input file & write to the compressed file + while (<$fh>) { + $z->print($_); + } + + # not forgetting to close the compressed file + $z->close(); =head1 Methods @@ -818,7 +878,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Deflate.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Deflate.pm,v diff -u -p -a -u -p -r1.8 Deflate.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Deflate.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Deflate.pm 22 Jan 2025 00:37:42 -0000 @@ -8,16 +8,16 @@ use bytes; require Exporter ; -use IO::Compress::RawDeflate 2.204 (); -use IO::Compress::Adapter::Deflate 2.204 ; +use IO::Compress::RawDeflate 2.212 (); +use IO::Compress::Adapter::Deflate 2.212 ; -use IO::Compress::Zlib::Constants 2.204 ; -use IO::Compress::Base::Common 2.204 qw(); +use IO::Compress::Zlib::Constants 2.212 ; +use IO::Compress::Base::Common 2.212 qw(); our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, %DEFLATE_CONSTANTS, $DeflateError); -$VERSION = '2.204'; +$VERSION = '2.212'; $DeflateError = ''; @ISA = qw(IO::Compress::RawDeflate Exporter); @@ -354,7 +354,7 @@ Defaults to 0. =back -=head2 Examples +=head2 Oneshot Examples Here are a few example that show the capabilities of the module. @@ -433,7 +433,10 @@ The format of the constructor for Cnew( $output [,OPTS] ) or die "IO::Compress::Deflate failed: $DeflateError\n"; -It returns an C object on success and undef on failure. +The constructor takes one mandatory parameter, C<$output>, defined below and +zero or more C, defined in L. + +It returns an C object on success and C on failure. The variable C<$DeflateError> will contain an error message on failure. If you are running Perl 5.005 or better the object, C<$z>, returned from @@ -446,6 +449,18 @@ these forms $z->print("hello world\n"); print $z "hello world\n"; +Below is a simple exaple of using the OO interface to create an output file +C and write some data to it. + + my $filename = "myfile.1950"; + my $z = IO::Compress::Deflate->new($filename) + or die "IO::Compress::Deflate failed: $DeflateError\n"; + + $z->print("abcde"); + $z->close(); + +See the L for more. + The mandatory parameter C<$output> is used to control the destination of the compressed data. This parameter can take one of these forms. @@ -585,7 +600,52 @@ This is a placeholder option. =head2 Examples -TODO +=head3 Streaming + +This very simple command line example demonstrates the streaming capabilities +of the module. The code reads data from STDIN or all the files given on the +commandline, compresses it, and writes the compressed data to STDOUT. + + use strict ; + use warnings ; + use IO::Compress::Deflate qw(deflate $DeflateError) ; + + my $z = IO::Compress::Deflate->new("-", Stream => 1) + or die "IO::Compress::Deflate failed: $DeflateError\n"; + + while (<>) { + $z->print("abcde"); + } + $z->close(); + +Note the use of C<"-"> to means C. Alternatively you can use C<\*STDOUT>. + +=head3 Compressing a file from the filesystem + +To read the contents of the file C and write the compressed +data to the file C there are a few options + +Start by creating the compression object and opening the input file + + use strict ; + use warnings ; + use IO::Compress::Deflate qw(deflate $DeflateError) ; + + my $input = "file1.txt"; + my $z = IO::Compress::Deflate->new("file1.txt.1950") + or die "IO::Compress::Deflate failed: $DeflateError\n"; + + # open the input file + open my $fh, "<", "file1.txt" + or die "Cannot open file1.txt: $!\n"; + + # loop through the input file & write to the compressed file + while (<$fh>) { + $z->print($_); + } + + # not forgetting to close the compressed file + $z->close(); =head1 Methods @@ -892,7 +952,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/FAQ.pod =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/FAQ.pod,v diff -u -p -a -u -p -r1.7 FAQ.pod --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/FAQ.pod 14 May 2024 19:38:55 -0000 1.7 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/FAQ.pod 22 Jan 2025 00:37:42 -0000 @@ -682,7 +682,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Gzip.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Gzip.pm,v diff -u -p -a -u -p -r1.8 Gzip.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Gzip.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Gzip.pm 22 Jan 2025 00:37:42 -0000 @@ -8,12 +8,12 @@ use bytes; require Exporter ; -use IO::Compress::RawDeflate 2.204 () ; -use IO::Compress::Adapter::Deflate 2.204 ; +use IO::Compress::RawDeflate 2.212 () ; +use IO::Compress::Adapter::Deflate 2.212 ; -use IO::Compress::Base::Common 2.204 qw(:Status ); -use IO::Compress::Gzip::Constants 2.204 ; -use IO::Compress::Zlib::Extra 2.204 ; +use IO::Compress::Base::Common 2.212 qw(:Status ); +use IO::Compress::Gzip::Constants 2.212 ; +use IO::Compress::Zlib::Extra 2.212 ; BEGIN { @@ -25,7 +25,7 @@ BEGIN our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, %DEFLATE_CONSTANTS, $GzipError); -$VERSION = '2.204'; +$VERSION = '2.212'; $GzipError = '' ; @ISA = qw(IO::Compress::RawDeflate Exporter); @@ -535,7 +535,7 @@ Defaults to 0. =back -=head2 Examples +=head2 Oneshot Examples Here are a few example that show the capabilities of the module. @@ -614,7 +614,10 @@ The format of the constructor for Cnew( $output [,OPTS] ) or die "IO::Compress::Gzip failed: $GzipError\n"; -It returns an C object on success and undef on failure. +The constructor takes one mandatory parameter, C<$output>, defined below and +zero or more C, defined in L. + +It returns an C object on success and C on failure. The variable C<$GzipError> will contain an error message on failure. If you are running Perl 5.005 or better the object, C<$z>, returned from @@ -627,6 +630,18 @@ these forms $z->print("hello world\n"); print $z "hello world\n"; +Below is a simple exaple of using the OO interface to create an output file +C and write some data to it. + + my $filename = "myfile.gz"; + my $z = IO::Compress::Gzip->new($filename) + or die "IO::Compress::Gzip failed: $GzipError\n"; + + $z->print("abcde"); + $z->close(); + +See the L for more. + The mandatory parameter C<$output> is used to control the destination of the compressed data. This parameter can take one of these forms. @@ -960,7 +975,52 @@ The ID header in an C sub-fi =head2 Examples -TODO +=head3 Streaming + +This very simple command line example demonstrates the streaming capabilities +of the module. The code reads data from STDIN or all the files given on the +commandline, compresses it, and writes the compressed data to STDOUT. + + use strict ; + use warnings ; + use IO::Compress::Gzip qw(gzip $GzipError) ; + + my $z = IO::Compress::Gzip->new("-", Stream => 1) + or die "IO::Compress::Gzip failed: $GzipError\n"; + + while (<>) { + $z->print("abcde"); + } + $z->close(); + +Note the use of C<"-"> to means C. Alternatively you can use C<\*STDOUT>. + +=head3 Compressing a file from the filesystem + +To read the contents of the file C and write the compressed +data to the file C there are a few options + +Start by creating the compression object and opening the input file + + use strict ; + use warnings ; + use IO::Compress::Gzip qw(gzip $GzipError) ; + + my $input = "file1.txt"; + my $z = IO::Compress::Gzip->new("file1.txt.gz") + or die "IO::Compress::Gzip failed: $GzipError\n"; + + # open the input file + open my $fh, "<", "file1.txt" + or die "Cannot open file1.txt: $!\n"; + + # loop through the input file & write to the compressed file + while (<$fh>) { + $z->print($_); + } + + # not forgetting to close the compressed file + $z->close(); =head1 Methods @@ -1267,7 +1327,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/RawDeflate.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/RawDeflate.pm,v diff -u -p -a -u -p -r1.8 RawDeflate.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/RawDeflate.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/RawDeflate.pm 22 Jan 2025 00:37:42 -0000 @@ -6,16 +6,16 @@ use strict ; use warnings; use bytes; -use IO::Compress::Base 2.204 ; -use IO::Compress::Base::Common 2.204 qw(:Status :Parse); -use IO::Compress::Adapter::Deflate 2.204 ; -use Compress::Raw::Zlib 2.204 qw(Z_DEFLATED Z_DEFAULT_COMPRESSION Z_DEFAULT_STRATEGY); +use IO::Compress::Base 2.212 ; +use IO::Compress::Base::Common 2.212 qw(:Status :Parse); +use IO::Compress::Adapter::Deflate 2.212 ; +use Compress::Raw::Zlib 2.212 qw(Z_DEFLATED Z_DEFAULT_COMPRESSION Z_DEFAULT_STRATEGY); require Exporter ; our ($VERSION, @ISA, @EXPORT_OK, %DEFLATE_CONSTANTS, %EXPORT_TAGS, $RawDeflateError); -$VERSION = '2.204'; +$VERSION = '2.212'; $RawDeflateError = ''; @ISA = qw(IO::Compress::Base Exporter); @@ -472,7 +472,7 @@ Defaults to 0. =back -=head2 Examples +=head2 Oneshot Examples Here are a few example that show the capabilities of the module. @@ -551,7 +551,10 @@ The format of the constructor for Cnew( $output [,OPTS] ) or die "IO::Compress::RawDeflate failed: $RawDeflateError\n"; -It returns an C object on success and undef on failure. +The constructor takes one mandatory parameter, C<$output>, defined below and +zero or more C, defined in L. + +It returns an C object on success and C on failure. The variable C<$RawDeflateError> will contain an error message on failure. If you are running Perl 5.005 or better the object, C<$z>, returned from @@ -564,6 +567,18 @@ these forms $z->print("hello world\n"); print $z "hello world\n"; +Below is a simple exaple of using the OO interface to create an output file +C and write some data to it. + + my $filename = "myfile.1951"; + my $z = IO::Compress::RawDeflate->new($filename) + or die "IO::Compress::RawDeflate failed: $RawDeflateError\n"; + + $z->print("abcde"); + $z->close(); + +See the L for more. + The mandatory parameter C<$output> is used to control the destination of the compressed data. This parameter can take one of these forms. @@ -703,7 +718,52 @@ This is a placeholder option. =head2 Examples -TODO +=head3 Streaming + +This very simple command line example demonstrates the streaming capabilities +of the module. The code reads data from STDIN or all the files given on the +commandline, compresses it, and writes the compressed data to STDOUT. + + use strict ; + use warnings ; + use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ; + + my $z = IO::Compress::RawDeflate->new("-", Stream => 1) + or die "IO::Compress::RawDeflate failed: $RawDeflateError\n"; + + while (<>) { + $z->print("abcde"); + } + $z->close(); + +Note the use of C<"-"> to means C. Alternatively you can use C<\*STDOUT>. + +=head3 Compressing a file from the filesystem + +To read the contents of the file C and write the compressed +data to the file C there are a few options + +Start by creating the compression object and opening the input file + + use strict ; + use warnings ; + use IO::Compress::RawDeflate qw(rawdeflate $RawDeflateError) ; + + my $input = "file1.txt"; + my $z = IO::Compress::RawDeflate->new("file1.txt.1951") + or die "IO::Compress::RawDeflate failed: $RawDeflateError\n"; + + # open the input file + open my $fh, "<", "file1.txt" + or die "Cannot open file1.txt: $!\n"; + + # loop through the input file & write to the compressed file + while (<$fh>) { + $z->print($_); + } + + # not forgetting to close the compressed file + $z->close(); =head1 Methods @@ -1010,7 +1070,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zip.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zip.pm,v diff -u -p -a -u -p -r1.8 Zip.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zip.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zip.pm 22 Jan 2025 00:37:42 -0000 @@ -4,41 +4,41 @@ use strict ; use warnings; use bytes; -use IO::Compress::Base::Common 2.204 qw(:Status ); -use IO::Compress::RawDeflate 2.204 (); -use IO::Compress::Adapter::Deflate 2.204 ; -use IO::Compress::Adapter::Identity 2.204 ; -use IO::Compress::Zlib::Extra 2.204 ; -use IO::Compress::Zip::Constants 2.204 ; +use IO::Compress::Base::Common 2.212 qw(:Status ); +use IO::Compress::RawDeflate 2.212 (); +use IO::Compress::Adapter::Deflate 2.212 ; +use IO::Compress::Adapter::Identity 2.212 ; +use IO::Compress::Zlib::Extra 2.212 ; +use IO::Compress::Zip::Constants 2.212 ; use File::Spec(); use Config; -use Compress::Raw::Zlib 2.204 (); +use Compress::Raw::Zlib 2.212 (); BEGIN { eval { require IO::Compress::Adapter::Bzip2 ; - IO::Compress::Adapter::Bzip2->import( 2.201 ); + IO::Compress::Adapter::Bzip2->VERSION( 2.212 ); require IO::Compress::Bzip2 ; - IO::Compress::Bzip2->import( 2.201 ); + IO::Compress::Bzip2->VERSION( 2.212 ); } ; eval { require IO::Compress::Adapter::Lzma ; - IO::Compress::Adapter::Lzma->import( 2.201 ); + IO::Compress::Adapter::Lzma->VERSION( 2.212 ); require IO::Compress::Lzma ; - IO::Compress::Lzma->import( 2.201 ); + IO::Compress::Lzma->VERSION( 2.212 ); } ; eval { require IO::Compress::Adapter::Xz ; - IO::Compress::Adapter::Xz->import( 2.201 ); + IO::Compress::Adapter::Xz->VERSION( 2.212 ); require IO::Compress::Xz ; - IO::Compress::Xz->import( 2.201 ); + IO::Compress::Xz->VERSION( 2.212 ); } ; eval { require IO::Compress::Adapter::Zstd ; - IO::Compress::Adapter::Zstd->import( 2.201 ); + IO::Compress::Adapter::Zstd->VERSION( 2.212 ); require IO::Compress::Zstd ; - IO::Compress::Zstd->import( 2.201 ); + IO::Compress::Zstd->VERSION( 2.212 ); } ; } @@ -47,7 +47,7 @@ require Exporter ; our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, %DEFLATE_CONSTANTS, $ZipError); -$VERSION = '2.204'; +$VERSION = '2.212'; $ZipError = ''; @ISA = qw(IO::Compress::RawDeflate Exporter); @@ -1206,7 +1206,7 @@ Defaults to 0. =back -=head2 Examples +=head2 Oneshot Examples Here are a few example that show the capabilities of the module. @@ -1317,7 +1317,10 @@ The format of the constructor for Cnew( $output [,OPTS] ) or die "IO::Compress::Zip failed: $ZipError\n"; -It returns an C object on success and undef on failure. +The constructor takes one mandatory parameter, C<$output>, defined below and +zero or more C, defined in L. + +It returns an C object on success and C on failure. The variable C<$ZipError> will contain an error message on failure. If you are running Perl 5.005 or better the object, C<$z>, returned from @@ -1330,6 +1333,18 @@ these forms $z->print("hello world\n"); print $z "hello world\n"; +Below is a simple exaple of using the OO interface to create an output file +C and write some data to it. + + my $filename = "myfile.zip"; + my $z = IO::Compress::Zip->new($filename) + or die "IO::Compress::Zip failed: $ZipError\n"; + + $z->print("abcde"); + $z->close(); + +See the L for more. + The mandatory parameter C<$output> is used to control the destination of the compressed data. This parameter can take one of these forms. @@ -1850,7 +1865,111 @@ This is a placeholder option. =head2 Examples -TODO +=head3 Streaming + +This very simple command line example demonstrates the streaming capabilities +of the module. The code reads data from STDIN or all the files given on the +commandline, compresses it, and writes the compressed data to STDOUT. + + use strict ; + use warnings ; + use IO::Compress::Zip qw(zip $ZipError) ; + + my $z = IO::Compress::Zip->new("-", Stream => 1) + or die "IO::Compress::Zip failed: $ZipError\n"; + + while (<>) { + $z->print("abcde"); + } + $z->close(); + +Note the use of C<"-"> to means C. Alternatively you can use C<\*STDOUT>. + +One problem with creating a zip archive directly from STDIN can be demonstrated by looking at +the contents of the zip file, output.zip, that we have just created +(assumg you have redirected it to a file called C). + + $ unzip -l output.zip + Archive: output.zip + Length Date Time Name + --------- ---------- ----- ---- + 12 2019-08-16 22:21 + --------- ------- + 12 1 file + +The archive member (filename) used is the empty string. + +If that doesn't suit your needs, you can explicitly set the filename used +in the zip archive by specifying the L option, like so + + my $z = IO::Compress::Zip->new("-", Name => "hello.txt", Stream => 1) + +Now the contents of the zip file looks like this + + $ unzip -l output.zip + Archive: output.zip + Length Date Time Name + --------- ---------- ----- ---- + 12 2019-08-16 22:22 hello.txt + --------- ------- + 12 1 file + +=head3 Compressing a file from the filesystem + +To read the contents of the file C and write the compressed +data to the file C there are a few options + +Start by creating the compression object and opening the input file + + use strict ; + use warnings ; + use IO::Compress::Zip qw(zip $ZipError) ; + + my $input = "file1.txt"; + my $z = IO::Compress::Zip->new("file1.txt.zip") + or die "IO::Compress::Zip failed: $ZipError\n"; + + # open the input file + open my $fh, "<", "file1.txt" + or die "Cannot open file1.txt: $!\n"; + + # loop through the input file & write to the compressed file + while (<$fh>) { + $z->print($_); + } + + # not forgetting to close the compressed file + $z->close(); + +=head3 Compressing multiple files + +To create a zip file, C, that contains the compressed contents +of the files C and C + + use strict ; + use warnings ; + use IO::Compress::Zip qw(zip $ZipError) ; + + my $z = IO::Compress::Zip->new("output.zip", Name => "alpha.txt") + or die "IO::Compress::Zip failed: $ZipError\n"; + + # open the input file + open my $fh, "<", "file1.txt" + or die "Cannot open file1.txt: $!\n"; + + # loop through the input file & write to the compressed file + while (<$fh>) { + $z->print($_); + } + + # move to next file + $z->newStream(Name => "beta.txt") + + while (<$fh>) { + $z->print($_); + } + + $z->close(); =head1 Methods @@ -2166,7 +2285,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Adapter/Bzip2.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Adapter/Bzip2.pm,v diff -u -p -a -u -p -r1.8 Bzip2.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Adapter/Bzip2.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Adapter/Bzip2.pm 22 Jan 2025 00:37:42 -0000 @@ -4,12 +4,12 @@ use strict; use warnings; use bytes; -use IO::Compress::Base::Common 2.204 qw(:Status); +use IO::Compress::Base::Common 2.212 qw(:Status); -use Compress::Raw::Bzip2 2.204 ; +use Compress::Raw::Bzip2 2.212 ; our ($VERSION); -$VERSION = '2.204'; +$VERSION = '2.212'; sub mkCompObject { Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Adapter/Deflate.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Adapter/Deflate.pm,v diff -u -p -a -u -p -r1.8 Deflate.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Adapter/Deflate.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Adapter/Deflate.pm 22 Jan 2025 00:37:42 -0000 @@ -4,13 +4,13 @@ use strict; use warnings; use bytes; -use IO::Compress::Base::Common 2.204 qw(:Status); -use Compress::Raw::Zlib 2.204 qw( !crc32 !adler32 ) ; +use IO::Compress::Base::Common 2.212 qw(:Status); +use Compress::Raw::Zlib 2.212 qw( !crc32 !adler32 ) ; require Exporter; our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, @EXPORT, %DEFLATE_CONSTANTS); -$VERSION = '2.204'; +$VERSION = '2.212'; @ISA = qw(Exporter); @EXPORT_OK = @Compress::Raw::Zlib::DEFLATE_CONSTANTS; %EXPORT_TAGS = %Compress::Raw::Zlib::DEFLATE_CONSTANTS; Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Adapter/Identity.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Adapter/Identity.pm,v diff -u -p -a -u -p -r1.8 Identity.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Adapter/Identity.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Adapter/Identity.pm 22 Jan 2025 00:37:42 -0000 @@ -4,10 +4,10 @@ use strict; use warnings; use bytes; -use IO::Compress::Base::Common 2.204 qw(:Status); +use IO::Compress::Base::Common 2.212 qw(:Status); our ($VERSION); -$VERSION = '2.204'; +$VERSION = '2.212'; sub mkCompObject { Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Base/Common.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Base/Common.pm,v diff -u -p -a -u -p -r1.8 Common.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Base/Common.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Base/Common.pm 22 Jan 2025 00:37:42 -0000 @@ -11,7 +11,7 @@ use File::GlobMapper; require Exporter; our ($VERSION, @ISA, @EXPORT, %EXPORT_TAGS, $HAS_ENCODE); @ISA = qw(Exporter); -$VERSION = '2.204'; +$VERSION = '2.212'; @EXPORT = qw( isaFilehandle isaFilename isaScalar whatIsInput whatIsOutput Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Gzip/Constants.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Gzip/Constants.pm,v diff -u -p -a -u -p -r1.8 Constants.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Gzip/Constants.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Gzip/Constants.pm 22 Jan 2025 00:37:42 -0000 @@ -9,7 +9,7 @@ require Exporter; our ($VERSION, @ISA, @EXPORT, %GZIP_OS_Names); our ($GZIP_FNAME_INVALID_CHAR_RE, $GZIP_FCOMMENT_INVALID_CHAR_RE); -$VERSION = '2.204'; +$VERSION = '2.212'; @ISA = qw(Exporter); Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zip/Constants.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zip/Constants.pm,v diff -u -p -a -u -p -r1.8 Constants.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zip/Constants.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zip/Constants.pm 22 Jan 2025 00:37:42 -0000 @@ -7,7 +7,7 @@ require Exporter; our ($VERSION, @ISA, @EXPORT, %ZIP_CM_MIN_VERSIONS); -$VERSION = '2.204'; +$VERSION = '2.212'; @ISA = qw(Exporter); Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zlib/Constants.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zlib/Constants.pm,v diff -u -p -a -u -p -r1.8 Constants.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zlib/Constants.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zlib/Constants.pm 22 Jan 2025 00:37:42 -0000 @@ -9,7 +9,7 @@ require Exporter; our ($VERSION, @ISA, @EXPORT); -$VERSION = '2.204'; +$VERSION = '2.212'; @ISA = qw(Exporter); Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zlib/Extra.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zlib/Extra.pm,v diff -u -p -a -u -p -r1.8 Extra.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zlib/Extra.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Compress/Zlib/Extra.pm 22 Jan 2025 00:37:42 -0000 @@ -8,9 +8,9 @@ use bytes; our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS); -$VERSION = '2.204'; +$VERSION = '2.212'; -use IO::Compress::Gzip::Constants 2.204 ; +use IO::Compress::Gzip::Constants 2.212 ; sub ExtraFieldError { Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/AnyInflate.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/AnyInflate.pm,v diff -u -p -a -u -p -r1.8 AnyInflate.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/AnyInflate.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/AnyInflate.pm 22 Jan 2025 00:37:42 -0000 @@ -6,22 +6,22 @@ use strict; use warnings; use bytes; -use IO::Compress::Base::Common 2.204 qw(:Parse); +use IO::Compress::Base::Common 2.212 qw(:Parse); -use IO::Uncompress::Adapter::Inflate 2.204 (); +use IO::Uncompress::Adapter::Inflate 2.212 (); -use IO::Uncompress::Base 2.204 ; -use IO::Uncompress::Gunzip 2.204 ; -use IO::Uncompress::Inflate 2.204 ; -use IO::Uncompress::RawInflate 2.204 ; -use IO::Uncompress::Unzip 2.204 ; +use IO::Uncompress::Base 2.212 ; +use IO::Uncompress::Gunzip 2.212 ; +use IO::Uncompress::Inflate 2.212 ; +use IO::Uncompress::RawInflate 2.212 ; +use IO::Uncompress::Unzip 2.212 ; require Exporter ; our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $AnyInflateError); -$VERSION = '2.204'; +$VERSION = '2.212'; $AnyInflateError = ''; @ISA = qw(IO::Uncompress::Base Exporter); @@ -421,7 +421,7 @@ C option. =back -=head2 Examples +=head2 OneShot Examples To read the contents of the file C and write the uncompressed data to the file C. @@ -481,6 +481,9 @@ The format of the constructor for IO::Un my $z = IO::Uncompress::AnyInflate->new( $input [OPTS] ) or die "IO::Uncompress::AnyInflate failed: $AnyInflateError\n"; +The constructor takes one mandatory parameter, C<$input>, defined below, and +zero or more C, defined in L. + Returns an C object on success and undef on failure. The variable C<$AnyInflateError> will contain an error message on failure. @@ -493,6 +496,20 @@ use either of these forms $line = $z->getline(); $line = <$z>; +Below is a simple exaple of using the OO interface to read the compressed file +C and write its contents to stdout. + + my $filename = "myfile.Compressed"; + my $z = IO::Uncompress::AnyInflate->new($filename) + or die "IO::Uncompress::AnyInflate failed: $AnyInflateError\n"; + + while (<$z>) { + print $_; + } + $z->close(); + +See L for further examples + The mandatory parameter C<$input> is used to determine the source of the compressed data. This parameter can take one of three forms. @@ -689,10 +706,6 @@ Defaults to 0. =back -=head2 Examples - -TODO - =head1 Methods =head2 read @@ -1001,7 +1014,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/AnyUncompress.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/AnyUncompress.pm,v diff -u -p -a -u -p -r1.8 AnyUncompress.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/AnyUncompress.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/AnyUncompress.pm 22 Jan 2025 00:37:42 -0000 @@ -4,16 +4,16 @@ use strict; use warnings; use bytes; -use IO::Compress::Base::Common 2.204 (); +use IO::Compress::Base::Common 2.212 (); -use IO::Uncompress::Base 2.204 ; +use IO::Uncompress::Base 2.212 ; require Exporter ; our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $AnyUncompressError); -$VERSION = '2.204'; +$VERSION = '2.212'; $AnyUncompressError = ''; @ISA = qw(IO::Uncompress::Base Exporter); @@ -33,26 +33,26 @@ BEGIN # Don't trigger any __DIE__ Hooks. local $SIG{__DIE__}; - eval ' use IO::Uncompress::Adapter::Inflate 2.204 ;'; - eval ' use IO::Uncompress::Adapter::Bunzip2 2.204 ;'; - eval ' use IO::Uncompress::Adapter::LZO 2.204 ;'; - eval ' use IO::Uncompress::Adapter::Lzf 2.204 ;'; - eval ' use IO::Uncompress::Adapter::UnLzma 2.204 ;'; - eval ' use IO::Uncompress::Adapter::UnXz 2.204 ;'; - eval ' use IO::Uncompress::Adapter::UnZstd 2.204 ;'; - eval ' use IO::Uncompress::Adapter::UnLzip 2.204 ;'; - - eval ' use IO::Uncompress::Bunzip2 2.204 ;'; - eval ' use IO::Uncompress::UnLzop 2.204 ;'; - eval ' use IO::Uncompress::Gunzip 2.204 ;'; - eval ' use IO::Uncompress::Inflate 2.204 ;'; - eval ' use IO::Uncompress::RawInflate 2.204 ;'; - eval ' use IO::Uncompress::Unzip 2.204 ;'; - eval ' use IO::Uncompress::UnLzf 2.204 ;'; - eval ' use IO::Uncompress::UnLzma 2.204 ;'; - eval ' use IO::Uncompress::UnXz 2.204 ;'; - eval ' use IO::Uncompress::UnZstd 2.204 ;'; - eval ' use IO::Uncompress::UnLzip 2.204 ;'; + eval ' use IO::Uncompress::Adapter::Inflate 2.212 ;'; + eval ' use IO::Uncompress::Adapter::Bunzip2 2.212 ;'; + eval ' use IO::Uncompress::Adapter::LZO 2.212 ;'; + eval ' use IO::Uncompress::Adapter::Lzf 2.212 ;'; + eval ' use IO::Uncompress::Adapter::UnLzma 2.212 ;'; + eval ' use IO::Uncompress::Adapter::UnXz 2.212 ;'; + eval ' use IO::Uncompress::Adapter::UnZstd 2.212 ;'; + eval ' use IO::Uncompress::Adapter::UnLzip 2.212 ;'; + + eval ' use IO::Uncompress::Bunzip2 2.212 ;'; + eval ' use IO::Uncompress::UnLzop 2.212 ;'; + eval ' use IO::Uncompress::Gunzip 2.212 ;'; + eval ' use IO::Uncompress::Inflate 2.212 ;'; + eval ' use IO::Uncompress::RawInflate 2.212 ;'; + eval ' use IO::Uncompress::Unzip 2.212 ;'; + eval ' use IO::Uncompress::UnLzf 2.212 ;'; + eval ' use IO::Uncompress::UnLzma 2.212 ;'; + eval ' use IO::Uncompress::UnXz 2.212 ;'; + eval ' use IO::Uncompress::UnZstd 2.212 ;'; + eval ' use IO::Uncompress::UnLzip 2.212 ;'; } @@ -578,7 +578,7 @@ C option. =back -=head2 Examples +=head2 OneShot Examples To read the contents of the file C and write the uncompressed data to the file C. @@ -638,6 +638,9 @@ The format of the constructor for IO::Un my $z = IO::Uncompress::AnyUncompress->new( $input [OPTS] ) or die "IO::Uncompress::AnyUncompress failed: $AnyUncompressError\n"; +The constructor takes one mandatory parameter, C<$input>, defined below, and +zero or more C, defined in L. + Returns an C object on success and undef on failure. The variable C<$AnyUncompressError> will contain an error message on failure. @@ -650,6 +653,20 @@ use either of these forms $line = $z->getline(); $line = <$z>; +Below is a simple exaple of using the OO interface to read the compressed file +C and write its contents to stdout. + + my $filename = "myfile.Compressed"; + my $z = IO::Uncompress::AnyUncompress->new($filename) + or die "IO::Uncompress::AnyUncompress failed: $AnyUncompressError\n"; + + while (<$z>) { + print $_; + } + $z->close(); + +See L for further examples + The mandatory parameter C<$input> is used to determine the source of the compressed data. This parameter can take one of three forms. @@ -793,10 +810,6 @@ Defaults to 0. =back -=head2 Examples - -TODO - =head1 Methods =head2 read @@ -1077,7 +1090,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Base.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Base.pm,v diff -u -p -a -u -p -r1.8 Base.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Base.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Base.pm 22 Jan 2025 00:37:42 -0000 @@ -9,12 +9,12 @@ our (@ISA, $VERSION, @EXPORT_OK, %EXPORT @ISA = qw(IO::File Exporter); -$VERSION = '2.204'; +$VERSION = '2.212'; use constant G_EOF => 0 ; use constant G_ERR => -1 ; -use IO::Compress::Base::Common 2.204 ; +use IO::Compress::Base::Common 2.212 ; use IO::File ; use Symbol; @@ -1567,7 +1567,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Bunzip2.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Bunzip2.pm,v diff -u -p -a -u -p -r1.8 Bunzip2.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Bunzip2.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Bunzip2.pm 22 Jan 2025 00:37:42 -0000 @@ -4,15 +4,15 @@ use strict ; use warnings; use bytes; -use IO::Compress::Base::Common 2.204 qw(:Status ); +use IO::Compress::Base::Common 2.212 qw(:Status ); -use IO::Uncompress::Base 2.204 ; -use IO::Uncompress::Adapter::Bunzip2 2.204 ; +use IO::Uncompress::Base 2.212 ; +use IO::Uncompress::Adapter::Bunzip2 2.212 ; require Exporter ; our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $Bunzip2Error); -$VERSION = '2.204'; +$VERSION = '2.212'; $Bunzip2Error = ''; @ISA = qw(IO::Uncompress::Base Exporter); @@ -420,7 +420,7 @@ C option. =back -=head2 Examples +=head2 OneShot Examples To read the contents of the file C and write the uncompressed data to the file C. @@ -480,6 +480,9 @@ The format of the constructor for IO::Un my $z = IO::Uncompress::Bunzip2->new( $input [OPTS] ) or die "IO::Uncompress::Bunzip2 failed: $Bunzip2Error\n"; +The constructor takes one mandatory parameter, C<$input>, defined below, and +zero or more C, defined in L. + Returns an C object on success and undef on failure. The variable C<$Bunzip2Error> will contain an error message on failure. @@ -492,6 +495,20 @@ use either of these forms $line = $z->getline(); $line = <$z>; +Below is a simple exaple of using the OO interface to read the compressed file +C and write its contents to stdout. + + my $filename = "myfile.bz2"; + my $z = IO::Uncompress::Bunzip2->new($filename) + or die "IO::Uncompress::Bunzip2 failed: $Bunzip2Error\n"; + + while (<$z>) { + print $_; + } + $z->close(); + +See L for further examples + The mandatory parameter C<$input> is used to determine the source of the compressed data. This parameter can take one of three forms. @@ -617,10 +634,6 @@ Default is 0. =back -=head2 Examples - -TODO - =head1 Methods =head2 read @@ -909,7 +922,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Gunzip.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Gunzip.pm,v diff -u -p -a -u -p -r1.8 Gunzip.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Gunzip.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Gunzip.pm 22 Jan 2025 00:37:42 -0000 @@ -9,12 +9,12 @@ use strict ; use warnings; use bytes; -use IO::Uncompress::RawInflate 2.204 ; +use IO::Uncompress::RawInflate 2.212 ; -use Compress::Raw::Zlib 2.204 () ; -use IO::Compress::Base::Common 2.204 qw(:Status ); -use IO::Compress::Gzip::Constants 2.204 ; -use IO::Compress::Zlib::Extra 2.204 ; +use Compress::Raw::Zlib 2.212 () ; +use IO::Compress::Base::Common 2.212 qw(:Status ); +use IO::Compress::Gzip::Constants 2.212 ; +use IO::Compress::Zlib::Extra 2.212 ; require Exporter ; @@ -28,7 +28,7 @@ Exporter::export_ok_tags('all'); $GunzipError = ''; -$VERSION = '2.204'; +$VERSION = '2.212'; sub new { @@ -557,7 +557,7 @@ C option. =back -=head2 Examples +=head2 OneShot Examples To read the contents of the file C and write the uncompressed data to the file C. @@ -617,6 +617,9 @@ The format of the constructor for IO::Un my $z = IO::Uncompress::Gunzip->new( $input [OPTS] ) or die "IO::Uncompress::Gunzip failed: $GunzipError\n"; +The constructor takes one mandatory parameter, C<$input>, defined below, and +zero or more C, defined in L. + Returns an C object on success and undef on failure. The variable C<$GunzipError> will contain an error message on failure. @@ -629,6 +632,20 @@ use either of these forms $line = $z->getline(); $line = <$z>; +Below is a simple exaple of using the OO interface to read the compressed file +C and write its contents to stdout. + + my $filename = "myfile.gz"; + my $z = IO::Uncompress::Gunzip->new($filename) + or die "IO::Uncompress::Gunzip failed: $GunzipError\n"; + + while (<$z>) { + print $_; + } + $z->close(); + +See L for further examples + The mandatory parameter C<$input> is used to determine the source of the compressed data. This parameter can take one of three forms. @@ -797,10 +814,6 @@ Defaults to 0. =back -=head2 Examples - -TODO - =head1 Methods =head2 read @@ -1125,7 +1138,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Inflate.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Inflate.pm,v diff -u -p -a -u -p -r1.8 Inflate.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Inflate.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Inflate.pm 22 Jan 2025 00:37:42 -0000 @@ -5,15 +5,15 @@ use strict ; use warnings; use bytes; -use IO::Compress::Base::Common 2.204 qw(:Status ); -use IO::Compress::Zlib::Constants 2.204 ; +use IO::Compress::Base::Common 2.212 qw(:Status ); +use IO::Compress::Zlib::Constants 2.212 ; -use IO::Uncompress::RawInflate 2.204 ; +use IO::Uncompress::RawInflate 2.212 ; require Exporter ; our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $InflateError); -$VERSION = '2.204'; +$VERSION = '2.212'; $InflateError = ''; @ISA = qw(IO::Uncompress::RawInflate Exporter); @@ -479,7 +479,7 @@ C option. =back -=head2 Examples +=head2 OneShot Examples To read the contents of the file C and write the uncompressed data to the file C. @@ -539,6 +539,9 @@ The format of the constructor for IO::Un my $z = IO::Uncompress::Inflate->new( $input [OPTS] ) or die "IO::Uncompress::Inflate failed: $InflateError\n"; +The constructor takes one mandatory parameter, C<$input>, defined below, and +zero or more C, defined in L. + Returns an C object on success and undef on failure. The variable C<$InflateError> will contain an error message on failure. @@ -551,6 +554,20 @@ use either of these forms $line = $z->getline(); $line = <$z>; +Below is a simple exaple of using the OO interface to read the compressed file +C and write its contents to stdout. + + my $filename = "myfile.1950"; + my $z = IO::Uncompress::Inflate->new($filename) + or die "IO::Uncompress::Inflate failed: $InflateError\n"; + + while (<$z>) { + print $_; + } + $z->close(); + +See L for further examples + The mandatory parameter C<$input> is used to determine the source of the compressed data. This parameter can take one of three forms. @@ -685,10 +702,6 @@ uncompressed data actually contained in =back -=head2 Examples - -TODO - =head1 Methods =head2 read @@ -997,7 +1010,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/RawInflate.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/RawInflate.pm,v diff -u -p -a -u -p -r1.8 RawInflate.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/RawInflate.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/RawInflate.pm 22 Jan 2025 00:37:42 -0000 @@ -5,16 +5,16 @@ use strict ; use warnings; use bytes; -use Compress::Raw::Zlib 2.204 ; -use IO::Compress::Base::Common 2.204 qw(:Status ); +use Compress::Raw::Zlib 2.212 ; +use IO::Compress::Base::Common 2.212 qw(:Status ); -use IO::Uncompress::Base 2.204 ; -use IO::Uncompress::Adapter::Inflate 2.204 ; +use IO::Uncompress::Base 2.212 ; +use IO::Uncompress::Adapter::Inflate 2.212 ; require Exporter ; our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, %DEFLATE_CONSTANTS, $RawInflateError); -$VERSION = '2.204'; +$VERSION = '2.212'; $RawInflateError = ''; @ISA = qw(IO::Uncompress::Base Exporter); @@ -624,7 +624,7 @@ C option. =back -=head2 Examples +=head2 OneShot Examples To read the contents of the file C and write the uncompressed data to the file C. @@ -684,6 +684,9 @@ The format of the constructor for IO::Un my $z = IO::Uncompress::RawInflate->new( $input [OPTS] ) or die "IO::Uncompress::RawInflate failed: $RawInflateError\n"; +The constructor takes one mandatory parameter, C<$input>, defined below, and +zero or more C, defined in L. + Returns an C object on success and undef on failure. The variable C<$RawInflateError> will contain an error message on failure. @@ -696,6 +699,20 @@ use either of these forms $line = $z->getline(); $line = <$z>; +Below is a simple exaple of using the OO interface to read the compressed file +C and write its contents to stdout. + + my $filename = "myfile.1951"; + my $z = IO::Uncompress::RawInflate->new($filename) + or die "IO::Uncompress::RawInflate failed: $RawInflateError\n"; + + while (<$z>) { + print $_; + } + $z->close(); + +See L for further examples + The mandatory parameter C<$input> is used to determine the source of the compressed data. This parameter can take one of three forms. @@ -813,10 +830,6 @@ This option is a no-op. =back -=head2 Examples - -TODO - =head1 Methods =head2 read @@ -1125,7 +1138,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Unzip.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Unzip.pm,v diff -u -p -a -u -p -r1.8 Unzip.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Unzip.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Unzip.pm 22 Jan 2025 00:37:42 -0000 @@ -9,14 +9,14 @@ use warnings; use bytes; use IO::File; -use IO::Uncompress::RawInflate 2.204 ; -use IO::Compress::Base::Common 2.204 qw(:Status ); -use IO::Uncompress::Adapter::Inflate 2.204 ; -use IO::Uncompress::Adapter::Identity 2.204 ; -use IO::Compress::Zlib::Extra 2.204 ; -use IO::Compress::Zip::Constants 2.204 ; +use IO::Uncompress::RawInflate 2.212 ; +use IO::Compress::Base::Common 2.212 qw(:Status ); +use IO::Uncompress::Adapter::Inflate 2.212 ; +use IO::Uncompress::Adapter::Identity 2.212 ; +use IO::Compress::Zlib::Extra 2.212 ; +use IO::Compress::Zip::Constants 2.212 ; -use Compress::Raw::Zlib 2.204 () ; +use Compress::Raw::Zlib 2.212 () ; BEGIN { @@ -24,13 +24,13 @@ BEGIN local $SIG{__DIE__}; eval{ require IO::Uncompress::Adapter::Bunzip2 ; - IO::Uncompress::Adapter::Bunzip2->import() } ; + IO::Uncompress::Adapter::Bunzip2->VERSION(2.212) } ; eval{ require IO::Uncompress::Adapter::UnLzma ; - IO::Uncompress::Adapter::UnLzma->import() } ; + IO::Uncompress::Adapter::UnLzma->VERSION(2.212) } ; eval{ require IO::Uncompress::Adapter::UnXz ; - IO::Uncompress::Adapter::UnXz->import() } ; + IO::Uncompress::Adapter::UnXz->VERSION(2.212) } ; eval{ require IO::Uncompress::Adapter::UnZstd ; - IO::Uncompress::Adapter::UnZstd->import() } ; + IO::Uncompress::Adapter::UnZstd->VERSION(2.212) } ; } @@ -38,7 +38,7 @@ require Exporter ; our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $UnzipError, %headerLookup); -$VERSION = '2.204'; +$VERSION = '2.212'; $UnzipError = ''; @ISA = qw(IO::Uncompress::RawInflate Exporter); @@ -1396,7 +1396,7 @@ C option. =back -=head2 Examples +=head2 OneShot Examples Say you have a zip file, C, that only contains a single member, you can read it and write the uncompressed data to the @@ -1459,6 +1459,9 @@ The format of the constructor for IO::Un my $z = IO::Uncompress::Unzip->new( $input [OPTS] ) or die "IO::Uncompress::Unzip failed: $UnzipError\n"; +The constructor takes one mandatory parameter, C<$input>, defined below, and +zero or more C, defined in L. + Returns an C object on success and undef on failure. The variable C<$UnzipError> will contain an error message on failure. @@ -1471,6 +1474,20 @@ use either of these forms $line = $z->getline(); $line = <$z>; +Below is a simple exaple of using the OO interface to read the compressed file +C and write its contents to stdout. + + my $filename = "myfile.zip"; + my $z = IO::Uncompress::Unzip->new($filename) + or die "IO::Uncompress::Unzip failed: $UnzipError\n"; + + while (<$z>) { + print $_; + } + $z->close(); + +See L for further examples + The mandatory parameter C<$input> is used to determine the source of the compressed data. This parameter can take one of three forms. @@ -1607,10 +1624,6 @@ The default for this option is off. =back -=head2 Examples - -TODO - =head1 Methods =head2 read @@ -1877,9 +1890,37 @@ Same as doing this =head1 EXAMPLES -=head2 Working with Net::FTP +=head2 Simple Read -See L +Say you have a zip file, C, that only contains a +single member, you can read it and write the uncompressed data to the +file C like this. + + use strict ; + use warnings ; + use IO::Uncompress::Unzip qw(unzip $UnzipError) ; + + my $filename = "file1.zip"; + my $z = IO::Uncompress::Unzip->new($filename) + or die "IO::Uncompress::Unzip failed: $UnzipError\n"; + open my $out, ">", "file1.txt"; + + while (<$z>) { + print $out $_; + } + $z->close(); + +If you have a zip file that contains multiple members and want to read a +specific member from the file, say C<"data1">, use the C option when +constructing the + + use strict ; + use warnings ; + use IO::Uncompress::Unzip qw(unzip $UnzipError) ; + + my $filename = "file1.zip"; + my $z = IO::Uncompress::Unzip->new($filename, Name => "data1") + or die "IO::Uncompress::Unzip failed: $UnzipError\n"; =head2 Walking through a zip file @@ -1925,6 +1966,10 @@ to read a zip file and unzip its content The script is available from L +=head2 Working with Net::FTP + +See L + =head1 SUPPORT General feedback/questions/bug reports should be sent to @@ -1967,7 +2012,7 @@ See the Changes file. =head1 COPYRIGHT AND LICENSE -Copyright (c) 2005-2023 Paul Marquess. All rights reserved. +Copyright (c) 2005-2024 Paul Marquess. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Adapter/Bunzip2.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Adapter/Bunzip2.pm,v diff -u -p -a -u -p -r1.8 Bunzip2.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Adapter/Bunzip2.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Adapter/Bunzip2.pm 22 Jan 2025 00:37:42 -0000 @@ -4,12 +4,12 @@ use strict; use warnings; use bytes; -use IO::Compress::Base::Common 2.204 qw(:Status); +use IO::Compress::Base::Common 2.212 qw(:Status); -use Compress::Raw::Bzip2 2.204 ; +use Compress::Raw::Bzip2 2.212 ; our ($VERSION, @ISA); -$VERSION = '2.204'; +$VERSION = '2.212'; sub mkUncompObject { Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Adapter/Identity.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Adapter/Identity.pm,v diff -u -p -a -u -p -r1.8 Identity.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Adapter/Identity.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Adapter/Identity.pm 22 Jan 2025 00:37:42 -0000 @@ -4,14 +4,14 @@ use warnings; use strict; use bytes; -use IO::Compress::Base::Common 2.204 qw(:Status); +use IO::Compress::Base::Common 2.212 qw(:Status); use IO::Compress::Zip::Constants ; our ($VERSION); -$VERSION = '2.204'; +$VERSION = '2.212'; -use Compress::Raw::Zlib 2.204 (); +use Compress::Raw::Zlib 2.212 (); sub mkUncompObject { Index: gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Adapter/Inflate.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Adapter/Inflate.pm,v diff -u -p -a -u -p -r1.8 Inflate.pm --- gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Adapter/Inflate.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/IO-Compress/lib/IO/Uncompress/Adapter/Inflate.pm 22 Jan 2025 00:37:42 -0000 @@ -4,11 +4,11 @@ use strict; use warnings; use bytes; -use IO::Compress::Base::Common 2.204 qw(:Status); -use Compress::Raw::Zlib 2.204 qw(Z_OK Z_BUF_ERROR Z_STREAM_END Z_FINISH MAX_WBITS); +use IO::Compress::Base::Common 2.212 qw(:Status); +use Compress::Raw::Zlib 2.212 qw(Z_OK Z_BUF_ERROR Z_STREAM_END Z_FINISH MAX_WBITS); our ($VERSION); -$VERSION = '2.204'; +$VERSION = '2.212'; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/000prereq.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/IO-Compress/t/000prereq.t diff -N gnu/usr.bin/perl/cpan/IO-Compress/t/000prereq.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/000prereq.t 14 May 2024 19:38:55 -0000 1.7 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,101 +0,0 @@ -BEGIN { - if ($ENV{PERL_CORE}) { - chdir 't' if -d 't'; - @INC = ("../lib", "lib/compress"); - } -} - -use lib qw(t t/compress); -use strict ; -use warnings ; - -use Test::More ; - -sub gotScalarUtilXS -{ - eval ' use Scalar::Util "dualvar" '; - return $@ ? 0 : 1 ; -} - -BEGIN -{ - # use Test::NoWarnings, if available - my $extra = 0 ; - $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; - - - my $VERSION = '2.204'; - my @NAMES = qw( - Compress::Raw::Bzip2 - Compress::Raw::Zlib - - Compress::Zlib - - IO::Compress::Adapter::Bzip2 - IO::Compress::Adapter::Deflate - IO::Compress::Adapter::Identity - IO::Compress::Base::Common - IO::Compress::Base - IO::Compress::Bzip2 - IO::Compress::Deflate - IO::Compress::Gzip::Constants - IO::Compress::Gzip - IO::Compress::RawDeflate - IO::Compress::Zip::Constants - IO::Compress::Zip - IO::Compress::Zlib::Constants - IO::Compress::Zlib::Extra - IO::Uncompress::Adapter::Bunzip2 - IO::Uncompress::Adapter::Identity - IO::Uncompress::Adapter::Inflate - IO::Uncompress::AnyInflate - IO::Uncompress::AnyUncompress - IO::Uncompress::Base - IO::Uncompress::Bunzip2 - IO::Uncompress::Gunzip - IO::Uncompress::Inflate - IO::Uncompress::RawInflate - IO::Uncompress::Unzip - - ); - - my @OPT = qw( - ); - - plan tests => 1 + 2 + @NAMES + @OPT + $extra ; - - foreach my $name (@NAMES) - { - use_ok($name, $VERSION); - } - - - foreach my $name (@OPT) - { - eval " require $name " ; - if ($@) - { - ok 1, "$name not available" - } - else - { - my $ver = eval("\$${name}::VERSION"); - is $ver, $VERSION, "$name version should be $VERSION" - or diag "$name version is $ver, need $VERSION" ; - } - } - - # need zlib 1.2.0 or better or zlib-ng - - ok Compress::Raw::Zlib::is_zlibng() || Compress::Raw::Zlib::ZLIB_VERNUM() >= 0x1200 - or diag "IO::Compress needs zlib 1.2.0 or better, you have " . Compress::Raw::Zlib::zlib_version(); - - use_ok('Scalar::Util') ; - -} - -ok gotScalarUtilXS(), "Got XS Version of Scalar::Util" - or diag <import; 1 }; plan tests => 841 + $extra ; }; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/002any-transparent.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/002any-transparent.t,v diff -u -p -a -u -p -r1.1.1.2 002any-transparent.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/002any-transparent.t 15 Feb 2023 01:32:41 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/002any-transparent.t 22 Jan 2025 00:37:42 -0000 @@ -18,7 +18,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 15 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/004gziphdr.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/004gziphdr.t,v diff -u -p -a -u -p -r1.1.1.4 004gziphdr.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/004gziphdr.t 15 Feb 2023 01:32:41 -0000 1.1.1.4 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/004gziphdr.t 22 Jan 2025 00:37:42 -0000 @@ -17,7 +17,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 918 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/005defhdr.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/005defhdr.t,v diff -u -p -a -u -p -r1.1.1.4 005defhdr.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/005defhdr.t 14 May 2024 19:36:33 -0000 1.1.1.4 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/005defhdr.t 22 Jan 2025 00:37:42 -0000 @@ -17,7 +17,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 114 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/006zip.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/006zip.t,v diff -u -p -a -u -p -r1.1.1.6 006zip.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/006zip.t 15 Feb 2023 01:32:41 -0000 1.1.1.6 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/006zip.t 22 Jan 2025 00:37:42 -0000 @@ -17,7 +17,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 108 + $extra ; @@ -26,9 +26,9 @@ BEGIN { eval { require IO::Compress::Bzip2 ; - IO::Compress::Bzip2->import( 2.010 ); + IO::Compress::Bzip2->VERSION( 2.010 ); require IO::Uncompress::Bunzip2 ; - IO::Uncompress::Bunzip2->import( 2.010 ); + IO::Uncompress::Bunzip2->VERSION( 2.010 ); } ; } @@ -401,4 +401,4 @@ EOM my $line = <$u>; is $line, qq["key","value"\n], "got line 1 from second member"; -} \ No newline at end of file +} Index: gnu/usr.bin/perl/cpan/IO-Compress/t/011-streamzip.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/011-streamzip.t,v diff -u -p -a -u -p -r1.1.1.3 011-streamzip.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/011-streamzip.t 14 May 2024 19:36:33 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/011-streamzip.t 22 Jan 2025 00:37:42 -0000 @@ -23,7 +23,7 @@ BEGIN # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 136 + $extra ; } Index: gnu/usr.bin/perl/cpan/IO-Compress/t/01misc.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/01misc.t,v diff -u -p -a -u -p -r1.1.1.5 01misc.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/01misc.t 15 Feb 2023 01:32:41 -0000 1.1.1.5 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/01misc.t 22 Jan 2025 00:37:42 -0000 @@ -17,7 +17,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 163 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/020isize.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/020isize.t,v diff -u -p -a -u -p -r1.3 020isize.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/020isize.t 15 Feb 2023 01:36:19 -0000 1.3 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/020isize.t 22 Jan 2025 00:37:42 -0000 @@ -22,7 +22,7 @@ BEGIN # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 76 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/050interop-gzip.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/050interop-gzip.t,v diff -u -p -a -u -p -r1.1.1.5 050interop-gzip.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/050interop-gzip.t 15 Feb 2023 01:32:41 -0000 1.1.1.5 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/050interop-gzip.t 22 Jan 2025 00:37:42 -0000 @@ -109,7 +109,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 7 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-bzip2.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-bzip2.t,v diff -u -p -a -u -p -r1.4 101truncate-bzip2.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-bzip2.t 15 Feb 2023 01:36:19 -0000 1.4 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-bzip2.t 22 Jan 2025 00:37:42 -0000 @@ -19,7 +19,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 3308 + $extra; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-deflate.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-deflate.t,v diff -u -p -a -u -p -r1.4 101truncate-deflate.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-deflate.t 15 Feb 2023 01:36:19 -0000 1.4 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-deflate.t 22 Jan 2025 00:37:42 -0000 @@ -19,7 +19,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 2552 + $extra; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-gzip.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-gzip.t,v diff -u -p -a -u -p -r1.4 101truncate-gzip.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-gzip.t 15 Feb 2023 01:36:19 -0000 1.4 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-gzip.t 22 Jan 2025 00:37:42 -0000 @@ -20,7 +20,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 3040 + $extra; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-rawdeflate.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-rawdeflate.t,v diff -u -p -a -u -p -r1.4 101truncate-rawdeflate.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-rawdeflate.t 14 May 2024 19:38:55 -0000 1.4 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-rawdeflate.t 22 Jan 2025 00:37:42 -0000 @@ -21,7 +21,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; my $tests = Compress::Raw::Zlib::is_zlibng() ? 615 : 625; plan tests => $tests + $extra; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-zip.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-zip.t,v diff -u -p -a -u -p -r1.4 101truncate-zip.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-zip.t 15 Feb 2023 01:36:19 -0000 1.4 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/101truncate-zip.t 22 Jan 2025 00:37:42 -0000 @@ -20,7 +20,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 7732 + $extra; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-gzip-only.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-gzip-only.t,v diff -u -p -a -u -p -r1.1.1.2 105oneshot-gzip-only.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-gzip-only.t 15 Feb 2023 01:32:41 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-gzip-only.t 22 Jan 2025 00:37:42 -0000 @@ -21,7 +21,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 70 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-zip-bzip2-only.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-zip-bzip2-only.t,v diff -u -p -a -u -p -r1.1.1.3 105oneshot-zip-bzip2-only.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-zip-bzip2-only.t 15 Feb 2023 01:32:41 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-zip-bzip2-only.t 22 Jan 2025 00:37:42 -0000 @@ -26,7 +26,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 248 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-zip-only.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-zip-only.t,v diff -u -p -a -u -p -r1.1.1.5 105oneshot-zip-only.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-zip-only.t 15 Feb 2023 01:32:41 -0000 1.1.1.5 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-zip-only.t 22 Jan 2025 00:37:42 -0000 @@ -22,7 +22,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 230 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-zip-store-only.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-zip-store-only.t,v diff -u -p -a -u -p -r1.3 105oneshot-zip-store-only.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-zip-store-only.t 15 Feb 2023 01:36:19 -0000 1.3 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/105oneshot-zip-store-only.t 22 Jan 2025 00:37:42 -0000 @@ -30,7 +30,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 1058 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/107multi-zip-only.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/107multi-zip-only.t,v diff -u -p -a -u -p -r1.1.1.2 107multi-zip-only.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/107multi-zip-only.t 15 Feb 2023 01:32:41 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/107multi-zip-only.t 22 Jan 2025 00:37:42 -0000 @@ -19,7 +19,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 21 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/108anyunc-transparent.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/108anyunc-transparent.t,v diff -u -p -a -u -p -r1.1.1.2 108anyunc-transparent.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/108anyunc-transparent.t 15 Feb 2023 01:32:41 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/108anyunc-transparent.t 22 Jan 2025 00:37:42 -0000 @@ -18,7 +18,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 15 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/111const-deflate.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/111const-deflate.t,v diff -u -p -a -u -p -r1.2 111const-deflate.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/111const-deflate.t 15 Feb 2023 01:38:22 -0000 1.2 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/111const-deflate.t 22 Jan 2025 00:37:42 -0000 @@ -18,7 +18,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 390 + $extra ; } Index: gnu/usr.bin/perl/cpan/IO-Compress/t/112utf8-zip.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/112utf8-zip.t,v diff -u -p -a -u -p -r1.1.1.2 112utf8-zip.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/112utf8-zip.t 15 Feb 2023 01:32:41 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/112utf8-zip.t 22 Jan 2025 00:37:42 -0000 @@ -32,7 +32,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 28 + $extra; } Index: gnu/usr.bin/perl/cpan/IO-Compress/t/113issues.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/113issues.t,v diff -u -p -a -u -p -r1.1.1.1 113issues.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/113issues.t 15 Feb 2023 01:32:41 -0000 1.1.1.1 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/113issues.t 22 Jan 2025 00:37:42 -0000 @@ -32,7 +32,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 3 + $extra; } Index: gnu/usr.bin/perl/cpan/IO-Compress/t/cz-01version.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/cz-01version.t,v diff -u -p -a -u -p -r1.1.1.3 cz-01version.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/cz-01version.t 15 Feb 2023 01:32:41 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/cz-01version.t 22 Jan 2025 00:37:42 -0000 @@ -16,7 +16,7 @@ BEGIN # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 2 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/cz-03zlib-v1.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/cz-03zlib-v1.t,v diff -u -p -a -u -p -r1.1.1.4 cz-03zlib-v1.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/cz-03zlib-v1.t 14 May 2024 19:36:33 -0000 1.1.1.4 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/cz-03zlib-v1.t 22 Jan 2025 00:37:42 -0000 @@ -21,7 +21,7 @@ BEGIN # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; my $count = 0 ; if ($] < 5.005) { Index: gnu/usr.bin/perl/cpan/IO-Compress/t/cz-06gzsetp.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/cz-06gzsetp.t,v diff -u -p -a -u -p -r1.1.1.3 cz-06gzsetp.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/cz-06gzsetp.t 15 Feb 2023 01:32:41 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/cz-06gzsetp.t 22 Jan 2025 00:37:42 -0000 @@ -32,7 +32,7 @@ BEGIN # use Test::NoWarnings, if available $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; } my $ver = Compress::Zlib::zlib_version(); Index: gnu/usr.bin/perl/cpan/IO-Compress/t/cz-08encoding.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/cz-08encoding.t,v diff -u -p -a -u -p -r1.1.1.3 cz-08encoding.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/cz-08encoding.t 15 Feb 2023 01:32:41 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/cz-08encoding.t 22 Jan 2025 00:37:42 -0000 @@ -26,7 +26,7 @@ BEGIN # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 29 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/cz-14gzopen.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/cz-14gzopen.t,v diff -u -p -a -u -p -r1.1.1.5 cz-14gzopen.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/cz-14gzopen.t 15 Feb 2023 01:32:41 -0000 1.1.1.5 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/cz-14gzopen.t 22 Jan 2025 00:37:42 -0000 @@ -18,7 +18,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 264 + $extra ; @@ -500,6 +500,17 @@ foreach my $stdio ( ['-', '-'], [*STDIN, skip "Cannot create non-writable file", 3 if -w $name ; + # double check non-writable for AFS + my $written = do { + no warnings; + my $fh; + open $fh, '>', $name && + print $fh "hello world" + }; + + skip "Cannot create non-writable file", 3 + if $written ; + ok ! -w $name, " input file not writable"; my $fil = gzopen($name, "wb") ; @@ -521,6 +532,17 @@ foreach my $stdio ( ['-', '-'], [*STDIN, skip "Cannot create non-readable file", 3 if -r $name ; + + # double check non-readable for AFS + my $readable = do { + no warnings; + my $fh; + open $fh, '<', $name && + read $fh, my $data, 1 + }; + + skip "Cannot create non-writable file", 3 + if $readable ; ok ! -r $name, " input file not readable"; $gzerrno = 0; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/globmapper.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/globmapper.t,v diff -u -p -a -u -p -r1.1.1.3 globmapper.t --- gnu/usr.bin/perl/cpan/IO-Compress/t/globmapper.t 15 Feb 2023 01:32:41 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/globmapper.t 22 Jan 2025 00:37:42 -0000 @@ -22,7 +22,7 @@ Perl $]" ) # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 68 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/compress/any.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/compress/any.pl,v diff -u -p -a -u -p -r1.1.1.2 any.pl --- gnu/usr.bin/perl/cpan/IO-Compress/t/compress/any.pl 15 Feb 2023 01:32:41 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/compress/any.pl 22 Jan 2025 00:37:42 -0000 @@ -12,7 +12,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 48 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/compress/anyunc.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/compress/anyunc.pl,v diff -u -p -a -u -p -r1.1.1.2 anyunc.pl --- gnu/usr.bin/perl/cpan/IO-Compress/t/compress/anyunc.pl 15 Feb 2023 01:32:41 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/compress/anyunc.pl 22 Jan 2025 00:37:42 -0000 @@ -12,7 +12,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 36 + $extra ; } Index: gnu/usr.bin/perl/cpan/IO-Compress/t/compress/destroy.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/compress/destroy.pl,v diff -u -p -a -u -p -r1.1.1.2 destroy.pl --- gnu/usr.bin/perl/cpan/IO-Compress/t/compress/destroy.pl 15 Feb 2023 01:32:41 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/compress/destroy.pl 22 Jan 2025 00:37:42 -0000 @@ -15,7 +15,7 @@ BEGIN # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 15 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/compress/encode.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/compress/encode.pl,v diff -u -p -a -u -p -r1.1.1.4 encode.pl --- gnu/usr.bin/perl/cpan/IO-Compress/t/compress/encode.pl 15 Feb 2023 01:32:41 -0000 1.1.1.4 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/compress/encode.pl 22 Jan 2025 00:37:42 -0000 @@ -19,7 +19,7 @@ BEGIN # use Test::NoWarnings, if available my $extra = 0 ; - my $st = eval { require Test::NoWarnings ; import Test::NoWarnings; 1; }; + my $st = eval { require Test::NoWarnings ; Test::NoWarnings->import; 1; }; $extra = 1 if $st ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/compress/generic.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/compress/generic.pl,v diff -u -p -a -u -p -r1.1.1.5 generic.pl --- gnu/usr.bin/perl/cpan/IO-Compress/t/compress/generic.pl 15 Feb 2023 01:32:41 -0000 1.1.1.5 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/compress/generic.pl 22 Jan 2025 00:37:42 -0000 @@ -14,7 +14,7 @@ BEGIN # use Test::NoWarnings, if available my $extra = 0 ; - my $st = eval { require Test::NoWarnings ; import Test::NoWarnings; 1; }; + my $st = eval { require Test::NoWarnings ; Test::NoWarnings->import; 1; }; $extra = 1 if $st ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/compress/merge.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/compress/merge.pl,v diff -u -p -a -u -p -r1.1.1.3 merge.pl --- gnu/usr.bin/perl/cpan/IO-Compress/t/compress/merge.pl 15 Feb 2023 01:32:41 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/compress/merge.pl 22 Jan 2025 00:37:42 -0000 @@ -17,7 +17,7 @@ BEGIN # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 165 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/compress/multi.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/compress/multi.pl,v diff -u -p -a -u -p -r1.1.1.5 multi.pl --- gnu/usr.bin/perl/cpan/IO-Compress/t/compress/multi.pl 15 Feb 2023 01:32:41 -0000 1.1.1.5 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/compress/multi.pl 22 Jan 2025 00:37:42 -0000 @@ -11,7 +11,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 1828 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/compress/newtied.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/compress/newtied.pl,v diff -u -p -a -u -p -r1.1.1.2 newtied.pl --- gnu/usr.bin/perl/cpan/IO-Compress/t/compress/newtied.pl 15 Feb 2023 01:32:41 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/compress/newtied.pl 22 Jan 2025 00:37:42 -0000 @@ -27,7 +27,7 @@ BEGIN # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => $tests + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/compress/oneshot.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/compress/oneshot.pl,v diff -u -p -a -u -p -r1.4 oneshot.pl --- gnu/usr.bin/perl/cpan/IO-Compress/t/compress/oneshot.pl 15 Feb 2023 01:36:19 -0000 1.4 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/compress/oneshot.pl 22 Jan 2025 00:37:42 -0000 @@ -14,7 +14,7 @@ BEGIN { # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 1007 + $extra ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/compress/prime.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/compress/prime.pl,v diff -u -p -a -u -p -r1.3 prime.pl --- gnu/usr.bin/perl/cpan/IO-Compress/t/compress/prime.pl 15 Feb 2023 01:36:19 -0000 1.3 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/compress/prime.pl 22 Jan 2025 00:37:42 -0000 @@ -17,7 +17,7 @@ BEGIN { # use Test::NoWarnings, if available $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; } Index: gnu/usr.bin/perl/cpan/IO-Compress/t/compress/tied.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/compress/tied.pl,v diff -u -p -a -u -p -r1.1.1.3 tied.pl --- gnu/usr.bin/perl/cpan/IO-Compress/t/compress/tied.pl 15 Feb 2023 01:32:41 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/compress/tied.pl 22 Jan 2025 00:37:42 -0000 @@ -17,7 +17,7 @@ BEGIN # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; my $tests ; $BadPerl = ($] >= 5.006 and $] <= 5.008) ; Index: gnu/usr.bin/perl/cpan/IO-Compress/t/compress/zlib-generic.pl =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Compress/t/compress/zlib-generic.pl,v diff -u -p -a -u -p -r1.1.1.2 zlib-generic.pl --- gnu/usr.bin/perl/cpan/IO-Compress/t/compress/zlib-generic.pl 15 Feb 2023 01:32:41 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Compress/t/compress/zlib-generic.pl 22 Jan 2025 00:37:42 -0000 @@ -11,7 +11,7 @@ BEGIN # use Test::NoWarnings, if available my $extra = 0 ; $extra = 1 - if eval { require Test::NoWarnings ; import Test::NoWarnings; 1 }; + if eval { require Test::NoWarnings ; Test::NoWarnings->import; 1 }; plan tests => 49 + $extra ; } Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/.editorconfig =================================================================== RCS file: gnu/usr.bin/perl/cpan/IO-Socket-IP/.editorconfig diff -N gnu/usr.bin/perl/cpan/IO-Socket-IP/.editorconfig --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/.editorconfig 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,4 @@ +root = true + +[*.{pm,pl,t}] +indent_size = 3 Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/lib/IO/Socket/IP.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/lib/IO/Socket/IP.pm,v diff -u -p -a -u -p -r1.7 IP.pm --- gnu/usr.bin/perl/cpan/IO-Socket-IP/lib/IO/Socket/IP.pm 14 May 2024 19:38:55 -0000 1.7 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/lib/IO/Socket/IP.pm 22 Jan 2025 00:37:42 -0000 @@ -1,21 +1,13 @@ # You may distribute under the terms of either the GNU General Public License # or the Artistic License (the same terms as Perl itself) # -# (C) Paul Evans, 2010-2020 -- leonerd@leonerd.org.uk +# (C) Paul Evans, 2010-2023 -- leonerd@leonerd.org.uk -package IO::Socket::IP; +package IO::Socket::IP 0.42; -use v5; -use strict; +use v5.14; use warnings; -# $VERSION needs to be set before use base 'IO::Socket' -# - https://rt.cpan.org/Ticket/Display.html?id=92107 -BEGIN { - our $VERSION = '0.41_01'; - $VERSION = eval $VERSION; -} - use base qw( IO::Socket ); use Carp; @@ -72,19 +64,19 @@ C - Family-neutral IP so =head1 SYNOPSIS - use IO::Socket::IP; + use IO::Socket::IP; - my $sock = IO::Socket::IP->new( - PeerHost => "www.google.com", - PeerPort => "http", - Type => SOCK_STREAM, - ) or die "Cannot construct socket - $@"; - - my $familyname = ( $sock->sockdomain == PF_INET6 ) ? "IPv6" : - ( $sock->sockdomain == PF_INET ) ? "IPv4" : - "unknown"; + my $sock = IO::Socket::IP->new( + PeerHost => "www.google.com", + PeerPort => "http", + Type => SOCK_STREAM, + ) or die "Cannot construct socket - $IO::Socket::errstr"; + + my $familyname = ( $sock->sockdomain == PF_INET6 ) ? "IPv6" : + ( $sock->sockdomain == PF_INET ) ? "IPv4" : + "unknown"; - printf "Connected to google via %s\n", $familyname; + printf "Connected to google via %s\n", $familyname; =head1 DESCRIPTION @@ -109,15 +101,15 @@ Changing C's default behavio C constructor with either C or C as the C parameter will yield an C object. - use IO::Socket::IP -register; + use IO::Socket::IP -register; - my $sock = IO::Socket->new( - Domain => PF_INET6, - LocalHost => "::1", - Listen => 1, - ) or die "Cannot create socket - $@\n"; + my $sock = IO::Socket->new( + Domain => PF_INET6, + LocalHost => "::1", + Listen => 1, + ) or die "Cannot create socket - $IO::Socket::errstr\n"; - print "Created a socket of type " . ref($sock) . "\n"; + print "Created a socket of type " . ref($sock) . "\n"; Note that C<-register> is a global setting that applies to the entire program; it cannot be applied only for certain callers, removed, or limited by lexical @@ -155,9 +147,9 @@ sub import die "Cannot socket(PF_INET6) - $!"; if( setsockopt $testsock, IPPROTO_IPV6, IPV6_V6ONLY, 0 ) { - if ($^O eq "dragonfly") { + if( $^O eq "dragonfly") { # dragonflybsd 6.4 lies about successfully turning this off - if (getsockopt $testsock, IPPROTO_IPV6, IPV6_V6ONLY) { + if( getsockopt $testsock, IPPROTO_IPV6, IPV6_V6ONLY ) { return $can_disable_v6only = 0; } } @@ -287,10 +279,10 @@ common boolean options). For example, both options given below are equivalent to setting C. - Sockopts => [ - [ SOL_SOCKET, SO_REUSEADDR ], - [ SOL_SOCKET, SO_REUSEADDR, pack( "i", 1 ) ], - ] + Sockopts => [ + [ SOL_SOCKET, SO_REUSEADDR ], + [ SOL_SOCKET, SO_REUSEADDR, pack( "i", 1 ) ], + ] =item V6Only => BOOL @@ -307,12 +299,12 @@ Note that not all platforms support disa OpenBSD and MirBSD, will fail with C if you attempt to disable it. To determine whether it is possible to disable, you may use the class method - if( IO::Socket::IP->CAN_DISABLE_V6ONLY ) { - ... - } - else { - ... - } + if( IO::Socket::IP->CAN_DISABLE_V6ONLY ) { + ... + } + else { + ... + } If your platform does not support disabling this option but you still want to listen for both C and C connections you will have to create @@ -343,9 +335,9 @@ timeout will apply to each connection at operation as a whole. Further note that the timeout does not apply to the initial hostname resolve operation, if connecting by hostname. -This behviour is copied inspired by C; for more fine grained -control over connection timeouts, consider performing a nonblocking connect -directly. +This behaviour is copied inspired by C; for more fine +grained control over connection timeouts, consider performing a nonblocking +connect directly. =back @@ -360,9 +352,9 @@ socket family to create. In this case, i the C flag, no host name, and a service name of C<"0">, and uses the family of the first returned result. -If the constructor fails, it will set C<$@> to an appropriate error message; -this may be from C<$!> or it may be some other string; not every failure -necessarily has an associated C value. +If the constructor fails, it will set C<$IO::Socket::errstr> and C<$@> to +an appropriate error message; this may be from C<$!> or it may be some other +string; not every failure necessarily has an associated C value. =head2 new (one arg) @@ -500,7 +492,7 @@ sub _io_socket_ip__configure } if( $err ) { - $@ = "$err"; + $IO::Socket::errstr = $@ = "$err"; $! = EINVAL; return; } @@ -527,7 +519,7 @@ sub _io_socket_ip__configure } if( $err ) { - $@ = "$err"; + $IO::Socket::errstr = $@ = "$err"; $! = EINVAL; return; } @@ -605,7 +597,7 @@ sub _io_socket_ip__configure else { ( my $err, @infos ) = getaddrinfo( "", "0", \%hints ); if( $err ) { - $@ = "$err"; + $IO::Socket::errstr = $@ = "$err"; $! = EINVAL; return; } @@ -654,12 +646,14 @@ sub setup foreach my $sockopt ( @{ ${*$self}{io_socket_ip_sockopts} } ) { my ( $level, $optname, $value ) = @$sockopt; - $self->setsockopt( $level, $optname, $value ) or ( $@ = "$!", return undef ); + $self->setsockopt( $level, $optname, $value ) or + ( $IO::Socket::errstr = $@ = "$!", return undef ); } if( defined ${*$self}{io_socket_ip_v6only} and defined $AF_INET6 and $info->{family} == $AF_INET6 ) { my $v6only = ${*$self}{io_socket_ip_v6only}; - $self->setsockopt( IPPROTO_IPV6, IPV6_V6ONLY, pack "i", $v6only ) or ( $@ = "$!", return undef ); + $self->setsockopt( IPPROTO_IPV6, IPV6_V6ONLY, pack "i", $v6only ) or + ( $IO::Socket::errstr = $@ = "$!", return undef ); } if( defined( my $addr = $info->{localaddr} ) ) { @@ -668,7 +662,8 @@ sub setup } if( defined( my $listenqueue = ${*$self}{io_socket_ip_listenqueue} ) ) { - $self->listen( $listenqueue ) or ( $@ = "$!", return undef ); + $self->listen( $listenqueue ) or + ( $IO::Socket::errstr = $@ = "$!", return undef ); } if( defined( my $addr = $info->{peeraddr} ) ) { @@ -698,7 +693,7 @@ sub setup # Pick the most appropriate error, stringified $! = ( grep defined, @{ ${*$self}{io_socket_ip_errors}} )[0]; - $@ = "$!"; + $IO::Socket::errstr = $@ = "$!"; return undef; } @@ -1062,28 +1057,28 @@ a lookup using the C or C< achieved by using L, or the C function can be called in a child process. - use IO::Socket::IP; - use Errno qw( EINPROGRESS EWOULDBLOCK ); + use IO::Socket::IP; + use Errno qw( EINPROGRESS EWOULDBLOCK ); - my @peeraddrinfo = ... # Caller must obtain the getaddinfo result here + my @peeraddrinfo = ... # Caller must obtain the getaddinfo result here - my $socket = IO::Socket::IP->new( - PeerAddrInfo => \@peeraddrinfo, - Blocking => 0, - ) or die "Cannot construct socket - $@"; + my $socket = IO::Socket::IP->new( + PeerAddrInfo => \@peeraddrinfo, + Blocking => 0, + ) or die "Cannot construct socket - $@"; - while( !$socket->connect and ( $! == EINPROGRESS || $! == EWOULDBLOCK ) ) { - my $wvec = ''; - vec( $wvec, fileno $socket, 1 ) = 1; - my $evec = ''; - vec( $evec, fileno $socket, 1 ) = 1; + while( !$socket->connect and ( $! == EINPROGRESS || $! == EWOULDBLOCK ) ) { + my $wvec = ''; + vec( $wvec, fileno $socket, 1 ) = 1; + my $evec = ''; + vec( $evec, fileno $socket, 1 ) = 1; - select( undef, $wvec, $evec, undef ) or die "Cannot select - $!"; - } + select( undef, $wvec, $evec, undef ) or die "Cannot select - $!"; + } - die "Cannot connect - $!" if $!; + die "Cannot connect - $!" if $!; - ... + ... The example above uses C, but any similar mechanism should work analogously. C takes care when creating new socket filehandles @@ -1108,9 +1103,9 @@ of the following special forms then spec The value of the C<...Host> argument will be split to give both the hostname and port (or service name): - hostname.example.org:http # Host name - 192.0.2.1:80 # IPv4 address - [2001:db8::1]:80 # IPv6 address + hostname.example.org:http # Host name + 192.0.2.1:80 # IPv4 address + [2001:db8::1]:80 # IPv6 address In each case, the port or service name (e.g. C<80>) is passed as the C or C argument. @@ -1119,7 +1114,7 @@ Either of C or C) will be tried first, but if the resolver does not understand it then the port number (C<80>) will be used instead. @@ -1137,17 +1132,17 @@ Returns a 2-element list, containing eit description if it could be parsed, or the given address and C if it was not recognised. - IO::Socket::IP->split_addr( "hostname:http" ) - # ( "hostname", "http" ) + IO::Socket::IP->split_addr( "hostname:http" ) + # ( "hostname", "http" ) - IO::Socket::IP->split_addr( "192.0.2.1:80" ) - # ( "192.0.2.1", "80" ) + IO::Socket::IP->split_addr( "192.0.2.1:80" ) + # ( "192.0.2.1", "80" ) - IO::Socket::IP->split_addr( "[2001:db8::1]:80" ) - # ( "2001:db8::1", "80" ) + IO::Socket::IP->split_addr( "[2001:db8::1]:80" ) + # ( "2001:db8::1", "80" ) - IO::Socket::IP->split_addr( "something.else" ) - # ( "something.else", undef ) + IO::Socket::IP->split_addr( "something.else" ) + # ( "something.else", undef ) =cut @@ -1178,7 +1173,7 @@ numeric address). This can be especially useful when combined with the C or C methods. - say "Connected to ", IO::Socket::IP->join_addr( $sock->peerhost_service ); + say "Connected to ", IO::Socket::IP->join_addr( $sock->peerhost_service ); =cut @@ -1258,12 +1253,12 @@ and receive" behaviour of specifying thi when using C<::IP>, perform first a blocking connect, then afterwards turn the socket into nonblocking mode. - my $sock = IO::Socket::IP->new( - PeerHost => $peer, - Timeout => 20, - ) or die "Cannot connect - $@"; + my $sock = IO::Socket::IP->new( + PeerHost => $peer, + Timeout => 20, + ) or die "Cannot connect - $@"; - $sock->blocking( 0 ); + $sock->blocking( 0 ); This code will behave identically under both C and C. Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/00use.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/00use.t,v diff -u -p -a -u -p -r1.1.1.2 00use.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/00use.t 15 Feb 2023 01:32:48 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/00use.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/01local-client-v4.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/01local-client-v4.t,v diff -u -p -a -u -p -r1.3 01local-client-v4.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/01local-client-v4.t 15 Feb 2023 01:36:19 -0000 1.3 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/01local-client-v4.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -30,7 +29,7 @@ foreach my $socktype (qw( SOCK_STREAM SO LocalHost => "127.0.0.1", Type => Socket->$socktype, Proto => ( $socktype eq "SOCK_STREAM" ? "tcp" : "udp" ), # Because IO::Socket::INET is stupid and always presumes tcp - ) or die "Cannot listen on PF_INET - $@"; + ) or die "Cannot listen on PF_INET - $IO::Socket::errstr"; my $socket = IO::Socket::IP->new( PeerHost => "127.0.0.1", @@ -39,7 +38,7 @@ foreach my $socktype (qw( SOCK_STREAM SO ); ok( defined $socket, "IO::Socket::IP->new constructs a $socktype socket" ) or - diag( " error was $@" ); + diag( " error was $IO::Socket::errstr" ); is( $socket->sockdomain, AF_INET, "\$socket->sockdomain for $socktype" ); is( $socket->socktype, Socket->$socktype, "\$socket->socktype for $socktype" ); Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/02local-server-v4.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/02local-server-v4.t,v diff -u -p -a -u -p -r1.3 02local-server-v4.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/02local-server-v4.t 15 Feb 2023 01:36:19 -0000 1.3 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/02local-server-v4.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -33,7 +32,7 @@ foreach my $socktype (qw( SOCK_STREAM SO ); ok( defined $testserver, "IO::Socket::IP->new constructs a $socktype socket" ) or - diag( " error was $@" ); + diag( " error was $IO::Socket::errstr" ); is( $testserver->sockdomain, AF_INET, "\$testserver->sockdomain for $socktype" ); is( $testserver->socktype, Socket->$socktype, "\$testserver->socktype for $socktype" ); @@ -53,7 +52,7 @@ foreach my $socktype (qw( SOCK_STREAM SO PeerPort => $testserver->sockport, Type => Socket->$socktype, Proto => ( $socktype eq "SOCK_STREAM" ? "tcp" : "udp" ), # Because IO::Socket::INET is stupid and always presumes tcp - ) or die "Cannot connect to PF_INET - $@"; + ) or die "Cannot connect to PF_INET - $IO::Socket::errstr"; my $testclient = ( $socktype eq "SOCK_STREAM" ) ? $testserver->accept : Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/03local-cross-v4.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/03local-cross-v4.t,v diff -u -p -a -u -p -r1.3 03local-cross-v4.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/03local-cross-v4.t 15 Feb 2023 01:36:19 -0000 1.3 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/03local-cross-v4.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -14,13 +13,13 @@ foreach my $socktype (qw( SOCK_STREAM SO LocalHost => "127.0.0.1", LocalPort => "0", Type => Socket->$socktype, - ) or die "Cannot listen on PF_INET - $@"; + ) or die "Cannot listen on PF_INET - $IO::Socket::errstr"; my $socket = IO::Socket::IP->new( PeerHost => "127.0.0.1", PeerService => $testserver->sockport, Type => Socket->$socktype, - ) or die "Cannot connect on PF_INET - $@"; + ) or die "Cannot connect on PF_INET - $IO::Socket::errstr"; my $testclient = ( $socktype eq "SOCK_STREAM" ) ? $testserver->accept : Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/04local-client-v6.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/04local-client-v6.t,v diff -u -p -a -u -p -r1.1.1.2 04local-client-v6.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/04local-client-v6.t 15 Feb 2023 01:32:48 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/04local-client-v6.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -54,7 +53,7 @@ foreach my $socktype (qw( SOCK_STREAM SO ); ok( defined $socket, "IO::Socket::IP->new constructs a $socktype socket" ) or - diag( " error was $@" ); + diag( " error was $IO::Socket::errstr" ); is( $socket->sockdomain, $AF_INET6, "\$socket->sockdomain for $socktype" ); is( $socket->socktype, Socket->$socktype, "\$socket->socktype for $socktype" ); Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/05local-server-v6.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/05local-server-v6.t,v diff -u -p -a -u -p -r1.3 05local-server-v6.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/05local-server-v6.t 15 Feb 2023 01:36:19 -0000 1.3 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/05local-server-v6.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -40,7 +39,7 @@ foreach my $socktype (qw( SOCK_STREAM SO ); ok( defined $testserver, "IO::Socket::IP->new constructs a $socktype socket" ) or - diag( " error was $@" ); + diag( " error was $IO::Socket::errstr" ); is( $testserver->sockdomain, $AF_INET6, "\$testserver->sockdomain for $socktype" ); is( $testserver->socktype, Socket->$socktype, "\$testserver->socktype for $socktype" ); Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/06local-cross-v6.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/06local-cross-v6.t,v diff -u -p -a -u -p -r1.3 06local-cross-v6.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/06local-cross-v6.t 15 Feb 2023 01:36:19 -0000 1.3 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/06local-cross-v6.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -17,13 +16,13 @@ foreach my $socktype (qw( SOCK_STREAM SO LocalHost => "::1", LocalPort => "0", Type => Socket->$socktype, - ) or die "Cannot listen on PF_INET6 - $@"; + ) or die "Cannot listen on PF_INET6 - $IO::Socket::errstr"; my $socket = IO::Socket::IP->new( PeerHost => "::1", PeerService => $testserver->sockport, Type => Socket->$socktype, - ) or die "Cannot connect on PF_INET6 - $@"; + ) or die "Cannot connect on PF_INET6 - $IO::Socket::errstr"; my $testclient = ( $socktype eq "SOCK_STREAM" ) ? $testserver->accept : Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/10args.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/10args.t,v diff -u -p -a -u -p -r1.1.1.2 10args.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/10args.t 15 Feb 2023 01:32:48 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/10args.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/11sockopts.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/11sockopts.t,v diff -u -p -a -u -p -r1.5 11sockopts.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/11sockopts.t 15 Feb 2023 01:36:19 -0000 1.5 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/11sockopts.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -22,7 +21,7 @@ TODO: { Type => SOCK_STREAM, Listen => 1, ReuseAddr => 1, - ) or die "Cannot socket() - $@"; + ) or die "Cannot socket() - $IO::Socket::errstr"; ok( $sock->getsockopt( SOL_SOCKET, SO_REUSEADDR ), 'SO_REUSEADDR set' ); @@ -33,7 +32,7 @@ TODO: { Sockopts => [ [ SOL_SOCKET, SO_REUSEADDR ], ], - ) or die "Cannot socket() - $@"; + ) or die "Cannot socket() - $IO::Socket::errstr"; ok( $sock->getsockopt( SOL_SOCKET, SO_REUSEADDR ), 'SO_REUSEADDR set via Sockopts' ); } @@ -51,7 +50,7 @@ SKIP: { Type => SOCK_STREAM, Listen => 1, ReusePort => 1, - ) or die "Cannot socket() - $@"; + ) or die "Cannot socket() - $IO::Socket::errstr"; ok( $sock->getsockopt( SOL_SOCKET, SO_REUSEPORT ), 'SO_REUSEPORT set' ); } @@ -65,7 +64,7 @@ SKIP: { Broadcast => 1, ); skip "Privileges required to set broadcast on datagram socket", 1 if !$sock and $! == EACCES; - die "Cannot socket() - $@" unless $sock; + die "Cannot socket() - $IO::Socket::errstr" unless $sock; ok( $sock->getsockopt( SOL_SOCKET, SO_BROADCAST ), 'SO_BROADCAST set' ); } Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/12port-fallback.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/12port-fallback.t,v diff -u -p -a -u -p -r1.1.1.2 12port-fallback.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/12port-fallback.t 15 Feb 2023 01:32:48 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/12port-fallback.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/13addrinfo.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/13addrinfo.t,v diff -u -p -a -u -p -r1.1.1.2 13addrinfo.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/13addrinfo.t 15 Feb 2023 01:32:48 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/13addrinfo.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -16,7 +15,7 @@ use Socket qw( SOCK_STREAM unpack_sockad Listen => 1, LocalHost => "127.0.0.1", Type => SOCK_STREAM, - ) or die "Cannot listen on PF_INET - $@"; + ) or die "Cannot listen on PF_INET - $IO::Socket::errstr"; my ( $err, @peeraddrinfo ) = getaddrinfo( "127.0.0.1", $testserver->sockport, { socktype => SOCK_STREAM } ); $err and die "Cannot getaddrinfo 127.0.0.1 - $err"; @@ -26,7 +25,7 @@ use Socket qw( SOCK_STREAM unpack_sockad ); ok( defined $socket, 'IO::Socket::IP->new( PeerAddrInfo => ... ) constructs a new socket' ) or - diag( " error was $@" ); + diag( " error was $IO::Socket::errstr" ); is_deeply( [ unpack_sockaddr_in $socket->peername ], [ unpack_sockaddr_in $testserver->sockname ], @@ -43,12 +42,12 @@ use Socket qw( SOCK_STREAM unpack_sockad ); ok( defined $socket, 'IO::Socket::IP->new( LocalAddrInfo => ... ) constructs a new socket' ) or - diag( " error was $@" ); + diag( " error was $IO::Socket::errstr" ); my $testclient = IO::Socket::INET->new( PeerHost => "127.0.0.1", PeerPort => $socket->sockport, - ) or die "Cannot connect to localhost - $@"; + ) or die "Cannot connect to localhost - $IO::Socket::errstr"; is_deeply( [ unpack_sockaddr_in $socket->sockname ], [ unpack_sockaddr_in $testclient->peername ], Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/14fileno.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/14fileno.t,v diff -u -p -a -u -p -r1.1.1.2 14fileno.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/14fileno.t 15 Feb 2023 01:32:48 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/14fileno.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -11,7 +10,7 @@ use Socket qw( AF_INET SOCK_STREAM ); socket( my $tmph, AF_INET, SOCK_STREAM, 0 ) or die "Cannot socket() - $!"; -my $socket = IO::Socket::IP->new or die "Cannot create IO::Socket::IP - $@"; +my $socket = IO::Socket::IP->new or die "Cannot create IO::Socket::IP - $IO::Socket::errstr"; $socket->socket( AF_INET, SOCK_STREAM, 0 ) or die "Cannot socket() - $!"; my $fileno = $socket->fileno; Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/15io-socket.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/15io-socket.t,v diff -u -p -a -u -p -r1.3 15io-socket.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/15io-socket.t 15 Feb 2023 01:36:19 -0000 1.3 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/15io-socket.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -20,7 +19,7 @@ use IO::Socket::IP -register; ); isa_ok( $sock, "IO::Socket::IP", 'IO::Socket->new( Domain => AF_INET )' ) or - diag( " error was $@" ); + diag( " error was $IO::Socket::errstr" ); $sock = IO::Socket->new( Domain => AF_INET, @@ -47,7 +46,7 @@ SKIP: { ); isa_ok( $sock, "IO::Socket::IP", 'IO::Socket->new( Domain => AF_INET6 )' ) or - diag( " error was $@" ); + diag( " error was $IO::Socket::errstr" ); $sock = IO::Socket->new( Domain => $AF_INET6, Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/16v6only.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/16v6only.t,v diff -u -p -a -u -p -r1.3 16v6only.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/16v6only.t 15 Feb 2023 01:36:19 -0000 1.3 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/16v6only.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -31,7 +30,7 @@ my $ECONNREFUSED_STR = "$!"; Type => SOCK_STREAM, V6Only => 1, GetAddrInfoFlags => 0, # disable AI_ADDRCONFIG - ) or die "Cannot listen on PF_INET6 - $@"; + ) or die "Cannot listen on PF_INET6 - $IO::Socket::errstr"; is( $listensock->getsockopt( IPPROTO_IPV6, IPV6_V6ONLY ), 1, 'IPV6_V6ONLY is 1 on $listensock' ); @@ -42,7 +41,7 @@ my $ECONNREFUSED_STR = "$!"; Type => SOCK_STREAM, GetAddrInfoFlags => 0, # disable AI_ADDRCONFIG ); - my $err = "$@"; + my $err = "$IO::Socket::errstr"; ok( !defined $testsock, 'Unable to connect PF_INET socket to PF_INET6 socket with V6Only true' ); like( $err, qr/\Q$ECONNREFUSED_STR/, 'Socket creation fails with connection refused' ); @@ -60,7 +59,7 @@ SKIP: { Type => SOCK_STREAM, V6Only => 0, GetAddrInfoFlags => 0, # disable AI_ADDRCONFIG - ) or die "Cannot listen on PF_INET6 - $@"; + ) or die "Cannot listen on PF_INET6 - $IO::Socket::errstr"; is( $listensock->getsockopt( IPPROTO_IPV6, IPV6_V6ONLY ), 0, 'IPV6_V6ONLY is 0 on $listensock' ); @@ -71,7 +70,7 @@ SKIP: { Type => SOCK_STREAM, GetAddrInfoFlags => 0, # disable AI_ADDRCONFIG ); - my $err = "$@"; + my $err = "$IO::Socket::errstr"; ok( defined $testsock, 'Connected PF_INET socket to PF_INET6 socket with V6Only false' ) or diag( "IO::Socket::IP->new failed - $err" ); Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/17gai-flags.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/17gai-flags.t,v diff -u -p -a -u -p -r1.1.1.2 17gai-flags.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/17gai-flags.t 15 Feb 2023 01:32:48 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/17gai-flags.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/18fdopen.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/18fdopen.t,v diff -u -p -a -u -p -r1.1.1.2 18fdopen.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/18fdopen.t 15 Feb 2023 01:32:48 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/18fdopen.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -13,7 +12,7 @@ my $s1 = IO::Socket::IP->new( LocalHost => "127.0.0.1", Type => SOCK_STREAM, Listen => 1, -) or die "Cannot listen on AF_INET - $@"; +) or die "Cannot listen on AF_INET - $IO::Socket::errstr"; my $s2 = IO::Socket::IP->new; $s2->fdopen( $s1->fileno, 'r' ) or die "Cannot fdopen - $!"; Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/19no-addrs.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/19no-addrs.t,v diff -u -p -a -u -p -r1.1.1.2 19no-addrs.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/19no-addrs.t 15 Feb 2023 01:32:48 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/19no-addrs.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -14,7 +13,7 @@ use Socket qw( SOCK_STREAM AF_INET ); { my $sock = IO::Socket::IP->new( Family => AF_INET ); - my $save_exc = $@; + my $save_exc = $IO::Socket::errstr; ok( defined $sock, 'Constructor yields handle for Family => AF_INET' ) or diag( "Exception was $save_exc" ); @@ -31,7 +30,7 @@ SKIP: { skip "Unable to bind to ::1", 4; my $sock = IO::Socket::IP->new( Family => $AF_INET6 ); - my $save_exc = $@; + my $save_exc = $IO::Socket::errstr; ok( defined $sock, 'Constructor yields handle for Family => AF_INET6' ) or diag( "Exception was $save_exc" ); @@ -44,7 +43,7 @@ SKIP: { # what family { my $sock = IO::Socket::IP->new( Type => SOCK_STREAM ); - my $save_exc = $@; + my $save_exc = $IO::Socket::errstr; ok( defined $sock, 'Constructor yields handle for Type => SOCK_STREAM' ) or diag( "Exception was $save_exc" ); Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/20subclass.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/20subclass.t,v diff -u -p -a -u -p -r1.1.1.2 20subclass.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/20subclass.t 15 Feb 2023 01:32:48 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/20subclass.t 22 Jan 2025 00:37:42 -0000 @@ -1,23 +1,26 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; use IO::Socket::IP; +package MySubclass { + use base qw( IO::Socket::IP ); +} + my $server = IO::Socket::IP->new( Listen => 1, LocalHost => "127.0.0.1", LocalPort => 0, -) or die "Cannot listen on PF_INET - $!"; +) or die "Cannot listen on PF_INET - $IO::Socket::errstr"; my $client = IO::Socket::IP->new( PeerHost => $server->sockhost, PeerPort => $server->sockport, -) or die "Cannot connect on PF_INET - $!"; +) or die "Cannot connect on PF_INET - $IO::Socket::errstr"; my $accepted = $server->accept( 'MySubclass' ) or die "Cannot accept - $!"; @@ -25,6 +28,3 @@ my $accepted = $server->accept( 'MySubcl isa_ok( $accepted, 'MySubclass' ); done_testing; - -package MySubclass; -use base qw( IO::Socket::IP ); Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/21as-inet.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/21as-inet.t,v diff -u -p -a -u -p -r1.1.1.2 21as-inet.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/21as-inet.t 15 Feb 2023 01:32:48 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/21as-inet.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -12,12 +11,12 @@ my $server = IO::Socket::IP->new( Listen => 1, LocalHost => "127.0.0.1", LocalPort => 0, -) or die "Cannot listen on PF_INET - $!"; +) or die "Cannot listen on PF_INET - $IO::Socket::errstr"; my $client = IO::Socket::IP->new( PeerHost => $server->sockhost, PeerPort => $server->sockport, -) or die "Cannot connect on PF_INET - $!"; +) or die "Cannot connect on PF_INET - $IO::Socket::errstr"; my $accepted = $server->accept or die "Cannot accept - $!"; Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/22timeout.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/22timeout.t,v diff -u -p -a -u -p -r1.2 22timeout.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/22timeout.t 15 Feb 2023 01:36:19 -0000 1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/22timeout.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -12,13 +11,13 @@ my $server = IO::Socket::IP->new( Listen => 1, LocalHost => "127.0.0.1", LocalPort => 0, -) or die "Cannot listen on PF_INET - $!"; +) or die "Cannot listen on PF_INET - $IO::Socket::errstr"; my $client = IO::Socket::IP->new( PeerHost => $server->sockhost, PeerPort => $server->sockport, Timeout => 0.1, -) or die "Cannot connect on PF_INET - $!"; +) or die "Cannot connect on PF_INET - $IO::Socket::errstr"; ok( defined $client, 'client constructed with Timeout' ); ok( $client->blocking, 'client is in blocking mode after connect' ); Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/30nonblocking-connect.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/30nonblocking-connect.t,v diff -u -p -a -u -p -r1.1.1.2 30nonblocking-connect.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/30nonblocking-connect.t 15 Feb 2023 01:32:48 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/30nonblocking-connect.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -28,7 +27,7 @@ my $testserver = IO::Socket::INET->new( Listen => 1, LocalHost => "127.0.0.1", Type => SOCK_STREAM, -) or die "Cannot listen on PF_INET - $@"; +) or die "Cannot listen on PF_INET - $IO::Socket::errstr"; my $socket = IO::Socket::IP->new( PeerHost => "127.0.0.1", @@ -38,7 +37,7 @@ my $socket = IO::Socket::IP->new( ); ok( defined $socket, 'IO::Socket::IP->new( Blocking => 0 ) constructs a socket' ) or - diag( " error was $@" ); + diag( " error was $IO::Socket::errstr" ); ok( defined $socket->fileno, '$socket has a fileno immediately after construction' ); Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/31nonblocking-connect-internet.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/31nonblocking-connect-internet.t,v diff -u -p -a -u -p -r1.1.1.2 31nonblocking-connect-internet.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/31nonblocking-connect-internet.t 15 Feb 2023 01:32:48 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/31nonblocking-connect-internet.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; @@ -32,7 +31,7 @@ SKIP: { ); ok( defined $socket, "defined \$socket for $test_host:$test_good_port" ) or - diag( " error was $@" ); + diag( " error was $IO::Socket::errstr" ); ok( defined $socket->fileno, '$socket has fileno' ); @@ -71,7 +70,7 @@ SKIP: { ); ok( defined $socket, "defined \$socket for $test_host:$test_bad_port" ) or - diag( " error was $@" ); + diag( " error was $IO::Socket::errstr" ); ok( defined $socket->fileno, '$socket has fileno' ); Index: gnu/usr.bin/perl/cpan/IO-Socket-IP/t/99pod.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Socket-IP/t/99pod.t,v diff -u -p -a -u -p -r1.1.1.2 99pod.t --- gnu/usr.bin/perl/cpan/IO-Socket-IP/t/99pod.t 15 Feb 2023 01:32:48 -0000 1.1.1.2 +++ gnu/usr.bin/perl/cpan/IO-Socket-IP/t/99pod.t 22 Jan 2025 00:37:42 -0000 @@ -1,7 +1,6 @@ #!/usr/bin/perl -use v5; -use strict; +use v5.14; use warnings; use Test::More; Index: gnu/usr.bin/perl/cpan/IO-Zlib/Zlib.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/IO-Zlib/Zlib.pm,v diff -u -p -a -u -p -r1.1.1.3 Zlib.pm --- gnu/usr.bin/perl/cpan/IO-Zlib/Zlib.pm 14 May 2024 19:36:33 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/IO-Zlib/Zlib.pm 22 Jan 2025 00:37:42 -0000 @@ -291,7 +291,7 @@ use Fcntl qw(SEEK_SET); use Symbol; use Tie::Handle; -our $VERSION = "1.14"; +our $VERSION = "1.15"; our $AUTOLOAD; our @ISA = qw(Tie::Handle); Index: gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigFloat.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigFloat.pm,v diff -u -p -a -u -p -r1.8 BigFloat.pm --- gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigFloat.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigFloat.pm 22 Jan 2025 00:37:42 -0000 @@ -5,12 +5,13 @@ package Math::BigFloat; # # The following hash values are used internally: -# sign : "+", "-", "+inf", "-inf", or "NaN" if not a number -# _m : mantissa ($LIB thingy) -# _es : sign of _e -# _e : exponent ($LIB thingy) -# _a : accuracy -# _p : precision +# +# sign : "+", "-", "+inf", "-inf", or "NaN" +# _m : absolute value of mantissa ($LIB thingy) +# _es : sign of exponent ("+" or "-") +# _e : absolute value of exponent ($LIB thingy) +# accuracy : accuracy (scalar) +# precision : precision (scalar) use 5.006001; use strict; @@ -20,7 +21,7 @@ use Carp qw< carp croak >; use Scalar::Util qw< blessed >; use Math::BigInt qw< >; -our $VERSION = '1.999837'; +our $VERSION = '2.003002'; $VERSION =~ tr/_//d; require Exporter; @@ -52,11 +53,11 @@ use overload '**' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bpow($_[0]) : $_[0] -> copy() -> bpow($_[1]); }, - '<<' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> blsft($_[0]) - : $_[0] -> copy() -> blsft($_[1]); }, + '<<' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bblsft($_[0]) + : $_[0] -> copy() -> bblsft($_[1]); }, - '>>' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> brsft($_[0]) - : $_[0] -> copy() -> brsft($_[1]); }, + '>>' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bbrsft($_[0]) + : $_[0] -> copy() -> bbrsft($_[1]); }, # overload key: assign @@ -72,9 +73,9 @@ use overload '**=' => sub { $_[0] -> bpow($_[1]); }, - '<<=' => sub { $_[0] -> blsft($_[1]); }, + '<<=' => sub { $_[0] -> bblsft($_[1]); }, - '>>=' => sub { $_[0] -> brsft($_[1]); }, + '>>=' => sub { $_[0] -> bbrsft($_[1]); }, # 'x=' => sub { }, @@ -227,7 +228,9 @@ $_trap_inf = 0; # constant for easier life my $nan = 'NaN'; -my $IMPORT = 0; # was import() called yet? used to make require work +# Has import() been called yet? This variable is needed to make "require" work. + +my $IMPORT = 0; # some digits of accuracy for blog(undef, 10); which we use in blog() for speed my $LOG_10 = @@ -252,10 +255,12 @@ sub FETCH { } sub STORE { - $rnd_mode = $_[0]->round_mode($_[1]); + $rnd_mode = (ref $_[0]) -> round_mode($_[1]); } BEGIN { + *objectify = \&Math::BigInt::objectify; + # when someone sets $rnd_mode, we catch this and check the value to see # whether it is valid or not. $rnd_mode = 'even'; @@ -269,55 +274,45 @@ sub DESTROY { } sub AUTOLOAD { - # make fxxx and bxxx both work by selectively mapping fxxx() to MBF::bxxx() + + # Make fxxx() work by mapping fxxx() to Math::BigFloat::bxxx(). + my $name = $AUTOLOAD; - $name =~ s/(.*):://; # split package - my $c = $1 || __PACKAGE__; - no strict 'refs'; - $c->import() if $IMPORT == 0; - if (!_method_alias($name)) { - if (!defined $name) { - # delayed load of Carp and avoid recursion - croak("$c: Can't call a method without name"); - } - if (!_method_hand_up($name)) { - # delayed load of Carp and avoid recursion - croak("Can't call $c\-\>$name, not a valid method"); - } - # try one level up, but subst. bxxx() for fxxx() since MBI only got - # bxxx() - $name =~ s/^f/b/; - return &{"Math::BigInt"."::$name"}(@_); - } + $name =~ s/^(.*):://; # strip package name + my $class = $1 || __PACKAGE__; + + $class -> import() if $IMPORT == 0; + + # E.g., "fabs" -> "babs", but "is_neg" -> "is_neg" + my $bname = $name; $bname =~ s/^f/b/; - $c .= "::$name"; - *{$c} = \&{$bname}; - &{$c}; # uses @_ -} -############################################################################## + # Map, e.g., Math::BigFloat::fabs() to Math::BigFloat::babs() + + if ($bname ne $name && Math::BigFloat -> can($bname)) { + no strict 'refs'; + return &{"Math::BigFloat::$bname"}(@_); + } + + # Map, e.g., Math::BigFloat::babs() to Math::BigInt::babs() -{ - # valid method aliases for AUTOLOAD - my %methods = map { $_ => 1 } - qw / fadd fsub fmul fdiv fround ffround fsqrt fmod fstr fsstr fpow fnorm - fint facmp fcmp fzero fnan finf finc fdec ffac fneg - fceil ffloor frsft flsft fone flog froot fexp - /; - # valid methods that can be handed up (for AUTOLOAD) - my %hand_ups = map { $_ => 1 } - qw / is_nan is_inf is_negative is_positive is_pos is_neg - accuracy precision div_scale round_mode fabs fnot - objectify upgrade downgrade - bone binf bnan bzero - bsub - /; + elsif (Math::BigInt -> can($bname)) { + no strict 'refs'; + return &{"Math::BigInt::$bname"}(@_); + } - sub _method_alias { exists $methods{$_[0]||''}; } - sub _method_hand_up { exists $hand_ups{$_[0]||''}; } + else { + croak("Can't call $class->$name(), not a valid method"); + } } +############################################################################## + +# Compare the following function with @ISA above. This inheritance mess needs a +# clean up. When doing so, also consider the BEGIN block and the AUTOLOAD code. +# Fixme! + sub isa { my ($self, $class) = @_; return if $class =~ /^Math::BigInt/; # we aren't one of these @@ -396,7 +391,7 @@ sub new { # Math::BigFloat or subclass - if (defined(blessed($wanted)) && $wanted -> isa($class)) { + if (defined(blessed($wanted)) && $wanted -> isa(__PACKAGE__)) { # Don't copy the accuracy and precision, because a new object should get # them from the global configuration. @@ -545,6 +540,10 @@ sub from_dec { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_dec'); @@ -575,6 +574,10 @@ sub from_hex { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_hex'); @@ -605,6 +608,10 @@ sub from_oct { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_oct'); @@ -635,6 +642,10 @@ sub from_bin { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_bin'); @@ -665,6 +676,10 @@ sub from_ieee754 { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_ieee754'); @@ -735,7 +750,7 @@ sub from_ieee754 { # The maximum exponent, minimum exponent, and exponent bias. - my $emax = Math::BigFloat -> new(2) -> bpow($w - 1) -> bdec(); + my $emax = $class -> new(2) -> bpow($w - 1) -> bdec(); my $emin = 1 - $emax; my $bias = $emax; @@ -839,7 +854,9 @@ sub bzero { my $selfref = ref $self; my $class = $selfref || $self; - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -867,14 +884,16 @@ sub bzero { #return $self -> round(@r); # this should work, but doesnt; fixme! if (@r) { - croak "can't specify both accuracy and precision" - if @r >= 2 && defined($r[0]) && defined($r[1]); - $self->{_a} = $r[0]; - $self->{_p} = $r[1]; + if (@r >= 2 && defined($r[0]) && defined($r[1])) { + carp "can't specify both accuracy and precision"; + return $self -> bnan(); + } + $self->{accuracy} = $r[0]; + $self->{precision} = $r[1]; } else { unless($selfref) { - $self->{_a} = $class -> accuracy(); - $self->{_p} = $class -> precision(); + $self->{accuracy} = $class -> accuracy(); + $self->{precision} = $class -> precision(); } } @@ -897,7 +916,9 @@ sub bone { my $selfref = ref $self; my $class = $selfref || $self; - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -933,14 +954,16 @@ sub bone { #return $self -> round(@r); # this should work, but doesnt; fixme! if (@r) { - croak "can't specify both accuracy and precision" - if @r >= 2 && defined($r[0]) && defined($r[1]); - $self->{_a} = $_[0]; - $self->{_p} = $_[1]; + if (@r >= 2 && defined($r[0]) && defined($r[1])) { + carp "can't specify both accuracy and precision"; + return $self -> bnan(); + } + $self->{accuracy} = $_[0]; + $self->{precision} = $_[1]; } else { unless($selfref) { - $self->{_a} = $class -> accuracy(); - $self->{_p} = $class -> precision(); + $self->{accuracy} = $class -> accuracy(); + $self->{precision} = $class -> precision(); } } @@ -970,7 +993,9 @@ sub binf { } } - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -1006,14 +1031,16 @@ sub binf { #return $self -> round(@r); # this should work, but doesnt; fixme! if (@r) { - croak "can't specify both accuracy and precision" - if @r >= 2 && defined($r[0]) && defined($r[1]); - $self->{_a} = $r[0]; - $self->{_p} = $r[1]; + if (@r >= 2 && defined($r[0]) && defined($r[1])) { + carp "can't specify both accuracy and precision"; + return $self -> bnan(); + } + $self->{accuracy} = $r[0]; + $self->{precision} = $r[1]; } else { unless($selfref) { - $self->{_a} = $class -> accuracy(); - $self->{_p} = $class -> precision(); + $self->{accuracy} = $class -> accuracy(); + $self->{precision} = $class -> precision(); } } @@ -1043,7 +1070,9 @@ sub bnan { } } - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -1071,14 +1100,16 @@ sub bnan { #return $self -> round(@r); # this should work, but doesnt; fixme! if (@r) { - croak "can't specify both accuracy and precision" - if @r >= 2 && defined($r[0]) && defined($r[1]); - $self->{_a} = $r[0]; - $self->{_p} = $r[1]; + if (@r >= 2 && defined($r[0]) && defined($r[1])) { + carp "can't specify both accuracy and precision"; + return $self -> bnan(); + } + $self->{accuracy} = $r[0]; + $self->{precision} = $r[1]; } else { unless($selfref) { - $self->{_a} = $class -> accuracy(); - $self->{_p} = $class -> precision(); + $self->{accuracy} = $class -> accuracy(); + $self->{precision} = $class -> precision(); } } @@ -1119,6 +1150,10 @@ sub bpi { my $class = $selfref || $self; my @r = @_; # rounding paramters + # Make "require" work. + + $class -> import() if $IMPORT == 0; + if ($selfref) { # bpi() called as an instance method return $self if $self -> modify('bpi'); } else { # bpi() called as a class method @@ -1244,7 +1279,7 @@ EOF $pi -> precision($r[1]); } - for my $key (qw/ sign _m _es _e _a _p /) { + for my $key (qw/ sign _m _es _e accuracy precision /) { $self -> {$key} = $pi -> {$key}; } @@ -1271,8 +1306,8 @@ sub copy { $copy->{_es} = $x->{_es}; $copy->{_m} = $LIB->_copy($x->{_m}); $copy->{_e} = $LIB->_copy($x->{_e}); - $copy->{_a} = $x->{_a} if exists $x->{_a}; - $copy->{_p} = $x->{_p} if exists $x->{_p}; + $copy->{accuracy} = $x->{accuracy} if exists $x->{accuracy}; + $copy->{precision} = $x->{precision} if exists $x->{precision}; return $copy; } @@ -1284,7 +1319,7 @@ sub as_int { return $x -> copy() if $x -> isa("Math::BigInt"); - # disable upgrading and downgrading + # Disable upgrading and downgrading. require Math::BigInt; my $upg = Math::BigInt -> upgrade(); @@ -1292,6 +1327,8 @@ sub as_int { Math::BigInt -> upgrade(undef); Math::BigInt -> downgrade(undef); + # Copy the value. + my $y; if ($x -> is_inf()) { $y = Math::BigInt -> binf($x->sign()); @@ -1307,7 +1344,11 @@ sub as_int { $y = Math::BigInt->new($x->{sign} . $LIB->_str($y)); } - # reset upgrading and downgrading + # Copy the remaining instance variables. + + ($y->{accuracy}, $y->{precision}) = ($x->{accuracy}, $x->{precision}); + + # Restore upgrading and downgrading. Math::BigInt -> upgrade($upg); Math::BigInt -> downgrade($dng); @@ -1321,17 +1362,22 @@ sub as_float { return $x -> copy() if $x -> isa("Math::BigFloat"); - # disable upgrading and downgrading + # Disable upgrading and downgrading. - require Math::BigFloat; my $upg = Math::BigFloat -> upgrade(); my $dng = Math::BigFloat -> downgrade(); Math::BigFloat -> upgrade(undef); Math::BigFloat -> downgrade(undef); + # Copy the value. + my $y = Math::BigFloat -> new($x); - # reset upgrading and downgrading + # Copy the remaining instance variables. + + ($y->{accuracy}, $y->{precision}) = ($x->{accuracy}, $x->{precision}); + + # Restore upgrading and downgrading. Math::BigFloat -> upgrade($upg); Math::BigFloat -> downgrade($dng); @@ -1339,6 +1385,47 @@ sub as_float { return $y; } +sub as_rat { + # return copy as a Math::BigRat representation of this Math::BigFloat + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; + + return $x -> copy() if $x -> isa("Math::BigRat"); + + # Disable upgrading and downgrading. + + require Math::BigRat; + my $upg = Math::BigRat -> upgrade(); + my $dng = Math::BigRat -> downgrade(); + Math::BigRat -> upgrade(undef); + Math::BigRat -> downgrade(undef); + + # Copy the value. + + my $y; + if ($x -> is_inf()) { + $y = Math::BigRat -> binf($x -> sign()); + } elsif ($x -> is_nan()) { + $y = Math::BigRat -> bnan(); + } else { + my @flt_parts = ($x->{sign}, $x->{_m}, $x->{_es}, $x->{_e}); + my @rat_parts = $class -> _flt_lib_parts_to_rat_lib_parts(@flt_parts); + $y = Math::BigRat -> new($rat_parts[0] . $LIB -> _str($rat_parts[1]) + . '/' . $LIB -> _str($rat_parts[2])); + } + + # Copy the remaining instance variables. + + ($y->{accuracy}, $y->{precision}) = ($x->{accuracy}, $x->{precision}); + + # Restore upgrading and downgrading. + + Math::BigRat -> upgrade($upg); + Math::BigRat -> downgrade($dng); + + return $y; +} + ############################################################################### # Boolean methods ############################################################################### @@ -2189,16 +2276,16 @@ sub bdiv { # shortcut to not run through _find_round_parameters again if (defined $params[0]) { - delete $x->{_a}; # clear before round + $x->{accuracy} = undef; # clear before round $x = $x->bround($params[0], $params[2]); # then round accordingly } else { - delete $x->{_p}; # clear before round + $x->{precision} = undef; # clear before round $x = $x->bfround($params[1], $params[2]); # then round accordingly } if ($fallback) { # clear a/p after round, since user did not request it - delete $x->{_a}; - delete $x->{_p}; + $x->{accuracy} = undef; + $x->{precision} = undef; } if (wantarray) { @@ -2208,8 +2295,8 @@ sub bdiv { } if ($fallback) { # clear a/p after round, since user did not request it - delete $rem->{_a}; - delete $rem->{_p}; + $rem->{accuracy} = undef; + $rem->{precision} = undef; } $x = $downgrade -> new($x -> bdstr(), @r) if defined($downgrade) && $x -> is_int(); @@ -2467,6 +2554,23 @@ sub bpow { return $x; } +sub binv { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + + return $x if $x->modify('binv'); + + my $inv = $class -> bdiv($class -> bone(), $x, @r); + + return $downgrade -> new($inv, @r) if defined($downgrade) + && ($inv -> is_int() || $inv -> is_inf() || $inv -> is_nan()); + + for my $key (qw/ sign _m _es _e /) { + $x -> {$key} = $inv -> {$key}; + } + + $x; +} + sub blog { # Return the logarithm of the operand. If a second operand is defined, that # value is used as the base, otherwise the base is assumed to be Euler's @@ -2475,24 +2579,56 @@ sub blog { my ($class, $x, $base, @r); # Only objectify the base if it is defined, since an undefined base, as in - # $x->blog() or $x->blog(undef) signals that the base is Euler's number. + # $x->blog() or $x->blog(undef) signals that the base is Euler's number = + # 2.718281828... if (!ref($_[0]) && $_[0] =~ /^[A-Za-z]|::/) { # E.g., Math::BigFloat->blog(256, 2) ($class, $x, $base, @r) = defined $_[2] ? objectify(2, @_) : objectify(1, @_); } else { - # E.g., Math::BigFloat::blog(256, 2) or $x->blog(2) + # E.g., $x->blog(2) or the deprecated Math::BigFloat::blog(256, 2) ($class, $x, $base, @r) = defined $_[1] ? objectify(2, @_) : objectify(1, @_); } return $x if $x->modify('blog'); + # Handle all exception cases and all trivial cases. I have used Wolfram + # Alpha (http://www.wolframalpha.com) as the reference for these cases. + return $x -> bnan(@r) if $x -> is_nan(); - return $upgrade -> blog($x, $base, @r) - if defined($upgrade) && $x -> is_neg(); + if (defined $base) { + $base = $class -> new($base) + unless defined(blessed($base)) && $base -> isa(__PACKAGE__); + if ($base -> is_nan() || $base -> is_one()) { + return $x -> bnan(@r); + } elsif ($base -> is_inf() || $base -> is_zero()) { + return $x -> bnan(@r) if $x -> is_inf() || $x -> is_zero(); + return $x -> bzero(@r); + } elsif ($base -> is_negative()) { # -inf < base < 0 + return $x -> bzero(@r) if $x -> is_one(); # x = 1 + return $x -> bone('+', @r) if $x == $base; # x = base + # we can't handle these cases, so upgrade, if we can + return $upgrade -> blog($x, $base, @r) if defined $upgrade; + return $x -> bnan(@r); + } + return $x -> bone(@r) if $x == $base; # 0 < base && 0 < x < inf + } + + if ($x -> is_inf()) { # x = +/-inf + my $sign = defined($base) && $base < 1 ? '-' : '+'; + return $x -> binf($sign, @r); + } elsif ($x -> is_neg()) { # -inf < x < 0 + return $upgrade -> blog($x, $base, @r) if defined $upgrade; + return $x -> bnan(@r); + } elsif ($x -> is_one()) { # x = 1 + return $x -> bzero(@r); + } elsif ($x -> is_zero()) { # x = 0 + my $sign = defined($base) && $base < 1 ? '+' : '-'; + return $x -> binf($sign, @r); + } # we need to limit the accuracy to protect against overflow my $fallback = 0; @@ -2513,85 +2649,33 @@ sub blog { $scale = abs($params[0] || $params[1]) + 4; # take whatever is defined } - my $done = 0; - if (defined $base) { - $base = $class -> new($base) - unless defined(blessed($base)) && $base -> isa($class); - if ($base -> is_nan() || $base -> is_one()) { - $x = $x -> bnan(); - $done = 1; - } elsif ($base -> is_inf() || $base -> is_zero()) { - if ($x -> is_inf() || $x -> is_zero()) { - $x = $x -> bnan(); - } else { - $x = $x -> bzero(@params); - } - $done = 1; - } elsif ($base -> is_negative()) { # -inf < base < 0 - if ($x -> is_one()) { # x = 1 - $x = $x -> bzero(@params); - } elsif ($x == $base) { - $x = $x -> bone('+', @params); # x = base - } else { - $x = $x -> bnan(); # otherwise - } - $done = 1; - } elsif ($x == $base) { - $x = $x -> bone('+', @params); # 0 < base && 0 < x < inf - $done = 1; - } - } + # When user set globals, they would interfere with our calculation, so + # disable them and later re-enable them. - # We now know that the base is either undefined or positive and finite. + my $ab = $class -> accuracy(); + my $pb = $class -> precision(); + $class -> accuracy(undef); + $class -> precision(undef); - unless ($done) { - if ($x -> is_inf()) { # x = +/-inf - my $sign = defined $base && $base < 1 ? '-' : '+'; - $x = $x -> binf($sign); - $done = 1; - } elsif ($x -> is_neg()) { # -inf < x < 0 - $x = $x -> bnan(); - $done = 1; - } elsif ($x -> is_one()) { # x = 1 - $x = $x -> bzero(@params); - $done = 1; - } elsif ($x -> is_zero()) { # x = 0 - my $sign = defined $base && $base < 1 ? '+' : '-'; - $x = $x -> binf($sign); - $done = 1; - } - } + # Disabling upgrading and downgrading is no longer necessary to avoid an + # infinite recursion, but it avoids unnecessary upgrading and downgrading in + # the intermediate computations. - if ($done) { - if ($fallback) { - # clear a/p after round, since user did not request it - delete $x->{_a}; - delete $x->{_p}; - } - return $downgrade -> new($x -> bdstr(), @r) - if defined($downgrade) && $x->is_int(); - return $x; - } + my $upg = $class -> upgrade(); + my $dng = $class -> downgrade(); + $class -> upgrade(undef); + $class -> downgrade(undef); - # when user set globals, they would interfere with our calculation, so - # disable them and later re-enable them - no strict 'refs'; - my $abr = "$class\::accuracy"; - my $ab = $$abr; - $$abr = undef; - my $pbr = "$class\::precision"; - my $pb = $$pbr; - $$pbr = undef; - # we also need to disable any set A or P on $x (_find_round_parameters took - # them already into account), since these would interfere, too - delete $x->{_a}; - delete $x->{_p}; - - $done = 0; - - # If both the invocand and the base are integers, try to calculate integer - # result first. This is very fast, and in case the real result was found, we - # can stop right here. + # We also need to disable any set A or P on $x (_find_round_parameters took + # them already into account), since these would interfere, too. + + $x->{accuracy} = undef; + $x->{precision} = undef; + + my $done = 0; + + # If both $x and $base are integers, try to calculate an integer result + # first. This is very fast, and if the exact result was found, we are done. if (defined($base) && $base -> is_int() && $x -> is_int()) { my $x_lib = $LIB -> _new($x -> bdstr()); @@ -2605,36 +2689,46 @@ sub blog { } } - unless ($done) { - - # First calculate the log to base e (using reduction by 10 and possibly - # also by 2), and if a different base was requested, convert the result. + # If the integer result was not accurate, compute the natural logarithm + # log($x) (using reduction by 10 and possibly also by 2), and if a + # different base was requested, convert the result with log($x)/log($base). - $x = $x->_log_10($scale); + unless ($done) { + $x = $x -> _log_10($scale); if (defined $base) { # log_b(x) = ln(x) / ln(b), so compute ln(b) - my $base_log_e = $base->copy()->_log_10($scale); - $x = $x->bdiv($base_log_e, $scale); + my $base_log_e = $base -> copy() -> _log_10($scale); + $x = $x -> bdiv($base_log_e, $scale); } } # shortcut to not run through _find_round_parameters again + if (defined $params[0]) { - $x = $x->bround($params[0], $params[2]); # then round accordingly + $x = $x -> bround($params[0], $params[2]); # then round accordingly } else { - $x = $x->bfround($params[1], $params[2]); # then round accordingly + $x = $x -> bfround($params[1], $params[2]); # then round accordingly } if ($fallback) { # clear a/p after round, since user did not request it - delete $x->{_a}; - delete $x->{_p}; + $x->{accuracy} = undef; + $x->{precision} = undef; + } + + # Restore globals. We need to do it like this, because setting one + # undefines the other. + + if (defined $ab) { + $class -> accuracy($ab); + } else { + $class -> precision($pb); } - # restore globals - $$abr = $ab; - $$pbr = $pb; + + $class -> upgrade($upg); + $class -> downgrade($dng); return $downgrade -> new($x -> bdstr(), @r) - if defined($downgrade) && $x->is_int(); + if defined($downgrade) && $x -> is_int(); return $x; } @@ -2642,63 +2736,83 @@ sub bexp { # Calculate e ** X (Euler's number to the power of X) my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); - return $x if $x->modify('bexp'); + return $x if $x -> modify('bexp'); - return $x->bnan(@r) if $x -> is_nan(); - return $x->binf(@r) if $x->{sign} eq '+inf'; - return $x->bzero(@r) if $x->{sign} eq '-inf'; + return $x -> bnan(@r) if $x -> is_nan(); + return $x -> binf(@r) if $x->{sign} eq '+inf'; + return $x -> bzero(@r) if $x->{sign} eq '-inf'; + + # Get the rounding parameters, if any. - # we need to limit the accuracy to protect against overflow my $fallback = 0; my ($scale, @params); - ($x, @params) = $x->_find_round_parameters(@r); + ($x, @params) = $x -> _find_round_parameters(@r); - # error in _find_round_parameters? - return $x->bnan(@r) if $x->{sign} eq 'NaN'; + # Error in _find_round_parameters? - # no rounding at all, so must use fallback - if (scalar @params == 0) { - # simulate old behaviour - $params[0] = $class->div_scale(); # and round to it as accuracy - $params[1] = undef; # P = undef - $scale = $params[0]+4; # at least four more for proper round - $params[2] = $r[2]; # round mode by caller or undef - $fallback = 1; # to clear a/p afterwards + return $x -> bnan(@r) if $x->{sign} eq 'NaN'; + + return $x -> bone(@r) if $x -> is_zero(); + + # If no rounding parameters are give, use fallback. + + if (!@params) { + $params[0] = $class -> div_scale(); # fallback accuracy + $params[1] = undef; # no precision + $params[2] = $r[2]; # rounding mode + $scale = $params[0]; + $fallback = 1; # to clear a/p afterwards } else { - # the 4 below is empirical, and there might be cases where it's not - # enough ... - $scale = abs($params[0] || $params[1]) + 4; # take whatever is defined + if (defined($params[0])) { + $scale = $params[0]; + } else { + # We perform the computations below using accuracy only, not + # precision, so when precision is given, we need to "convert" this + # to accuracy. To do that, we need to know, at least approximately, + # how many digits there will be in the final result. + # + # log10(exp($x)) = log(exp($x)) / log(10) = $x / log(10) + + #$scale = 1 + int(log($ms) / log(10) + $es) - $params[1]; + my $ndig = $x -> numify() / log(10); + $scale = 1 + int($ndig) - $params[1]; + } } - return $x->bone(@params) if $x->is_zero(); + # Add extra digits to reduce the consequence of round-off errors in the + # intermediate computations. - if (!$x->isa('Math::BigFloat')) { - $x = Math::BigFloat->new($x); + $scale += 4; + + if (!$x -> isa('Math::BigFloat')) { + $x = Math::BigFloat -> new($x); $class = ref($x); } - # when user set globals, they would interfere with our calculation, so - # disable them and later re-enable them - no strict 'refs'; - my $abr = "$class\::accuracy"; - my $ab = $$abr; - $$abr = undef; - my $pbr = "$class\::precision"; - my $pb = $$pbr; - $$pbr = undef; - # we also need to disable any set A or P on $x (_find_round_parameters took - # them already into account), since these would interfere, too - delete $x->{_a}; - delete $x->{_p}; + # When user set globals, they would interfere with our calculation, so + # disable them and later re-enable them. + + my $ab = $class -> accuracy(); + my $pb = $class -> precision(); + $class -> accuracy(undef); + $class -> precision(undef); # Disabling upgrading and downgrading is no longer necessary to avoid an # infinite recursion, but it avoids unnecessary upgrading and downgrading in # the intermediate computations. - local $Math::BigInt::upgrade = undef; - local $Math::BigFloat::downgrade = undef; + my $upg = $class -> upgrade(); + my $dng = $class -> downgrade(); + $class -> upgrade(undef); + $class -> downgrade(undef); - my $x_org = $x->copy(); + # We also need to disable any set A or P on $x (_find_round_parameters took + # them already into account), since these would interfere, too. + + $x->{accuracy} = undef; + $x->{precision} = undef; + + my $x_orig = $x -> copy(); # We use the following Taylor series: @@ -2764,16 +2878,17 @@ sub bexp { my $F = $LIB->_new(42); my $step = 42; - # Compute how many steps we need to take to get $A and $B sufficiently - # big + # Compute number of steps needed to get $A and $B sufficiently large. + my $steps = _len_to_steps($scale - 4); # print STDERR "# Doing $steps steps for ", $scale-4, " digits\n"; + while ($step++ <= $steps) { # calculate $a * $f + 1 - $A = $LIB->_mul($A, $F); - $A = $LIB->_inc($A); + $A = $LIB -> _mul($A, $F); + $A = $LIB -> _inc($A); # increment f - $F = $LIB->_inc($F); + $F = $LIB -> _inc($F); } # Compute $B as factorial of $steps (this is faster than doing it @@ -2792,47 +2907,160 @@ sub bexp { $x->{_e} = $LIB->_new($scale); } - # $x contains now an estimate of e, with some surplus digits, so we can - # round - if (!$x_org->is_one()) { - # Reduce size of fractional part, followup with integer power of two. - my $lshift = 0; - while ($lshift < 30 && $x_org->bacmp(2 << $lshift) > 0) { - $lshift++; - } - # Raise $x to the wanted power and round it. - if ($lshift == 0) { - $x = $x->bpow($x_org, @params); - } else { - my($mul, $rescale) = (1 << $lshift, $scale+1+$lshift); - $x = $x -> bpow(scalar $x_org->bdiv($mul, $rescale), $rescale) - -> bpow($mul, @params); - } - } else { + # Now $x contains now an estimate of e, with some additional digits. + + if ($x_orig -> is_one()) { + # else just round the already computed result - delete $x->{_a}; - delete $x->{_p}; + + $x->{accuracy} = undef; + $x->{precision} = undef; + # shortcut to not run through _find_round_parameters again + if (defined $params[0]) { - $x = $x->bround($params[0], $params[2]); # then round accordingly + $x = $x -> bround($params[0], $params[2]); # then round accordingly } else { - $x = $x->bfround($params[1], $params[2]); # then round accordingly + $x = $x -> bfround($params[1], $params[2]); # then round accordingly } + + } else { + + # Use the fact exp(x) = exp(x/n)**n. In our case, n = 2**i for some + # integer i. We use this to compute exp(y) where y = x / (2**i) and + # 1 <= |y| < 2. + # + # The code below is similar to the code found in to_ieee754(). + + # We need to find the base 2 exponent. First make an estimate of the + # base 2 exponent, before adjusting it below. We could skip this + # estimation and go straight to the while-loops below, but the loops + # are slow, especially when the final exponent is far from zero and + # even more so if the number of digits is large. This initial + # estimation speeds up the computation dramatically. + # + # log2($m * 10**$e) = log10($m + 10**$e) * log(10)/log(2) + # = (log10($m) + $e) * log(10)/log(2) + # = (log($m)/log(10) + $e) * log(10)/log(2) + + my ($m, $e) = $x_orig -> nparts(); + my $ms = $m -> numify(); + my $es = $e -> numify(); + + # We start off by initializing the exponent to zero and the mantissa to + # the input value. Then we increase the mantissa and decrease the + # exponent, or vice versa, until the mantissa is in the desired range + # or we hit one of the limits for the exponent. + + my $mant = $x_orig -> copy() -> babs(); + my $expo; + + my $one = $class -> bone(); + my $two = $class -> new("2"); + my $half = $class -> new("0.5"); + + my $expo_est = (log(abs($ms))/log(10) + $es) * log(10)/log(2); + $expo_est = int($expo_est); + + # Don't multiply by a number raised to a negative exponent. This will + # cause a division, whose result is truncated to some fixed number of + # digits. Instead, multiply by the inverse number raised to a positive + # exponent. + + $expo = $class -> new($expo_est); + if ($expo_est > 0) { + $mant = $mant -> bmul($half -> copy() -> bpow($expo)); + } elsif ($expo_est < 0) { + my $expo_abs = $expo -> copy() -> bneg(); + $mant = $mant -> bmul($two -> copy() -> bpow($expo_abs)); + } + + # Final adjustment of the estimate above. + + while ($mant -> bcmp($two) >= 0) { # $mant <= $two + $mant = $mant -> bmul($half); + $expo = $expo -> binc(); + } + + while ($mant -> bcmp($one) < 0) { # $mant > $one + $mant = $mant -> bmul($two); + $expo = $expo -> bdec(); + } + + # Because of the upscaling, we need some additional digits. + + my $rescale = int($scale + abs($expo) * log(2) / log(10) + 1); + $rescale = 4 if $rescale < 4; + + $x = $x -> bpow($mant, $rescale); + my $pow2 = $two -> bpow($expo, $rescale); + $pow2 -> bneg() if $x_orig -> is_negative(); + + # The bpow() below fails with the GMP and GMPz libraries if abs($pow2) + # >= 2**30 = 1073741824. With the Pari library, it fails already when + # abs($pow) >= 2**13 = 8192. With the Calc library, it is rediculously + # slow when abs($pow2) is large. Fixme? + + croak "cannot compute bexp(); input value is too large" + if $pow2 -> copy() -> babs() -> bcmp("1073741824") >= 0; + + $x = $x -> bpow($pow2, $rescale); + + # Rounding parameters given as arguments currently don't override + # instance variables, so accuracy (which is set in the computations + # above) must be undefined before rounding. Fixme. + + $x->{accuracy} = undef; + $x -> round(@params); } + if ($fallback) { # clear a/p after round, since user did not request it - delete $x->{_a}; - delete $x->{_p}; + $x->{accuracy} = undef; + $x->{precision} = undef; + } + + # Restore globals. We need to do it like this, because setting one + # undefines the other. + + if (defined $ab) { + $class -> accuracy($ab); + } else { + $class -> precision($pb); + } + + $class -> upgrade($upg); + $class -> downgrade($dng); + + # If downgrading, remember to preserve the relevant instance parameters. + # There should be a more elegant way to do this. Fixme. + + if ($downgrade && $x -> is_int()) { + @r = ($x->{accuracy}, $x->{_r}); + my $tmp = $downgrade -> new($x, @r); + %$x = %$tmp; + return bless $x, $downgrade; } - # restore globals - $$abr = $ab; - $$pbr = $pb; - return $downgrade -> new($x -> bdstr(), @r) - if defined($downgrade) && $x -> is_int(); $x; } +sub bilog2 { + croak "Method ", (caller(0))[3], "() not implemented yet"; +} + +sub bilog10 { + croak "Method ", (caller(0))[3], "() not implemented yet"; +} + +sub bclog2 { + croak "Method ", (caller(0))[3], "() not implemented yet"; +} + +sub bclog10 { + croak "Method ", (caller(0))[3], "() not implemented yet"; +} + sub bnok { # Calculate n over k (binomial coefficient or "choose" function) as integer. # set up parameters @@ -2868,106 +3096,190 @@ sub bsin { # Calculate a sinus of x. my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); - # taylor: x^3 x^5 x^7 x^9 - # sin = x - --- + --- - --- + --- ... - # 3! 5! 7! 9! + # First we apply range reduction to x. This is because if x is large, the + # Taylor series converges slowly and requires higher accuracy in the + # intermediate computation. The Taylor series is: + # + # x^3 x^5 x^7 x^9 + # sin(x) = x - --- + --- - --- + --- ... + # 3! 5! 7! 9! - return $x if $x->modify('bsin'); + return $x if $x -> modify('bsin'); - return $x -> bzero(@r) if $x->is_zero(); - return $x -> bnan(@r) if $x->is_nan() || $x->is_inf(); + return $x -> bzero(@r) if $x -> is_zero(); + return $x -> bnan(@r) if $x -> is_nan() || $x -> is_inf(); + + # Get the rounding parameters, if any. - # we need to limit the accuracy to protect against overflow my $fallback = 0; my ($scale, @params); - ($x, @params) = $x->_find_round_parameters(@r); + ($x, @params) = $x -> _find_round_parameters(@r); - # error in _find_round_parameters? - return $x->bnan(@r) if $x->is_nan(); + # Error in _find_round_parameters? - # no rounding at all, so must use fallback - if (scalar @params == 0) { - # simulate old behaviour - $params[0] = $class->div_scale(); # and round to it as accuracy - $params[1] = undef; # disable P - $scale = $params[0]+4; # at least four more for proper round - $params[2] = $r[2]; # round mode by caller or undef - $fallback = 1; # to clear a/p afterwards + return $x -> bnan(@r) if $x -> is_nan(); + + # If no rounding parameters are given, use fallback. + + if (!@params) { + $params[0] = $class -> div_scale(); # fallback accuracy + $params[1] = undef; # no precision + $params[2] = $r[2]; # rounding mode + $scale = $params[0]; + $fallback = 1; # to clear a/p afterwards } else { - # the 4 below is empirical, and there might be cases where it is not - # enough... - $scale = abs($params[0] || $params[1]) + 4; # take whatever is defined + if (defined($params[0])) { + $scale = $params[0]; + } else { + # We perform the computations below using accuracy only, not + # precision, so when precision is given, we need to "convert" this + # to accuracy. + $scale = 1 - $params[1]; + } } - # when user set globals, they would interfere with our calculation, so + # Add more digits to the scale if the magnitude of $x is large. + + my ($m, $e) = $x -> nparts(); + $scale += $e if $x >= 10; + $scale = 4 if $scale < 4; + + # When user set globals, they would interfere with our calculation, so # disable them and later re-enable them - no strict 'refs'; - my $abr = "$class\::accuracy"; - my $ab = $$abr; - $$abr = undef; - my $pbr = "$class\::precision"; - my $pb = $$pbr; - $$pbr = undef; - # we also need to disable any set A or P on $x (_find_round_parameters took - # them already into account), since these would interfere, too - delete $x->{_a}; - delete $x->{_p}; + + my $ab = $class -> accuracy(); + my $pb = $class -> precision(); + $class -> accuracy(undef); + $class -> precision(undef); # Disabling upgrading and downgrading is no longer necessary to avoid an # infinite recursion, but it avoids unnecessary upgrading and downgrading in # the intermediate computations. - local $Math::BigInt::upgrade = undef; - local $Math::BigFloat::downgrade = undef; + my $upg = $class -> upgrade(); + my $dng = $class -> downgrade(); + $class -> upgrade(undef); + $class -> downgrade(undef); - my $over = $x * $x; # X ^ 2 - my $x2 = $over->copy(); # X ^ 2; difference between terms - $over = $over->bmul($x); # X ^ 3 as starting value - my $sign = 1; # start with -= - my $below = $class->new(6); - my $factorial = $class->new(4); - delete $x->{_a}; - delete $x->{_p}; + # We also need to disable any set A or P on $x (_find_round_parameters took + # them already into account), since these would interfere, too. + + $x->{accuracy} = undef; + $x->{precision} = undef; + + my $sin_prev; # the previous approximation of sin(x) + my $sin; # the current approximation of sin(x) - my $limit = $class->new("1E-". ($scale-1)); while (1) { - # we calculate the next term, and add it to the last - # when the next term is below our limit, it won't affect the outcome - # anymore, so we stop: - my $next = $over->copy()->bdiv($below, $scale); - last if $next->bacmp($limit) <= 0; - if ($sign == 0) { - $x = $x->badd($next); - } else { - $x = $x->bsub($next); + # Compute constants to the current scale. + + my $pi = $class -> bpi($scale); # 𝜋 + my $twopi = $pi -> copy() -> bmul("2"); # 2𝜋 + my $halfpi = $pi -> copy() -> bmul("0.5"); # 𝜋/2 + + # Use the fact that sin(-x) = -sin(x) to reduce the range to the + # interval to [0,∞). + + my $xsgn = $x < 0 ? -1 : 1; + my $x = $x -> copy() -> babs(); + + # Use the fact that sin(2𝜋x) = sin(x) to reduce the range to the + # interval to [0, 2𝜋). + + $x = $x -> bmod($twopi, $scale); + + # Use the fact that sin(x+𝜋) = -sin(x) to reduce the range to the + # interval to [0,𝜋). + + if ($x -> bcmp($pi) > 0) { + $xsgn = -$xsgn; + $x = $x -> bsub($pi); } - $sign = 1-$sign; # alternate - # calculate things for the next term - $over = $over->bmul($x2); # $x*$x - $below = $below->bmul($factorial); # n*(n+1) - $factorial = $factorial->binc(); - $below = $below -> bmul($factorial); # n*(n+1) - $factorial = $factorial->binc(); - } - # shortcut to not run through _find_round_parameters again - if (defined $params[0]) { - $x = $x->bround($params[0], $params[2]); # then round accordingly - } else { - $x = $x->bfround($params[1], $params[2]); # then round accordingly + # Use the fact that sin(𝜋-x) = sin(x) to reduce the range to the + # interval [0,𝜋/2). + + if ($x -> bcmp($halfpi) > 0) { + $x = $x -> bsub($pi) -> bneg(); # 𝜋 - x + } + + my $tol = $class -> new("1E-". ($scale-1)); + + my $xsq = $x -> copy() -> bmul($x, $scale) -> bneg(); + my $term = $x -> copy(); + my $fac = $class -> bone(); + my $n = $class -> bone(); + + $sin = $x -> copy(); # initialize sin(x) to the first term + + while (1) { + $n -> binc(); + $fac = $n -> copy(); + $n -> binc(); + $fac -> bmul($n); + + $term -> bmul($xsq, $scale) -> bdiv($fac, $scale); + + $sin -> badd($term, $scale); + last if $term -> copy() -> babs() -> bcmp($tol) < 0; + } + + $sin -> bneg() if $xsgn < 0; + + # Rounding parameters given as arguments currently don't override + # instance variables, so accuracy (which is set in the computations + # above) must be undefined before rounding. Fixme. + + $sin->{accuracy} = undef; + $sin -> round(@params); + + # Compare the current approximation of sin(x) with the previous one, + # and if they are identical, we're done. + + if (defined $sin_prev) { + last if $sin -> bcmp($sin_prev) == 0; + } + + # If the current approximation of sin(x) is different from the previous + # approximation, double the scale (accuracy) and retry. + + $sin_prev = $sin; + $scale *= 2; } + + # Assign the result to the invocand. + + %$x = %$sin; + if ($fallback) { # clear a/p after round, since user did not request it - delete $x->{_a}; - delete $x->{_p}; + $x->{accuracy} = undef; + $x->{precision} = undef; + } + + # Restore globals. We need to do it like this, because setting one + # undefines the other. + + if (defined $ab) { + $class -> accuracy($ab); + } else { + $class -> precision($pb); + } + + $class -> upgrade($upg); + $class -> downgrade($dng); + + # If downgrading, remember to preserve the relevant instance parameters. + # There should be a more elegant way to do this. Fixme. + + if ($downgrade && $x -> is_int()) { + @r = ($x->{accuracy}, $x->{_r}); + my $tmp = $downgrade -> new($x, @r); + %$x = %$tmp; + return bless $x, $downgrade; } - # restore globals - $$abr = $ab; - $$pbr = $pb; - return $downgrade -> new($x -> bdstr(), @r) - if defined($downgrade) && $x -> is_int(); $x; } @@ -3003,19 +3315,28 @@ sub bcos { $scale = abs($params[0] || $params[1]) + 4; # take whatever is defined } - # when user set globals, they would interfere with our calculation, so - # disable them and later re-enable them - no strict 'refs'; - my $abr = "$class\::accuracy"; - my $ab = $$abr; - $$abr = undef; - my $pbr = "$class\::precision"; - my $pb = $$pbr; - $$pbr = undef; - # we also need to disable any set A or P on $x (_find_round_parameters took - # them already into account), since these would interfere, too - delete $x->{_a}; - delete $x->{_p}; + # When user set globals, they would interfere with our calculation, so + # disable them and later re-enable them. + + my $ab = $class -> accuracy(); + my $pb = $class -> precision(); + $class -> accuracy(undef); + $class -> precision(undef); + + # Disabling upgrading and downgrading is no longer necessary to avoid an + # infinite recursion, but it avoids unnecessary upgrading and downgrading in + # the intermediate computations. + + my $upg = $class -> upgrade(); + my $dng = $class -> downgrade(); + $class -> upgrade(undef); + $class -> downgrade(undef); + + # We also need to disable any set A or P on $x (_find_round_parameters took + # them already into account), since these would interfere, too. + + $x->{accuracy} = undef; + $x->{precision} = undef; my $over = $x * $x; # X ^ 2 my $x2 = $over->copy(); # X ^ 2; difference between terms @@ -3023,8 +3344,8 @@ sub bcos { my $below = $class->new(2); my $factorial = $class->new(3); $x = $x->bone(); - delete $x->{_a}; - delete $x->{_p}; + $x->{accuracy} = undef; + $x->{precision} = undef; my $limit = $class->new("1E-". ($scale-1)); #my $steps = 0; @@ -3057,12 +3378,21 @@ sub bcos { } if ($fallback) { # clear a/p after round, since user did not request it - delete $x->{_a}; - delete $x->{_p}; + $x->{accuracy} = undef; + $x->{precision} = undef; + } + + # Restore globals. We need to do it like this, because setting one + # undefines the other. + + if (defined $ab) { + $class -> accuracy($ab); + } else { + $class -> precision($pb); } - # restore globals - $$abr = $ab; - $$pbr = $pb; + + $class -> upgrade($upg); + $class -> downgrade($dng); return $downgrade -> new($x -> bdstr(), @r) if defined($downgrade) && $x -> is_int(); @@ -3158,24 +3488,26 @@ sub batan { # When user set globals, they would interfere with our calculation, so # disable them and later re-enable them. - no strict 'refs'; - my $abr = "$class\::accuracy"; - my $ab = $$abr; - $$abr = undef; - my $pbr = "$class\::precision"; - my $pb = $$pbr; - $$pbr = undef; - # We also need to disable any set A or P on $x (_find_round_parameters - # took them already into account), since these would interfere, too - delete $x->{_a}; - delete $x->{_p}; + + my $ab = $class -> accuracy(); + my $pb = $class -> precision(); + $class -> accuracy(undef); + $class -> precision(undef); # Disabling upgrading and downgrading is no longer necessary to avoid an # infinite recursion, but it avoids unnecessary upgrading and downgrading in # the intermediate computations. - local $Math::BigInt::upgrade = undef; - local $Math::BigFloat::downgrade = undef; + my $upg = $class -> upgrade(); + my $dng = $class -> downgrade(); + $class -> upgrade(undef); + $class -> downgrade(undef); + + # We also need to disable any set A or P on $x (_find_round_parameters took + # them already into account), since these would interfere, too. + + $x->{accuracy} = undef; + $x->{precision} = undef; my $over = $x * $x; # X ^ 2 my $x2 = $over->copy(); # X ^ 2; difference between terms @@ -3183,8 +3515,8 @@ sub batan { my $sign = 1; # start with -= my $below = $class->new(3); my $two = $class->new(2); - delete $x->{_a}; - delete $x->{_p}; + $x->{accuracy} = undef; + $x->{precision} = undef; my $limit = $class->new("1E-". ($scale-1)); #my $steps = 0; @@ -3225,13 +3557,21 @@ sub batan { } if ($fallback) { # Clear a/p after round, since user did not request it. - delete $x->{_a}; - delete $x->{_p}; + $x->{accuracy} = undef; + $x->{precision} = undef; + } + + # Restore globals. We need to do it like this, because setting one + # undefines the other. + + if (defined $ab) { + $class -> accuracy($ab); + } else { + $class -> precision($pb); } - # restore globals - $$abr = $ab; - $$pbr = $pb; + $class -> upgrade($upg); + $class -> downgrade($dng); return $downgrade -> new($x -> bdstr(), @r) if defined($downgrade) && ($x -> is_int() || $x -> is_inf()); @@ -3322,8 +3662,8 @@ sub batan2 { $y = $y -> round(@r); if ($fallback) { - delete $y->{_a}; - delete $y->{_p}; + $y->{accuracy} = undef; + $y->{precision} = undef; } return $y; @@ -3369,124 +3709,30 @@ sub bsqrt { $scale = abs($params[0] || $params[1]) + 4; # take whatever is defined } - # when user set globals, they would interfere with our calculation, so - # disable them and later re-enable them - no strict 'refs'; - my $abr = "$class\::accuracy"; - my $ab = $$abr; - $$abr = undef; - my $pbr = "$class\::precision"; - my $pb = $$pbr; - $$pbr = undef; - # we also need to disable any set A or P on $x (_find_round_parameters took - # them already into account), since these would interfere, too - delete $x->{_a}; - delete $x->{_p}; + # Shift the significand left or right to get the desired number of digits, + # which is 2*$scale with possibly one extra digit to ensure that the + # exponent is an even number. - # Disabling upgrading and downgrading is no longer necessary to avoid an - # infinite recursion, but it avoids unnecessary upgrading and downgrading in - # the intermediate computations. + my $l = $LIB -> _len($x->{_m}); + my $n = 2 * $scale - $l; # how much should we shift? + $n++ if ($l % 2 xor $LIB -> _is_odd($x->{_e})); + my ($na, $ns) = $n < 0 ? (abs($n), "-") : ($n, "+"); + $na = $LIB -> _new($na); - local $Math::BigInt::upgrade = undef; - local $Math::BigFloat::downgrade = undef; + $x->{_m} = $ns eq "+" ? $LIB -> _lsft($x->{_m}, $na, 10) + : $LIB -> _rsft($x->{_m}, $na, 10); - my $i = $LIB->_copy($x->{_m}); - $i = $LIB->_lsft($i, $x->{_e}, 10) unless $LIB->_is_zero($x->{_e}); - my $xas = Math::BigInt->bzero(); - $xas->{value} = $i; - - my $gs = $xas->copy()->bsqrt(); # some guess - - if (($x->{_es} ne '-') # guess can't be accurate if there are - # digits after the dot - && ($xas->bacmp($gs * $gs) == 0)) # guess hit the nail on the head? - { - # exact result, copy result over to keep $x - $x->{_m} = $gs->{value}; - $x->{_e} = $LIB->_zero(); - $x->{_es} = '+'; - $x = $x->bnorm(); - # shortcut to not run through _find_round_parameters again - if (defined $params[0]) { - $x = $x->bround($params[0], $params[2]); # then round accordingly - } else { - $x = $x->bfround($params[1], $params[2]); # then round accordingly - } - if ($fallback) { - # clear a/p after round, since user did not request it - delete $x->{_a}; - delete $x->{_p}; - } - # re-enable A and P, upgrade is taken care of by "local" - ${"$class\::accuracy"} = $ab; - ${"$class\::precision"} = $pb; - return $x; - } + $x->{_m} = $LIB -> _sqrt($x->{_m}); - # sqrt(2) = 1.4 because sqrt(2*100) = 1.4*10; so we can increase the - # accuracy of the result by multiplying the input by 100 and then divide the - # integer result of sqrt(input) by 10. Rounding afterwards returns the real - # result. - - # The following steps will transform 123.456 (in $x) into 123456 (in $y1) - my $y1 = $LIB->_copy($x->{_m}); - - my $length = $LIB->_len($y1); - - # Now calculate how many digits the result of sqrt(y1) would have - my $digits = int($length / 2); - - # But we need at least $scale digits, so calculate how many are missing - my $shift = $scale - $digits; - - # This happens if the input had enough digits - # (we take care of integer guesses above) - $shift = 0 if $shift < 0; - - # Multiply in steps of 100, by shifting left two times the "missing" digits - my $s2 = $shift * 2; - - # We now make sure that $y1 has the same odd or even number of digits than - # $x had. So when _e of $x is odd, we must shift $y1 by one digit left, - # because we always must multiply by steps of 100 (sqrt(100) is 10) and not - # steps of 10. The length of $x does not count, since an even or odd number - # of digits before the dot is not changed by adding an even number of digits - # after the dot (the result is still odd or even digits long). - $s2++ if $LIB->_is_odd($x->{_e}); - - $y1 = $LIB->_lsft($y1, $LIB->_new($s2), 10); - - # now take the square root and truncate to integer - $y1 = $LIB->_sqrt($y1); - - # By "shifting" $y1 right (by creating a negative _e) we calculate the final - # result, which is than later rounded to the desired scale. - - # calculate how many zeros $x had after the '.' (or before it, depending - # on sign of $dat, the result should have half as many: - my $dat = $LIB->_num($x->{_e}); - $dat = -$dat if $x->{_es} eq '-'; - $dat += $length; - - if ($dat > 0) { - # no zeros after the dot (e.g. 1.23, 0.49 etc) - # preserve half as many digits before the dot than the input had - # (but round this "up") - $dat = int(($dat+1)/2); - } else { - $dat = int(($dat)/2); - } - $dat -= $LIB->_len($y1); - if ($dat < 0) { - $dat = abs($dat); - $x->{_e} = $LIB->_new($dat); - $x->{_es} = '-'; - } else { - $x->{_e} = $LIB->_new($dat); - $x->{_es} = '+'; - } - $x->{_m} = $y1; - $x = $x->bnorm(); + # Adjust the exponent by the amount that we shifted the significand. The + # square root of the exponent is simply half of it: sqrt(10^(2*a)) = 10^a. + + ($x->{_e}, $x->{_es}) = $LIB -> _ssub($x->{_e}, $x->{_es}, $na, $ns); + $x->{_e} = $LIB -> _div($x->{_e}, $LIB -> _new("2")); + + # Normalize to get rid of any trailing zeros in the significand. + + $x -> bnorm(); # shortcut to not run through _find_round_parameters again if (defined $params[0]) { @@ -3494,17 +3740,15 @@ sub bsqrt { } else { $x = $x->bfround($params[1], $params[2]); # then round accordingly } + if ($fallback) { # clear a/p after round, since user did not request it - delete $x->{_a}; - delete $x->{_p}; + $x->{accuracy} = undef; + $x->{precision} = undef; } - # restore globals - $$abr = $ab; - $$pbr = $pb; - return $downgrade -> new($x -> bdstr(), @r) - if defined($downgrade) && ($x -> is_int() || $x -> is_inf()); + return $downgrade -> new($x, @r) + if defined($downgrade) && $x -> is_int(); $x; } @@ -3556,26 +3800,28 @@ sub broot { $scale = abs($params[0] || $params[1]) + 4; # take whatever is defined } - # when user set globals, they would interfere with our calculation, so - # disable them and later re-enable them - no strict 'refs'; - my $abr = "$class\::accuracy"; - my $ab = $$abr; - $$abr = undef; - my $pbr = "$class\::precision"; - my $pb = $$pbr; - $$pbr = undef; - # we also need to disable any set A or P on $x (_find_round_parameters took - # them already into account), since these would interfere, too - delete $x->{_a}; - delete $x->{_p}; + # When user set globals, they would interfere with our calculation, so + # disable them and later re-enable them. + + my $ab = $class -> accuracy(); + my $pb = $class -> precision(); + $class -> accuracy(undef); + $class -> precision(undef); # Disabling upgrading and downgrading is no longer necessary to avoid an # infinite recursion, but it avoids unnecessary upgrading and downgrading in # the intermediate computations. - local $Math::BigInt::upgrade = undef; - local $Math::BigFloat::downgrade = undef; + my $upg = $class -> upgrade(); + my $dng = $class -> downgrade(); + $class -> upgrade(undef); + $class -> downgrade(undef); + + # We also need to disable any set A or P on $x (_find_round_parameters took + # them already into account), since these would interfere, too. + + $x->{accuracy} = undef; + $x->{precision} = undef; # remember sign and make $x positive, since -4 ** (1/2) => -2 my $sign = 0; @@ -3623,8 +3869,8 @@ sub broot { } if ($done == 0) { my $u = $class->bone()->bdiv($y, $scale+4); - delete $u->{_a}; - delete $u->{_p}; + $u->{accuracy} = undef; + $u->{precision} = undef; $x = $x->bpow($u, $scale+4); # el cheapo } } @@ -3638,12 +3884,21 @@ sub broot { } if ($fallback) { # clear a/p after round, since user did not request it - delete $x->{_a}; - delete $x->{_p}; + $x->{accuracy} = undef; + $x->{precision} = undef; + } + + # Restore globals. We need to do it like this, because setting one + # undefines the other. + + if (defined $ab) { + $class -> accuracy($ab); + } else { + $class -> precision($pb); } - # restore globals - $$abr = $ab; - $$pbr = $pb; + + $class -> upgrade($upg); + $class -> downgrade($dng); return $downgrade -> new($x -> bdstr(), @r) if defined($downgrade) && ($x -> is_int() || $x -> is_inf()); @@ -3785,7 +4040,7 @@ sub bmfac { } sub blsft { - # shift left by $y (multiply by $b ** $y) + # shift left by $y in base $b, i.e., multiply by $b ** $y # set up parameters my ($class, $x, $y, $b, @r) @@ -3798,7 +4053,8 @@ sub blsft { return $x -> bnan(@r) if $x -> is_nan() || $y -> is_nan(); $b = 2 if !defined $b; - $b = $class -> new($b) unless ref($b) && $b -> isa($class); + $b = $class -> new($b) + unless defined(blessed($b)) && $b -> isa(__PACKAGE__); return $x -> bnan(@r) if $b -> is_nan(); # There needs to be more checking for special cases here. Fixme! @@ -3814,7 +4070,7 @@ sub blsft { } sub brsft { - # shift right by $y (divide $b ** $y) + # shift right by $y in base $b, i.e., divide by $b ** $y # set up parameters my ($class, $x, $y, $b, @r) @@ -3829,7 +4085,8 @@ sub brsft { # There needs to be more checking for special cases here. Fixme! $b = 2 if !defined $b; - $b = $class -> new($b) unless ref($b) && $b -> isa($class); + $b = $class -> new($b) + unless defined(blessed($b)) && $b -> isa(__PACKAGE__); return $x -> bnan(@r) if $b -> is_nan(); # shift by a negative amount? @@ -3847,6 +4104,88 @@ sub brsft { # Bitwise methods ############################################################################### +# Bitwise left shift. + +sub bblsft { + # We don't call objectify(), because the bitwise methods should not + # upgrade/downgrade, even when upgrading/downgrading is enabled. + + my ($class, $x, $y, @r) = ref($_[0]) ? (ref($_[0]), @_) : @_; + + my $xint = Math::BigInt -> bblsft($x, $y, @r); + + # Temporarily disable downgrading. + + my $dng = $class -> downgrade(); + $class -> downgrade(undef); + + # convert to our class without downgrading. + + my $xflt = $class -> new($xint); + + # Reset downgrading. + + $class -> downgrade($dng); + + # If we are called as a class method, the first operand might not be an + # object of this class, so check. + + if (defined(blessed($x)) && $x -> isa(__PACKAGE__)) { + $x -> {sign} = $xflt -> {sign}; + $x -> {_m} = $xflt -> {_m}; + $x -> {_es} = $xflt -> {_es}; + $x -> {_e} = $xflt -> {_e}; + } else { + $x = $xflt; + } + + # Now we might downgrade. + + return $downgrade -> new($x) if defined($downgrade); + $x -> round(@r); +} + +# Bitwise right shift. + +sub bbrsft { + # We don't call objectify(), because the bitwise methods should not + # upgrade/downgrade, even when upgrading/downgrading is enabled. + + my ($class, $x, $y, @r) = ref($_[0]) ? (ref($_[0]), @_) : @_; + + my $xint = Math::BigInt -> bbrsft($x, $y, @r); + + # Temporarily disable downgrading. + + my $dng = $class -> downgrade(); + $class -> downgrade(undef); + + # Convert to our class without downgrading. + + my $xflt = $class -> new($xint); + + # Reset downgrading. + + $class -> downgrade($dng); + + # If we are called as a class method, the first operand might not be an + # object of this class, so check. + + if (defined(blessed($x)) && $x -> isa(__PACKAGE__)) { + $x -> {sign} = $xflt -> {sign}; + $x -> {_m} = $xflt -> {_m}; + $x -> {_es} = $xflt -> {_es}; + $x -> {_e} = $xflt -> {_e}; + } else { + $x = $xflt; + } + + # Now we might downgrade. + + return $downgrade -> new($x) if defined($downgrade); + $x -> round(@r); +} + sub band { my ($class, $x, $y, @r) = ref($_[0]) && ref($_[0]) eq ref($_[1]) ? (ref($_[0]), @_) @@ -3856,16 +4195,18 @@ sub band { return $x -> bnan(@r) if $x -> is_nan() || $y -> is_nan(); - my $xtmp = Math::BigInt -> new($x -> bint()); # to Math::BigInt - $xtmp = $xtmp -> band($y); + my $xint = $x -> as_int(); # to Math::BigInt + my $yint = $y -> as_int(); # to Math::BigInt - return $xtmp -> round(@r) if defined $downgrade; + $xint = $xint -> band($yint); - $xtmp = $class -> new($xtmp); # back to Math::BigFloat - $x -> {sign} = $xtmp -> {sign}; - $x -> {_m} = $xtmp -> {_m}; - $x -> {_es} = $xtmp -> {_es}; - $x -> {_e} = $xtmp -> {_e}; + return $xint -> round(@r) if defined $downgrade; + + my $xflt = $class -> new($xint); # back to Math::BigFloat + $x -> {sign} = $xflt -> {sign}; + $x -> {_m} = $xflt -> {_m}; + $x -> {_es} = $xflt -> {_es}; + $x -> {_e} = $xflt -> {_e}; return $x -> round(@r); } @@ -3879,16 +4220,18 @@ sub bior { return $x -> bnan(@r) if $x -> is_nan() || $y -> is_nan(); - my $xtmp = Math::BigInt -> new($x -> bint()); # to Math::BigInt - $xtmp = $xtmp -> bior($y); + my $xint = $x -> as_int(); # to Math::BigInt + my $yint = $y -> as_int(); # to Math::BigInt + + $xint = $xint -> bior($yint); - return $xtmp -> round(@r) if defined $downgrade; + return $xint -> round(@r) if defined $downgrade; - $xtmp = $class -> new($xtmp); # back to Math::BigFloat - $x -> {sign} = $xtmp -> {sign}; - $x -> {_m} = $xtmp -> {_m}; - $x -> {_es} = $xtmp -> {_es}; - $x -> {_e} = $xtmp -> {_e}; + my $xflt = $class -> new($xint); # back to Math::BigFloat + $x -> {sign} = $xflt -> {sign}; + $x -> {_m} = $xflt -> {_m}; + $x -> {_es} = $xflt -> {_es}; + $x -> {_e} = $xflt -> {_e}; return $x -> round(@r); } @@ -3902,16 +4245,18 @@ sub bxor { return $x -> bnan(@r) if $x -> is_nan() || $y -> is_nan(); - my $xtmp = Math::BigInt -> new($x -> bint()); # to Math::BigInt - $xtmp = $xtmp -> bxor($y); + my $xint = $x -> as_int(); # to Math::BigInt + my $yint = $y -> as_int(); # to Math::BigInt - return $xtmp -> round(@r) if defined $downgrade; + $xint = $xint -> bxor($yint); - $xtmp = $class -> new($xtmp); # back to Math::BigFloat - $x -> {sign} = $xtmp -> {sign}; - $x -> {_m} = $xtmp -> {_m}; - $x -> {_es} = $xtmp -> {_es}; - $x -> {_e} = $xtmp -> {_e}; + return $xint -> round(@r) if defined $downgrade; + + my $xflt = $class -> new($xint); # back to Math::BigFloat + $x -> {sign} = $xflt -> {sign}; + $x -> {_m} = $xflt -> {_m}; + $x -> {_es} = $xflt -> {_es}; + $x -> {_e} = $xflt -> {_e}; return $x -> round(@r); } @@ -3923,16 +4268,16 @@ sub bnot { return $x -> bnan(@r) if $x -> is_nan(); - my $xtmp = Math::BigInt -> new($x -> bint()); # to Math::BigInt - $xtmp = $xtmp -> bnot(); + my $xint = $x -> as_int(); # to Math::BigInt + $xint = $xint -> bnot(); - return $xtmp -> round(@r) if defined $downgrade; + return $xint -> round(@r) if defined $downgrade; - $xtmp = $class -> new($xtmp); # back to Math::BigFloat - $x -> {sign} = $xtmp -> {sign}; - $x -> {_m} = $xtmp -> {_m}; - $x -> {_es} = $xtmp -> {_es}; - $x -> {_e} = $xtmp -> {_e}; + my $xflt = $class -> new($xint); # back to Math::BigFloat + $x -> {sign} = $xflt -> {sign}; + $x -> {_m} = $xflt -> {_m}; + $x -> {_es} = $xflt -> {_es}; + $x -> {_e} = $xflt -> {_e}; return $x -> round(@r); } @@ -3959,12 +4304,12 @@ sub bround { return $x; } - # Scale is now either $x->{_a}, $accuracy, or the input argument. Test + # Scale is now either $x->{accuracy}, $accuracy, or the input argument. Test # whether $x already has lower accuracy, do nothing in this case but do # round if the accuracy is the same, since a math operation might want to # round a number with A=5 to 5 digits afterwards again - if (defined $x->{_a} && $x->{_a} < $scale) { + if (defined $x->{accuracy} && $x->{accuracy} < $scale) { return $downgrade -> new($x) if defined($downgrade) && ($x->is_int() || $x->is_inf() || $x->is_nan()); return $x; @@ -3983,7 +4328,7 @@ sub bround { # 1: never round a 0 # 2: if we should keep more digits than the mantissa has, do nothing if ($x->is_zero() || $LIB->_len($x->{_m}) <= $scale) { - $x->{_a} = $scale if !defined $x->{_a} || $x->{_a} > $scale; + $x->{accuracy} = $scale if !defined $x->{accuracy} || $x->{accuracy} > $scale; return $downgrade -> new($x) if defined($downgrade) && ($x->is_int() || $x->is_inf() || $x->is_nan()); return $x; @@ -3994,8 +4339,8 @@ sub bround { $m = $m->bround($scale, $mode); # round mantissa $x->{_m} = $m->{value}; # get our mantissa back - $x->{_a} = $scale; # remember rounding - delete $x->{_p}; # and clear P + $x->{accuracy} = $scale; # remember rounding + $x->{precision} = undef; # and clear P # bnorm() downgrades if necessary, so no need to check whether to downgrade. $x->bnorm(); # del trailing zeros gen. by bround() @@ -4020,7 +4365,7 @@ sub bfround { # never round a 0, +-inf, NaN if ($x->is_zero()) { - $x->{_p} = $scale if !defined $x->{_p} || $x->{_p} < $scale; # -3 < -2 + $x->{precision} = $scale if !defined $x->{precision} || $x->{precision} < $scale; # -3 < -2 return $downgrade -> new($x) if defined($downgrade) && ($x->is_int() || $x->is_inf() || $x->is_nan()); return $x; @@ -4033,14 +4378,14 @@ sub bfround { } # don't round if x already has lower precision - if (defined $x->{_p} && $x->{_p} < 0 && $scale < $x->{_p}) { + if (defined $x->{precision} && $x->{precision} < 0 && $scale < $x->{precision}) { return $downgrade -> new($x) if defined($downgrade) && ($x->is_int() || $x->is_inf() || $x->is_nan()); return $x; } - $x->{_p} = $scale; # remember round in any case - delete $x->{_a}; # and clear A + $x->{precision} = $scale; # remember round in any case + $x->{accuracy} = undef; # and clear A if ($scale < 0) { # round right from the '.' @@ -4229,12 +4574,14 @@ sub bgcd { my ($class, @args) = objectify(0, @_); my $x = shift @args; - $x = ref($x) && $x -> isa($class) ? $x -> copy() : $class -> new($x); + $x = defined(blessed($x)) && $x -> isa(__PACKAGE__) ? $x -> copy() + : $class -> new($x); return $class->bnan() unless $x -> is_int(); while (@args) { my $y = shift @args; - $y = $class->new($y) unless ref($y) && $y -> isa($class); + $y = $class->new($y) + unless defined(blessed($y)) && $y -> isa(__PACKAGE__); return $class->bnan() unless $y -> is_int(); # greatest common divisor @@ -4268,12 +4615,14 @@ sub blcm { my ($class, @args) = objectify(0, @_); my $x = shift @args; - $x = ref($x) && $x -> isa($class) ? $x -> copy() : $class -> new($x); + $x = defined(blessed($x)) && $x -> isa(__PACKAGE__) ? $x -> copy() + : $class -> new($x); return $class->bnan() if $x->{sign} !~ /^[+-]$/; # x NaN? while (@args) { my $y = shift @args; - $y = $class -> new($y) unless ref($y) && $y -> isa($class); + $y = $class -> new($y) + unless defined(blessed($y)) && $y -> isa(__PACKAGE__); return $x->bnan() unless $y -> is_int(); my $gcd = $x -> bgcd($y); $x = $x -> bdiv($gcd) -> bmul($y); @@ -4394,17 +4743,13 @@ sub sparts { # Finite number. - my $mant = $x -> copy(); + my $mant = $class -> new($x); $mant->{_es} = '+'; $mant->{_e} = $LIB->_zero(); $mant = $downgrade -> new($mant) if defined $downgrade; return $mant unless wantarray; - my $expo = bless { sign => $x -> {_es}, - _m => $LIB->_copy($x -> {_e}), - _es => '+', - _e => $LIB->_zero(), - }, $class; + my $expo = $class -> new($x -> {_es} . $LIB->_str($x -> {_e})); $expo = $downgrade -> new($expo) if defined $downgrade; return ($mant, $expo); } @@ -4675,14 +5020,14 @@ sub bstr { $es = '-'.$es if $x->{sign} eq '-'; # if set accuracy or precision, pad with zeros on the right side - if ((defined $x->{_a}) && ($not_zero)) { + if ((defined $x->{accuracy}) && ($not_zero)) { # 123400 => 6, 0.1234 => 4, 0.001234 => 4 - my $zeros = $x->{_a} - $cad; # cad == 0 => 12340 - $zeros = $x->{_a} - $len if $cad != $len; + my $zeros = $x->{accuracy} - $cad; # cad == 0 => 12340 + $zeros = $x->{accuracy} - $len if $cad != $len; $es .= $dot.'0' x $zeros if $zeros > 0; - } elsif ((($x->{_p} || 0) < 0)) { + } elsif ((($x->{precision} || 0) < 0)) { # 123400 => 6, 0.1234 => 4, 0.001234 => 6 - my $zeros = -$x->{_p} + $cad; + my $zeros = -$x->{precision} + $cad; $es .= $dot.'0' x $zeros if $zeros > 0; } $es; @@ -4705,7 +5050,7 @@ sub bdstr { # Upgrade? return $upgrade -> bdstr($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4756,7 +5101,7 @@ sub bsstr { # Upgrade? return $upgrade -> bsstr($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4781,7 +5126,7 @@ sub bnstr { # Upgrade? return $upgrade -> bnstr($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4832,7 +5177,7 @@ sub bestr { # Upgrade? return $upgrade -> bestr($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4887,7 +5232,7 @@ sub bfstr { # Upgrade? return $upgrade -> bfstr($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4921,7 +5266,7 @@ sub to_hex { # Upgrade? return $upgrade -> to_hex($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4952,8 +5297,8 @@ sub to_oct { # Upgrade? - return $upgrade -> to_hex($x, @r) - if defined($upgrade) && !$x -> isa($class); + return $upgrade -> to_oct($x, @r) + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4984,8 +5329,8 @@ sub to_bin { # Upgrade? - return $upgrade -> to_hex($x, @r) - if defined($upgrade) && !$x -> isa($class); + return $upgrade -> to_bin($x, @r) + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -5327,10 +5672,10 @@ sub numify { sub import { my $class = shift; $IMPORT++; # remember we did import() - - my @import = ('objectify'); my @a; # unrecognized arguments + my @import = (); + while (@_) { my $param = shift; @@ -5391,6 +5736,13 @@ sub import { next; } + # Fall-back accuracy. + + if ($param eq 'div_scale') { + $class -> div_scale(shift); + next; + } + # Backend library. if ($param =~ /^(lib|try|only)\z/) { @@ -5415,10 +5767,11 @@ sub import { Math::BigInt -> import(@import); - # find out which one was actually loaded + # find out which library was actually loaded $LIB = Math::BigInt -> config('lib'); - $class->export_to_level(1, $class, @a); # export wanted functions + $class -> SUPER::import(@a); # for subclasses + $class -> export_to_level(1, $class, @a) if @a; # need this, too } sub _len_to_steps { @@ -5460,7 +5813,7 @@ sub _log { my $class = ref $x; # in case of $x == 1, result is 0 - return $x->bzero() if $x->is_one(); + return $x -> bzero() if $x -> is_one(); # XXX TODO: rewrite this in a similar manner to bexp() @@ -5479,56 +5832,49 @@ sub _log { # ln (x) = 2 | --- + - * --- + - * --- + ... | x > 1/2 # |_ x 2 x^2 3 x^3 _| - my ($limit, $v, $u, $below, $factor, $next, $over, $f); + # scale used in intermediate computations + my $scaleup = $scale + 4; - $v = $x->copy(); + my ($v, $u, $numer, $denom, $factor, $f); + + $v = $x -> copy(); $v = $v -> binc(); # v = x+1 - $x = $x->bdec(); - $u = $x->copy(); # u = x-1; x = x-1 - $x = $x->bdiv($v, $scale); # first term: u/v - $below = $v->copy(); - $over = $u->copy(); + $x = $x -> bdec(); + $u = $x -> copy(); # u = x-1; x = x-1 + + $x = $x -> bdiv($v, $scaleup); # first term: u/v + + $numer = $u -> copy(); # numerator + $denom = $v -> copy(); # denominator + $u = $u -> bmul($u); # u^2 $v = $v -> bmul($v); # v^2 - $below = $below->bmul($v); # u^3, v^3 - $over = $over->bmul($u); - $factor = $class->new(3); - $f = $class->new(2); - $limit = $class->new("1E-". ($scale-1)); + $numer = $numer -> bmul($u); # u^3 + $denom = $denom -> bmul($v); # v^3 - while (3 < 5) { - # we calculate the next term, and add it to the last - # when the next term is below our limit, it won't affect the outcome - # anymore, so we stop + $factor = $class -> new(3); + $f = $class -> new(2); - # calculating the next term simple from over/below will result in quite - # a time hog if the input has many digits, since over and below will - # accumulate more and more digits, and the result will also have many - # digits, but in the end it is rounded to $scale digits anyway. So if we - # round $over and $below first, we save a lot of time for the division - # (not with log(1.2345), but try log (123**123) to see what I mean. This - # can introduce a rounding error if the division result would be f.i. - # 0.1234500000001 and we round it to 5 digits it would become 0.12346, - # but if we truncated $over and $below we might get 0.12345. Does this - # matter for the end result? So we give $over and $below 4 more digits - # to be on the safe side (unscientific error handling as usual... :+D - - $next = $over->copy()->bround($scale+4) - ->bdiv($below->copy()->bmul($factor)->bround($scale+4), - $scale); + while (1) { + my $next = $numer -> copy() -> bround($scaleup) + -> bdiv($denom -> copy() -> bmul($factor) -> bround($scaleup), $scaleup); - last if $next->bacmp($limit) <= 0; + $next->{accuracy} = undef; + $next->{precision} = undef; + my $x_prev = $x -> copy(); + $x = $x -> badd($next); + + last if $x -> bacmp($x_prev) == 0; - delete $next->{_a}; - delete $next->{_p}; - $x = $x->badd($next); # calculate things for the next term - $over *= $u; - $below *= $v; - $factor = $factor->badd($f); + $numer = $numer -> bmul($u); + $denom = $denom -> bmul($v); + $factor = $factor -> badd($f); } - $x->bmul($f); # $x *= 2 + + $x = $x -> bmul($f); # $x *= 2 + $x = $x -> bround($scale); } sub _log_10 { @@ -5557,8 +5903,12 @@ sub _log_10 { # In addition, the values for blog(2) and blog(10) are cached. - # Calculate nr of digits before dot. x = 123, dbd = 3; x = 1.23, dbd = 1; - # x = 0.0123, dbd = -1; x = 0.000123, dbd = -3, etc. + # Calculate the number of digits before the dot, i.e., 1 + floor(log10(x)): + # x = 123 => dbd = 3 + # x = 1.23 => dbd = 1 + # x = 0.0123 => dbd = -1 + # x = 0.000123 => dbd = -3 + # etc. my $dbd = $LIB->_num($x->{_e}); $dbd = -$dbd if $x->{_es} eq '-'; @@ -5569,6 +5919,13 @@ sub _log_10 { my $calc = 1; # do some calculation? + # No upgrading or downgrading in the intermediate computations. + + my $upg = $class -> upgrade(); + my $dng = $class -> downgrade(); + $class -> upgrade(undef); + $class -> downgrade(undef); + # disable the shortcut for 10, since we need log(10) and this would recurse # infinitely deep if ($x->{_es} eq '+' && # $x == 10 @@ -5629,7 +5986,6 @@ sub _log_10 { # at import() time, since not everybody needs this) $LOG_10 = $class->new($LOG_10, undef, undef) unless ref $LOG_10; - #print "x = $x, dbd = $dbd, calc = $calc\n"; # got more than one digit before the dot, or more than one zero after # the dot, so do: # log(123) == log(1.23) + log(10) * 2 @@ -5641,13 +5997,6 @@ sub _log_10 { } else { # else: slower, compute and cache result - # Disabling upgrading and downgrading is no longer necessary to - # avoid an infinite recursion, but it avoids unnecessary upgrading - # and downgrading in the intermediate computations. - - local $Math::BigInt::upgrade = undef; - local $Math::BigFloat::downgrade = undef; - # shorten the time to calculate log(10) based on the following: # log(1.25 * 8) = log(1.25) + log(8) # = log(1.25) + log(2) + log(2) + log(2) @@ -5715,14 +6064,6 @@ sub _log_10 { $l_2 = $LOG_2->copy(); # copy() for the mul below } else { # else: slower, compute and cache result - - # Disabling upgrading and downgrading is no longer necessary to - # avoid an infinite recursion, but it avoids unnecessary upgrading - # and downgrading in the intermediate computations. - - local $Math::BigInt::upgrade = undef; - local $Math::BigFloat::downgrade = undef; - $l_2 = $two->copy(); $l_2 = $l_2->_log($scale); # scale+4, actually $LOG_2 = $l_2->copy(); # cache the result for later @@ -5738,6 +6079,11 @@ sub _log_10 { $x = $x->badd($l_10) if defined $l_10; # correct it by ln(10) $x = $x->badd($l_2) if defined $l_2; # and maybe by ln(2) + # Restore globals + + $class -> upgrade($upg); + $class -> downgrade($dng); + # all done, $x contains now the result $x; } @@ -5781,26 +6127,28 @@ sub _pow { $scale = abs($params[0] || $params[1]) + 4; # take whatever is defined } - # when user set globals, they would interfere with our calculation, so - # disable them and later re-enable them - no strict 'refs'; - my $abr = "$class\::accuracy"; - my $ab = $$abr; - $$abr = undef; - my $pbr = "$class\::precision"; - my $pb = $$pbr; - $$pbr = undef; - # we also need to disable any set A or P on $x (_find_round_parameters took - # them already into account), since these would interfere, too - delete $x->{_a}; - delete $x->{_p}; + # When user set globals, they would interfere with our calculation, so + # disable them and later re-enable them. + + my $ab = $class -> accuracy(); + my $pb = $class -> precision(); + $class -> accuracy(undef); + $class -> precision(undef); # Disabling upgrading and downgrading is no longer necessary to avoid an # infinite recursion, but it avoids unnecessary upgrading and downgrading in # the intermediate computations. - local $Math::BigInt::upgrade = undef; - local $Math::BigFloat::downgrade = undef; + my $upg = $class -> upgrade(); + my $dng = $class -> downgrade(); + $class -> upgrade(undef); + $class -> downgrade(undef); + + # We also need to disable any set A or P on $x (_find_round_parameters took + # them already into account), since these would interfere, too. + + $x->{accuracy} = undef; + $x->{precision} = undef; my ($limit, $v, $u, $below, $factor, $next, $over); @@ -5843,12 +6191,22 @@ sub _pow { } if ($fallback) { # clear a/p after round, since user did not request it - delete $x->{_a}; - delete $x->{_p}; + $x->{accuracy} = undef; + $x->{precision} = undef; } - # restore globals - $$abr = $ab; - $$pbr = $pb; + + # Restore globals. We need to do it like this, because setting one + # undefines the other. + + if (defined $ab) { + $class -> accuracy($ab); + } else { + $class -> precision($pb); + } + + $class -> upgrade($upg); + $class -> downgrade($dng); + $x; } @@ -5993,6 +6351,8 @@ Math::BigFloat - arbitrary size floating # Bitwise methods + $x->bblsft($y); # bitwise left shift + $x->bbrsft($y); # bitwise right shift $x->band($y); # bitwise and $x->bior($y); # bitwise inclusive or $x->bxor($y); # bitwise exclusive or @@ -6290,6 +6650,12 @@ Multiply $x by $y, and then add $z to th This method was added in v1.87 of Math::BigInt (June 2007). +=item binv() + + $x->binv(); + +Invert the value of $x, i.e., compute 1/$x. + =item bdiv() $q = $x->bdiv($y); @@ -6618,16 +6984,6 @@ See the respective low-level library doc See L for more details about using a different low-level library. -=head2 Using Math::BigInt::Lite - -For backwards compatibility reasons it is still possible to -request a different storage class for use with Math::BigFloat: - - use Math::BigFloat with => 'Math::BigInt::Lite'; - -However, this request is ignored, as the current code now uses the low-level -math library for directly storing the number parts. - =head1 EXPORTS C exports nothing by default, but can export the C @@ -6637,21 +6993,6 @@ method: print bpi(10), "\n"; -=head1 CAVEATS - -Do not try to be clever to insert some operations in between switching -libraries: - - require Math::BigFloat; - my $matter = Math::BigFloat->bone() + 4; # load BigInt and Calc - Math::BigFloat->import( lib => 'Pari' ); # load Pari, too - my $anti_matter = Math::BigFloat->bone()+4; # now use Pari - -This will create objects with numbers stored in two different backend libraries, -and B will happen when you use these together: - - my $flash_and_bang = $matter + $anti_matter; # Don't do this! - =over =item stringify, bstr() @@ -6771,28 +7112,6 @@ L -=item * CPAN Ratings - -L - -=item * The Bignum mailing list - -=over 4 - -=item * Post to mailing list - -C - -=item * View mailing list - -L - -=item * Subscribe/Unsubscribe - -L - -=back - =back =head1 LICENSE @@ -6802,10 +7121,12 @@ the same terms as Perl itself. =head1 SEE ALSO -L and L as well as the backends -L, L, and L. +L and L as well as the backend libraries +L, L, and L, +L, and L. -The pragmas L, L and L. +The pragmas L, L, and L might also be of interest. In +addition there is the L pragma which does upgrading and downgrading. =head1 AUTHORS Index: gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigInt.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigInt.pm,v diff -u -p -a -u -p -r1.8 BigInt.pm --- gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigInt.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigInt.pm 22 Jan 2025 00:37:42 -0000 @@ -8,10 +8,11 @@ package Math::BigInt; # # The following hash values are used: -# value: unsigned int with actual value (as a Math::BigInt::Calc or similar) -# sign : +, -, NaN, +inf, -inf -# _a : accuracy -# _p : precision +# +# sign : "+", "-", "+inf", "-inf", or "NaN" +# value : unsigned int with actual value ($LIB thingy) +# accuracy : accuracy (scalar) +# precision : precision (scalar) # Remember not to take shortcuts ala $xs = $x->{value}; $LIB->foo($xs); since # underlying lib might change the reference! @@ -23,7 +24,7 @@ use warnings; use Carp qw< carp croak >; use Scalar::Util qw< blessed refaddr >; -our $VERSION = '1.999837'; +our $VERSION = '2.003002'; $VERSION =~ tr/_//d; require Exporter; @@ -58,14 +59,15 @@ use overload '%' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bmod($_[0]) : $_[0] -> copy() -> bmod($_[1]); }, + '**' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bpow($_[0]) : $_[0] -> copy() -> bpow($_[1]); }, - '<<' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> blsft($_[0]) - : $_[0] -> copy() -> blsft($_[1]); }, + '<<' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bblsft($_[0]) + : $_[0] -> copy() -> bblsft($_[1]); }, - '>>' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> brsft($_[0]) - : $_[0] -> copy() -> brsft($_[1]); }, + '>>' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bbrsft($_[0]) + : $_[0] -> copy() -> bbrsft($_[1]); }, # overload key: assign @@ -81,9 +83,9 @@ use overload '**=' => sub { $_[0] -> bpow($_[1]); }, - '<<=' => sub { $_[0] -> blsft($_[1]); }, + '<<=' => sub { $_[0] -> bblsft($_[1]); }, - '>>=' => sub { $_[0] -> brsft($_[1]); }, + '>>=' => sub { $_[0] -> bbrsft($_[1]); }, # 'x=' => sub { }, @@ -235,7 +237,7 @@ my $nan = 'NaN'; my $DEFAULT_LIB = 'Math::BigInt::Calc'; my $LIB; -# Has import() been called yet? Needed to make "require" work. +# Has import() been called yet? This variable is needed to make "require" work. my $IMPORT = 0; @@ -254,7 +256,7 @@ sub FETCH { } sub STORE { - $rnd_mode = $_[0]->round_mode($_[1]); + $rnd_mode = (ref $_[0]) -> round_mode($_[1]); } BEGIN { @@ -275,216 +277,355 @@ sub round_mode { my $self = shift; my $class = ref($self) || $self || __PACKAGE__; - if (@_) { # setter + # setter/mutator + + if (@_) { my $m = shift; croak("The value for 'round_mode' must be defined") unless defined $m; croak("Unknown round mode '$m'") unless $m =~ /^(even|odd|\+inf|\-inf|zero|trunc|common)$/; - no strict 'refs'; - ${"${class}::round_mode"} = $m; + + if (ref($self) && exists $self -> {round_mode}) { + $self->{round_mode} = $m; + } else { + no strict 'refs'; + ${"${class}::round_mode"} = $m; + } } - else { # getter - no strict 'refs'; - my $m = ${"${class}::round_mode"}; - defined($m) ? $m : $round_mode; + # getter/accessor + + else { + if (ref($self) && exists $self -> {round_mode}) { + return $self->{round_mode}; + } else { + no strict 'refs'; + my $m = ${"${class}::round_mode"}; + return defined($m) ? $m : $round_mode; + } } } sub upgrade { - no strict 'refs'; - # make Class->upgrade() work my $self = shift; my $class = ref($self) || $self || __PACKAGE__; - # need to set new value? - if (@_ > 0) { - return ${"${class}::upgrade"} = $_[0]; + # setter/mutator + + if (@_) { + my $u = shift; + if (ref($self) && exists $self -> {upgrade}) { + $self -> {upgrade} = $u; + } else { + no strict 'refs'; + ${"${class}::upgrade"} = $u; + } + } + + # getter/accessor + + else { + if (ref($self) && exists $self -> {upgrade}) { + return $self -> {upgrade}; + } else { + no strict 'refs'; + return ${"${class}::upgrade"}; + } } - ${"${class}::upgrade"}; } sub downgrade { - no strict 'refs'; - # make Class->downgrade() work my $self = shift; my $class = ref($self) || $self || __PACKAGE__; - # need to set new value? - if (@_ > 0) { - return ${"${class}::downgrade"} = $_[0]; + + # setter/mutator + + if (@_) { + my $d = shift; + if (ref($self) && exists $self -> {downgrade}) { + $self -> {downgrade} = $d; + } else { + no strict 'refs'; + ${"${class}::downgrade"} = $d; + } + } + + # getter/accessor + + else { + if (ref($self) && exists $self -> {downgrade}) { + return $self -> {downgrade}; + } else { + no strict 'refs'; + return ${"${class}::downgrade"}; + } } - ${"${class}::downgrade"}; } sub div_scale { my $self = shift; my $class = ref($self) || $self || __PACKAGE__; - if (@_) { # setter - my $ds = shift; - croak("The value for 'div_scale' must be defined") unless defined $ds; - croak("The value for 'div_scale' must be positive") unless $ds > 0; - $ds = $ds -> numify() if defined(blessed($ds)); - no strict 'refs'; - ${"${class}::div_scale"} = $ds; + # setter/mutator + + if (@_) { + my $f = shift; + croak("The value for 'div_scale' must be defined") unless defined $f; + $f = $f -> can('numify') ? $f -> numify() : 0 + "$f" if ref($f); + # also croak on non-numerical + croak "div_scale must be a number, not '$f'" + unless $f =~/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?\z/; + croak "div_scale must be an integer, not '$f'" + if $f != int $f; + # It is not documented what div_scale <= 0 means, but Astro::Units sets + # div_scale to 0 and fails its tests if this is not supported. So we + # silently support div_scale = 0. + croak "div_scale must be positive, not '$f'" if $f < 0; + + if (ref($self) && exists $self -> {div_scale}) { + $self -> {div_scale} = $f; + } else { + no strict 'refs'; + ${"${class}::div_scale"} = $f; + } } - else { # getter - no strict 'refs'; - my $ds = ${"${class}::div_scale"}; - defined($ds) ? $ds : $div_scale; + # getter/accessor + + else { + if (ref($self) && exists $self -> {div_scale}) { + return $self -> {div_scale}; + } else { + no strict 'refs'; + my $f = ${"${class}::div_scale"}; + return defined($f) ? $f : $div_scale; + } } } sub accuracy { - # $x->accuracy($a); ref($x) $a - # $x->accuracy(); ref($x) - # Class->accuracy(); class - # Class->accuracy($a); class $a - my $x = shift; my $class = ref($x) || $x || __PACKAGE__; - no strict 'refs'; - if (@_ > 0) { + # setter/mutator + + if (@_) { my $a = shift; + if (defined $a) { - $a = $a->numify() if ref($a) && $a->can('numify'); - # also croak on non-numerical - if (!$a || $a <= 0) { - croak('Argument to accuracy must be greater than zero'); - } - if (int($a) != $a) { - croak('Argument to accuracy must be an integer'); - } + $a = $a -> can('numify') ? $a -> numify() : 0 + "$a" if ref($a); + croak "accuracy must be a number, not '$a'" + if $a !~ /^\s*[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?\s*\z/; + croak "accuracy must be an integer, not '$a'" + if $a != int $a; } if (ref($x)) { - # Set instance variable. - $x = $x->bround($a) if $a; # not for undef, 0 - $x->{_a} = $a; # set/overwrite, even if not rounded - delete $x->{_p}; # clear P - # Why return class variable here? Fixme! - $a = ${"${class}::accuracy"} unless defined $a; + $x = $x -> bround($a) if defined $a; + $x -> {precision} = undef; # clear instance P + $x -> {accuracy} = $a; # set instance A } else { - # Set class variable. - ${"${class}::accuracy"} = $a; # set global A - ${"${class}::precision"} = undef; # clear global P + no strict 'refs'; + ${"${class}::precision"} = undef; # clear class P + ${"${class}::accuracy"} = $a; # set class A } - - return $a; # shortcut } - # Return instance variable. - return $x->{_a} if ref($x) && (defined($x->{_a}) || defined($x->{_p})); + # getter/accessor - # Return class variable. - return ${"${class}::accuracy"}; + else { + if (ref($x)) { + return $x -> {accuracy}; + } else { + no strict 'refs'; + return ${"${class}::accuracy"}; + } + } } sub precision { - # $x->precision($p); ref($x) $p - # $x->precision(); ref($x) - # Class->precision(); class - # Class->precision($p); class $p - my $x = shift; my $class = ref($x) || $x || __PACKAGE__; - no strict 'refs'; - if (@_ > 0) { + # setter/mutator + + if (@_) { my $p = shift; + if (defined $p) { - $p = $p->numify() if ref($p) && $p->can('numify'); - if ($p != int $p) { - croak('Argument to precision must be an integer'); - } + $p = $p -> can('numify') ? $p -> numify() : 0 + "$p" if ref($p); + croak "precision must be a number, not '$p'" + if $p !~ /^\s*[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?\s*\z/; + croak "precision must be an integer, not '$p'" + if $p != int $p; + } + + if (ref($x)) { + $x = $x -> bfround($p) if defined $p; + $x -> {accuracy} = undef; # clear instance A + $x -> {precision} = $p; # set instance P + } else { + no strict 'refs'; + ${"${class}::accuracy"} = undef; # clear class A + ${"${class}::precision"} = $p; # set class P } + } + + # getter/accessor + else { if (ref($x)) { - # Set instance variable. - $x = $x->bfround($p) if $p; # not for undef, 0 - $x->{_p} = $p; # set/overwrite, even if not rounded - delete $x->{_a}; # clear A - # Why return class variable here? Fixme! - $p = ${"${class}::precision"} unless defined $p; + return $x -> {precision}; + } else { + no strict 'refs'; + return ${"${class}::precision"}; + } + } +} + +sub trap_inf { + my $self = shift; + my $class = ref($self) || $self || __PACKAGE__; + + # setter/mutator + + if (@_) { + my $b = shift() ? 1 : 0; + if (ref($self) && exists $self -> {trap_inf}) { + $self -> {trap_inf} = $b; + } else { + no strict 'refs'; + ${"${class}::_trap_inf"} = $b; + } + } + + # getter/accessor + + else { + if (ref($self) && exists $self -> {trap_inf}) { + return $self -> {trap_inf}; } else { - # Set class variable. - ${"${class}::precision"} = $p; # set global P - ${"${class}::accuracy"} = undef; # clear global A + no strict 'refs'; + return ${"${class}::_trap_inf"}; } + } +} + +sub trap_nan { + my $self = shift; + my $class = ref($self) || $self || __PACKAGE__; - return $p; # shortcut + # setter/mutator + + if (@_) { + my $b = shift() ? 1 : 0; + if (ref($self) && exists $self -> {trap_nan}) { + $self -> {trap_nan} = $b; + } else { + no strict 'refs'; + ${"${class}::_trap_nan"} = $b; + } } - # Return instance variable. - return $x->{_p} if ref($x) && (defined($x->{_a}) || defined($x->{_p})); + # getter/accessor - # Return class variable. - return ${"${class}::precision"}; + else { + if (ref($self) && exists $self -> {trap_nan}) { + return $self -> {trap_nan}; + } else { + no strict 'refs'; + return ${"${class}::_trap_nan"}; + } + } } sub config { # return (or set) configuration data. my $class = shift || __PACKAGE__; - no strict 'refs'; + # setter/mutator + # + # $class -> config(var => value, ...) + # $class -> config({ var => value, ... }) + if (@_ > 1 || (@_ == 1 && (ref($_[0]) eq 'HASH'))) { # try to set given options as arguments from hash - my $args = $_[0]; - if (ref($args) ne 'HASH') { - $args = { @_ }; + # If the argument is a hash ref, make a copy of it, since keys will be + # deleted below and we don't want to modify the input hash. + + my $args = ref($_[0]) eq 'HASH' ? { %{ $_[0] } }: { @_ }; + + # We use this special handling of accuracy and precision because + # accuracy() always sets precision to undef and precision() always sets + # accuracy to undef. With out this special treatment, the following + # would result in both accuracy and precision being undef. + # + # $x -> config(accuracy => 3, precision => undef) + + croak "config(): both accuracy and precision are defined" + if defined($args -> {accuracy}) && defined ($args -> {precision}); + + if (defined $args -> {accuracy}) { + $class -> accuracy($args -> {accuracy}); + } elsif (defined $args -> {precision}) { + $class -> precision($args -> {precision}); + } else { + $class -> accuracy(undef); # also sets precision to undef } - # these values can be "set" - my $set_args = {}; + + delete $args->{accuracy}; + delete $args->{precision}; + + # Set any remaining keys. + foreach my $key (qw/ - accuracy precision round_mode div_scale upgrade downgrade trap_inf trap_nan /) { - $set_args->{$key} = $args->{$key} if exists $args->{$key}; + # use a method call to check argument + $class->$key($args->{$key}) if exists $args->{$key}; delete $args->{$key}; } - if (keys %$args > 0) { + + # If there are any keys left, they are invalid. + + if (keys %$args) { croak("Illegal key(s) '", join("', '", keys %$args), "' passed to $class\->config()"); } - foreach my $key (keys %$set_args) { - if ($key =~ /^trap_(inf|nan)\z/) { - ${"${class}::_trap_$1"} = ($set_args->{"trap_$1"} ? 1 : 0); - next; - } - # use a call instead of just setting the $variable to check argument - $class->$key($set_args->{$key}); - } } - # now return actual configuration + # Now build the full configuration. my $cfg = { lib => $LIB, - lib_version => ${"${LIB}::VERSION"}, + lib_version => $LIB -> VERSION(), class => $class, - trap_nan => ${"${class}::_trap_nan"}, - trap_inf => ${"${class}::_trap_inf"}, - version => ${"${class}::VERSION"}, + version => $class -> VERSION(), }; + foreach my $key (qw/ accuracy precision round_mode div_scale upgrade downgrade + trap_inf trap_nan /) { - $cfg->{$key} = ${"${class}::$key"}; + $cfg->{$key} = $class -> $key(); } + + # getter/accessor + # + # $class -> config("var") + if (@_ == 1 && (ref($_[0]) ne 'HASH')) { - # calls of the style config('lib') return just this value return $cfg->{$_[0]}; } + $cfg; } @@ -493,13 +634,12 @@ sub _scale_a { # used by bround() and bfround(), may return undef for scale (means no op) my ($x, $scale, $mode) = @_; - $scale = $x->{_a} unless defined $scale; + $scale = $x->{accuracy} unless defined $scale; - no strict 'refs'; my $class = ref($x); - $scale = ${ $class . '::accuracy' } unless defined $scale; - $mode = ${ $class . '::round_mode' } unless defined $mode; + $scale = $class -> accuracy() unless defined $scale; + $mode = $class -> round_mode() unless defined $mode; if (defined $scale) { $scale = $scale->can('numify') ? $scale->numify() @@ -515,13 +655,12 @@ sub _scale_p { # used by bround() and bfround(), may return undef for scale (means no op) my ($x, $scale, $mode) = @_; - $scale = $x->{_p} unless defined $scale; + $scale = $x->{precision} unless defined $scale; - no strict 'refs'; my $class = ref($x); - $scale = ${ $class . '::precision' } unless defined $scale; - $mode = ${ $class . '::round_mode' } unless defined $mode; + $scale = $class -> precision() unless defined $scale; + $mode = $class -> round_mode() unless defined $mode; if (defined $scale) { $scale = $scale->can('numify') ? $scale->numify() @@ -578,7 +717,7 @@ sub new { # Math::BigInt or subclass - if (defined(blessed($wanted)) && $wanted -> isa($class)) { + if (defined(blessed($wanted)) && $wanted -> isa(__PACKAGE__)) { # Don't copy the accuracy and precision, because a new object should get # them from the global configuration. @@ -710,6 +849,10 @@ sub from_dec { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_dec'); @@ -746,6 +889,10 @@ sub from_hex { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_hex'); @@ -782,6 +929,10 @@ sub from_oct { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_oct'); @@ -818,6 +969,10 @@ sub from_bin { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_bin'); @@ -854,6 +1009,10 @@ sub from_bytes { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_bytes'); @@ -877,6 +1036,10 @@ sub from_base { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_base'); @@ -921,6 +1084,10 @@ sub from_base_num { my $selfref = ref $self; my $class = $selfref || $self; + # Make "require" work. + + $class -> import() if $IMPORT == 0; + # Don't modify constant (read-only) objects. return $self if $selfref && $self->modify('from_base_num'); @@ -933,14 +1100,16 @@ sub from_base_num { for my $i (0 .. $#$nums) { # Make sure we have an object. $nums -> [$i] = $class -> new($nums -> [$i]) - unless ref($nums -> [$i]) && $nums -> [$i] -> isa($class); + unless defined(blessed($nums -> [$i])) + && $nums -> [$i] -> isa(__PACKAGE__); # Make sure we have a finite, non-negative integer. croak "the elements must be finite non-negative integers" if $nums -> [$i] -> is_neg() || ! $nums -> [$i] -> is_int(); } my $base = shift; - $base = $class -> new($base) unless ref($base) && $base -> isa($class); + $base = $class -> new($base) + unless defined(blessed($base)) && $base -> isa(__PACKAGE__); my @r = @_; @@ -974,7 +1143,9 @@ sub bzero { my $selfref = ref $self; my $class = $selfref || $self; - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -996,13 +1167,15 @@ sub bzero { # instance with the class variables. if (@r) { - croak "can't specify both accuracy and precision" - if @r >= 2 && defined($r[0]) && defined($r[1]); - $self->{_a} = $_[0]; - $self->{_p} = $_[1]; + if (@r >= 2 && defined($r[0]) && defined($r[1])) { + carp "can't specify both accuracy and precision"; + return $self -> bnan(); + } + $self->{accuracy} = $_[0]; + $self->{precision} = $_[1]; } elsif (!$selfref) { - $self->{_a} = $class -> accuracy(); - $self->{_p} = $class -> precision(); + $self->{accuracy} = $class -> accuracy(); + $self->{precision} = $class -> precision(); } return $self; @@ -1024,7 +1197,9 @@ sub bone { my $selfref = ref $self; my $class = $selfref || $self; - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -1053,13 +1228,15 @@ sub bone { # instance with the class variables. if (@r) { - croak "can't specify both accuracy and precision" - if @r >= 2 && defined($r[0]) && defined($r[1]); - $self->{_a} = $_[0]; - $self->{_p} = $_[1]; + if (@r >= 2 && defined($r[0]) && defined($r[1])) { + carp "can't specify both accuracy and precision"; + return $self -> bnan(); + } + $self->{accuracy} = $_[0]; + $self->{precision} = $_[1]; } elsif (!$selfref) { - $self->{_a} = $class -> accuracy(); - $self->{_p} = $class -> precision(); + $self->{accuracy} = $class -> accuracy(); + $self->{precision} = $class -> precision(); } return $self; @@ -1088,7 +1265,9 @@ sub binf { } } - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -1118,13 +1297,15 @@ sub binf { # instance with the class variables. if (@r) { - croak "can't specify both accuracy and precision" - if @r >= 2 && defined($r[0]) && defined($r[1]); - $self->{_a} = $_[0]; - $self->{_p} = $_[1]; + if (@r >= 2 && defined($r[0]) && defined($r[1])) { + carp "can't specify both accuracy and precision"; + return $self -> bnan(); + } + $self->{accuracy} = $_[0]; + $self->{precision} = $_[1]; } elsif (!$selfref) { - $self->{_a} = $class -> accuracy(); - $self->{_p} = $class -> precision(); + $self->{accuracy} = $class -> accuracy(); + $self->{precision} = $class -> precision(); } return $self; @@ -1153,7 +1334,9 @@ sub bnan { } } - $self->import() if $IMPORT == 0; # make require work + # Make "require" work. + + $class -> import() if $IMPORT == 0; # Don't modify constant (read-only) objects. @@ -1173,13 +1356,15 @@ sub bnan { # instance with the class variables. if (@r) { - croak "can't specify both accuracy and precision" - if @r >= 2 && defined($r[0]) && defined($r[1]); - $self->{_a} = $_[0]; - $self->{_p} = $_[1]; + if (@r >= 2 && defined($r[0]) && defined($r[1])) { + carp "can't specify both accuracy and precision"; + return $self -> bnan(); + } + $self->{accuracy} = $_[0]; + $self->{precision} = $_[1]; } elsif (!$selfref) { - $self->{_a} = $class -> accuracy(); - $self->{_p} = $class -> precision(); + $self->{accuracy} = $class -> accuracy(); + $self->{precision} = $class -> precision(); } return $self; @@ -1219,6 +1404,10 @@ sub bpi { my $class = $selfref || $self; my @r = @_; # rounding paramters + # Make "require" work. + + $class -> import() if $IMPORT == 0; + if ($selfref) { # bpi() called as an instance method return $self if $self -> modify('bpi'); } else { # bpi() called as a class method @@ -1250,8 +1439,8 @@ sub copy { $copy->{sign} = $x->{sign}; $copy->{value} = $LIB->_copy($x->{value}); - $copy->{_a} = $x->{_a} if exists $x->{_a}; - $copy->{_p} = $x->{_p} if exists $x->{_p}; + $copy->{accuracy} = $x->{accuracy} if exists $x->{accuracy}; + $copy->{precision} = $x->{precision} if exists $x->{precision}; return $copy; } @@ -1260,21 +1449,24 @@ sub as_int { my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; - # If called as an instance method, and the instance class is something we - # upgrade to, $x might not be a Math::BigInt, so don't just call copy(). - return $x -> copy() if $x -> isa("Math::BigInt"); - # disable upgrading and downgrading + # Disable upgrading and downgrading. my $upg = Math::BigInt -> upgrade(); my $dng = Math::BigInt -> downgrade(); Math::BigInt -> upgrade(undef); Math::BigInt -> downgrade(undef); + # Copy the value. + my $y = Math::BigInt -> new($x); - # reset upgrading and downgrading + # Copy the remaining instance variables. + + ($y->{accuracy}, $y->{precision}) = ($x->{accuracy}, $x->{precision}); + + # Restore upgrading and downgrading Math::BigInt -> upgrade($upg); Math::BigInt -> downgrade($dng); @@ -1286,7 +1478,7 @@ sub as_float { my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; - # disable upgrading and downgrading + # Disable upgrading and downgrading. require Math::BigFloat; my $upg = Math::BigFloat -> upgrade(); @@ -1294,9 +1486,15 @@ sub as_float { Math::BigFloat -> upgrade(undef); Math::BigFloat -> downgrade(undef); + # Copy the value. + my $y = Math::BigFloat -> new($x); - # reset upgrading and downgrading + # Copy the remaining instance variables. + + ($y->{accuracy}, $y->{precision}) = ($x->{accuracy}, $x->{precision}); + + # Restore upgrading and downgrading.. Math::BigFloat -> upgrade($upg); Math::BigFloat -> downgrade($dng); @@ -1308,7 +1506,7 @@ sub as_rat { my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; - # disable upgrading and downgrading + # Disable upgrading and downgrading. require Math::BigRat; my $upg = Math::BigRat -> upgrade(); @@ -1318,7 +1516,11 @@ sub as_rat { my $y = Math::BigRat -> new($x); - # reset upgrading and downgrading + # Copy the remaining instance variables. + + ($y->{accuracy}, $y->{precision}) = ($x->{accuracy}, $x->{precision}); + + # Restore upgrading and downgrading. Math::BigRat -> upgrade($upg); Math::BigRat -> downgrade($dng); @@ -1446,7 +1648,7 @@ sub bcmp { carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; return $upgrade->bcmp($x, $y) - if defined($upgrade) && (!$x->isa($class) || !$y->isa($class)); + if defined($upgrade) && (!$x->isa(__PACKAGE__) || !$y->isa(__PACKAGE__)); if (($x->{sign} !~ /^[+-]$/) || ($y->{sign} !~ /^[+-]$/)) { # handle +-inf and NaN @@ -1489,7 +1691,7 @@ sub bacmp { carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; return $upgrade->bacmp($x, $y) - if defined($upgrade) && (!$x->isa($class) || !$y->isa($class)); + if defined($upgrade) && (!$x->isa(__PACKAGE__) || !$y->isa(__PACKAGE__)); if (($x->{sign} !~ /^[+-]$/) || ($y->{sign} !~ /^[+-]$/)) { # handle +-inf and NaN @@ -1578,7 +1780,8 @@ sub bneg { return $x if $x->modify('bneg'); - return $upgrade -> bneg($x, @r) if defined($upgrade) && !$x->isa($class); + return $upgrade -> bneg($x, @r) + if defined($upgrade) && !$x->isa(__PACKAGE__); # Don't negate +0 so we always have the normalized form +0. Does nothing for # 'NaN'. @@ -1595,7 +1798,12 @@ sub babs { return $x if $x->modify('babs'); - return $upgrade -> babs($x, @r) if defined($upgrade) && !$x->isa($class); + # This call to the upgrade class must either be commented out or the method + # must be implemented in the upgrade class(es) to avoid infinite recursion. + # It doesn't help to check whether $x isa $upgrade, because there might be + # several levels of upgrading. Also see the test file t/upgrade2.t + #return $upgrade -> babs($x, @r) + # if defined($upgrade) && !$x->isa(__PACKAGE__); $x->{sign} =~ s/^-/+/; @@ -1608,7 +1816,12 @@ sub bsgn { return $x if $x->modify('bsgn'); - return $upgrade -> bsgn($x, @r) if defined($upgrade) && !$x->isa($class); + # This call to the upgrade class must either be commented out or the method + # must be implemented in the upgrade class(es) to avoid infinite recursion. + # It doesn't help to check whether $x isa $upgrade, because there might be + # several levels of upgrading. Also see the test file t/upgrade2.t + #return $upgrade -> bsgn($x, @r) + # if defined($upgrade) && !$x->isa(__PACKAGE__); return $x -> bone("+", @r) if $x -> is_pos(); return $x -> bone("-", @r) if $x -> is_neg(); @@ -1638,7 +1851,8 @@ sub binc { return $x->round(@r) if $x -> is_inf() || $x -> is_nan(); - return $upgrade -> binc($x, @r) if defined($upgrade) && !$x -> isa($class); + return $upgrade -> binc($x, @r) + if defined($upgrade) && !$x -> isa(__PACKAGE__); if ($x->{sign} eq '+') { $x->{value} = $LIB->_inc($x->{value}); @@ -1658,7 +1872,8 @@ sub bdec { return $x->round(@r) if $x -> is_inf() || $x -> is_nan(); - return $upgrade -> bdec($x, @r) if defined($upgrade) && !$x -> isa($class);; + return $upgrade -> bdec($x, @r) + if defined($upgrade) && !$x -> isa(__PACKAGE__);; if ($x->{sign} eq '-') { $x->{value} = $LIB->_inc($x->{value}); @@ -1778,7 +1993,7 @@ sub badd { $r[3] = $y; # no push! return $upgrade->badd($x, $y, @r) - if defined($upgrade) && (!$x->isa($class) || !$y->isa($class)); + if defined($upgrade) && (!$x->isa(__PACKAGE__) || !$y->isa(__PACKAGE__)); # Inf and NaN handling if ($x->{sign} !~ /^[+-]$/ || $y->{sign} !~ /^[+-]$/) { @@ -1815,7 +2030,7 @@ sub bsub { return $x if $x -> modify('bsub'); return $upgrade -> bsub($x, $y, @r) - if defined($upgrade) && (!$x->isa($class) || !$y->isa($class)); + if defined($upgrade) && (!$x->isa(__PACKAGE__) || !$y->isa(__PACKAGE__)); return $x -> round(@r) if $y -> is_zero(); @@ -1861,7 +2076,7 @@ sub bmul { } return $upgrade->bmul($x, $y, @r) - if defined($upgrade) && (!$x->isa($class) || !$y->isa($class)); + if defined($upgrade) && (!$x->isa(__PACKAGE__) || !$y->isa(__PACKAGE__)); $r[3] = $y; # no push here @@ -1892,8 +2107,9 @@ sub bmuladd { $z->{sign} =~ /^[+-]$/) { return $upgrade->bmuladd($x, $y, $z, @r) - if defined($upgrade) - && (!$x->isa($class) || !$y->isa($class) || !$z->isa($class)); + if defined($upgrade) && (!$x->isa(__PACKAGE__) || + !$y->isa(__PACKAGE__) || + !$z->isa(__PACKAGE__)); # TODO: what if $y and $z have A or P set? $r[3] = $z; # no push here @@ -2179,8 +2395,8 @@ sub bdiv { } $rem -> {sign} = $ysign; } - $rem -> {_a} = $x -> {_a}; - $rem -> {_p} = $x -> {_p}; + $rem -> {accuracy} = $x -> {accuracy}; + $rem -> {precision} = $x -> {precision}; $rem = $rem -> round(@r); return ($x, $rem); } @@ -2323,8 +2539,8 @@ sub btdiv { if (wantarray) { $rem -> {sign} = $xsign; $rem -> {sign} = '+' if $LIB -> _is_zero($rem -> {value}); - $rem -> {_a} = $x -> {_a}; - $rem -> {_p} = $x -> {_p}; + $rem -> {accuracy} = $x -> {accuracy}; + $rem -> {precision} = $x -> {precision}; $rem = $rem -> round(@r); return ($x, $rem); } @@ -2373,7 +2589,8 @@ sub bmod { } return $upgrade -> bmod($x, $y, @r) - if defined($upgrade) && (!$x -> isa($class) || !$y -> isa($class)); + if defined($upgrade) && (!$x -> isa(__PACKAGE__) || + !$y -> isa(__PACKAGE__)); # Calc new sign and in case $y == +/- 1, return $x. @@ -2424,7 +2641,8 @@ sub btmod { } return $upgrade -> btmod($x, $y, @r) - if defined($upgrade) && (!$x -> isa($class) || !$y -> isa($class)); + if defined($upgrade) && (!$x -> isa(__PACKAGE__) || + !$y -> isa(__PACKAGE__)); $r[3] = $y; # no push! @@ -2472,7 +2690,8 @@ sub bmodinv { $y->is_one('-')); return $upgrade -> bmodinv($x, $y, @r) - if defined($upgrade) && (!$x -> isa($class) || !$y -> isa($class)); + if defined($upgrade) && (!$x -> isa(__PACKAGE__) || + !$y -> isa(__PACKAGE__)); # Return NaN if $x = 0, or $x modulo $y is zero. The only valid case when # $x = 0 is when $y = 1 or $y = -1, but that was covered above. @@ -2554,8 +2773,8 @@ sub bmodpow { } return $upgrade -> bmodinv($num, $exp, $mod, @r) - if defined($upgrade) && (!$num -> isa($class) || - !$exp -> isa($class) || + if defined($upgrade) && (!$num -> isa(__PACKAGE__) || + !$exp -> isa(__PACKAGE__) || !$mod -> ($class)); # Compute 'a (mod m)', ignoring the signs on 'a' and 'm'. If the resulting @@ -2682,7 +2901,7 @@ sub bpow { # returning zero, not NaN, is that all output is in the open interval (0,1), # and truncating that to integer gives zero. - if ($y->{sign} eq '-' || !$y -> isa($class)) { + if ($y->{sign} eq '-' || !$y -> isa(__PACKAGE__)) { return $x -> bzero(@r); } @@ -2693,6 +2912,20 @@ sub bpow { $x -> round(@r); } +sub binv { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); + + return $x if $x -> modify('binv'); + + return $x -> binf("+", @r) if $x -> is_zero(); + return $x -> bzero(@r) if $x -> is_inf(); + return $x -> bnan(@r) if $x -> is_nan(); + return $x -> round(@r) if $x -> is_one("+") || $x -> is_one("-"); + + return $upgrade -> binv($x, @r) if defined $upgrade; + $x -> bzero(@r); +} + sub blog { # Return the logarithm of the operand. If a second operand is defined, that # value is used as the base, otherwise the base is assumed to be Euler's @@ -2700,10 +2933,11 @@ sub blog { my ($class, $x, $base, @r); - # Don't objectify the base, since an undefined base, as in $x->blog() or - # $x->blog(undef) signals that the base is Euler's number. + # Only objectify the base if it is defined, since an undefined base, as in + # $x->blog() or $x->blog(undef) signals that the base is Euler's number = + # 2.718281828... - if (!ref($_[0]) && $_[0] =~ /^[a-z]\w*(?:::[a-z]\w*)*$/i) { + if (!ref($_[0]) && $_[0] =~ /^[a-z]\w*(?:::\w+)*$/i) { # E.g., Math::BigInt->blog(256, 2) ($class, $x, $base, @r) = defined $_[2] ? objectify(2, @_) : objectify(1, @_); @@ -2721,7 +2955,8 @@ sub blog { return $x -> bnan(@r) if $x -> is_nan(); if (defined $base) { - $base = $class -> new($base) unless ref $base; + $base = $class -> new($base) + unless defined(blessed($base)) && $base -> isa(__PACKAGE__); if ($base -> is_nan() || $base -> is_one()) { return $x -> bnan(@r); } elsif ($base -> is_inf() || $base -> is_zero()) { @@ -2729,18 +2964,26 @@ sub blog { return $x -> bzero(@r); } elsif ($base -> is_negative()) { # -inf < base < 0 return $x -> bzero(@r) if $x -> is_one(); # x = 1 - return $x -> bone(@r) if $x == $base; # x = base - return $x -> bnan(@r); # otherwise + return $x -> bone('+', @r) if $x == $base; # x = base + # we can't handle these cases, so upgrade, if we can + return $upgrade -> blog($x, $base, @r) if defined $upgrade; + return $x -> bnan(@r); } return $x -> bone(@r) if $x == $base; # 0 < base && 0 < x < inf } # We now know that the base is either undefined or >= 2 and finite. - return $x -> binf('+', @r) if $x -> is_inf(); # x = +/-inf - return $x -> bnan(@r) if $x -> is_neg(); # -inf < x < 0 - return $x -> bzero(@r) if $x -> is_one(); # x = 1 - return $x -> binf('-', @r) if $x -> is_zero(); # x = 0 + if ($x -> is_inf()) { # x = +/-inf + return $x -> binf('+', @r); + } elsif ($x -> is_neg()) { # -inf < x < 0 + return $upgrade -> blog($x, $base, @r) if defined $upgrade; + return $x -> bnan(@r); + } elsif ($x -> is_one()) { # x = 1 + return $x -> bzero(@r); + } elsif ($x -> is_zero()) { # x = 0 + return $x -> binf('-', @r); + } # At this point we are done handling all exception cases and trivial cases. @@ -2750,15 +2993,31 @@ sub blog { # the default base is e (Euler's number) which is not an integer if (!defined $base) { require Math::BigFloat; - my $u = Math::BigFloat->blog($x)->as_int(); + + # disable upgrading and downgrading + + my $upg = Math::BigFloat -> upgrade(); + my $dng = Math::BigFloat -> downgrade(); + Math::BigFloat -> upgrade(undef); + Math::BigFloat -> downgrade(undef); + + my $u = Math::BigFloat -> blog($x) -> as_int(); + + # reset upgrading and downgrading + + Math::BigFloat -> upgrade($upg); + Math::BigFloat -> downgrade($dng); + # modify $x in place + $x->{value} = $u->{value}; - $x->{sign} = $u->{sign}; + $x->{sign} = $u->{sign}; + return $x -> round(@r); } - my ($rc) = $LIB->_log_int($x->{value}, $base->{value}); - return $x->bnan(@r) unless defined $rc; # not possible to take log? + my ($rc) = $LIB -> _log_int($x->{value}, $base->{value}); + return $x -> bnan(@r) unless defined $rc; # not possible to take log? $x->{value} = $rc; $x = $x -> round(@r); } @@ -2784,6 +3043,82 @@ sub bexp { return $x -> round(@r); } +sub bilog2 { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + + return $x if $x -> modify('bilog2'); + + return $upgrade -> new($x, @r) unless $x -> isa(__PACKAGE__); + + return $x -> bnan(@r) if $x -> is_nan(); + return $x -> binf("+", @r) if $x -> is_inf("+"); + return $x -> binf("-", @r) if $x -> is_zero(); + if ($x -> is_neg()) { + return $upgrade -> bilog2($x, @r) if $upgrade; + return $x -> bnan(@r); + } + + $x -> {value} = $LIB -> _ilog2($x -> {value}); + return $x -> round(@r); +} + +sub bilog10 { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + + return $x if $x -> modify('bilog10'); + + return $upgrade -> new($x, @r) unless $x -> isa(__PACKAGE__); + + return $x -> bnan(@r) if $x -> is_nan(); + return $x -> binf("+", @r) if $x -> is_inf("+"); + return $x -> binf("-", @r) if $x -> is_zero(); + if ($x -> is_neg()) { + return $upgrade -> bilog2($x, @r) if $upgrade; + return $x -> bnan(@r); + } + + $x -> {value} = $LIB -> _ilog10($x -> {value}); + return $x -> round(@r); +} + +sub bclog2 { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + + return $x if $x -> modify('bclog2'); + + return $upgrade -> new($x, @r) unless $x -> isa(__PACKAGE__); + + return $x -> bnan(@r) if $x -> is_nan(); + return $x -> binf("+", @r) if $x -> is_inf("+"); + return $x -> binf("-", @r) if $x -> is_zero(); + if ($x -> is_neg()) { + return $upgrade -> bilog2($x, @r) if $upgrade; + return $x -> bnan(@r); + } + + $x -> {value} = $LIB -> _clog2($x -> {value}); + return $x -> round(@r); +} + +sub bclog10 { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + + return $x if $x -> modify('bclog10'); + + return $upgrade -> new($x, @r) unless $x -> isa(__PACKAGE__); + + return $x -> bnan(@r) if $x -> is_nan(); + return $x -> binf("+", @r) if $x -> is_inf("+"); + return $x -> binf("-", @r) if $x -> is_zero(); + if ($x -> is_neg()) { + return $upgrade -> bilog2($x, @r) if $upgrade; + return $x -> bnan(@r); + } + + $x -> {value} = $LIB -> _clog10($x -> {value}); + return $x -> round(@r); +} + sub bnok { # Calculate n over k (binomial coefficient or "choose" function) as # integer. @@ -2827,7 +3162,8 @@ sub bnok { # At this point, both n and k are real numbers. return $upgrade -> bnok($n, $k, @r) - if defined($upgrade) && (!$n -> isa($class) || !$k -> isa($class)); + if defined($upgrade) && (!$n -> isa(__PACKAGE__) || + !$k -> isa(__PACKAGE__)); my $sign = 1; @@ -2862,7 +3198,19 @@ sub bnok { } } - $n->{value} = $LIB->_nok($n->{value}, $k->{value}); + # Some backends, e.g., Math::BigInt::GMP do not allow values of n and k + # that are larger than the largest unsigned integer, so check for this, and + # use the simpler and slower generic method in the superclass if n and/or k + # are larger than the largest unsigned integer. + + my $uintmax = $LIB -> _new(~0); + if ($LIB -> _acmp($n->{value}, $uintmax) > 0 || + $LIB -> _acmp($k->{value}, $uintmax) > 0) + { + $n->{value} = $LIB -> SUPER::_nok($n->{value}, $k->{value}); + } else { + $n->{value} = $LIB -> _nok($n->{value}, $k->{value}); + } $n = $n -> bneg() if $sign == -1; $n -> round(@r); @@ -2989,42 +3337,58 @@ sub ackermann { } sub bsin { - # Calculate sin(x) to N digits. Unless upgrading is in effect, returns the - # result truncated to an integer. my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); - return $x if $x->modify('bsin'); + return $x if $x -> modify('bsin'); - return $x->bnan(@r) if $x->{sign} !~ /^[+-]\z/; # -inf +inf or NaN => NaN - return $x->bzero(@r) if $x->is_zero(); + # Trivial cases. - return $upgrade -> bsin($x, @r) if defined $upgrade; + return $x -> bzero(@r) if $x -> is_zero(); + return $x -> bnan(@r) if $x -> is_inf() || $x -> is_nan(); - require Math::BigFloat; - # calculate the result and truncate it to integer - my $t = Math::BigFloat->new($x)->bsin(@r)->as_int(); + if ($upgrade) { + my $xtmp = $upgrade -> bsin($x, @r); + if ($xtmp -> is_int()) { + $xtmp = $xtmp -> as_int(); + %$x = %$xtmp; + } else { + %$x = %$xtmp; + bless $x, $upgrade; + } + return $x; + } - $x = $x->bone(@r) if $t->is_one(); - $x = $x->bzero(@r) if $t->is_zero(); - $x->round(@r); + # When x is an integer, sin(x) truncated to an integer is always zero. + + $x -> bzero(@r); } sub bcos { - # Calculate cos(x) to N digits. Unless upgrading is in effect, returns the - # result truncated to an integer. my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); - return $x if $x->modify('bcos'); + return $x if $x -> modify('bcos'); - return $x->bnan(@r) if $x->{sign} !~ /^[+-]\z/; # -inf +inf or NaN => NaN - return $x->bone(@r) if $x->is_zero(); + # Trivial cases. - return $upgrade -> bcos($x, @r) if defined $upgrade; + return $x -> bone(@r) if $x -> is_zero(); + return $x -> bnan(@r) if $x -> is_inf() || $x -> is_nan(); - require Math::BigFloat; - my $tmp = Math::BigFloat -> bcos($x, @r) -> as_int(); - $x->{value} = $tmp->{value}; - return $x -> round(@r); + if ($upgrade) { + my $xtmp = $upgrade -> bcos($x, @r); + if ($xtmp -> is_int()) { + $xtmp = $xtmp -> as_int(); + %$x = %$xtmp; + } else { + %$x = %$xtmp; + bless $x, $upgrade; + } + return $x; + } + + # When x is a non-zero integer, cos(x) truncated to an integer is always + # zero. + + $x -> bzero(@r); } sub batan { @@ -3100,15 +3464,21 @@ sub bsqrt { # calculate square root of $x my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); - return $x if $x->modify('bsqrt'); + return $x if $x -> modify('bsqrt'); - return $x->bnan(@r) if $x->{sign} !~ /^\+/; # -x or -inf or NaN => NaN - return $x->round(@r) if $x->{sign} eq '+inf'; # sqrt(+inf) == inf + return $x -> bnan(@r) if $x -> is_nan(); + return $x -> round(@r) if $x -> is_zero() || $x -> is_inf("+"); - return $upgrade->bsqrt($x, @r) if defined $upgrade; + if ($upgrade) { + $x = $upgrade -> bsqrt($x, @r); + $x = $x -> as_int() if $x -> is_int(); + return $x; + } - $x->{value} = $LIB->_sqrt($x->{value}); - $x->round(@r); + return $x -> bnan(@r) if $x -> is_neg(); + + $x->{value} = $LIB -> _sqrt($x->{value}); + return $x -> round(@r); } sub broot { @@ -3146,7 +3516,7 @@ sub bfac { return $x->bnan(@r) if $x->{sign} ne '+'; # NaN, <0 => NaN return $upgrade -> bfac($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); $x->{value} = $LIB->_fac($x->{value}); $x->round(@r); @@ -3162,7 +3532,7 @@ sub bdfac { return $x->bone(@r) if $x <= 1; return $upgrade -> bdfac($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); croak("bdfac() requires a newer version of the $LIB library.") unless $LIB->can('_dfac'); @@ -3179,7 +3549,8 @@ sub btfac { return $x->bnan(@r) if $x->is_nan(); - return $upgrade -> btfac($x, @r) if defined($upgrade) && !$x -> isa($class); + return $upgrade -> btfac($x, @r) + if defined($upgrade) && !$x -> isa(__PACKAGE__); my $k = $class -> new("3"); return $x->bnan(@r) if $x <= -$k; @@ -3204,7 +3575,7 @@ sub bmfac { return $x->bnan(@r) if $x->is_nan() || $k->is_nan() || $k < 1 || $x <= -$k; return $upgrade -> bmfac($x, $k, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); my $one = $class -> bone(); return $x->bone(@r) if $x <= $one; @@ -3226,7 +3597,7 @@ sub bfib { return $x if $x->modify('bfib'); return $upgrade -> bfib($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # List context. @@ -3235,43 +3606,50 @@ sub bfib { croak("bfib() can't return an infinitely long list of numbers") if $x -> is_inf(); - # Use the backend library to compute the first $x Fibonacci numbers. + my $n = $x -> numify(); + + my @y; - my @values = $LIB->_fib($x->{value}); + $y[0] = $x -> copy() -> babs(); + $y[0]{value} = $LIB -> _zero(); + return @y if $n == 0; - # Make objects out of them. The last element in the array is the - # invocand. + $y[1] = $y[0] -> copy(); + $y[1]{value} = $LIB -> _one(); + return @y if $n == 1; - for (my $i = 0 ; $i < $#values ; ++ $i) { - my $fib = $class -> bzero(); - $fib -> {value} = $values[$i]; - $values[$i] = $fib; + for (my $i = 2 ; $i <= abs($n) ; $i++) { + $y[$i] = $y[$i - 1] -> copy(); + $y[$i]{value} = $LIB -> _add($LIB -> _copy($y[$i - 1]{value}), + $y[$i - 2]{value}); } - $x -> {value} = $values[-1]; - $values[-1] = $x; + # The last element in the array is the invocand. + + $x->{value} = $y[-1]{value}; + $y[-1] = $x; # If negative, insert sign as appropriate. if ($x -> is_neg()) { - for (my $i = 2 ; $i <= $#values ; $i += 2) { - $values[$i]{sign} = '-'; + for (my $i = 2 ; $i <= $#y ; $i += 2) { + $y[$i]{sign} = '-'; } } - @values = map { $_ -> round(@r) } @values; - return @values; + @y = map { $_ -> round(@r) } @y; + return @y; } # Scalar context. else { - return $x if $x->modify('bdfac') || $x -> is_inf('+'); - return $x->bnan() if $x -> is_nan() || $x -> is_inf('-'); + return $x if $x -> is_inf('+'); + return $x -> bnan() if $x -> is_nan() || $x -> is_inf('-'); $x->{sign} = $x -> is_neg() && $x -> is_even() ? '-' : '+'; - $x->{value} = $LIB->_fib($x->{value}); - return $x->round(@r); + $x->{value} = $LIB -> _fib($x->{value}); + return $x -> round(@r); } } @@ -3285,58 +3663,65 @@ sub blucas { return $x if $x->modify('blucas'); return $upgrade -> blucas($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # List context. if (wantarray) { return () if $x -> is_nan(); - croak("blucas() can't return an infinitely long list of numbers") - if $x -> is_inf(); + croak("bfib() can't return an infinitely long list of numbers") + if $x -> is_inf(); + + my $n = $x -> numify(); - # Use the backend library to compute the first $x Lucas numbers. + my @y; - my @values = $LIB->_lucas($x->{value}); + $y[0] = $x -> copy() -> babs(); + $y[0]{value} = $LIB -> _two(); + return @y if $n == 0; - # Make objects out of them. The last element in the array is the - # invocand. + $y[1] = $y[0] -> copy(); + $y[1]{value} = $LIB -> _one(); + return @y if $n == 1; - for (my $i = 0 ; $i < $#values ; ++ $i) { - my $lucas = $class -> bzero(); - $lucas -> {value} = $values[$i]; - $values[$i] = $lucas; + for (my $i = 2 ; $i <= abs($n) ; $i++) { + $y[$i] = $y[$i - 1] -> copy(); + $y[$i]{value} = $LIB -> _add($LIB -> _copy($y[$i - 1]{value}), + $y[$i - 2]{value}); } - $x -> {value} = $values[-1]; - $values[-1] = $x; + # The last element in the array is the invocand. + + $x->{value} = $y[-1]{value}; + $y[-1] = $x; # If negative, insert sign as appropriate. if ($x -> is_neg()) { - for (my $i = 2 ; $i <= $#values ; $i += 2) { - $values[$i]{sign} = '-'; + for (my $i = 2 ; $i <= $#y ; $i += 2) { + $y[$i]{sign} = '-'; } } - @values = map { $_ -> round(@r) } @values; - return @values; + @y = map { $_ -> round(@r) } @y; + return @y; } # Scalar context. else { - return $x if $x -> is_inf('+'); - return $x->bnan() if $x -> is_nan() || $x -> is_inf('-'); + return $x if $x -> is_inf('+'); + return $x -> bnan() if $x -> is_nan() || $x -> is_inf('-'); $x->{sign} = $x -> is_neg() && $x -> is_even() ? '-' : '+'; - $x->{value} = $LIB->_lucas($x->{value}); - return $x->round(@r); + $x->{value} = $LIB -> _lucas($x->{value}); + return $x -> round(@r); } } sub blsft { # (BINT or num_str, BINT or num_str) return BINT - # compute x << y, base n, y >= 0 + # compute $x << $y, base $n my ($class, $x, $y, $b, @r); @@ -3354,43 +3739,119 @@ sub blsft { } return $x if $x -> modify('blsft'); - return $x -> bnan() if ($x -> {sign} !~ /^[+-]$/ || - $y -> {sign} !~ /^[+-]$/); - return $x -> round(@r) if $y -> is_zero(); - return $x -> bzero(@r) if $x -> is_zero(); # 0 => 0 - $b = 2 if !defined $b; - return $x -> bnan(@r) if $b <= 0 || $y -> {sign} eq '-'; + # The default base is 2. + + $b = 2 unless defined $b; $b = $class -> new($b) unless defined(blessed($b)); - #return $upgrade -> blsft($x, $y, $b, @r) - # if defined($upgrade) && (!$x -> isa($class) || - # !$y -> isa($class) || - # !$b -> isa($class)); + # Handle "foreign" objects. + + return $upgrade -> blsft($x, $y, $b, @r) + if defined($upgrade) && (!$x -> isa(__PACKAGE__) || + !$y -> isa(__PACKAGE__) || + !$b -> isa(__PACKAGE__)); + + # Handle NaN cases. + + return $x -> bnan(@r) + if $x -> is_nan() || $y -> is_nan() || $b -> is_nan(); + + # blsft($x, -$y, $b) = brsft($x, $y, $b) + + return $x -> brsft($y -> copy() -> bneg(), $b, @r) if $y -> is_neg(); + + # Now handle all cases where at least one operand is ±Inf or the result + # will be ±Inf or NaN. + + if ($y -> is_inf("+")) { + if ($b -> is_one("-")) { + return $x -> bnan(@r); + } elsif ($b -> is_one("+")) { + return $x -> round(@r); + } elsif ($b -> is_zero()) { + return $x -> bnan(@r) if $x -> is_inf(); + return $x -> bzero(@r); + } else { + return $x -> binf("-", @r) if $x -> is_negative(); + return $x -> binf("+", @r) if $x -> is_positive(); + return $x -> bnan(@r); + } + } + + if ($b -> is_inf()) { + return $x -> bnan(@r) if $x -> is_zero() || $y -> is_zero(); + if ($b -> is_inf("-")) { + return $x -> binf("+", @r) + if ($x -> is_negative() && $y -> is_odd() || + $x -> is_positive() && $y -> is_even()); + return $x -> binf("-", @r); + } else { + return $x -> binf("-", @r) if $x -> is_negative(); + return $x -> binf("+", @r); + } + } + + if ($b -> is_zero()) { + return $x -> round(@r) if $y -> is_zero(); + return $x -> bnan(@r) if $x -> is_inf(); + return $x -> bzero(@r); + } + + if ($x -> is_inf()) { + if ($b -> is_negative()) { + if ($x -> is_inf("-")) { + if ($y -> is_even()) { + return $x -> round(@r); + } else { + return $x -> binf("+", @r); + } + } else { + if ($y -> is_even()) { + return $x -> round(@r); + } else { + return $x -> binf("-", @r); + } + } + } else { + return $x -> round(@r); + } + } + + # At this point, we know that both the input and the output is finite. + # Handle some trivial cases. + + return $x -> round(@r) if $x -> is_zero() || $y -> is_zero() + || $b -> is_one("+") + || $b -> is_one("-") && $y -> is_even(); - # shift by a negative amount? - #return $x -> brsft($y -> copy() -> babs(), $b) if $y -> {sign} =~ /^-/; + return $x -> bneg(@r) if $b -> is_one("-") && $y -> is_odd(); # While some of the libraries support an arbitrarily large base, not all of # them do, so rather than returning an incorrect result in those cases, # disallow bases that don't work with all libraries. my $uintmax = ~0; - croak("Base is too large.") if $b > $uintmax; - - $b = $b -> numify(); - - return $x -> bnan() if $b <= 0 || $y -> {sign} eq '-'; - - $x -> {value} = $LIB -> _lsft($x -> {value}, $y -> {value}, $b); + if ($x -> bcmp($uintmax) > 0) { + $x = $x -> bmul($b -> bpow($y)); + } else { + my $neg = 0; + if ($b -> is_negative()) { + $neg = 1 if $y -> is_odd(); + $b = $b -> babs(); + } + $b = $b -> numify(); + $x -> {value} = $LIB -> _lsft($x -> {value}, $y -> {value}, $b); + $x -> {sign} =~ tr/+-/-+/ if $neg; + } $x -> round(@r); } sub brsft { # (BINT or num_str, BINT or num_str) return BINT - # compute x >> y, base n, y >= 0 + # compute $x >> $y, base $n - my ($class, $x, $y, $b, @r) = (ref($_[0]), @_); + my ($class, $x, $y, $b, @r); # Objectify the base only when it is defined, since an undefined base, as # in $x->blsft(3) or $x->blog(3, undef) means use the default base 2. @@ -3406,75 +3867,263 @@ sub brsft { } return $x if $x -> modify('brsft'); - return $x -> bnan(@r) if $x -> {sign} !~ /^[+-]$/ || - $y -> {sign} !~ /^[+-]$/; - return $x -> round(@r) if $y -> is_zero(); - return $x -> bzero(@r) if $x -> is_zero(); # 0 => 0 - $b = 2 if !defined $b; - return $x -> bnan(@r) if $b <= 0 || $y -> {sign} eq '-'; + # The default base is 2. + + $b = 2 unless defined $b; $b = $class -> new($b) unless defined(blessed($b)); - # Shifting right by a positive amount might lead to a non-integer result, so - # include this case in the test. + # Handle "foreign" objects. return $upgrade -> brsft($x, $y, $b, @r) - if defined($upgrade) && (!$x -> isa($class) || - !$y -> isa($class) || - !$b -> isa($class) || - $y -> is_pos()); + if defined($upgrade) && (!$x -> isa(__PACKAGE__) || + !$y -> isa(__PACKAGE__) || + !$b -> isa(__PACKAGE__)); - # While some of the libraries support an arbitrarily large base, not all of - # them do, so rather than returning an incorrect result in those cases, - # disallow bases that don't work with all libraries. + # Handle NaN cases. - my $uintmax = ~0; - croak("Base is too large.") if $b > $uintmax; + return $x -> bnan(@r) + if $x -> is_nan() || $y -> is_nan() || $b -> is_nan(); - $b = $b -> numify(); + # brsft($x, -$y, $b) = blsft($x, $y, $b) - # this only works for negative numbers when shifting in base 2 - if (($x -> {sign} eq '-') && ($b == 2)) { - return $x -> round(@r) if $x -> is_one('-'); # -1 => -1 - if (!$y -> is_one()) { - # although this is O(N*N) in calc (as_bin!) it is O(N) in Pari et - # al but perhaps there is a better emulation for two's complement - # shift... - # if $y != 1, we must simulate it by doing: - # convert to bin, flip all bits, shift, and be done - $x = $x -> binc(); # -3 => -2 - my $bin = $x -> as_bin(); - $bin =~ s/^-0b//; # strip '-0b' prefix - $bin =~ tr/10/01/; # flip bits - # now shift - if ($y >= CORE::length($bin)) { - $bin = '0'; # shifting to far right creates -1 - # 0, because later increment makes - # that 1, attached '-' makes it '-1' - # because -1 >> x == -1 ! + return $x -> blsft($y -> copy() -> bneg(), $b, @r) if $y -> is_neg(); + + # Now handle all cases where at least one operand is ±Inf or the result + # will be ±Inf or NaN. + + if ($b -> is_inf()) { + return $x -> bnan(@r) if $x -> is_inf() || $y -> is_zero(); + if ($b -> is_inf("+")) { + if ($x -> is_negative()) { + return $x -> bone("-", @r); } else { - $bin =~ s/.{$y}$//; # cut off at the right side - $bin = '1' . $bin; # extend left side by one dummy '1' - $bin =~ tr/10/01/; # flip bits back + return $x -> bzero(@r); + } + } else { + if ($x -> is_negative()) { + return $y -> is_odd() ? $x -> bzero(@r) + : $x -> bone("-", @r); + } elsif ($x -> is_positive()) { + return $y -> is_odd() ? $x -> bone("-", @r) + : $x -> bzero(@r); + } else { + return $x -> bzero(@r); } - my $res = $class -> new('0b' . $bin); # add prefix and convert back - $res = $res -> binc(); # remember to increment - $x -> {value} = $res -> {value}; # take over value - return $x -> round(@r); # we are done now, magic, isn't? } + } - # x < 0, n == 2, y == 1 - $x = $x -> bdec(); # n == 2, but $y == 1: this fixes it + if ($b -> is_zero()) { + return $x -> round(@r) if $y -> is_zero(); + return $x -> bnan(@r) if $x -> is_zero(); + return $x -> is_negative() ? $x -> binf("-", @r) + : $x -> binf("+", @r); } - $x -> {value} = $LIB -> _rsft($x -> {value}, $y -> {value}, $b); - $x -> round(@r); + if ($y -> is_inf("+")) { + if ($b -> is_one("-")) { + return $x -> bnan(@r); + } elsif ($b -> is_one("+")) { + return $x -> round(@r); + } else { + return $x -> bnan(@r) if $x -> is_inf(); + return $x -> is_negative() ? $x -> bone("-", @r) + : $x -> bzero(@r); + } + } + + if ($x -> is_inf()) { + if ($b -> is_negative()) { + if ($x -> is_inf("-")) { + if ($y -> is_even()) { + return $x -> round(@r); + } else { + return $x -> binf("+", @r); + } + } else { + if ($y -> is_even()) { + return $x -> round(@r); + } else { + return $x -> binf("-", @r); + } + } + } else { + return $x -> round(@r); + } + } + + # At this point, we know that both the input and the output is finite. + # Handle some trivial cases. + + return $x -> round(@r) if $x -> is_zero() || $y -> is_zero() + || $b -> is_one("+") + || $b -> is_one("-") && $y -> is_even(); + + return $x -> bneg(@r) if $b -> is_one("-") && $y -> is_odd(); + + # We know that $y is positive. Shifting right by a positive amount might + # lead to a non-integer result. + + return $upgrade -> brsft($x, $y, $b, @r) if defined($upgrade); + + # This only works for negative numbers when shifting in base 2. + if ($x -> is_neg() && $b -> bcmp("2") == 0) { + return $x -> round(@r) if $x -> is_one('-'); # -1 => -1 + # Although this is O(N*N) in Math::BigInt::Calc->_as_bin(), it is O(N) + # in Pari et al., but perhaps there is a better emulation for two's + # complement shift ... if $y != 1, we must simulate it by doing: + # convert to bin, flip all bits, shift, and be done + $x = $x -> binc(); # -3 => -2 + my $bin = $x -> to_bin(); # convert to string + $bin =~ s/^-//; # strip leading minus + $bin =~ tr/10/01/; # flip bits + my $nbits = CORE::length($bin); + return $x -> bone("-", @r) if $y >= $nbits; + $bin = substr $bin, 0, $nbits - $y; # keep most significant bits + $bin = '1' . $bin; # prepend one dummy '1' + $bin =~ tr/10/01/; # flip bits back + my $res = $class -> from_bin($bin); # convert back from string + $res = $res -> binc(); # remember to increment + $x -> {value} = $res -> {value}; # take over value + return $x -> round(@r); + } + + # While some of the libraries support an arbitrarily large base, not all of + # them do, so rather than returning an incorrect result in those cases, use + # division. + + my $uintmax = ~0; + if ($x -> bcmp($uintmax) > 0 || $x -> is_neg() || $b -> is_negative()) { + $x = $x -> bdiv($b -> bpow($y)); + } else { + $b = $b -> numify(); + $x -> {value} = $LIB -> _rsft($x -> {value}, $y -> {value}, $b); + } + + return $x -> round(@r); } ############################################################################### # Bitwise methods ############################################################################### +# Bitwise left shift. + +sub bblsft { + # We don't call objectify(), because the bitwise methods should not + # upgrade/downgrade, even when upgrading/downgrading is enabled. + + my ($class, $x, $y, @r); + + # $x -> bblsft($y) + + if (ref($_[0])) { + ($class, $x, $y, @r) = (ref($_[0]), @_); + $y = $y -> as_int() + if ref($y) && !$y -> isa(__PACKAGE__) && $y -> can('as_int'); + $y = $class -> new(int($y)) unless ref($y); + } + + # $class -> bblsft($x, $y) + + else { + ($class, $x, $y, @r) = @_; + for ($x, $y) { + $_ = $_ -> as_int() + if ref($_) && !$_ -> isa(__PACKAGE__) && $_ -> can('as_int'); + $_ = $class -> new(int($_)) unless ref($_); + } + } + + return $x if $x -> modify('bblsft'); + + return $x -> bnan(@r) if $x -> is_nan() || $y -> is_nan(); + + # bblsft($x, -$y) = bbrsft($x, $y) + + return $x -> bbrsft($y -> copy() -> bneg()) if $y -> is_neg(); + + # Shifting infinitely far to the left. + + if ($y -> is_inf("+")) { + return $x -> binf("+", @r) if $x -> is_pos(); + return $x -> binf("-", @r) if $x -> is_neg(); + return $x -> bnan(@r); + } + + # These cases change nothing. + + return $x -> round(@r) if $x -> is_zero() || $x -> is_inf() || + $y -> is_zero(); + + $x -> {value} = $LIB -> _lsft($x -> {value}, $y -> {value}, 2); + $x -> round(@r); +} + +# Bitwise right shift. + +sub bbrsft { + # We don't call objectify(), because the bitwise methods should not + # upgrade/downgrade, even when upgrading/downgrading is enabled. + + my ($class, $x, $y, @r); + + # $x -> bblsft($y) + + if (ref($_[0])) { + ($class, $x, $y, @r) = (ref($_[0]), @_); + $y = $y -> as_int() + if ref($y) && !$y -> isa(__PACKAGE__) && $y -> can('as_int'); + $y = $class -> new(int($y)) unless ref($y); + } + + # $class -> bblsft($x, $y) + + else { + ($class, $x, $y, @r) = @_; + for ($x, $y) { + $_ = $_ -> as_int() + if ref($_) && !$_ -> isa(__PACKAGE__) && $_ -> can('as_int'); + $_ = $class -> new(int($_)) unless ref($_); + } + } + + return $x if $x -> modify('bbrsft'); + + return $x -> bnan(@r) if $x -> is_nan() || $y -> is_nan(); + + # bbrsft($x, -$y) = bblsft($x, $y) + + return $x -> bblsft($y -> copy() -> bneg()) if $y -> is_neg(); + + # Shifting infinitely far to the right. + + if ($y -> is_inf("+")) { + return $x -> bnan(@r) if $x -> is_inf(); + return $x -> bone("-", @r) if $x -> is_neg(); + return $x -> bzero(@r); + } + + # These cases change nothing. + + return $x -> round(@r) if $x -> is_zero() || $x -> is_inf() || + $y -> is_zero(); + + # At this point, $x is either positive or negative, not zero. + + if ($x -> is_pos()) { + $x -> {value} = $LIB -> _rsft($x -> {value}, $y -> {value}, 2); + } else { + my $n = $x -> {value}; + my $d = $LIB -> _pow($LIB -> _new("2"), $y -> {value}); + my ($p, $q) = $LIB -> _div($n, $d); + $p = $LIB -> _inc($p) unless $LIB -> _is_zero($q); + $x -> {value} = $p; + } + + $x -> round(@r); +} + sub band { #(BINT or num_str, BINT or num_str) return BINT # compute x & y @@ -3485,8 +4134,8 @@ sub band { return $x if $x->modify('band'); return $upgrade -> band($x, $y, @r) - if defined($upgrade) && (!$x -> isa($class) || - !$y -> isa($class)); + if defined($upgrade) && (!$x -> isa(__PACKAGE__) || + !$y -> isa(__PACKAGE__)); $r[3] = $y; # no push! @@ -3511,8 +4160,8 @@ sub bior { return $x if $x->modify('bior'); return $upgrade -> bior($x, $y, @r) - if defined($upgrade) && (!$x -> isa($class) || - !$y -> isa($class)); + if defined($upgrade) && (!$x -> isa(__PACKAGE__) || + !$y -> isa(__PACKAGE__)); $r[3] = $y; # no push! @@ -3537,8 +4186,8 @@ sub bxor { return $x if $x->modify('bxor'); return $upgrade -> bxor($x, $y, @r) - if defined($upgrade) && (!$x -> isa($class) || - !$y -> isa($class)); + if defined($upgrade) && (!$x -> isa(__PACKAGE__) || + !$y -> isa(__PACKAGE__)); $r[3] = $y; # no push! @@ -3561,7 +4210,7 @@ sub bnot { return $x if $x->modify('bnot'); return $upgrade -> bnot($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); $x -> binc() -> bneg(@r); } @@ -3576,11 +4225,19 @@ sub round { my ($class, $self, @args) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); - # $x->round(undef, undef) signals no rounding + # These signal no rounding: + # + # $x->round(undef) + # $x->round(undef, undef, ...) + # + # The "@args <= 3" is necessary because the final set of parameters that + # will be used for rounding depend on the "extra arguments", if any. - if (@args >= 2 && @args <= 3 && !defined($args[0]) && !defined($args[1])) { - $self->{_a} = undef; - $self->{_p} = undef; + if (@args == 1 && !defined($args[0]) || + @args >= 2 && @args <= 3 && !defined($args[0]) && !defined($args[1])) + { + $self->{accuracy} = undef; + $self->{precision} = undef; return $self; } @@ -3605,8 +4262,8 @@ sub round { if (!defined $a) { foreach ($self, @args) { # take the defined one, or if both defined, the one that is smaller - $a = $_->{_a} - if (defined $_->{_a}) && (!defined $a || $_->{_a} < $a); + $a = $_->{accuracy} + if (defined $_->{accuracy}) && (!defined $a || $_->{accuracy} < $a); } } if (!defined $p) { @@ -3614,17 +4271,15 @@ sub round { foreach ($self, @args) { # take the defined one, or if both defined, the one that is bigger # -2 > -3, and 3 > 2 - $p = $_->{_p} - if (defined $_->{_p}) && (!defined $p || $_->{_p} > $p); + $p = $_->{precision} + if (defined $_->{precision}) && (!defined $p || $_->{precision} > $p); } } - no strict 'refs'; - # if still none defined, use globals unless (defined $a || defined $p) { - $a = ${"$class\::accuracy"}; - $p = ${"$class\::precision"}; + $a = $class -> accuracy(); + $p = $class -> precision(); } # A == 0 is useless, so undef it to signal no rounding @@ -3636,7 +4291,7 @@ sub round { # set A and set P is an fatal error return $self->bnan() if defined $a && defined $p; - $r = ${"$class\::round_mode"} unless defined $r; + $r = $class -> round_mode() unless defined $r; if ($r !~ /^(even|odd|[+-]inf|zero|trunc|common)$/) { croak("Unknown round mode '$r'"); } @@ -3644,10 +4299,10 @@ sub round { # now round, by calling either bround or bfround: if (defined $a) { $self = $self->bround(int($a), $r) - if !defined $self->{_a} || $self->{_a} >= $a; + if !defined $self->{accuracy} || $self->{accuracy} >= $a; } else { # both can't be undefined due to early out $self = $self->bfround(int($p), $r) - if !defined $self->{_p} || $self->{_p} <= $p; + if !defined $self->{precision} || $self->{precision} <= $p; } # bround() or bfround() already called bnorm() if nec. @@ -3667,7 +4322,7 @@ sub bround { return $x if !defined $scale || $x->modify('bround'); # no-op if ($x->is_zero() || $scale == 0) { - $x->{_a} = $scale if !defined $x->{_a} || $x->{_a} > $scale; # 3 > 2 + $x->{accuracy} = $scale if !defined $x->{accuracy} || $x->{accuracy} > $scale; # 3 > 2 return $x; } return $x if $x->{sign} !~ /^[+-]$/; # inf, NaN @@ -3681,7 +4336,7 @@ sub bround { # scale < 0, but > -len (not >=!) if (($scale < 0 && $scale < -$len-1) || ($scale >= $len)) { - $x->{_a} = $scale if !defined $x->{_a} || $x->{_a} > $scale; # 3 > 2 + $x->{accuracy} = $scale if !defined $x->{accuracy} || $x->{accuracy} > $scale; # 3 > 2 return $x; } @@ -3749,10 +4404,10 @@ sub bround { } $x->{value} = $LIB->_new($xs) if $put_back == 1; # put back, if needed - $x->{_a} = $scale if $scale >= 0; + $x->{accuracy} = $scale if $scale >= 0; if ($scale < 0) { - $x->{_a} = $len+$scale; - $x->{_a} = 0 if $scale < -$len; + $x->{accuracy} = $len+$scale; + $x->{accuracy} = 0 if $scale < -$len; } $x; } @@ -3770,8 +4425,8 @@ sub bfround { # no-op for Math::BigInt objects if $n <= 0 $x = $x->bround($x->length()-$scale, $mode) if $scale > 0; - delete $x->{_a}; # delete to save memory - $x->{_p} = $scale; # store new _p + $x->{accuracy} = undef; + $x->{precision} = $scale; # store new precision $x; } @@ -3788,7 +4443,7 @@ sub bfloor { my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); return $upgrade -> bfloor($x) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); $x->round(@r); } @@ -3798,7 +4453,7 @@ sub bceil { my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); return $upgrade -> bceil($x) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); $x->round(@r); } @@ -3808,7 +4463,7 @@ sub bint { my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); return $upgrade -> bint($x) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); $x->round(@r); } @@ -3838,7 +4493,7 @@ sub bgcd { if (defined $upgrade) { my $do_upgrade = 0; for my $arg (@args) { - unless ($arg -> isa($class)) { + unless ($arg -> isa(__PACKAGE__)) { $do_upgrade = 1; last; } @@ -3847,13 +4502,15 @@ sub bgcd { } my $x = shift @args; - $x = ref($x) && $x -> isa($class) ? $x -> copy() : $class -> new($x); + $x = defined(blessed($x)) && $x -> isa(__PACKAGE__) ? $x -> copy() + : $class -> new($x); return $class->bnan() if $x->{sign} !~ /^[+-]$/; # x NaN? while (@args) { my $y = shift @args; - $y = $class->new($y) unless ref($y) && $y -> isa($class); + $y = $class->new($y) + unless defined(blessed($y)) && $y -> isa(__PACKAGE__); return $class->bnan() if $y->{sign} !~ /^[+-]$/; # y NaN? $x->{value} = $LIB->_gcd($x->{value}, $y->{value}); last if $LIB->_is_one($x->{value}); @@ -3883,7 +4540,7 @@ sub blcm { if (defined $upgrade) { my $do_upgrade = 0; for my $arg (@args) { - unless ($arg -> isa($class)) { + unless ($arg -> isa(__PACKAGE__)) { $do_upgrade = 1; last; } @@ -3892,12 +4549,14 @@ sub blcm { } my $x = shift @args; - $x = ref($x) && $x -> isa($class) ? $x -> copy() : $class -> new($x); + $x = defined(blessed($x)) && $x -> isa(__PACKAGE__) ? $x -> copy() + : $class -> new($x); return $class->bnan() if $x->{sign} !~ /^[+-]$/; # x NaN? while (@args) { my $y = shift @args; - $y = $class -> new($y) unless ref($y) && $y -> isa($class); + $y = $class -> new($y) + unless defined(blessed($y)) && $y -> isa(__PACKAGE__); return $x->bnan() if $y->{sign} !~ /^[+-]$/; # y not integer $x -> {value} = $LIB->_lcm($x -> {value}, $y -> {value}); } @@ -3974,7 +4633,7 @@ sub exponent { # Upgrade? return $upgrade -> exponent($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); if ($x->{sign} !~ /^[+-]$/) { my $s = $x->{sign}; @@ -3996,15 +4655,15 @@ sub mantissa { # Upgrade? return $upgrade -> mantissa($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); if ($x->{sign} !~ /^[+-]$/) { # for NaN, +inf, -inf: keep the sign return $class->new($x->{sign}, @r); } my $m = $x->copy(); - delete $m->{_p}; - delete $m->{_a}; + $m -> precision(undef); + $m -> accuracy(undef); # that's a bit inefficient: my $zeros = $LIB->_zeros($m->{value}); @@ -4021,7 +4680,7 @@ sub parts { # Upgrade? return $upgrade -> parts($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); ($x->mantissa(@r), $x->exponent(@r)); } @@ -4056,7 +4715,7 @@ sub sparts { # Upgrade? return $upgrade -> sparts($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number. @@ -4088,7 +4747,7 @@ sub nparts { # Upgrade? return $upgrade -> nparts($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number. @@ -4126,7 +4785,7 @@ sub eparts { # Upgrade? return $upgrade -> eparts($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number. @@ -4185,7 +4844,7 @@ sub dparts { # Upgrade? return $upgrade -> dparts($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number. @@ -4223,7 +4882,7 @@ sub fparts { # Upgrade? return $upgrade -> fparts($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # N => N/1 @@ -4239,7 +4898,7 @@ sub numerator { carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; return $upgrade -> numerator($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); return $x -> copy() -> round(@r); } @@ -4250,7 +4909,7 @@ sub denominator { carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; return $upgrade -> denominator($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); return $x -> is_nan() ? $class -> bnan(@r) : $class -> bone(@r); } @@ -4274,7 +4933,7 @@ sub bstr { # Upgrade? return $upgrade -> bstr($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4300,7 +4959,7 @@ sub bsstr { # Upgrade? return $upgrade -> bsstr($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4328,7 +4987,7 @@ sub bnstr { # Upgrade? return $upgrade -> bnstr($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4362,7 +5021,7 @@ sub bestr { # Upgrade? return $upgrade -> bestr($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4401,7 +5060,7 @@ sub bdstr { # Upgrade? return $upgrade -> bdstr($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4426,7 +5085,7 @@ sub bfstr { # Upgrade? return $upgrade -> bfstr($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4450,7 +5109,7 @@ sub to_hex { # Upgrade? return $upgrade -> to_hex($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4475,7 +5134,7 @@ sub to_oct { # Upgrade? return $upgrade -> to_oct($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4500,7 +5159,7 @@ sub to_bin { # Upgrade? return $upgrade -> to_bin($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); # Finite number @@ -4519,7 +5178,7 @@ sub to_bytes { if $x -> is_neg() || ! $x -> is_int(); return $upgrade -> to_bytes($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); croak("to_bytes() requires a newer version of the $LIB library.") unless $LIB->can('_to_bytes'); @@ -4556,7 +5215,8 @@ sub to_base { unless $LIB->can('_to_base'); return $upgrade -> to_base($x, $base, $cs, @r) - if defined($upgrade) && (!$x -> isa($class) || !$base -> isa($class)); + if defined($upgrade) && (!$x -> isa(__PACKAGE__) || + !$base -> isa(__PACKAGE__)); return $LIB->_to_base($x->{value}, $base -> {value}, defined($cs) ? $cs : ()); @@ -4582,7 +5242,8 @@ sub to_base_num { unless $LIB->can('_to_base'); return $upgrade -> to_base_num($x, $base, @r) - if defined($upgrade) && (!$x -> isa($class) || !$base -> isa($class)); + if defined($upgrade) && (!$x -> isa(__PACKAGE__) || + !$base -> isa(__PACKAGE__)); # Get a reference to an array of library thingies, and replace each element # with a Math::BigInt object using that thingy. @@ -4608,7 +5269,7 @@ sub as_hex { return $x->bstr() if $x->{sign} !~ /^[+-]$/; # inf, nan etc return $upgrade -> as_hex($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); my $hex = $LIB->_as_hex($x->{value}); return $x->{sign} eq '-' ? "-$hex" : $hex; @@ -4624,7 +5285,7 @@ sub as_oct { return $x->bstr() if $x->{sign} !~ /^[+-]$/; # inf, nan etc return $upgrade -> as_oct($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); my $oct = $LIB->_as_oct($x->{value}); return $x->{sign} eq '-' ? "-$oct" : $oct; @@ -4640,7 +5301,7 @@ sub as_bin { return $x->bstr() if $x->{sign} !~ /^[+-]$/; # inf, nan etc return $upgrade -> as_bin($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); my $bin = $LIB->_as_bin($x->{value}); return $x->{sign} eq '-' ? "-$bin" : $bin; @@ -4671,7 +5332,7 @@ sub numify { } return $upgrade -> numify($x, @r) - if defined($upgrade) && !$x -> isa($class); + if defined($upgrade) && !$x -> isa(__PACKAGE__); my $num = 0 + $LIB->_num($x->{value}); return $x->{sign} eq '-' ? -$num : $num; @@ -4735,8 +5396,6 @@ sub objectify { $count ||= @a; unshift @a, $class; - no strict 'refs'; - # What we upgrade to, if anything. Note that we need the whole upgrade # chain, since there might be multiple levels of upgrading. E.g., class A # upgrades to class B, which upgrades to class C. Delay getting the chain @@ -4748,11 +5407,8 @@ sub objectify { # Disable downgrading, because Math::BigFloat -> foo('1.0', '2.0') needs # floats. - my $down; - if (defined ${"$a[0]::downgrade"}) { - $down = ${"$a[0]::downgrade"}; - ${"$a[0]::downgrade"} = undef; - } + my $dng = $class -> downgrade(); + $class -> downgrade(undef); ARG: for my $i (1 .. $count) { @@ -4761,13 +5417,13 @@ sub objectify { # Perl scalars are fed to the appropriate constructor. unless ($ref) { - $a[$i] = $a[0] -> new($a[$i]); + $a[$i] = $class -> new($a[$i]); next; } # If it is an object of the right class, all is fine. - next if $ref -> isa($a[0]); + next if $ref -> isa($class); # Upgrading is OK, so skip further tests if the argument is upgraded, # but first get the whole upgrade chain if we haven't got it yet. @@ -4794,7 +5450,7 @@ sub objectify { my $recheck = 0; - if ($a[0] -> isa('Math::BigInt')) { + if ($class -> isa('Math::BigInt')) { if ($a[$i] -> can('as_int')) { $a[$i] = $a[$i] -> as_int(); $recheck = 1; @@ -4804,10 +5460,17 @@ sub objectify { } } - elsif ($a[0] -> isa('Math::BigFloat')) { + elsif ($class -> isa('Math::BigRat')) { + if ($a[$i] -> can('as_rat')) { + $a[$i] = $a[$i] -> as_rat(); + $recheck = 1; + } + } + + elsif ($class -> isa('Math::BigFloat')) { if ($a[$i] -> can('as_float')) { $a[$i] = $a[$i] -> as_float(); - $recheck = $1; + $recheck = 1; } } @@ -4819,23 +5482,23 @@ sub objectify { # Perl scalars are fed to the appropriate constructor. unless ($ref) { - $a[$i] = $a[0] -> new($a[$i]); + $a[$i] = $class -> new($a[$i]); next; } # If it is an object of the right class, all is fine. - next if $ref -> isa($a[0]); + next if $ref -> isa($class); } # Last resort. - $a[$i] = $a[0] -> new($a[$i]); + $a[$i] = $class -> new($a[$i]); } - # Reset the downgrading. + # Restore the downgrading. - ${"$a[0]::downgrade"} = $down; + $class -> downgrade($dng); return @a; } @@ -4905,6 +5568,13 @@ sub import { next; } + # Fall-back accuracy. + + if ($param eq 'div_scale') { + $class -> div_scale(shift); + next; + } + # Backend library. if ($param =~ /^(lib|try|only)\z/) { @@ -5009,10 +5679,8 @@ sub import { # Any non-':constant' stuff is handled by our parent, Exporter - if (@a) { - $class->SUPER::import(@a); # need it for subclasses - $class->export_to_level(1, $class, @a); # need it for Math::BigFloat - } + $class -> SUPER::import(@a); # for subclasses + $class -> export_to_level(1, $class, @a) if @a; # need this, too # We might not have loaded any backend library yet, either because the user # didn't specify any, or because the specified libraries failed to load and @@ -5072,7 +5740,6 @@ sub _find_round_parameters { # @args all 'other' arguments (0 for unary, 1 for binary ops) my $class = ref($self); # find out class of argument(s) - no strict 'refs'; # convert to normal scalar for speed and correctness in inner parts $a = $a->can('numify') ? $a->numify() : "$a" if defined $a && ref($a); @@ -5082,8 +5749,8 @@ sub _find_round_parameters { if (!defined $a) { foreach ($self, @args) { # take the defined one, or if both defined, the one that is smaller - $a = $_->{_a} - if (defined $_->{_a}) && (!defined $a || $_->{_a} < $a); + $a = $_->{accuracy} + if (defined $_->{accuracy}) && (!defined $a || $_->{accuracy} < $a); } } if (!defined $p) { @@ -5091,14 +5758,14 @@ sub _find_round_parameters { foreach ($self, @args) { # take the defined one, or if both defined, the one that is bigger # -2 > -3, and 3 > 2 - $p = $_->{_p} - if (defined $_->{_p}) && (!defined $p || $_->{_p} > $p); + $p = $_->{precision} + if (defined $_->{precision}) && (!defined $p || $_->{precision} > $p); } } # if still none defined, use globals (#2) - $a = ${"$class\::accuracy"} unless defined $a; - $p = ${"$class\::precision"} unless defined $p; + $a = $class -> accuracy() unless defined $a; + $p = $class -> precision() unless defined $p; # A == 0 is useless, so undef it to signal no rounding $a = undef if defined $a && $a == 0; @@ -5109,7 +5776,7 @@ sub _find_round_parameters { # set A and set P is an fatal error return ($self->bnan()) if defined $a && defined $p; # error - $r = ${"$class\::round_mode"} unless defined $r; + $r = $class -> round_mode() unless defined $r; if ($r !~ /^(even|odd|[+-]inf|zero|trunc|common)$/) { croak("Unknown round mode '$r'"); } @@ -5858,6 +6525,9 @@ Math::BigInt - arbitrary size integer ma Math::BigInt->round_mode($m); # set global round mode, must be one of # 'even', 'odd', '+inf', '-inf', 'zero', # 'trunc', or 'common' + Math::BigInt->div_scale($n); # set fallback accuracy + Math::BigInt->trap_inf($b); # trap infinities or not + Math::BigInt->trap_nan($b); # trap NaNs or not Math::BigInt->config(); # return hash with configuration # Constructor methods (when the class methods below are used as instance @@ -5935,10 +6605,15 @@ Math::BigInt - arbitrary size integer ma $x->btmod($y); # modulus (truncated) $x->bmodinv($mod); # modular multiplicative inverse $x->bmodpow($y,$mod); # modular exponentiation (($x ** $y) % $mod) + $x->binv() # inverse (1/$x) $x->bpow($y); # power of arguments (x ** y) $x->blog(); # logarithm of $x to base e (Euler's number) $x->blog($base); # logarithm of $x to base $base (e.g., base 2) $x->bexp(); # calculate e ** $x where e is Euler's number + $x->bilog2(); # log2($x) rounded down to nearest int + $x->bilog10(); # log10($x) rounded down to nearest int + $x->bclog2(); # log2($x) rounded up to nearest int + $x->bclog10(); # log19($x) rounded up to nearest int $x->bnok($y); # x over y (binomial coefficient n over k) $x->buparrow($n, $y); # Knuth's up-arrow notation $x->backermann($y); # the Ackermann function @@ -5962,6 +6637,8 @@ Math::BigInt - arbitrary size integer ma # Bitwise methods + $x->bblsft($y); # bitwise left shift + $x->bbrsft($y); # bitwise right shift $x->band($y); # bitwise and $x->bior($y); # bitwise inclusive or $x->bxor($y); # bitwise exclusive or @@ -6230,6 +6907,15 @@ attempt to return an infinite number of Set/get the rounding mode. +=item trap_inf() + +Set/get the value determining whether infinities should cause a fatal error or +not. + +=item trap_nan() + +Set/get the value determining whether NaNs should cause a fatal error or not. + =item upgrade() Set/get the class for upgrading. When a computation might result in a @@ -6740,6 +7426,12 @@ Multiply $x by $y, and then add $z to th This method was added in v1.87 of Math::BigInt (June 2007). +=item binv() + + $x->binv(); + +Invert the value of $x, i.e., compute 1/$x. + =item bdiv() $x->bdiv($y); # divide, set $x to quotient @@ -6869,6 +7561,42 @@ This method was added in v1.82 of Math:: See also L. +=item bilog2() + +Base 2 logarithm rounded down towards the nearest integer. + + $x->bilog2(); # int(log2(x)) = int(log(x)/log(2)) + +In list context a second argument is returned. This is 1 if the result is +exact, i.e., the input is an exact power of 2, and 0 otherwise. + +=item bilog10() + +Base 10 logarithm rounded down towards the nearest integer. + + $x->bilog10(); # int(log10(x)) = int(log(x)/log(10)) + +In list context a second argument is returned. This is 1 if the result is +exact, i.e., the input is an exact power of 10, and 0 otherwise. + +=item bclog2() + +Base 2 logarithm rounded up towards the nearest integer. + + $x->bclog2(); # ceil(log2(x)) = ceil(log(x)/log(2)) + +In list context a second argument is returned. This is 1 if the result is +exact, i.e., the input is an exact power of 2, and 0 otherwise. + +=item bclog10() + +Base 10 logarithm rounded up towards the nearest integer. + + $x->bclog10(); # ceil(log10(x)) = ceil(log(x)/log(10)) + +In list context a second argument is returned. This is 1 if the result is +exact, i.e., the input is an exact power of 10, and 0 otherwise. + =item bnok() $x->bnok($y); # x over y (binomial coefficient n over k) @@ -7103,28 +7831,70 @@ If $n is -12, the following values, L(0) =item brsft() +Right shift. + $x->brsft($n); # right shift $n places in base 2 $x->brsft($n, $b); # right shift $n places in base $b The latter is equivalent to - $x -> bdiv($b -> copy() -> bpow($n)) + $x -> bdiv($b -> copy() -> bpow($n)); =item blsft() +Left shift. + $x->blsft($n); # left shift $n places in base 2 $x->blsft($n, $b); # left shift $n places in base $b The latter is equivalent to - $x -> bmul($b -> copy() -> bpow($n)) + $x -> bmul($b -> copy() -> bpow($n)); =back =head2 Bitwise methods +For all bitwise methods, the operands are truncated to integers, i.e., rounded +towards zero, if necessary, before the method is applied. The bitwise methods +never upgrade, and they always return an integer. + =over +=item bbrsft() + +Bitwise right shift. This is equivalent to Perl's CE> operator. + + $x -> bbrsft($n); # right shift $n places in base 2 + +If C<$n> is negative, the shifting is done in the opposite direction, so these +two are equivalent for all C<$x> and C<$n> + + $y = $x -> bbrsft($n); + $y = $x -> bblsft(-$n); + +and also equivalent to + + $y = $x -> bdiv(ref($x) -> new(2) -> bpow($n)); # if $n > 0 + $y = $x -> bmul(ref($x) -> new(2) -> bpow(-$n)); # if $n < 0 + +=item bblsft() + +Bitwise left shift. This is equivalent to Perl's CE> operator. + + $x -> bblsft($n); # left shift $n places in base 2 + +If C<$n> is negative, the shifting is done in the opposite direction, so these +two are equivalent for all C<$x> and C<$n> + + $y = $x -> bblsft($n); + $y = $x -> bbrsft(-$n); + +and also equivalent to + + $y = $x -> bmul(ref($x) -> new(2) -> bpow($n)); # if $n > 0 + $y = $x -> bdiv(ref($x) -> new(2) -> bpow($n)); # if $n < 0 + =item band() $x->band($y); # bitwise and @@ -8270,20 +9040,21 @@ store additional hash keys in the object that must be defined, e.g.: # Globals - $accuracy = undef; - $precision = -2; # round to 2 decimal places - $round_mode = 'even'; - $div_scale = 40; + our $accuracy = 2; # round to 2 decimal places + our $precision = undef; + our $round_mode = 'even'; + our $div_scale = 40; Additionally, you might want to provide the following two globals to allow -auto-upgrading and auto-downgrading to work correctly: +auto-upgrading and auto-downgrading: - $upgrade = undef; - $downgrade = undef; + our $upgrade = undef; + our $downgrade = undef; This allows Math::BigInt to correctly retrieve package globals from the -subclass, like C<$SubClass::precision>. See t/Math/BigInt/Subclass.pm or -t/Math/BigFloat/SubClass.pm completely functional subclass examples. +subclass, like C<$SubClass::precision>. See C, +C, or C for subclass +examples. Don't forget to @@ -8299,16 +9070,22 @@ When used like this: use Math::BigInt upgrade => 'Foo::Bar'; -certain operations 'upgrade' their calculation and thus the result to the class -Foo::Bar. Usually this is used in conjunction with Math::BigFloat: +any operation whose result cannot be represented as an integer is upgraded to +the class Foo::Bar. Usually this is used in conjunction with Math::BigFloat: use Math::BigInt upgrade => 'Math::BigFloat'; +For example, the following returns 3 as a Math::BigInt when no upgrading is +defined, and 3.125 as a Math::BigFloat if Math::BigInt is set to upgrade to +Math::BigFloat: + + $x = Math::BigInt -> new(25) -> bdiv(8); + As a shortcut, you can use the module L: use bignum; -Also good for one-liners: +which is also good for one-liners: perl -Mbignum -le 'print 2 ** 255' @@ -8546,28 +9323,6 @@ L -=item * CPAN Ratings - -L - -=item * The Bignum mailing list - -=over 4 - -=item * Post to mailing list - -C - -=item * View mailing list - -L - -=item * Subscribe/Unsubscribe - -L - -=back - =back =head1 LICENSE @@ -8577,11 +9332,12 @@ the same terms as Perl itself. =head1 SEE ALSO -L and L as well as the backends -L, L, and L. +L and L as well as the backend libraries +L, L, and L, +L, and L. -The pragmas L, L and L also might be of interest -because they solve the autoupgrading/downgrading issue, at least partly. +The pragmas L, L, and L might also be of interest. In +addition there is the L pragma which does upgrading and downgrading. =head1 AUTHORS Index: gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigRat.pm =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigRat.pm diff -N gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigRat.pm --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigRat.pm 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,3425 @@ +# +# "Tax the rat farms." - Lord Vetinari +# + +# The following hash values are used: + +# sign : "+", "-", "+inf", "-inf", or "NaN" +# _d : denominator +# _n : numerator (value = _n/_d) +# accuracy : accuracy +# precision : precision + +# You should not look at the innards of a BigRat - use the methods for this. + +package Math::BigRat; + +use 5.006; +use strict; +use warnings; + +use Carp qw< carp croak >; +use Scalar::Util qw< blessed >; + +use Math::BigFloat (); + +our $VERSION = '2.003002'; +$VERSION =~ tr/_//d; + +our @ISA = qw(Math::BigFloat); + +our ($accuracy, $precision, $round_mode, $div_scale, + $upgrade, $downgrade, $_trap_nan, $_trap_inf); + +use overload + + # overload key: with_assign + + '+' => sub { $_[0] -> copy() -> badd($_[1]); }, + + '-' => sub { my $c = $_[0] -> copy; + $_[2] ? $c -> bneg() -> badd( $_[1]) + : $c -> bsub($_[1]); }, + + '*' => sub { $_[0] -> copy() -> bmul($_[1]); }, + + '/' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bdiv($_[0]) + : $_[0] -> copy() -> bdiv($_[1]); }, + + '%' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bmod($_[0]) + : $_[0] -> copy() -> bmod($_[1]); }, + + '**' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bpow($_[0]) + : $_[0] -> copy() -> bpow($_[1]); }, + + '<<' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bblsft($_[0]) + : $_[0] -> copy() -> bblsft($_[1]); }, + + '>>' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bbrsft($_[0]) + : $_[0] -> copy() -> bbrsft($_[1]); }, + + # overload key: assign + + '+=' => sub { $_[0] -> badd($_[1]); }, + + '-=' => sub { $_[0] -> bsub($_[1]); }, + + '*=' => sub { $_[0] -> bmul($_[1]); }, + + '/=' => sub { scalar $_[0] -> bdiv($_[1]); }, + + '%=' => sub { $_[0] -> bmod($_[1]); }, + + '**=' => sub { $_[0] -> bpow($_[1]); }, + + '<<=' => sub { $_[0] -> bblsft($_[1]); }, + + '>>=' => sub { $_[0] -> bbrsft($_[1]); }, + +# 'x=' => sub { }, + +# '.=' => sub { }, + + # overload key: num_comparison + + '<' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> blt($_[0]) + : $_[0] -> blt($_[1]); }, + + '<=' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> ble($_[0]) + : $_[0] -> ble($_[1]); }, + + '>' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bgt($_[0]) + : $_[0] -> bgt($_[1]); }, + + '>=' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bge($_[0]) + : $_[0] -> bge($_[1]); }, + + '==' => sub { $_[0] -> beq($_[1]); }, + + '!=' => sub { $_[0] -> bne($_[1]); }, + + # overload key: 3way_comparison + + '<=>' => sub { my $cmp = $_[0] -> bcmp($_[1]); + defined($cmp) && $_[2] ? -$cmp : $cmp; }, + + 'cmp' => sub { $_[2] ? "$_[1]" cmp $_[0] -> bstr() + : $_[0] -> bstr() cmp "$_[1]"; }, + + # overload key: str_comparison + +# 'lt' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bstrlt($_[0]) +# : $_[0] -> bstrlt($_[1]); }, +# +# 'le' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bstrle($_[0]) +# : $_[0] -> bstrle($_[1]); }, +# +# 'gt' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bstrgt($_[0]) +# : $_[0] -> bstrgt($_[1]); }, +# +# 'ge' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bstrge($_[0]) +# : $_[0] -> bstrge($_[1]); }, +# +# 'eq' => sub { $_[0] -> bstreq($_[1]); }, +# +# 'ne' => sub { $_[0] -> bstrne($_[1]); }, + + # overload key: binary + + '&' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> band($_[0]) + : $_[0] -> copy() -> band($_[1]); }, + + '&=' => sub { $_[0] -> band($_[1]); }, + + '|' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bior($_[0]) + : $_[0] -> copy() -> bior($_[1]); }, + + '|=' => sub { $_[0] -> bior($_[1]); }, + + '^' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bxor($_[0]) + : $_[0] -> copy() -> bxor($_[1]); }, + + '^=' => sub { $_[0] -> bxor($_[1]); }, + +# '&.' => sub { }, + +# '&.=' => sub { }, + +# '|.' => sub { }, + +# '|.=' => sub { }, + +# '^.' => sub { }, + +# '^.=' => sub { }, + + # overload key: unary + + 'neg' => sub { $_[0] -> copy() -> bneg(); }, + +# '!' => sub { }, + + '~' => sub { $_[0] -> copy() -> bnot(); }, + +# '~.' => sub { }, + + # overload key: mutators + + '++' => sub { $_[0] -> binc() }, + + '--' => sub { $_[0] -> bdec() }, + + # overload key: func + + 'atan2' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> batan2($_[0]) + : $_[0] -> copy() -> batan2($_[1]); }, + + 'cos' => sub { $_[0] -> copy() -> bcos(); }, + + 'sin' => sub { $_[0] -> copy() -> bsin(); }, + + 'exp' => sub { $_[0] -> copy() -> bexp($_[1]); }, + + 'abs' => sub { $_[0] -> copy() -> babs(); }, + + 'log' => sub { $_[0] -> copy() -> blog(); }, + + 'sqrt' => sub { $_[0] -> copy() -> bsqrt(); }, + + 'int' => sub { $_[0] -> copy() -> bint(); }, + + # overload key: conversion + + 'bool' => sub { $_[0] -> is_zero() ? '' : 1; }, + + '""' => sub { $_[0] -> bstr(); }, + + '0+' => sub { $_[0] -> numify(); }, + + '=' => sub { $_[0]->copy(); }, + + ; + +BEGIN { + *objectify = \&Math::BigInt::objectify; + + *AUTOLOAD = \&Math::BigFloat::AUTOLOAD; # can't inherit AUTOLOAD + *as_number = \&as_int; + *is_pos = \&is_positive; + *is_neg = \&is_negative; +} + +############################################################################## +# Global constants and flags. Access these only via the accessor methods! + +$accuracy = $precision = undef; +$round_mode = 'even'; +$div_scale = 40; +$upgrade = undef; +$downgrade = undef; + +# These are internally, and not to be used from the outside at all! + +$_trap_nan = 0; # are NaNs ok? set w/ config() +$_trap_inf = 0; # are infs ok? set w/ config() + +# the math backend library + +my $LIB = 'Math::BigInt::Calc'; + +my $nan = 'NaN'; + +# Has import() been called yet? This variable is needed to make "require" work. + +my $IMPORT = 0; + +# Compare the following function with @ISA above. This inheritance mess needs a +# clean up. When doing so, also consider the BEGIN block and the AUTOLOAD code. +# Fixme! + +sub isa { + return 0 if $_[1] =~ /^Math::Big(Int|Float)/; # we aren't + UNIVERSAL::isa(@_); +} + +############################################################################## + +sub new { + my $proto = shift; + my $protoref = ref $proto; + my $class = $protoref || $proto; + + # Make "require" work. + + $class -> import() if $IMPORT == 0; + + # Check the way we are called. + + if ($protoref) { + croak("new() is a class method, not an instance method"); + } + + if (@_ < 1) { + #carp("Using new() with no argument is deprecated;", + # " use bzero() or new(0) instead"); + return $class -> bzero(); + } + + if (@_ > 2) { + carp("Superfluous arguments to new() ignored."); + } + + # Get numerator and denominator. If any of the arguments is undefined, + # return zero. + + my ($n, $d) = @_; + + if (@_ == 1 && !defined $n || + @_ == 2 && (!defined $n || !defined $d)) + { + #carp("Use of uninitialized value in new()"); + return $class -> bzero(); + } + + # Initialize a new object. + + my $self = bless {}, $class; + + # One or two input arguments may be given. First handle the numerator $n. + + if (ref($n)) { + $n = Math::BigFloat -> new($n, undef, undef) + unless ($n -> isa('Math::BigRat') || + $n -> isa('Math::BigInt') || + $n -> isa('Math::BigFloat')); + } else { + if (defined $d) { + # If the denominator is defined, the numerator is not a string + # fraction, e.g., "355/113". + $n = Math::BigFloat -> new($n, undef, undef); + } else { + # If the denominator is undefined, the numerator might be a string + # fraction, e.g., "355/113". + if ($n =~ m| ^ \s* (\S+) \s* / \s* (\S+) \s* $ |x) { + $n = Math::BigFloat -> new($1, undef, undef); + $d = Math::BigFloat -> new($2, undef, undef); + } else { + $n = Math::BigFloat -> new($n, undef, undef); + } + } + } + + # At this point $n is an object and $d is either an object or undefined. An + # undefined $d means that $d was not specified by the caller (not that $d + # was specified as an undefined value). + + unless (defined $d) { + #return $n -> copy($n) if $n -> isa('Math::BigRat'); + if ($n -> isa('Math::BigRat')) { + return $downgrade -> new($n) + if defined($downgrade) && $n -> is_int(); + return $class -> copy($n); + } + + if ($n -> is_nan()) { + return $class -> bnan(); + } + + if ($n -> is_inf()) { + return $class -> binf($n -> sign()); + } + + if ($n -> isa('Math::BigInt')) { + $self -> {_n} = $LIB -> _new($n -> copy() -> babs(undef, undef) + -> bstr()); + $self -> {_d} = $LIB -> _one(); + $self -> {sign} = $n -> sign(); + return $downgrade -> new($n) if defined $downgrade; + return $self; + } + + if ($n -> isa('Math::BigFloat')) { + my $m = $n -> mantissa(undef, undef) -> babs(undef, undef); + my $e = $n -> exponent(undef, undef); + $self -> {_n} = $LIB -> _new($m -> bstr()); + $self -> {_d} = $LIB -> _one(); + + if ($e > 0) { + $self -> {_n} = $LIB -> _lsft($self -> {_n}, + $LIB -> _new($e -> bstr()), 10); + } elsif ($e < 0) { + $self -> {_d} = $LIB -> _lsft($self -> {_d}, + $LIB -> _new(-$e -> bstr()), 10); + + my $gcd = $LIB -> _gcd($LIB -> _copy($self -> {_n}), + $self -> {_d}); + if (!$LIB -> _is_one($gcd)) { + $self -> {_n} = $LIB -> _div($self->{_n}, $gcd); + $self -> {_d} = $LIB -> _div($self->{_d}, $gcd); + } + } + + $self -> {sign} = $n -> sign(); + return $downgrade -> new($n, undef, undef) + if defined($downgrade) && $n -> is_int(); + return $self; + } + + die "I don't know how to handle this"; # should never get here + } + + # At the point we know that both $n and $d are defined. We know that $n is + # an object, but $d might still be a scalar. Now handle $d. + + $d = Math::BigFloat -> new($d, undef, undef) + unless ref($d) && ($d -> isa('Math::BigRat') || + $d -> isa('Math::BigInt') || + $d -> isa('Math::BigFloat')); + + # At this point both $n and $d are objects. + + if ($n -> is_nan() || $d -> is_nan()) { + return $class -> bnan(); + } + + # At this point neither $n nor $d is a NaN. + + if ($n -> is_zero()) { + if ($d -> is_zero()) { # 0/0 = NaN + return $class -> bnan(); + } + return $class -> bzero(); + } + + if ($d -> is_zero()) { + return $class -> binf($d -> sign()); + } + + # At this point, neither $n nor $d is a NaN or a zero. + + # Copy them now before manipulating them. + + $n = $n -> copy(); + $d = $d -> copy(); + + if ($d < 0) { # make sure denominator is positive + $n -> bneg(); + $d -> bneg(); + } + + if ($n -> is_inf()) { + return $class -> bnan() if $d -> is_inf(); # Inf/Inf = NaN + return $class -> binf($n -> sign()); + } + + # At this point $n is finite. + + return $class -> bzero() if $d -> is_inf(); + return $class -> binf($d -> sign()) if $d -> is_zero(); + + # At this point both $n and $d are finite and non-zero. + + if ($n < 0) { + $n -> bneg(); + $self -> {sign} = '-'; + } else { + $self -> {sign} = '+'; + } + + if ($n -> isa('Math::BigRat')) { + + if ($d -> isa('Math::BigRat')) { + + # At this point both $n and $d is a Math::BigRat. + + # p r p * s (p / gcd(p, r)) * (s / gcd(s, q)) + # - / - = ----- = --------------------------------- + # q s q * r (q / gcd(s, q)) * (r / gcd(p, r)) + + my $p = $n -> {_n}; + my $q = $n -> {_d}; + my $r = $d -> {_n}; + my $s = $d -> {_d}; + my $gcd_pr = $LIB -> _gcd($LIB -> _copy($p), $r); + my $gcd_sq = $LIB -> _gcd($LIB -> _copy($s), $q); + $self -> {_n} = $LIB -> _mul($LIB -> _div($LIB -> _copy($p), $gcd_pr), + $LIB -> _div($LIB -> _copy($s), $gcd_sq)); + $self -> {_d} = $LIB -> _mul($LIB -> _div($LIB -> _copy($q), $gcd_sq), + $LIB -> _div($LIB -> _copy($r), $gcd_pr)); + + return $downgrade -> new($n->bstr()) + if defined($downgrade) && $self -> is_int(); + return $self; # no need for $self -> bnorm() here + } + + # At this point, $n is a Math::BigRat and $d is a Math::Big(Int|Float). + + my $p = $n -> {_n}; + my $q = $n -> {_d}; + my $m = $d -> mantissa(); + my $e = $d -> exponent(); + + # / p + # | ------------ if e > 0 + # | q * m * 10^e + # | + # p | p + # - / (m * 10^e) = | ----- if e == 0 + # q | q * m + # | + # | p * 10^-e + # | -------- if e < 0 + # \ q * m + + $self -> {_n} = $LIB -> _copy($p); + $self -> {_d} = $LIB -> _mul($LIB -> _copy($q), $m); + if ($e > 0) { + $self -> {_d} = $LIB -> _lsft($self -> {_d}, $e, 10); + } elsif ($e < 0) { + $self -> {_n} = $LIB -> _lsft($self -> {_n}, -$e, 10); + } + + return $self -> bnorm(); + + } else { + + if ($d -> isa('Math::BigRat')) { + + # At this point $n is a Math::Big(Int|Float) and $d is a + # Math::BigRat. + + my $m = $n -> mantissa(); + my $e = $n -> exponent(); + my $p = $d -> {_n}; + my $q = $d -> {_d}; + + # / q * m * 10^e + # | ------------ if e > 0 + # | p + # | + # p | m * q + # (m * 10^e) / - = | ----- if e == 0 + # q | p + # | + # | q * m + # | --------- if e < 0 + # \ p * 10^-e + + $self -> {_n} = $LIB -> _mul($LIB -> _copy($q), $m); + $self -> {_d} = $LIB -> _copy($p); + if ($e > 0) { + $self -> {_n} = $LIB -> _lsft($self -> {_n}, $e, 10); + } elsif ($e < 0) { + $self -> {_d} = $LIB -> _lsft($self -> {_d}, -$e, 10); + } + return $self -> bnorm(); + + } else { + + # At this point $n and $d are both a Math::Big(Int|Float) + + my $m1 = $n -> mantissa(); + my $e1 = $n -> exponent(); + my $m2 = $d -> mantissa(); + my $e2 = $d -> exponent(); + + # / + # | m1 * 10^(e1 - e2) + # | ----------------- if e1 > e2 + # | m2 + # | + # m1 * 10^e1 | m1 + # ---------- = | -- if e1 = e2 + # m2 * 10^e2 | m2 + # | + # | m1 + # | ----------------- if e1 < e2 + # | m2 * 10^(e2 - e1) + # \ + + $self -> {_n} = $LIB -> _new($m1 -> bstr()); + $self -> {_d} = $LIB -> _new($m2 -> bstr()); + my $ediff = $e1 - $e2; + if ($ediff > 0) { + $self -> {_n} = $LIB -> _lsft($self -> {_n}, + $LIB -> _new($ediff -> bstr()), + 10); + } elsif ($ediff < 0) { + $self -> {_d} = $LIB -> _lsft($self -> {_d}, + $LIB -> _new(-$ediff -> bstr()), + 10); + } + + return $self -> bnorm(); + } + } + + return $downgrade -> new($self -> bstr()) + if defined($downgrade) && $self -> is_int(); + return $self; +} + +sub copy { + my $self = shift; + my $selfref = ref $self; + my $class = $selfref || $self; + + # If called as a class method, the object to copy is the next argument. + + $self = shift() unless $selfref; + + my $copy = bless {}, $class; + + $copy->{sign} = $self->{sign}; + $copy->{_d} = $LIB->_copy($self->{_d}); + $copy->{_n} = $LIB->_copy($self->{_n}); + $copy->{accuracy} = $self->{accuracy} if defined $self->{accuracy}; + $copy->{precision} = $self->{precision} if defined $self->{precision}; + + #($copy, $copy->{accuracy}, $copy->{precision}) + # = $copy->_find_round_parameters(@_); + + return $copy; +} + +sub bnan { + my $self = shift; + my $selfref = ref $self; + my $class = $selfref || $self; + + # Make "require" work. + + $class -> import() if $IMPORT == 0; + + $self = bless {}, $class unless $selfref; + + if ($_trap_nan) { + croak ("Tried to set a variable to NaN in $class->bnan()"); + } + + return $downgrade -> bnan() if defined $downgrade; + + $self -> {sign} = $nan; + $self -> {_n} = $LIB -> _zero(); + $self -> {_d} = $LIB -> _one(); + + ($self, $self->{accuracy}, $self->{precision}) + = $self->_find_round_parameters(@_); + + return $self; +} + +sub binf { + my $self = shift; + my $selfref = ref $self; + my $class = $selfref || $self; + + # Make "require" work. + + $class -> import() if $IMPORT == 0; + + $self = bless {}, $class unless $selfref; + + my $sign = shift(); + $sign = defined($sign) && substr($sign, 0, 1) eq '-' ? '-inf' : '+inf'; + + if ($_trap_inf) { + croak ("Tried to set a variable to +-inf in $class->binf()"); + } + + return $downgrade -> binf($sign) if defined $downgrade; + + $self -> {sign} = $sign; + $self -> {_n} = $LIB -> _zero(); + $self -> {_d} = $LIB -> _one(); + + ($self, $self->{accuracy}, $self->{precision}) + = $self->_find_round_parameters(@_); + + return $self; +} + +sub bone { + my $self = shift; + my $selfref = ref $self; + my $class = $selfref || $self; + + # Make "require" work. + + $class -> import() if $IMPORT == 0; + + my $sign = shift(); + $sign = '+' unless defined($sign) && $sign eq '-'; + + return $downgrade -> bone($sign) if defined $downgrade; + + $self = bless {}, $class unless $selfref; + $self -> {sign} = $sign; + $self -> {_n} = $LIB -> _one(); + $self -> {_d} = $LIB -> _one(); + + ($self, $self->{accuracy}, $self->{precision}) + = $self->_find_round_parameters(@_); + + return $self; +} + +sub bzero { + my $self = shift; + my $selfref = ref $self; + my $class = $selfref || $self; + + # Make "require" work. + + $class -> import() if $IMPORT == 0; + + return $downgrade -> bzero() if defined $downgrade; + + $self = bless {}, $class unless $selfref; + $self -> {sign} = '+'; + $self -> {_n} = $LIB -> _zero(); + $self -> {_d} = $LIB -> _one(); + + ($self, $self->{accuracy}, $self->{precision}) + = $self->_find_round_parameters(@_); + + return $self; +} + +############################################################################## + +sub config { + # return (later set?) configuration data as hash ref + my $class = shift() || 'Math::BigRat'; + + if (@_ == 1 && ref($_[0]) ne 'HASH') { + my $cfg = $class->SUPER::config(); + return $cfg->{$_[0]}; + } + + my $cfg = $class->SUPER::config(@_); + + # now we need only to override the ones that are different from our parent + $cfg->{class} = $class; + $cfg->{with} = $LIB; + + $cfg; +} + +############################################################################### +# String conversion methods +############################################################################### + +sub bstr { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); + + carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; + + # Inf and NaN + + if ($x->{sign} ne '+' && $x->{sign} ne '-') { + return $x->{sign} unless $x->{sign} eq '+inf'; # -inf, NaN + return 'inf'; # +inf + } + + # Upgrade? + + return $upgrade -> bstr($x, @r) + if defined($upgrade) && !$x -> isa($class); + + # Finite number + + my $s = ''; + $s = $x->{sign} if $x->{sign} ne '+'; # '+3/2' => '3/2' + + my $str = $x->{sign} eq '-' ? '-' : ''; + $str .= $LIB->_str($x->{_n}); + $str .= '/' . $LIB->_str($x->{_d}) unless $LIB -> _is_one($x->{_d}); + return $str; +} + +sub bsstr { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); + + carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; + + # Inf and NaN + + if ($x->{sign} ne '+' && $x->{sign} ne '-') { + return $x->{sign} unless $x->{sign} eq '+inf'; # -inf, NaN + return 'inf'; # +inf + } + + # Upgrade? + + return $upgrade -> bsstr($x, @r) + if defined($upgrade) && !$x -> isa($class); + + # Finite number + + my $str = $x->{sign} eq '-' ? '-' : ''; + $str .= $LIB->_str($x->{_n}); + $str .= '/' . $LIB->_str($x->{_d}) unless $LIB -> _is_one($x->{_d}); + return $str; +} + +sub bfstr { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); + + carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; + + # Inf and NaN + + if ($x->{sign} ne '+' && $x->{sign} ne '-') { + return $x->{sign} unless $x->{sign} eq '+inf'; # -inf, NaN + return 'inf'; # +inf + } + + # Upgrade? + + return $upgrade -> bfstr($x, @r) + if defined($upgrade) && !$x -> isa($class); + + # Finite number + + my $str = $x->{sign} eq '-' ? '-' : ''; + $str .= $LIB->_str($x->{_n}); + $str .= '/' . $LIB->_str($x->{_d}) unless $LIB -> _is_one($x->{_d}); + return $str; +} + +sub bnorm { + # reduce the number to the shortest form + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + # Both parts must be objects of whatever we are using today. + if (my $c = $LIB->_check($x->{_n})) { + croak("n did not pass the self-check ($c) in bnorm()"); + } + if (my $c = $LIB->_check($x->{_d})) { + croak("d did not pass the self-check ($c) in bnorm()"); + } + + # no normalize for NaN, inf etc. + if ($x->{sign} !~ /^[+-]$/) { + return $downgrade -> new($x) if defined $downgrade; + return $x; + } + + # normalize zeros to 0/1 + if ($LIB->_is_zero($x->{_n})) { + return $downgrade -> bzero() if defined($downgrade); + $x->{sign} = '+'; # never leave a -0 + $x->{_d} = $LIB->_one() unless $LIB->_is_one($x->{_d}); + return $x; + } + + # n/1 + if ($LIB->_is_one($x->{_d})) { + return $downgrade -> new($x) if defined($downgrade); + return $x; # no need to reduce + } + + # Compute the GCD. + my $gcd = $LIB->_gcd($LIB->_copy($x->{_n}), $x->{_d}); + if (!$LIB->_is_one($gcd)) { + $x->{_n} = $LIB->_div($x->{_n}, $gcd); + $x->{_d} = $LIB->_div($x->{_d}, $gcd); + } + + $x; +} + +############################################################################## +# sign manipulation + +sub bneg { + # (BRAT or num_str) return BRAT + # negate number or make a negated number from string + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + return $x if $x->modify('bneg'); + + # for +0 do not negate (to have always normalized +0). Does nothing for 'NaN' + $x->{sign} =~ tr/+-/-+/ + unless ($x->{sign} eq '+' && $LIB->_is_zero($x->{_n})); + + return $downgrade -> new($x) + if defined($downgrade) && $LIB -> _is_one($x->{_d}); + $x; +} + +############################################################################## +# mul/add/div etc + +sub badd { + # add two rational numbers + + # set up parameters + my ($class, $x, $y, @r) = (ref($_[0]), @_); + # objectify is costly, so avoid it + if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { + ($class, $x, $y, @r) = objectify(2, @_); + } + + unless ($x -> is_finite() && $y -> is_finite()) { + if ($x -> is_nan() || $y -> is_nan()) { + return $x -> bnan(@r); + } elsif ($x -> is_inf("+")) { + return $x -> bnan(@r) if $y -> is_inf("-"); + return $x -> binf("+", @r); + } elsif ($x -> is_inf("-")) { + return $x -> bnan(@r) if $y -> is_inf("+"); + return $x -> binf("-", @r); + } elsif ($y -> is_inf("+")) { + return $x -> binf("+", @r); + } elsif ($y -> is_inf("-")) { + return $x -> binf("-", @r); + } + } + + # 1 1 gcd(3, 4) = 1 1*3 + 1*4 7 + # - + - = --------- = -- + # 4 3 4*3 12 + + # we do not compute the gcd() here, but simple do: + # 5 7 5*3 + 7*4 43 + # - + - = --------- = -- + # 4 3 4*3 12 + + # and bnorm() will then take care of the rest + + # 5 * 3 + $x->{_n} = $LIB->_mul($x->{_n}, $y->{_d}); + + # 7 * 4 + my $m = $LIB->_mul($LIB->_copy($y->{_n}), $x->{_d}); + + # 5 * 3 + 7 * 4 + ($x->{_n}, $x->{sign}) = $LIB -> _sadd($x->{_n}, $x->{sign}, $m, $y->{sign}); + + # 4 * 3 + $x->{_d} = $LIB->_mul($x->{_d}, $y->{_d}); + + # normalize result, and possible round + $x->bnorm()->round(@r); +} + +sub bsub { + # subtract two rational numbers + + # set up parameters + my ($class, $x, $y, @r) = (ref($_[0]), @_); + # objectify is costly, so avoid it + if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { + ($class, $x, $y, @r) = objectify(2, @_); + } + + # flip sign of $x, call badd(), then flip sign of result + $x->{sign} =~ tr/+-/-+/ + unless $x->{sign} eq '+' && $x -> is_zero(); # not -0 + $x = $x->badd($y, @r); # does norm and round + $x->{sign} =~ tr/+-/-+/ + unless $x->{sign} eq '+' && $x -> is_zero(); # not -0 + + $x->bnorm(); +} + +sub bmul { + # multiply two rational numbers + + # set up parameters + my ($class, $x, $y, @r) = (ref($_[0]), @_); + # objectify is costly, so avoid it + if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { + ($class, $x, $y, @r) = objectify(2, @_); + } + + return $x->bnan() if $x->{sign} eq 'NaN' || $y->{sign} eq 'NaN'; + + # inf handling + if ($x->{sign} =~ /^[+-]inf$/ || $y->{sign} =~ /^[+-]inf$/) { + return $x->bnan() if $x->is_zero() || $y->is_zero(); + # result will always be +-inf: + # +inf * +/+inf => +inf, -inf * -/-inf => +inf + # +inf * -/-inf => -inf, -inf * +/+inf => -inf + return $x->binf() if ($x->{sign} =~ /^\+/ && $y->{sign} =~ /^\+/); + return $x->binf() if ($x->{sign} =~ /^-/ && $y->{sign} =~ /^-/); + return $x->binf('-'); + } + + # x == 0 # also: or y == 1 or y == -1 + if ($x -> is_zero()) { + $x = $downgrade -> bzero($x) if defined $downgrade; + return wantarray ? ($x, $class->bzero()) : $x; + } + + if ($y -> is_zero()) { + $x = defined($downgrade) ? $downgrade -> bzero($x) : $x -> bzero(); + return wantarray ? ($x, $class->bzero()) : $x; + } + + # According to Knuth, this can be optimized by doing gcd twice (for d + # and n) and reducing in one step. This saves us a bnorm() at the end. + # + # p s p * s (p / gcd(p, r)) * (s / gcd(s, q)) + # - * - = ----- = --------------------------------- + # q r q * r (q / gcd(s, q)) * (r / gcd(p, r)) + + my $gcd_pr = $LIB -> _gcd($LIB -> _copy($x->{_n}), $y->{_d}); + my $gcd_sq = $LIB -> _gcd($LIB -> _copy($y->{_n}), $x->{_d}); + + $x->{_n} = $LIB -> _mul(scalar $LIB -> _div($x->{_n}, $gcd_pr), + scalar $LIB -> _div($LIB -> _copy($y->{_n}), + $gcd_sq)); + $x->{_d} = $LIB -> _mul(scalar $LIB -> _div($x->{_d}, $gcd_sq), + scalar $LIB -> _div($LIB -> _copy($y->{_d}), + $gcd_pr)); + + # compute new sign + $x->{sign} = $x->{sign} eq $y->{sign} ? '+' : '-'; + + $x->bnorm()->round(@r); +} + +sub bdiv { + # (dividend: BRAT or num_str, divisor: BRAT or num_str) return + # (BRAT, BRAT) (quo, rem) or BRAT (only rem) + + # set up parameters + my ($class, $x, $y, @r) = (ref($_[0]), @_); + # objectify is costly, so avoid it + if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { + ($class, $x, $y, @r) = objectify(2, @_); + } + + return $x if $x->modify('bdiv'); + + my $wantarray = wantarray; # call only once + + # At least one argument is NaN. This is handled the same way as in + # Math::BigInt -> bdiv(). See the comments in the code implementing that + # method. + + if ($x -> is_nan() || $y -> is_nan()) { + if ($wantarray) { + return $downgrade -> bnan(), $downgrade -> bnan() + if defined($downgrade); + return $x -> bnan(), $class -> bnan(); + } else { + return $downgrade -> bnan() + if defined($downgrade); + return $x -> bnan(); + } + } + + # Divide by zero and modulo zero. This is handled the same way as in + # Math::BigInt -> bdiv(). See the comments in the code implementing that + # method. + + if ($y -> is_zero()) { + my ($quo, $rem); + if ($wantarray) { + $rem = $x -> copy(); + } + if ($x -> is_zero()) { + $quo = $x -> bnan(); + } else { + $quo = $x -> binf($x -> {sign}); + } + + $quo = $downgrade -> new($quo) + if defined($downgrade) && $quo -> is_int(); + $rem = $downgrade -> new($rem) + if $wantarray && defined($downgrade) && $rem -> is_int(); + return $wantarray ? ($quo, $rem) : $quo; + } + + # Numerator (dividend) is +/-inf. This is handled the same way as in + # Math::BigInt -> bdiv(). See the comments in the code implementing that + # method. + + if ($x -> is_inf()) { + my ($quo, $rem); + $rem = $class -> bnan() if $wantarray; + if ($y -> is_inf()) { + $quo = $x -> bnan(); + } else { + my $sign = $x -> bcmp(0) == $y -> bcmp(0) ? '+' : '-'; + $quo = $x -> binf($sign); + } + + $quo = $downgrade -> new($quo) + if defined($downgrade) && $quo -> is_int(); + $rem = $downgrade -> new($rem) + if $wantarray && defined($downgrade) && $rem -> is_int(); + return $wantarray ? ($quo, $rem) : $quo; + } + + # Denominator (divisor) is +/-inf. This is handled the same way as in + # Math::BigFloat -> bdiv(). See the comments in the code implementing that + # method. + + if ($y -> is_inf()) { + my ($quo, $rem); + if ($wantarray) { + if ($x -> is_zero() || $x -> bcmp(0) == $y -> bcmp(0)) { + $rem = $x -> copy(); + $quo = $x -> bzero(); + } else { + $rem = $class -> binf($y -> {sign}); + $quo = $x -> bone('-'); + } + $quo = $downgrade -> new($quo) + if defined($downgrade) && $quo -> is_int(); + $rem = $downgrade -> new($rem) + if defined($downgrade) && $rem -> is_int(); + return ($quo, $rem); + } else { + if ($y -> is_inf()) { + if ($x -> is_nan() || $x -> is_inf()) { + return $downgrade -> bnan() if defined $downgrade; + return $x -> bnan(); + } else { + return $downgrade -> bzero() if defined $downgrade; + return $x -> bzero(); + } + } + } + } + + # At this point, both the numerator and denominator are finite numbers, and + # the denominator (divisor) is non-zero. + + # x == 0? + if ($x->is_zero()) { + return $wantarray ? ($downgrade -> bzero(), $downgrade -> bzero()) + : $downgrade -> bzero() if defined $downgrade; + return $wantarray ? ($x, $class->bzero()) : $x; + } + + # XXX TODO: list context, upgrade + # According to Knuth, this can be optimized by doing gcd twice (for d and n) + # and reducing in one step. This would save us the bnorm() at the end. + # + # p r p * s (p / gcd(p, r)) * (s / gcd(s, q)) + # - / - = ----- = --------------------------------- + # q s q * r (q / gcd(s, q)) * (r / gcd(p, r)) + + $x->{_n} = $LIB->_mul($x->{_n}, $y->{_d}); + $x->{_d} = $LIB->_mul($x->{_d}, $y->{_n}); + + # compute new sign + $x->{sign} = $x->{sign} eq $y->{sign} ? '+' : '-'; + + $x -> bnorm(); + if (wantarray) { + my $rem = $x -> copy(); + $x = $x -> bfloor(); + $x = $x -> round(@r); + $rem = $rem -> bsub($x -> copy()) -> bmul($y); + $x = $downgrade -> new($x) if defined($downgrade) && $x -> is_int(); + $rem = $downgrade -> new($rem) if defined($downgrade) && $rem -> is_int(); + return $x, $rem; + } else { + return $x -> round(@r); + } +} + +sub bmod { + # compute "remainder" (in Perl way) of $x / $y + + # set up parameters + my ($class, $x, $y, @r) = (ref($_[0]), @_); + # objectify is costly, so avoid it + if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { + ($class, $x, $y, @r) = objectify(2, @_); + } + + return $x if $x->modify('bmod'); + + # At least one argument is NaN. This is handled the same way as in + # Math::BigInt -> bmod(). + + if ($x -> is_nan() || $y -> is_nan()) { + return $x -> bnan(); + } + + # Modulo zero. This is handled the same way as in Math::BigInt -> bmod(). + + if ($y -> is_zero()) { + return $downgrade -> bzero() if defined $downgrade; + return $x; + } + + # Numerator (dividend) is +/-inf. This is handled the same way as in + # Math::BigInt -> bmod(). + + if ($x -> is_inf()) { + return $x -> bnan(); + } + + # Denominator (divisor) is +/-inf. This is handled the same way as in + # Math::BigInt -> bmod(). + + if ($y -> is_inf()) { + if ($x -> is_zero() || $x -> bcmp(0) == $y -> bcmp(0)) { + return $downgrade -> new($x) if defined($downgrade) && $x -> is_int(); + return $x; + } else { + return $downgrade -> binf($y -> sign()) if defined($downgrade); + return $x -> binf($y -> sign()); + } + } + + # At this point, both the numerator and denominator are finite numbers, and + # the denominator (divisor) is non-zero. + + if ($x->is_zero()) { # 0 / 7 = 0, mod 0 + return $downgrade -> bzero() if defined $downgrade; + return $x; + } + + # Compute $x - $y * floor($x/$y). This can probably be optimized by working + # on a lower level. + + $x -> bsub($x -> copy() -> bdiv($y) -> bfloor() -> bmul($y)); + return $x -> round(@r); +} + +############################################################################## +# bdec/binc + +sub bdec { + # decrement value (subtract 1) + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + + if ($x->{sign} !~ /^[+-]$/) { # NaN, inf, -inf + return $downgrade -> new($x) if defined $downgrade; + return $x; + } + + if ($x->{sign} eq '-') { + $x->{_n} = $LIB->_add($x->{_n}, $x->{_d}); # -5/2 => -7/2 + } else { + if ($LIB->_acmp($x->{_n}, $x->{_d}) < 0) # n < d? + { + # 1/3 -- => -2/3 + $x->{_n} = $LIB->_sub($LIB->_copy($x->{_d}), $x->{_n}); + $x->{sign} = '-'; + } else { + $x->{_n} = $LIB->_sub($x->{_n}, $x->{_d}); # 5/2 => 3/2 + } + } + $x->bnorm()->round(@r); +} + +sub binc { + # increment value (add 1) + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + + if ($x->{sign} !~ /^[+-]$/) { # NaN, inf, -inf + return $downgrade -> new($x) if defined $downgrade; + return $x; + } + + if ($x->{sign} eq '-') { + if ($LIB->_acmp($x->{_n}, $x->{_d}) < 0) { + # -1/3 ++ => 2/3 (overflow at 0) + $x->{_n} = $LIB->_sub($LIB->_copy($x->{_d}), $x->{_n}); + $x->{sign} = '+'; + } else { + $x->{_n} = $LIB->_sub($x->{_n}, $x->{_d}); # -5/2 => -3/2 + } + } else { + $x->{_n} = $LIB->_add($x->{_n}, $x->{_d}); # 5/2 => 7/2 + } + $x->bnorm()->round(@r); +} + +sub binv { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); + + return $x if $x -> modify('binv'); + + return $x -> round(@r) if $x -> is_nan(); + return $x -> bzero(@r) if $x -> is_inf(); + return $x -> binf("+", @r) if $x -> is_zero(); + + ($x -> {_n}, $x -> {_d}) = ($x -> {_d}, $x -> {_n}); + $x -> round(@r); +} + +############################################################################## +# is_foo methods (the rest is inherited) + +sub is_int { + # return true if arg (BRAT or num_str) is an integer + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + return 1 if ($x->{sign} =~ /^[+-]$/) && # NaN and +-inf aren't + $LIB->_is_one($x->{_d}); # x/y && y != 1 => no integer + 0; +} + +sub is_zero { + # return true if arg (BRAT or num_str) is zero + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + return 1 if $x->{sign} eq '+' && $LIB->_is_zero($x->{_n}); + 0; +} + +sub is_one { + # return true if arg (BRAT or num_str) is +1 or -1 if signis given + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + croak "too many arguments for is_one()" if @_ > 2; + my $sign = $_[1] || ''; + $sign = '+' if $sign ne '-'; + return 1 if ($x->{sign} eq $sign && + $LIB->_is_one($x->{_n}) && $LIB->_is_one($x->{_d})); + 0; +} + +sub is_odd { + # return true if arg (BFLOAT or num_str) is odd or false if even + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + return 1 if ($x->{sign} =~ /^[+-]$/) && # NaN & +-inf aren't + ($LIB->_is_one($x->{_d}) && $LIB->_is_odd($x->{_n})); # x/2 is not, but 3/1 + 0; +} + +sub is_even { + # return true if arg (BINT or num_str) is even or false if odd + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + return 0 if $x->{sign} !~ /^[+-]$/; # NaN & +-inf aren't + return 1 if ($LIB->_is_one($x->{_d}) # x/3 is never + && $LIB->_is_even($x->{_n})); # but 4/1 is + 0; +} + +############################################################################## +# parts() and friends + +sub numerator { + my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); + + # NaN, inf, -inf + return Math::BigInt->new($x->{sign}) if ($x->{sign} !~ /^[+-]$/); + + my $n = Math::BigInt->new($LIB->_str($x->{_n})); + $n->{sign} = $x->{sign}; + $n; +} + +sub denominator { + my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); + + # NaN + return Math::BigInt->new($x->{sign}) if $x->{sign} eq 'NaN'; + # inf, -inf + return Math::BigInt->bone() if $x->{sign} !~ /^[+-]$/; + + Math::BigInt->new($LIB->_str($x->{_d})); +} + +sub parts { + my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); + + my $c = 'Math::BigInt'; + + return ($c->bnan(), $c->bnan()) if $x->{sign} eq 'NaN'; + return ($c->binf(), $c->binf()) if $x->{sign} eq '+inf'; + return ($c->binf('-'), $c->binf()) if $x->{sign} eq '-inf'; + + my $n = $c->new($LIB->_str($x->{_n})); + $n->{sign} = $x->{sign}; + my $d = $c->new($LIB->_str($x->{_d})); + ($n, $d); +} + +sub dparts { + my $x = shift; + my $class = ref $x; + + croak("dparts() is an instance method") unless $class; + + if ($x -> is_nan()) { + return $class -> bnan(), $class -> bnan() if wantarray; + return $class -> bnan(); + } + + if ($x -> is_inf()) { + return $class -> binf($x -> sign()), $class -> bzero() if wantarray; + return $class -> binf($x -> sign()); + } + + # 355/113 => 3 + 16/113 + + my ($q, $r) = $LIB -> _div($LIB -> _copy($x -> {_n}), $x -> {_d}); + + my $int = Math::BigRat -> new($x -> {sign} . $LIB -> _str($q)); + return $int unless wantarray; + + my $frc = Math::BigRat -> new($x -> {sign} . $LIB -> _str($r), + $LIB -> _str($x -> {_d})); + + return $int, $frc; +} + +sub fparts { + my $x = shift; + my $class = ref $x; + + croak("fparts() is an instance method") unless $class; + + return ($class -> bnan(), + $class -> bnan()) if $x -> is_nan(); + + my $numer = $x -> copy(); + my $denom = $class -> bzero(); + + $denom -> {_n} = $numer -> {_d}; + $numer -> {_d} = $LIB -> _one(); + + return ($numer, $denom); +} + +sub length { + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + return $nan unless $x->is_int(); + $LIB->_len($x->{_n}); # length(-123/1) => length(123) +} + +sub digit { + my ($class, $x, $n) = ref($_[0]) ? (undef, $_[0], $_[1]) : objectify(1, @_); + + return $nan unless $x->is_int(); + $LIB->_digit($x->{_n}, $n || 0); # digit(-123/1, 2) => digit(123, 2) +} + +############################################################################## +# special calc routines + +sub bceil { + my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); + + if ($x->{sign} !~ /^[+-]$/ || # NaN or inf or + $LIB->_is_one($x->{_d})) # integer + { + return $downgrade -> new($x) if defined $downgrade; + return $x; + } + + $x->{_n} = $LIB->_div($x->{_n}, $x->{_d}); # 22/7 => 3/1 w/ truncate + $x->{_d} = $LIB->_one(); # d => 1 + $x->{_n} = $LIB->_inc($x->{_n}) if $x->{sign} eq '+'; # +22/7 => 4/1 + $x->{sign} = '+' if $x->{sign} eq '-' && $LIB->_is_zero($x->{_n}); # -0 => 0 + return $downgrade -> new($x) if defined $downgrade; + $x; +} + +sub bfloor { + my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); + + if ($x->{sign} !~ /^[+-]$/ || # NaN or inf or + $LIB->_is_one($x->{_d})) # integer + { + return $downgrade -> new($x) if defined $downgrade; + return $x; + } + + $x->{_n} = $LIB->_div($x->{_n}, $x->{_d}); # 22/7 => 3/1 w/ truncate + $x->{_d} = $LIB->_one(); # d => 1 + $x->{_n} = $LIB->_inc($x->{_n}) if $x->{sign} eq '-'; # -22/7 => -4/1 + return $downgrade -> new($x) if defined $downgrade; + $x; +} + +sub bint { + my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); + + if ($x->{sign} !~ /^[+-]$/ || # NaN or inf or + $LIB->_is_one($x->{_d})) # integer + { + return $downgrade -> new($x) if defined $downgrade; + return $x; + } + + $x->{_n} = $LIB->_div($x->{_n}, $x->{_d}); # 22/7 => 3/1 w/ truncate + $x->{_d} = $LIB->_one(); # d => 1 + $x->{sign} = '+' if $x->{sign} eq '-' && $LIB -> _is_zero($x->{_n}); + return $downgrade -> new($x) if defined $downgrade; + return $x; +} + +sub bfac { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + + # if $x is not an integer + if (($x->{sign} ne '+') || (!$LIB->_is_one($x->{_d}))) { + return $x->bnan(); + } + + $x->{_n} = $LIB->_fac($x->{_n}); + # since _d is 1, we don't need to reduce/norm the result + $x->round(@r); +} + +sub bpow { + # power ($x ** $y) + + # set up parameters + my ($class, $x, $y, @r) = (ref($_[0]), @_); + + # objectify is costly, so avoid it + if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { + ($class, $x, $y, @r) = objectify(2, @_); + } + + return $x if $x->modify('bpow'); + + # $x and/or $y is a NaN + return $x->bnan() if $x->is_nan() || $y->is_nan(); + + # $x and/or $y is a +/-Inf + if ($x->is_inf("-")) { + return $x->bzero() if $y->is_negative(); + return $x->bnan() if $y->is_zero(); + return $x if $y->is_odd(); + return $x->bneg(); + } elsif ($x->is_inf("+")) { + return $x->bzero() if $y->is_negative(); + return $x->bnan() if $y->is_zero(); + return $x; + } elsif ($y->is_inf("-")) { + return $x->bnan() if $x -> is_one("-"); + return $x->binf("+") if $x > -1 && $x < 1; + return $x->bone() if $x -> is_one("+"); + return $x->bzero(); + } elsif ($y->is_inf("+")) { + return $x->bnan() if $x -> is_one("-"); + return $x->bzero() if $x > -1 && $x < 1; + return $x->bone() if $x -> is_one("+"); + return $x->binf("+"); + } + + if ($x -> is_zero()) { + return $x -> bone() if $y -> is_zero(); + return $x -> binf() if $y -> is_negative(); + return $x; + } + + # We don't support complex numbers, so upgrade or return NaN. + + if ($x -> is_negative() && !$y -> is_int()) { + return $upgrade -> bpow($upgrade -> new($x), $y, @r) + if defined $upgrade; + return $x -> bnan(); + } + + if ($x -> is_one("+") || $y -> is_one()) { + return $x; + } + + if ($x -> is_one("-")) { + return $x if $y -> is_odd(); + return $x -> bneg(); + } + + # (a/b)^-(c/d) = (b/a)^(c/d) + ($x->{_n}, $x->{_d}) = ($x->{_d}, $x->{_n}) if $y->is_negative(); + + unless ($LIB->_is_one($y->{_n})) { + $x->{_n} = $LIB->_pow($x->{_n}, $y->{_n}); + $x->{_d} = $LIB->_pow($x->{_d}, $y->{_n}); + $x->{sign} = '+' if $x->{sign} eq '-' && $LIB->_is_even($y->{_n}); + } + + unless ($LIB->_is_one($y->{_d})) { + return $x->bsqrt(@r) if $LIB->_is_two($y->{_d}); # 1/2 => sqrt + return $x->broot($LIB->_str($y->{_d}), @r); # 1/N => root(N) + } + + return $x->round(@r); +} + +sub blog { + # Return the logarithm of the operand. If a second operand is defined, that + # value is used as the base, otherwise the base is assumed to be Euler's + # constant. + + my ($class, $x, $base, @r); + + # Don't objectify the base, since an undefined base, as in $x->blog() or + # $x->blog(undef) signals that the base is Euler's number. + + if (!ref($_[0]) && $_[0] =~ /^[A-Za-z]|::/) { + # E.g., Math::BigRat->blog(256, 2) + ($class, $x, $base, @r) = + defined $_[2] ? objectify(2, @_) : objectify(1, @_); + } else { + # E.g., Math::BigRat::blog(256, 2) or $x->blog(2) + ($class, $x, $base, @r) = + defined $_[1] ? objectify(2, @_) : objectify(1, @_); + } + + return $x if $x->modify('blog'); + + # Handle all exception cases and all trivial cases. I have used Wolfram Alpha + # (http://www.wolframalpha.com) as the reference for these cases. + + return $x -> bnan() if $x -> is_nan(); + + if (defined $base) { + $base = $class -> new($base) unless ref $base; + if ($base -> is_nan() || $base -> is_one()) { + return $x -> bnan(); + } elsif ($base -> is_inf() || $base -> is_zero()) { + return $x -> bnan() if $x -> is_inf() || $x -> is_zero(); + return $x -> bzero(); + } elsif ($base -> is_negative()) { # -inf < base < 0 + return $x -> bzero() if $x -> is_one(); # x = 1 + return $x -> bone() if $x == $base; # x = base + return $x -> bnan(); # otherwise + } + return $x -> bone() if $x == $base; # 0 < base && 0 < x < inf + } + + # We now know that the base is either undefined or positive and finite. + + if ($x -> is_inf()) { # x = +/-inf + my $sign = defined $base && $base < 1 ? '-' : '+'; + return $x -> binf($sign); + } elsif ($x -> is_neg()) { # -inf < x < 0 + return $x -> bnan(); + } elsif ($x -> is_one()) { # x = 1 + return $x -> bzero(); + } elsif ($x -> is_zero()) { # x = 0 + my $sign = defined $base && $base < 1 ? '+' : '-'; + return $x -> binf($sign); + } + + # Now take care of the cases where $x and/or $base is 1/N. + # + # log(1/N) / log(B) = -log(N)/log(B) + # log(1/N) / log(1/B) = log(N)/log(B) + # log(N) / log(1/B) = -log(N)/log(B) + + my $neg = 0; + if ($x -> numerator() -> is_one()) { + $x -> binv(); + $neg = !$neg; + } + if (defined(blessed($base)) && $base -> isa($class)) { + if ($base -> numerator() -> is_one()) { + $base = $base -> copy() -> binv(); + $neg = !$neg; + } + } + + # disable upgrading and downgrading + + require Math::BigFloat; + my $upg = Math::BigFloat -> upgrade(); + my $dng = Math::BigFloat -> downgrade(); + Math::BigFloat -> upgrade(undef); + Math::BigFloat -> downgrade(undef); + + # At this point we are done handling all exception cases and trivial cases. + + $base = Math::BigFloat -> new($base) if defined $base; + my $xnum = Math::BigFloat -> new($LIB -> _str($x->{_n})); + my $xden = Math::BigFloat -> new($LIB -> _str($x->{_d})); + my $xstr = $xnum -> bdiv($xden) -> blog($base, @r) -> bsstr(); + + # reset upgrading and downgrading + + Math::BigFloat -> upgrade($upg); + Math::BigFloat -> downgrade($dng); + + my $xobj = Math::BigRat -> new($xstr); + $x -> {sign} = $xobj -> {sign}; + $x -> {_n} = $xobj -> {_n}; + $x -> {_d} = $xobj -> {_d}; + + return $neg ? $x -> bneg() : $x; +} + +sub bexp { + # set up parameters + my ($class, $x, $y, @r) = (ref($_[0]), @_); + + # objectify is costly, so avoid it + if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { + ($class, $x, $y, @r) = objectify(1, @_); + } + + return $x->binf(@r) if $x->{sign} eq '+inf'; + return $x->bzero(@r) if $x->{sign} eq '-inf'; + + # we need to limit the accuracy to protect against overflow + my $fallback = 0; + my ($scale, @params); + ($x, @params) = $x->_find_round_parameters(@r); + + # also takes care of the "error in _find_round_parameters?" case + return $x if $x->{sign} eq 'NaN'; + + # no rounding at all, so must use fallback + if (scalar @params == 0) { + # simulate old behaviour + $params[0] = $class->div_scale(); # and round to it as accuracy + $params[1] = undef; # P = undef + $scale = $params[0]+4; # at least four more for proper round + $params[2] = $r[2]; # round mode by caller or undef + $fallback = 1; # to clear a/p afterwards + } else { + # the 4 below is empirical, and there might be cases where it's not enough... + $scale = abs($params[0] || $params[1]) + 4; # take whatever is defined + } + + return $x->bone(@params) if $x->is_zero(); + + # See the comments in Math::BigFloat on how this algorithm works. + # Basically we calculate A and B (where B is faculty(N)) so that A/B = e + + my $x_org = $x->copy(); + if ($scale <= 75) { + # set $x directly from a cached string form + $x->{_n} = + $LIB->_new("90933395208605785401971970164779391644753259799242"); + $x->{_d} = + $LIB->_new("33452526613163807108170062053440751665152000000000"); + $x->{sign} = '+'; + } else { + # compute A and B so that e = A / B. + + # After some terms we end up with this, so we use it as a starting point: + my $A = $LIB->_new("90933395208605785401971970164779391644753259799242"); + my $F = $LIB->_new(42); my $step = 42; + + # Compute how many steps we need to take to get $A and $B sufficiently big + my $steps = Math::BigFloat::_len_to_steps($scale - 4); + # print STDERR "# Doing $steps steps for ", $scale-4, " digits\n"; + while ($step++ <= $steps) { + # calculate $a * $f + 1 + $A = $LIB->_mul($A, $F); + $A = $LIB->_inc($A); + # increment f + $F = $LIB->_inc($F); + } + # compute $B as factorial of $steps (this is faster than doing it manually) + my $B = $LIB->_fac($LIB->_new($steps)); + + # print "A ", $LIB->_str($A), "\nB ", $LIB->_str($B), "\n"; + + $x->{_n} = $A; + $x->{_d} = $B; + $x->{sign} = '+'; + } + + # $x contains now an estimate of e, with some surplus digits, so we can round + if (!$x_org->is_one()) { + # raise $x to the wanted power and round it in one step: + $x->bpow($x_org, @params); + } else { + # else just round the already computed result + delete $x->{accuracy}; delete $x->{precision}; + # shortcut to not run through _find_round_parameters again + if (defined $params[0]) { + $x->bround($params[0], $params[2]); # then round accordingly + } else { + $x->bfround($params[1], $params[2]); # then round accordingly + } + } + if ($fallback) { + # clear a/p after round, since user did not request it + delete $x->{accuracy}; delete $x->{precision}; + } + + $x; +} + +sub bnok { + # set up parameters + my ($class, $x, $y, @r) = (ref($_[0]), @_); + + # objectify is costly, so avoid it + if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { + ($class, $x, $y, @r) = objectify(2, @_); + } + + return $x->bnan() if $x->is_nan() || $y->is_nan(); + return $x->bnan() if (($x->is_finite() && !$x->is_int()) || + ($y->is_finite() && !$y->is_int())); + + my $xint = Math::BigInt -> new($x -> bstr()); + my $yint = Math::BigInt -> new($y -> bstr()); + $xint -> bnok($yint); + my $xrat = Math::BigRat -> new($xint); + + $x -> {sign} = $xrat -> {sign}; + $x -> {_n} = $xrat -> {_n}; + $x -> {_d} = $xrat -> {_d}; + + return $x; +} + +sub broot { + # set up parameters + my ($class, $x, $y, @r) = (ref($_[0]), @_); + # objectify is costly, so avoid it + if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { + ($class, $x, $y, @r) = objectify(2, @_); + } + + # Convert $x into a Math::BigFloat. + + my $xd = Math::BigFloat -> new($LIB -> _str($x->{_d})); + my $xflt = Math::BigFloat -> new($LIB -> _str($x->{_n})) -> bdiv($xd); + $xflt -> {sign} = $x -> {sign}; + + # Convert $y into a Math::BigFloat. + + my $yd = Math::BigFloat -> new($LIB -> _str($y->{_d})); + my $yflt = Math::BigFloat -> new($LIB -> _str($y->{_n})) -> bdiv($yd); + $yflt -> {sign} = $y -> {sign}; + + # Compute the root and convert back to a Math::BigRat. + + $xflt -> broot($yflt, @r); + my $xtmp = Math::BigRat -> new($xflt -> bsstr()); + + $x -> {sign} = $xtmp -> {sign}; + $x -> {_n} = $xtmp -> {_n}; + $x -> {_d} = $xtmp -> {_d}; + + return $x; +} + +sub bmodpow { + # set up parameters + my ($class, $x, $y, $m, @r) = (ref($_[0]), @_); + # objectify is costly, so avoid it + if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { + ($class, $x, $y, $m, @r) = objectify(3, @_); + } + + # Convert $x, $y, and $m into Math::BigInt objects. + + my $xint = Math::BigInt -> new($x -> copy() -> bint()); + my $yint = Math::BigInt -> new($y -> copy() -> bint()); + my $mint = Math::BigInt -> new($m -> copy() -> bint()); + + $xint -> bmodpow($yint, $mint, @r); + my $xtmp = Math::BigRat -> new($xint -> bsstr()); + + $x -> {sign} = $xtmp -> {sign}; + $x -> {_n} = $xtmp -> {_n}; + $x -> {_d} = $xtmp -> {_d}; + return $x; +} + +sub bmodinv { + # set up parameters + my ($class, $x, $y, @r) = (ref($_[0]), @_); + # objectify is costly, so avoid it + if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { + ($class, $x, $y, @r) = objectify(2, @_); + } + + # Convert $x and $y into Math::BigInt objects. + + my $xint = Math::BigInt -> new($x -> copy() -> bint()); + my $yint = Math::BigInt -> new($y -> copy() -> bint()); + + $xint -> bmodinv($yint, @r); + my $xtmp = Math::BigRat -> new($xint -> bsstr()); + + $x -> {sign} = $xtmp -> {sign}; + $x -> {_n} = $xtmp -> {_n}; + $x -> {_d} = $xtmp -> {_d}; + return $x; +} + +sub bsqrt { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + + return $x->bnan() if $x->{sign} !~ /^[+]/; # NaN, -inf or < 0 + return $x if $x->{sign} eq '+inf'; # sqrt(inf) == inf + return $x->round(@r) if $x->is_zero() || $x->is_one(); + + my $n = $x -> {_n}; + my $d = $x -> {_d}; + + # Look for an exact solution. For the numerator and the denominator, take + # the square root and square it and see if we got the original value. If we + # did, for both the numerator and the denominator, we have an exact + # solution. + + { + my $nsqrt = $LIB -> _sqrt($LIB -> _copy($n)); + my $n2 = $LIB -> _mul($LIB -> _copy($nsqrt), $nsqrt); + if ($LIB -> _acmp($n, $n2) == 0) { + my $dsqrt = $LIB -> _sqrt($LIB -> _copy($d)); + my $d2 = $LIB -> _mul($LIB -> _copy($dsqrt), $dsqrt); + if ($LIB -> _acmp($d, $d2) == 0) { + $x -> {_n} = $nsqrt; + $x -> {_d} = $dsqrt; + return $x->round(@r); + } + } + } + + local $Math::BigFloat::upgrade = undef; + local $Math::BigFloat::downgrade = undef; + local $Math::BigFloat::precision = undef; + local $Math::BigFloat::accuracy = undef; + local $Math::BigInt::upgrade = undef; + local $Math::BigInt::precision = undef; + local $Math::BigInt::accuracy = undef; + + my $xn = Math::BigFloat -> new($LIB -> _str($n)); + my $xd = Math::BigFloat -> new($LIB -> _str($d)); + + my $xtmp = Math::BigRat -> new($xn -> bdiv($xd) -> bsqrt() -> bsstr()); + + $x -> {sign} = $xtmp -> {sign}; + $x -> {_n} = $xtmp -> {_n}; + $x -> {_d} = $xtmp -> {_d}; + + $x->round(@r); +} + +sub blsft { + my ($class, $x, $y, $b) = objectify(2, @_); + + $b = 2 if !defined $b; + $b = $class -> new($b) unless ref($b) && $b -> isa($class); + + return $x -> bnan() if $x -> is_nan() || $y -> is_nan() || $b -> is_nan(); + + # shift by a negative amount? + return $x -> brsft($y -> copy() -> babs(), $b) if $y -> {sign} =~ /^-/; + + $x -> bmul($b -> bpow($y)); +} + +sub brsft { + my ($class, $x, $y, $b) = objectify(2, @_); + + $b = 2 if !defined $b; + $b = $class -> new($b) unless ref($b) && $b -> isa($class); + + return $x -> bnan() if $x -> is_nan() || $y -> is_nan() || $b -> is_nan(); + + # shift by a negative amount? + return $x -> blsft($y -> copy() -> babs(), $b) if $y -> {sign} =~ /^-/; + + # the following call to bdiv() will return either quotient (scalar context) + # or quotient and remainder (list context). + $x -> bdiv($b -> bpow($y)); +} + +############################################################################### +# Bitwise methods +############################################################################### + +# Bitwise left shift. + +sub bblsft { + # We don't call objectify(), because the bitwise methods should not + # upgrade/downgrade, even when upgrading/downgrading is enabled. + + my ($class, $x, $y, @r) = ref($_[0]) ? (ref($_[0]), @_) : @_; + + my $xint = Math::BigInt -> bblsft($x, $y, @r); + + # Temporarily disable downgrading. + + my $dng = $class -> downgrade(); + $class -> downgrade(undef); + + # Convert to our class without downgrading. + + my $xrat = $class -> new($xint); + + # Reset downgrading. + + $class -> downgrade($dng); + + # If we are called as a class method, the first operand might not be an + # object of this class, so check. + + if (defined(blessed($x)) && $x -> isa(__PACKAGE__)) { + $x -> {sign} = $xrat -> {sign}; + $x -> {_n} = $xrat -> {_n}; + $x -> {_d} = $xrat -> {_d}; + } else { + $x = $xrat; + } + + # Now we might downgrade. + + return $downgrade -> new($x) if defined($downgrade); + $x -> round(@r); +} + +# Bitwise right shift. + +sub bbrsft { + # We don't call objectify(), because the bitwise methods should not + # upgrade/downgrade, even when upgrading/downgrading is enabled. + + my ($class, $x, $y, @r) = ref($_[0]) ? (ref($_[0]), @_) : @_; + + my $xint = Math::BigInt -> bbrsft($x, $y, @r); + + # Temporarily disable downgrading. + + my $dng = $class -> downgrade(); + $class -> downgrade(undef); + + # Convert to our class without downgrading. + + my $xrat = $class -> new($xint); + + # Reset downgrading. + + $class -> downgrade($dng); + + # If we are called as a class method, the first operand might not be an + # object of this class, so check. + + if (defined(blessed($x)) && $x -> isa(__PACKAGE__)) { + $x -> {sign} = $xrat -> {sign}; + $x -> {_n} = $xrat -> {_n}; + $x -> {_d} = $xrat -> {_d}; + } else { + $x = $xrat; + } + + # Now we might downgrade. + + return $downgrade -> new($x) if defined($downgrade); + $x -> round(@r); +} + +sub band { + my $x = shift; + my $xref = ref($x); + my $class = $xref || $x; + + croak 'band() is an instance method, not a class method' unless $xref; + croak 'Not enough arguments for band()' if @_ < 1; + + my $y = shift; + $y = $class -> new($y) unless ref($y); + + my @r = @_; + + my $xint = $x -> as_int(); # to Math::BigInt + my $yint = $y -> as_int(); # to Math::BigInt + + $xint = $xint -> band($yint); + + my $xrat = $class -> new($xint); # back to Math::BigRat + $x -> {sign} = $xrat -> {sign}; + $x -> {_n} = $xrat -> {_n}; + $x -> {_d} = $xrat -> {_d}; + + return $x -> round(@r); +} + +sub bior { + my $x = shift; + my $xref = ref($x); + my $class = $xref || $x; + + croak 'bior() is an instance method, not a class method' unless $xref; + croak 'Not enough arguments for bior()' if @_ < 1; + + my $y = shift; + $y = $class -> new($y) unless ref($y); + + my @r = @_; + + my $xint = $x -> as_int(); # to Math::BigInt + my $yint = $y -> as_int(); # to Math::BigInt + + $xint = $xint -> bior($yint); + + my $xrat = $class -> new($xint); # back to Math::BigRat + $x -> {sign} = $xrat -> {sign}; + $x -> {_n} = $xrat -> {_n}; + $x -> {_d} = $xrat -> {_d}; + + return $x -> round(@r); +} + +sub bxor { + my $x = shift; + my $xref = ref($x); + my $class = $xref || $x; + + croak 'bxor() is an instance method, not a class method' unless $xref; + croak 'Not enough arguments for bxor()' if @_ < 1; + + my $y = shift; + $y = $class -> new($y) unless ref($y); + + my @r = @_; + + my $xint = $x -> as_int(); # to Math::BigInt + my $yint = $y -> as_int(); # to Math::BigInt + + $xint = $xint -> bxor($yint); + + my $xrat = $class -> new($xint); # back to Math::BigRat + $x -> {sign} = $xrat -> {sign}; + $x -> {_n} = $xrat -> {_n}; + $x -> {_d} = $xrat -> {_d}; + + return $x -> round(@r); +} + +sub bnot { + my $x = shift; + my $xref = ref($x); + my $class = $xref || $x; + + croak 'bnot() is an instance method, not a class method' unless $xref; + + my @r = @_; + + my $xint = $x -> as_int(); # to Math::BigInt + $xint = $xint -> bnot(); + + my $xrat = $class -> new($xint); # back to Math::BigRat + $x -> {sign} = $xrat -> {sign}; + $x -> {_n} = $xrat -> {_n}; + $x -> {_d} = $xrat -> {_d}; + + return $x -> round(@r); +} + +############################################################################## +# round + +sub round { + my $x = shift; + return $downgrade -> new($x) if defined($downgrade) && + ($x -> is_int() || $x -> is_inf() || $x -> is_nan()); + $x; +} + +sub bround { + my $x = shift; + return $downgrade -> new($x) if defined($downgrade) && + ($x -> is_int() || $x -> is_inf() || $x -> is_nan()); + $x; +} + +sub bfround { + my $x = shift; + return $downgrade -> new($x) if defined($downgrade) && + ($x -> is_int() || $x -> is_inf() || $x -> is_nan()); + $x; +} + +############################################################################## +# comparing + +sub bcmp { + # compare two signed numbers + + # set up parameters + my ($class, $x, $y) = (ref($_[0]), @_); + + # objectify is costly, so avoid it + if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { + ($class, $x, $y) = objectify(2, @_); + } + + if ($x->{sign} !~ /^[+-]$/ || $y->{sign} !~ /^[+-]$/) { + # $x is NaN and/or $y is NaN + return if $x->{sign} eq $nan || $y->{sign} eq $nan; + # $x and $y are both either +inf or -inf + return 0 if $x->{sign} eq $y->{sign} && $x->{sign} =~ /^[+-]inf$/; + # $x = +inf and $y < +inf + return +1 if $x->{sign} eq '+inf'; + # $x = -inf and $y > -inf + return -1 if $x->{sign} eq '-inf'; + # $x < +inf and $y = +inf + return -1 if $y->{sign} eq '+inf'; + # $x > -inf and $y = -inf + return +1; + } + + # $x >= 0 and $y < 0 + return 1 if $x->{sign} eq '+' && $y->{sign} eq '-'; + # $x < 0 and $y >= 0 + return -1 if $x->{sign} eq '-' && $y->{sign} eq '+'; + + # At this point, we know that $x and $y have the same sign. + + # shortcut + my $xz = $LIB->_is_zero($x->{_n}); + my $yz = $LIB->_is_zero($y->{_n}); + return 0 if $xz && $yz; # 0 <=> 0 + return -1 if $xz && $y->{sign} eq '+'; # 0 <=> +y + return 1 if $yz && $x->{sign} eq '+'; # +x <=> 0 + + my $t = $LIB->_mul($LIB->_copy($x->{_n}), $y->{_d}); + my $u = $LIB->_mul($LIB->_copy($y->{_n}), $x->{_d}); + + my $cmp = $LIB->_acmp($t, $u); # signs are equal + $cmp = -$cmp if $x->{sign} eq '-'; # both are '-' => reverse + $cmp; +} + +sub bacmp { + # compare two numbers (as unsigned) + + # set up parameters + my ($class, $x, $y) = (ref($_[0]), @_); + # objectify is costly, so avoid it + if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { + ($class, $x, $y) = objectify(2, @_); + } + + if (($x->{sign} !~ /^[+-]$/) || ($y->{sign} !~ /^[+-]$/)) { + # handle +-inf and NaN + return if (($x->{sign} eq $nan) || ($y->{sign} eq $nan)); + return 0 if $x->{sign} =~ /^[+-]inf$/ && $y->{sign} =~ /^[+-]inf$/; + return 1 if $x->{sign} =~ /^[+-]inf$/ && $y->{sign} !~ /^[+-]inf$/; + return -1; + } + + my $t = $LIB->_mul($LIB->_copy($x->{_n}), $y->{_d}); + my $u = $LIB->_mul($LIB->_copy($y->{_n}), $x->{_d}); + $LIB->_acmp($t, $u); # ignore signs +} + +sub beq { + my $self = shift; + my $selfref = ref $self; + #my $class = $selfref || $self; + + croak 'beq() is an instance method, not a class method' unless $selfref; + croak 'Wrong number of arguments for beq()' unless @_ == 1; + + my $cmp = $self -> bcmp(shift); + return defined($cmp) && ! $cmp; +} + +sub bne { + my $self = shift; + my $selfref = ref $self; + #my $class = $selfref || $self; + + croak 'bne() is an instance method, not a class method' unless $selfref; + croak 'Wrong number of arguments for bne()' unless @_ == 1; + + my $cmp = $self -> bcmp(shift); + return defined($cmp) && ! $cmp ? '' : 1; +} + +sub blt { + my $self = shift; + my $selfref = ref $self; + #my $class = $selfref || $self; + + croak 'blt() is an instance method, not a class method' unless $selfref; + croak 'Wrong number of arguments for blt()' unless @_ == 1; + + my $cmp = $self -> bcmp(shift); + return defined($cmp) && $cmp < 0; +} + +sub ble { + my $self = shift; + my $selfref = ref $self; + #my $class = $selfref || $self; + + croak 'ble() is an instance method, not a class method' unless $selfref; + croak 'Wrong number of arguments for ble()' unless @_ == 1; + + my $cmp = $self -> bcmp(shift); + return defined($cmp) && $cmp <= 0; +} + +sub bgt { + my $self = shift; + my $selfref = ref $self; + #my $class = $selfref || $self; + + croak 'bgt() is an instance method, not a class method' unless $selfref; + croak 'Wrong number of arguments for bgt()' unless @_ == 1; + + my $cmp = $self -> bcmp(shift); + return defined($cmp) && $cmp > 0; +} + +sub bge { + my $self = shift; + my $selfref = ref $self; + #my $class = $selfref || $self; + + croak 'bge() is an instance method, not a class method' + unless $selfref; + croak 'Wrong number of arguments for bge()' unless @_ == 1; + + my $cmp = $self -> bcmp(shift); + return defined($cmp) && $cmp >= 0; +} + +############################################################################## +# output conversion + +sub numify { + # convert 17/8 => float (aka 2.125) + my ($self, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + # Non-finite number. + + if ($x -> is_nan()) { + require Math::Complex; + my $inf = $Math::Complex::Inf; + return $inf - $inf; + } + + if ($x -> is_inf()) { + require Math::Complex; + my $inf = $Math::Complex::Inf; + return $x -> is_negative() ? -$inf : $inf; + } + + # Finite number. + + my $abs = $LIB->_is_one($x->{_d}) + ? $LIB->_num($x->{_n}) + : Math::BigFloat -> new($LIB->_str($x->{_n})) + -> bdiv($LIB->_str($x->{_d})) + -> bstr(); + return $x->{sign} eq '-' ? 0 - $abs : 0 + $abs; +} + +sub as_int { + my ($class, $x) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + + return $x -> copy() if $x -> isa("Math::BigInt"); + + # Disable upgrading and downgrading. + + require Math::BigInt; + my $upg = Math::BigInt -> upgrade(); + my $dng = Math::BigInt -> downgrade(); + Math::BigInt -> upgrade(undef); + Math::BigInt -> downgrade(undef); + + # Copy the value. + + my $y; + if ($x -> is_inf()) { + $y = Math::BigInt -> binf($x->sign()); + } elsif ($x -> is_nan()) { + $y = Math::BigInt -> bnan(); + } else { + my $int = $LIB -> _div($LIB -> _copy($x->{_n}), $x->{_d}); # 22/7 => 3 + $y = Math::BigInt -> new($LIB -> _str($int)); + $y = $y -> bneg() if $x -> is_neg(); + } + + # Copy the remaining instance variables. + + ($y->{accuracy}, $y->{precision}) = ($x->{accuracy}, $x->{precision}); + + # Restore upgrading and downgrading. + + Math::BigInt -> upgrade($upg); + Math::BigInt -> downgrade($dng); + + return $y; +} + +sub as_rat { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; + + return $x -> copy() if $x -> isa("Math::BigRat"); + + # Disable upgrading and downgrading. + + my $upg = Math::BigRat -> upgrade(); + my $dng = Math::BigRat -> downgrade(); + Math::BigRat -> upgrade(undef); + Math::BigRat -> downgrade(undef); + + # Copy the value. + + my $y = Math::BigRat -> new($x); + + # Copy the remaining instance variables. + + ($y->{accuracy}, $y->{precision}) = ($x->{accuracy}, $x->{precision}); + + # Restore upgrading and downgrading + + Math::BigRat -> upgrade($upg); + Math::BigRat -> downgrade($dng); + + return $y; +} + +sub as_float { + my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); + + return $x -> copy() if $x -> isa("Math::BigFloat"); + + # Disable upgrading and downgrading. + + require Math::BigFloat; + my $upg = Math::BigFloat -> upgrade(); + my $dng = Math::BigFloat -> downgrade(); + Math::BigFloat -> upgrade(undef); + Math::BigFloat -> downgrade(undef); + + # Copy the value. + + my $y; + if ($x -> is_inf()) { + $y = Math::BigFloat -> binf($x->sign()); + } elsif ($x -> is_nan()) { + $y = Math::BigFloat -> bnan(); + } else { + $y = Math::BigFloat -> new($LIB -> _str($x->{_n})); + $y -> {sign} = $x -> {sign}; + unless ($LIB -> _is_one($x->{_d})) { + my $xd = Math::BigFloat -> new($LIB -> _str($x->{_d})); + $y -> bdiv($xd, @r); + } + } + + # Copy the remaining instance variables. + + ($y->{accuracy}, $y->{precision}) = ($x->{accuracy}, $x->{precision}); + + # Restore upgrading and downgrading. + + Math::BigFloat -> upgrade($upg); + Math::BigFloat -> downgrade($dng); + + return $y; +} + +sub to_hex { + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + # Inf and NaN + + if ($x->{sign} ne '+' && $x->{sign} ne '-') { + return $x->{sign} unless $x->{sign} eq '+inf'; # -inf, NaN + return 'inf'; # +inf + } + + return $nan unless $x->is_int(); + + my $str = $LIB->_to_hex($x->{_n}); + return $x->{sign} eq "-" ? "-$str" : $str; +} + +sub to_oct { + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + # Inf and NaN + + if ($x->{sign} ne '+' && $x->{sign} ne '-') { + return $x->{sign} unless $x->{sign} eq '+inf'; # -inf, NaN + return 'inf'; # +inf + } + + return $nan unless $x->is_int(); + + my $str = $LIB->_to_oct($x->{_n}); + return $x->{sign} eq "-" ? "-$str" : $str; +} + +sub to_bin { + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + # Inf and NaN + + if ($x->{sign} ne '+' && $x->{sign} ne '-') { + return $x->{sign} unless $x->{sign} eq '+inf'; # -inf, NaN + return 'inf'; # +inf + } + + return $nan unless $x->is_int(); + + my $str = $LIB->_to_bin($x->{_n}); + return $x->{sign} eq "-" ? "-$str" : $str; +} + +sub as_bin { + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + return $x unless $x->is_int(); + + my $s = $x->{sign}; + $s = '' if $s eq '+'; + $s . $LIB->_as_bin($x->{_n}); +} + +sub as_hex { + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + return $x unless $x->is_int(); + + my $s = $x->{sign}; $s = '' if $s eq '+'; + $s . $LIB->_as_hex($x->{_n}); +} + +sub as_oct { + my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); + + return $x unless $x->is_int(); + + my $s = $x->{sign}; $s = '' if $s eq '+'; + $s . $LIB->_as_oct($x->{_n}); +} + +############################################################################## + +# Create a Math::BigRat from a decimal string. This is an equivalent to +# from_hex(), from_oct(), and from_bin(). It is like new() except that it does +# not accept anything but a string representing a finite decimal number. + +sub from_dec { + my $self = shift; + my $selfref = ref $self; + my $class = $selfref || $self; + + # Make "require" work. + + $class -> import() if $IMPORT == 0; + + # Don't modify constant (read-only) objects. + + return $self if $selfref && $self->modify('from_dec'); + + my $str = shift; + my @r = @_; + + # If called as a class method, initialize a new object. + + $self = bless {}, $class unless $selfref; + + if (my @parts = $class -> _dec_str_to_flt_lib_parts($str)) { + my ($mant_sgn, $mant_abs, $expo_sgn, $expo_abs) = @parts; + $self->{sign} = $mant_sgn; + $self->{_n} = $mant_abs; + if ($expo_sgn eq "+") { + $self->{_n} = $LIB -> _lsft($self->{_n}, $expo_abs, 10); + $self->{_d} = $LIB -> _one(); + } else { + $self->{_d} = $LIB -> _1ex($mant_abs); + } + + my $gcd = $LIB -> _gcd($LIB -> _copy($self->{_n}), $self->{_d}); + if (!$LIB -> _is_one($gcd)) { + $self -> {_n} = $LIB -> _div($self->{_n}, $gcd); + $self -> {_d} = $LIB -> _div($self->{_d}, $gcd); + } + + return $downgrade -> new($self -> bstr(), @r) + if defined($downgrade) && $self -> is_int(); + return $self; + } + + return $self -> bnan(@r); +} + +sub from_hex { + my $class = shift; + + # The relationship should probably go the otherway, i.e, that new() calls + # from_hex(). Fixme! + my ($x, @r) = @_; + $x =~ s|^\s*(?:0?[Xx]_*)?|0x|; + $class->new($x, @r); +} + +sub from_bin { + my $class = shift; + + # The relationship should probably go the otherway, i.e, that new() calls + # from_bin(). Fixme! + my ($x, @r) = @_; + $x =~ s|^\s*(?:0?[Bb]_*)?|0b|; + $class->new($x, @r); +} + +sub from_oct { + my $class = shift; + + # Why is this different from from_hex() and from_bin()? Fixme! + my @parts; + for my $c (@_) { + push @parts, Math::BigInt->from_oct($c); + } + $class->new (@parts); +} + +############################################################################## +# import + +sub import { + my $class = shift; + $IMPORT++; # remember we did import() + my @a; # unrecognized arguments + + my @import = (); + + while (@_) { + my $param = shift; + + # Enable overloading of constants. + + if ($param eq ':constant') { + overload::constant + + integer => sub { + $class -> new(shift); + }, + + float => sub { + $class -> new(shift); + }, + + binary => sub { + # E.g., a literal 0377 shall result in an object whose value + # is decimal 255, but new("0377") returns decimal 377. + return $class -> from_oct($_[0]) if $_[0] =~ /^0_*[0-7]/; + $class -> new(shift); + }; + next; + } + + # Upgrading. + + if ($param eq 'upgrade') { + $class -> upgrade(shift); + next; + } + + # Downgrading. + + if ($param eq 'downgrade') { + $class -> downgrade(shift); + next; + } + + # Accuracy. + + if ($param eq 'accuracy') { + $class -> accuracy(shift); + next; + } + + # Precision. + + if ($param eq 'precision') { + $class -> precision(shift); + next; + } + + # Rounding mode. + + if ($param eq 'round_mode') { + $class -> round_mode(shift); + next; + } + + # Fall-back accuracy. + + if ($param eq 'div_scale') { + $class -> div_scale(shift); + next; + } + + # Backend library. + + if ($param =~ /^(lib|try|only)\z/) { + push @import, $param; + push @import, shift() if @_; + next; + } + + if ($param eq 'with') { + # alternative class for our private parts() + # XXX: no longer supported + # $LIB = shift() || 'Calc'; + # carp "'with' is no longer supported, use 'lib', 'try', or 'only'"; + shift; + next; + } + + # Unrecognized parameter. + + push @a, $param; + } + + Math::BigInt -> import(@import); + + # find out which library was actually loaded + $LIB = Math::BigInt -> config("lib"); + + $class -> SUPER::import(@a); # for subclasses + $class -> export_to_level(1, $class, @a) if @a; # need this, too +} + +1; + +__END__ + +=pod + +=head1 NAME + +Math::BigRat - arbitrary size rational number math package + +=head1 SYNOPSIS + + use Math::BigRat; + + my $x = Math::BigRat->new('3/7'); $x += '5/9'; + + print $x->bstr(), "\n"; + print $x ** 2, "\n"; + + my $y = Math::BigRat->new('inf'); + print "$y ", ($y->is_inf ? 'is' : 'is not'), " infinity\n"; + + my $z = Math::BigRat->new(144); $z->bsqrt(); + +=head1 DESCRIPTION + +Math::BigRat complements Math::BigInt and Math::BigFloat by providing support +for arbitrary big rational numbers. + +=head2 MATH LIBRARY + +You can change the underlying module that does the low-level +math operations by using: + + use Math::BigRat try => 'GMP'; + +Note: This needs Math::BigInt::GMP installed. + +The following would first try to find Math::BigInt::Foo, then +Math::BigInt::Bar, and when this also fails, revert to Math::BigInt::Calc: + + use Math::BigRat try => 'Foo,Math::BigInt::Bar'; + +If you want to get warned when the fallback occurs, replace "try" with "lib": + + use Math::BigRat lib => 'Foo,Math::BigInt::Bar'; + +If you want the code to die instead, replace "try" with "only": + + use Math::BigRat only => 'Foo,Math::BigInt::Bar'; + +=head1 METHODS + +Any methods not listed here are derived from Math::BigFloat (or +Math::BigInt), so make sure you check these two modules for further +information. + +=over + +=item new() + + $x = Math::BigRat->new('1/3'); + +Create a new Math::BigRat object. Input can come in various forms: + + $x = Math::BigRat->new(123); # scalars + $x = Math::BigRat->new('inf'); # infinity + $x = Math::BigRat->new('123.3'); # float + $x = Math::BigRat->new('1/3'); # simple string + $x = Math::BigRat->new('1 / 3'); # spaced + $x = Math::BigRat->new('1 / 0.1'); # w/ floats + $x = Math::BigRat->new(Math::BigInt->new(3)); # BigInt + $x = Math::BigRat->new(Math::BigFloat->new('3.1')); # BigFloat + $x = Math::BigRat->new(Math::BigInt::Lite->new('2')); # BigLite + + # You can also give D and N as different objects: + $x = Math::BigRat->new( + Math::BigInt->new(-123), + Math::BigInt->new(7), + ); # => -123/7 + +=item numerator() + + $n = $x->numerator(); + +Returns a copy of the numerator (the part above the line) as signed BigInt. + +=item denominator() + + $d = $x->denominator(); + +Returns a copy of the denominator (the part under the line) as positive BigInt. + +=item parts() + + ($n, $d) = $x->parts(); + +Return a list consisting of (signed) numerator and (unsigned) denominator as +BigInts. + +=item dparts() + +Returns the integer part and the fraction part. + +=item fparts() + +Returns the smallest possible numerator and denominator so that the numerator +divided by the denominator gives back the original value. For finite numbers, +both values are integers. Mnemonic: fraction. + +=item numify() + + my $y = $x->numify(); + +Returns the object as a scalar. This will lose some data if the object +cannot be represented by a normal Perl scalar (integer or float), so +use L or L instead. + +This routine is automatically used whenever a scalar is required: + + my $x = Math::BigRat->new('3/1'); + @array = (0, 1, 2, 3); + $y = $array[$x]; # set $y to 3 + +=item as_int() + +=item as_number() + + $x = Math::BigRat->new('13/7'); + print $x->as_int(), "\n"; # '1' + +Returns a copy of the object as BigInt, truncated to an integer. + +C is an alias for C. + +=item as_float() + + $x = Math::BigRat->new('13/7'); + print $x->as_float(), "\n"; # '1' + + $x = Math::BigRat->new('2/3'); + print $x->as_float(5), "\n"; # '0.66667' + +Returns a copy of the object as BigFloat, preserving the +accuracy as wanted, or the default of 40 digits. + +This method was added in v0.22 of Math::BigRat (April 2008). + +=item as_hex() + + $x = Math::BigRat->new('13'); + print $x->as_hex(), "\n"; # '0xd' + +Returns the BigRat as hexadecimal string. Works only for integers. + +=item as_bin() + + $x = Math::BigRat->new('13'); + print $x->as_bin(), "\n"; # '0x1101' + +Returns the BigRat as binary string. Works only for integers. + +=item as_oct() + + $x = Math::BigRat->new('13'); + print $x->as_oct(), "\n"; # '015' + +Returns the BigRat as octal string. Works only for integers. + +=item from_hex() + + my $h = Math::BigRat->from_hex('0x10'); + +Create a BigRat from a hexadecimal number in string form. + +=item from_oct() + + my $o = Math::BigRat->from_oct('020'); + +Create a BigRat from an octal number in string form. + +=item from_bin() + + my $b = Math::BigRat->from_bin('0b10000000'); + +Create a BigRat from an binary number in string form. + +=item bnan() + + $x = Math::BigRat->bnan(); + +Creates a new BigRat object representing NaN (Not A Number). +If used on an object, it will set it to NaN: + + $x->bnan(); + +=item bzero() + + $x = Math::BigRat->bzero(); + +Creates a new BigRat object representing zero. +If used on an object, it will set it to zero: + + $x->bzero(); + +=item binf() + + $x = Math::BigRat->binf($sign); + +Creates a new BigRat object representing infinity. The optional argument is +either '-' or '+', indicating whether you want infinity or minus infinity. +If used on an object, it will set it to infinity: + + $x->binf(); + $x->binf('-'); + +=item bone() + + $x = Math::BigRat->bone($sign); + +Creates a new BigRat object representing one. The optional argument is +either '-' or '+', indicating whether you want one or minus one. +If used on an object, it will set it to one: + + $x->bone(); # +1 + $x->bone('-'); # -1 + +=item length() + + $len = $x->length(); + +Return the length of $x in digits for integer values. + +=item digit() + + print Math::BigRat->new('123/1')->digit(1); # 1 + print Math::BigRat->new('123/1')->digit(-1); # 3 + +Return the N'ths digit from X when X is an integer value. + +=item bnorm() + + $x->bnorm(); + +Reduce the number to the shortest form. This routine is called +automatically whenever it is needed. + +=item bfac() + + $x->bfac(); + +Calculates the factorial of $x. For instance: + + print Math::BigRat->new('3/1')->bfac(), "\n"; # 1*2*3 + print Math::BigRat->new('5/1')->bfac(), "\n"; # 1*2*3*4*5 + +Works currently only for integers. + +=item bround()/round()/bfround() + +Are not yet implemented. + +=item bmod() + + $x->bmod($y); + +Returns $x modulo $y. When $x is finite, and $y is finite and non-zero, the +result is identical to the remainder after floored division (F-division). If, +in addition, both $x and $y are integers, the result is identical to the result +from Perl's % operator. + +=item bmodinv() + + $x->bmodinv($mod); # modular multiplicative inverse + +Returns the multiplicative inverse of C<$x> modulo C<$mod>. If + + $y = $x -> copy() -> bmodinv($mod) + +then C<$y> is the number closest to zero, and with the same sign as C<$mod>, +satisfying + + ($x * $y) % $mod = 1 % $mod + +If C<$x> and C<$y> are non-zero, they must be relative primes, i.e., +C. 'C' is returned when no modular multiplicative +inverse exists. + +=item bmodpow() + + $num->bmodpow($exp,$mod); # modular exponentiation + # ($num**$exp % $mod) + +Returns the value of C<$num> taken to the power C<$exp> in the modulus +C<$mod> using binary exponentiation. C is far superior to +writing + + $num ** $exp % $mod + +because it is much faster - it reduces internal variables into +the modulus whenever possible, so it operates on smaller numbers. + +C also supports negative exponents. + + bmodpow($num, -1, $mod) + +is exactly equivalent to + + bmodinv($num, $mod) + +=item bneg() + + $x->bneg(); + +Used to negate the object in-place. + +=item is_one() + + print "$x is 1\n" if $x->is_one(); + +Return true if $x is exactly one, otherwise false. + +=item is_zero() + + print "$x is 0\n" if $x->is_zero(); + +Return true if $x is exactly zero, otherwise false. + +=item is_pos()/is_positive() + + print "$x is >= 0\n" if $x->is_positive(); + +Return true if $x is positive (greater than or equal to zero), otherwise +false. Please note that '+inf' is also positive, while 'NaN' and '-inf' aren't. + +C is an alias for C. + +=item is_neg()/is_negative() + + print "$x is < 0\n" if $x->is_negative(); + +Return true if $x is negative (smaller than zero), otherwise false. Please +note that '-inf' is also negative, while 'NaN' and '+inf' aren't. + +C is an alias for C. + +=item is_int() + + print "$x is an integer\n" if $x->is_int(); + +Return true if $x has a denominator of 1 (e.g. no fraction parts), otherwise +false. Please note that '-inf', 'inf' and 'NaN' aren't integer. + +=item is_odd() + + print "$x is odd\n" if $x->is_odd(); + +Return true if $x is odd, otherwise false. + +=item is_even() + + print "$x is even\n" if $x->is_even(); + +Return true if $x is even, otherwise false. + +=item bceil() + + $x->bceil(); + +Set $x to the next bigger integer value (e.g. truncate the number to integer +and then increment it by one). + +=item bfloor() + + $x->bfloor(); + +Truncate $x to an integer value. + +=item bint() + + $x->bint(); + +Round $x towards zero. + +=item bsqrt() + + $x->bsqrt(); + +Calculate the square root of $x. + +=item broot() + + $x->broot($n); + +Calculate the N'th root of $x. + +=item badd() + + $x->badd($y); + +Adds $y to $x and returns the result. + +=item bmul() + + $x->bmul($y); + +Multiplies $y to $x and returns the result. + +=item bsub() + + $x->bsub($y); + +Subtracts $y from $x and returns the result. + +=item bdiv() + + $q = $x->bdiv($y); + ($q, $r) = $x->bdiv($y); + +In scalar context, divides $x by $y and returns the result. In list context, +does floored division (F-division), returning an integer $q and a remainder $r +so that $x = $q * $y + $r. The remainer (modulo) is equal to what is returned +by C<< $x->bmod($y) >>. + +=item binv() + + $x->binv(); + +Inverse of $x. + +=item bdec() + + $x->bdec(); + +Decrements $x by 1 and returns the result. + +=item binc() + + $x->binc(); + +Increments $x by 1 and returns the result. + +=item copy() + + my $z = $x->copy(); + +Makes a deep copy of the object. + +Please see the documentation in L for further details. + +=item bstr()/bsstr() + + my $x = Math::BigRat->new('8/4'); + print $x->bstr(), "\n"; # prints 1/2 + print $x->bsstr(), "\n"; # prints 1/2 + +Return a string representing this object. + +=item bcmp() + + $x->bcmp($y); + +Compares $x with $y and takes the sign into account. +Returns -1, 0, 1 or undef. + +=item bacmp() + + $x->bacmp($y); + +Compares $x with $y while ignoring their sign. Returns -1, 0, 1 or undef. + +=item beq() + + $x -> beq($y); + +Returns true if and only if $x is equal to $y, and false otherwise. + +=item bne() + + $x -> bne($y); + +Returns true if and only if $x is not equal to $y, and false otherwise. + +=item blt() + + $x -> blt($y); + +Returns true if and only if $x is equal to $y, and false otherwise. + +=item ble() + + $x -> ble($y); + +Returns true if and only if $x is less than or equal to $y, and false +otherwise. + +=item bgt() + + $x -> bgt($y); + +Returns true if and only if $x is greater than $y, and false otherwise. + +=item bge() + + $x -> bge($y); + +Returns true if and only if $x is greater than or equal to $y, and false +otherwise. + +=item blsft()/brsft() + +Used to shift numbers left/right. + +Please see the documentation in L for further details. + +=item band() + + $x->band($y); # bitwise and + +=item bior() + + $x->bior($y); # bitwise inclusive or + +=item bxor() + + $x->bxor($y); # bitwise exclusive or + +=item bnot() + + $x->bnot(); # bitwise not (two's complement) + +=item bpow() + + $x->bpow($y); + +Compute $x ** $y. + +Please see the documentation in L for further details. + +=item blog() + + $x->blog($base, $accuracy); # logarithm of x to the base $base + +If C<$base> is not defined, Euler's number (e) is used: + + print $x->blog(undef, 100); # log(x) to 100 digits + +=item bexp() + + $x->bexp($accuracy); # calculate e ** X + +Calculates two integers A and B so that A/B is equal to C, where C is +Euler's number. + +This method was added in v0.20 of Math::BigRat (May 2007). + +See also C. + +=item bnok() + + $x->bnok($y); # x over y (binomial coefficient n over k) + +Calculates the binomial coefficient n over k, also called the "choose" +function. The result is equivalent to: + + ( n ) n! + | - | = ------- + ( k ) k!(n-k)! + +This method was added in v0.20 of Math::BigRat (May 2007). + +=item config() + + Math::BigRat->config("trap_nan" => 1); # set + $accu = Math::BigRat->config("accuracy"); # get + +Set or get configuration parameter values. Read-only parameters are marked as +RO. Read-write parameters are marked as RW. The following parameters are +supported. + + Parameter RO/RW Description + Example + ============================================================ + lib RO Name of the math backend library + Math::BigInt::Calc + lib_version RO Version of the math backend library + 0.30 + class RO The class of config you just called + Math::BigRat + version RO version number of the class you used + 0.10 + upgrade RW To which class numbers are upgraded + undef + downgrade RW To which class numbers are downgraded + undef + precision RW Global precision + undef + accuracy RW Global accuracy + undef + round_mode RW Global round mode + even + div_scale RW Fallback accuracy for div, sqrt etc. + 40 + trap_nan RW Trap NaNs + undef + trap_inf RW Trap +inf/-inf + undef + +=back + +=head1 NUMERIC LITERALS + +After C all numeric literals in the given scope +are converted to C objects. This conversion happens at compile +time. Every non-integer is convert to a NaN. + +For example, + + perl -MMath::BigRat=:constant -le 'print 2**150' + +prints the exact value of C<2**150>. Note that without conversion of constants +to objects the expression C<2**150> is calculated using Perl scalars, which +leads to an inaccurate result. + +Please note that strings are not affected, so that + + use Math::BigRat qw/:constant/; + + $x = "1234567890123456789012345678901234567890" + + "123456789123456789"; + +does give you what you expect. You need an explicit Math::BigRat->new() around +at least one of the operands. You should also quote large constants to prevent +loss of precision: + + use Math::BigRat; + + $x = Math::BigRat->new("1234567889123456789123456789123456789"); + +Without the quotes Perl first converts the large number to a floating point +constant at compile time, and then converts the result to a Math::BigRat object +at run time, which results in an inaccurate result. + +=head2 Hexadecimal, octal, and binary floating point literals + +Perl (and this module) accepts hexadecimal, octal, and binary floating point +literals, but use them with care with Perl versions before v5.32.0, because some +versions of Perl silently give the wrong result. Below are some examples of +different ways to write the number decimal 314. + +Hexadecimal floating point literals: + + 0x1.3ap+8 0X1.3AP+8 + 0x1.3ap8 0X1.3AP8 + 0x13a0p-4 0X13A0P-4 + +Octal floating point literals (with "0" prefix): + + 01.164p+8 01.164P+8 + 01.164p8 01.164P8 + 011640p-4 011640P-4 + +Octal floating point literals (with "0o" prefix) (requires v5.34.0): + + 0o1.164p+8 0O1.164P+8 + 0o1.164p8 0O1.164P8 + 0o11640p-4 0O11640P-4 + +Binary floating point literals: + + 0b1.0011101p+8 0B1.0011101P+8 + 0b1.0011101p8 0B1.0011101P8 + 0b10011101000p-2 0B10011101000P-2 + +=head1 BUGS + +Please report any bugs or feature requests to +C, or through the web interface at +L (requires login). +We will be notified, and then you'll automatically be notified of progress on +your bug as I make changes. + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command. + + perldoc Math::BigInt + +You can also look for information at: + +=over 4 + +=item * GitHub + +L + +=item * RT: CPAN's request tracker + +L + +=item * MetaCPAN + +L + +=item * CPAN Testers Matrix + +L + +=back + +=head1 LICENSE + +This program is free software; you may redistribute it and/or modify it under +the same terms as Perl itself. + +=head1 SEE ALSO + +L and L as well as the backend libraries +L, L, and L, +L, and L. + +The pragmas L, L, and L might also be of interest. In +addition there is the L pragma which does upgrading and downgrading. + +=head1 AUTHORS + +=over 4 + +=item * + +Tels L 2001-2009. + +=item * + +Maintained by Peter John Acklam 2011- + +=back + +=cut Index: gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigInt/Calc.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigInt/Calc.pm,v diff -u -p -a -u -p -r1.8 Calc.pm --- gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigInt/Calc.pm 14 May 2024 19:38:55 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigInt/Calc.pm 22 Jan 2025 00:37:42 -0000 @@ -7,7 +7,7 @@ use warnings; use Carp qw< carp croak >; use Math::BigInt::Lib; -our $VERSION = '1.999837'; +our $VERSION = '2.003002'; $VERSION =~ tr/_//d; our @ISA = ('Math::BigInt::Lib'); @@ -1712,6 +1712,156 @@ sub _log_int { return $x, 1 if $acmp == 0; # result is exact return $x, 0; # result is too small +} + +sub _ilog2 { + # calculate int(log2($x)) + + # There is virtually nothing to gain from computing this any differently + # than _log_int(), but it is important that we don't use the method + # inherited from the parent, because that method is very slow for backend + # libraries whose internal representation uses base 10. + + my ($c, $x) = @_; + ($x, my $is_exact) = $c -> _log_int($x, $c -> _two()); + return wantarray ? ($x, $is_exact) : $x; +} + +sub _ilog10 { + # calculate int(log10($x)) + + my ($c, $x) = @_; + + # X == 0 => NaN + return if @$x == 1 && $x->[0] == 0; + + # X == 1 => 0 (is exact) + if (@$x == 1 && $x->[0] == 1) { + @$x = 0; + return wantarray ? ($x, 1) : $x; + } + + my $x_orig = $c -> _copy($x); + my $nm1 = $c -> _len($x) - 1; + + my $xtmp = $c -> _new($nm1); + @$x = @$xtmp; + + return $x unless wantarray; + + # See if the original $x is an exact power of 10, in which case all but the + # most significan chunks are 0, and the most significant chunk is a power + # of 10. + + my $is_pow10 = 1; + for my $i (0 .. $#$x_orig - 1) { + last unless $is_pow10 = $x_orig->[$i] == 0; + } + $is_pow10 &&= $x_orig->[-1] == 10**int(0.5 + log($x_orig->[-1]) / log(10)); + + return wantarray ? ($x, 1) : $x if $is_pow10; + return wantarray ? ($x, 0) : $x; +} + +sub _clog2 { + # calculate ceil(log2($x)) + + my ($c, $x) = @_; + + # X == 0 => NaN + + return if @$x == 1 && $x->[0] == 0; + + # X == 1 => 0 (is exact) + + if (@$x == 1 && $x->[0] == 1) { + @$x = 0; + return wantarray ? ($x, 1) : $x; + } + + my $base = $c -> _two(); + my $acmp = $c -> _acmp($x, $base); + + # X == BASE => 1 (is exact) + + if ($acmp == 0) { + @$x = 1; + return wantarray ? ($x, 1) : $x; + } + + # 1 < X < BASE => 0 (is truncated) + + if ($acmp < 0) { + @$x = 0; + return wantarray ? ($x, 0) : $x; + } + + # Compute a guess for the result based on: + # $guess = int( length_in_base_10(X) / (log(base) / log(10)) ) + + my $len = $c -> _len($x); + my $log = log(2) / log(10); + my $guess = $c -> _new(int($len / $log)); + my $x_orig = $c -> _copy($x); + @$x = @$guess; + + my $trial = $c -> _pow($c -> _copy($base), $x); + $acmp = $c -> _acmp($trial, $x_orig); + + # Too big? + + while ($acmp > 0) { + $c -> _div($trial, $base); + $c -> _dec($x); + $acmp = $c -> _acmp($trial, $x_orig); + } + + # Too small? + + while ($acmp < 0) { + $c -> _mul($trial, $base); + $c -> _inc($x); + $acmp = $c -> _acmp($trial, $x_orig); + } + + return wantarray ? ($x, 1) : $x if $acmp == 0; # result is exact + return wantarray ? ($x, 0) : $x; # result is too small +} + +sub _clog10 { + # calculate ceil(log2($x)) + my ($c, $x) = @_; + + # X == 0 => NaN + return if @$x == 1 && $x->[0] == 0; + + # X == 1 => 0 (is exact) + if (@$x == 1 && $x->[0] == 1) { + @$x = 0; + return wantarray ? ($x, 1) : $x; + } + + # Get the number of base 10 digits. $n is the desired output, except when + # $x is an exact power of 10, in which case $n is 1 too big. + + my $n = $c -> _len($x); + + # See if $x is an exact power of 10, in which case all but the most + # significan chunks are 0, and the most significant chunk is a power of 10. + + my $is_pow10 = 1; + for my $i (0 .. $#$x - 1) { + last unless $is_pow10 = $x->[$i] == 0; + } + $is_pow10 &&= $x->[-1] == 10**int(0.5 + log($x->[-1]) / log(10)); + + $n-- if $is_pow10; + + my $xtmp = $c ->_new($n); + @$x = @$xtmp; + + return wantarray ? ($x, 1) : $x if $is_pow10; # result is exact + return wantarray ? ($x, 0) : $x; # result is too small } # for debugging: Index: gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigInt/Lib.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigInt/Lib.pm,v diff -u -p -a -u -p -r1.1.1.5 Lib.pm --- gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigInt/Lib.pm 14 May 2024 19:36:35 -0000 1.1.1.5 +++ gnu/usr.bin/perl/cpan/Math-BigInt/lib/Math/BigInt/Lib.pm 22 Jan 2025 00:37:42 -0000 @@ -4,7 +4,7 @@ use 5.006001; use strict; use warnings; -our $VERSION = '1.999837'; +our $VERSION = '2.003002'; $VERSION =~ tr/_//d; use Carp; @@ -710,19 +710,22 @@ sub _log_int { # X == 1 => 0 (is exact) if ($class -> _is_one($x)) { - return $class -> _zero(), 1; + return $class -> _zero(), 1 if wantarray; + return $class -> _zero(); } my $cmp = $class -> _acmp($x, $base); # X == BASE => 1 (is exact) if ($cmp == 0) { - return $class -> _one(), 1; + return $class -> _one(), 1 if wantarray; + return $class -> _one(); } # 1 < X < BASE => 0 (is truncated) if ($cmp < 0) { - return $class -> _zero(), 0; + return $class -> _zero(), 0 if wantarray; + return $class -> _zero(); } my $y; @@ -745,10 +748,6 @@ sub _log_int { my $trial = $class -> _pow($class -> _copy($base), $y); my $acmp = $class -> _acmp($trial, $x); - # Did we get the exact result? - - return $y, 1 if $acmp == 0; - # Too small? while ($acmp < 0) { @@ -765,8 +764,93 @@ sub _log_int { $acmp = $class -> _acmp($trial, $x); } - return $y, 1 if $acmp == 0; # result is exact - return $y, 0; # result is too small + return wantarray ? ($y, 1) : $y if $acmp == 0; # result is exact + return wantarray ? ($y, 0) : $y; # result is too small +} + +sub _ilog2 { + my ($class, $x) = @_; + + return if $class -> _is_zero($x); + + my $str = $class -> _to_hex($x); + + # First do the bits in all but the most significant hex digit. + + my $y = $class -> _new(length($str) - 1); + $y = $class -> _mul($y, $class -> _new(4)); + + # Now add the number of bits in the most significant hex digit. + + my $n = int log(hex(substr($str, 0, 1))) / log(2); + $y = $class -> _add($y, $class -> _new($n)); + return $y unless wantarray; + + my $pow2 = $class -> _lsft($class -> _one(), $y, 2); + my $is_exact = $class -> _acmp($x, $pow2) == 0 ? 1 : 0; + return $y, $is_exact; +} + +sub _ilog10 { + my ($class, $x) = @_; + + return if $class -> _is_zero($x); + + my $str = $class -> _str($x); + my $len = length($str); + my $y = $class -> _new($len - 1); + return $y unless wantarray; + + #my $pow10 = $class -> _1ex($y); + #my $is_exact = $class -> _acmp($x, $pow10) ? 1 : 0; + + my $is_exact = $str =~ /^10*$/ ? 1 : 0; + return $y, $is_exact; +} + +sub _clog2 { + my ($class, $x) = @_; + + return if $class -> _is_zero($x); + + my $str = $class -> _to_hex($x); + + # First do the bits in all but the most significant hex digit. + + my $y = $class -> _new(length($str) - 1); + $y = $class -> _mul($y, $class -> _new(4)); + + # Now add the number of bits in the most significant hex digit. + + my $n = int log(hex(substr($str, 0, 1))) / log(2); + $y = $class -> _add($y, $class -> _new($n)); + + # $y is now 1 too small unless $y is an exact power of 2. + + my $pow2 = $class -> _lsft($class -> _one(), $y, 2); + my $is_exact = $class -> _acmp($x, $pow2) == 0 ? 1 : 0; + $y = $class -> _inc($y) if $is_exact == 0; + return $y, $is_exact if wantarray; + return $y; +} + +sub _clog10 { + my ($class, $x) = @_; + + return if $class -> _is_zero($x); + + my $str = $class -> _str($x); + my $len = length($str); + + if ($str =~ /^10*$/) { + my $y = $class -> _new($len - 1); + return $y, 1 if wantarray; + return $y; + } + + my $y = $class -> _new($len); + return $y, 0 if wantarray; + return $y; } sub _sqrt { @@ -2303,6 +2387,47 @@ has two output arguments, the OBJECT and it is 1 if OBJ is the exact result, 0 if the result was truncted to give OBJ, and undef if it is unknown whether OBJ is the exact result. +=item CLASS-E_ilog2(OBJ) + +Returns the base 2 logarithm of OBJ rounded downwards to the nearest integer, +i.e., C. In list context, this method returns two output +arguments, the OBJECT and a STATUS. The STATUS is Perl scalar; it is 1 if OBJ +is the exact result, 0 if the result was truncted to give OBJ, and undef if it +is unknown whether OBJ is the exact result. + +This method is equivalent to the more general method _log_int() when it is used +with base 2 argument, but _ilog2() method might be faster. + +=item CLASS-E_ilog10(OBJ) + +Returns the base 10 logarithm of OBJ rounded downwards to the nearest integer, +i.e., C. In list context, this method returns two output +arguments, the OBJECT and a STATUS. The STATUS is Perl scalar; it is 1 if OBJ +is the exact result, 0 if the result was truncted to give OBJ, and undef if it +is unknown whether OBJ is the exact result. + +This method is equivalent to the more general method _log_int() when it is used +with base 10 argument, but _ilog10() method might be faster. + +Also, the output from _ilog10() is always 1 smaller than the output from +_len(). + +=item CLASS-E_clog2(OBJ) + +Returns the base 2 logarithm of OBJ rounded upwards to the nearest integer, +i.e., C. In list context, this method returns two output +arguments, the OBJECT and a STATUS. The STATUS is Perl scalar; it is 1 if OBJ +is the exact result, 0 if the result was truncted to give OBJ, and undef if it +is unknown whether OBJ is the exact result. + +=item CLASS-E_clog10(OBJ) + +Returns the base 10 logarithm of OBJ rounded upnwards to the nearest integer, +i.e., C. In list context, this method returns two output +arguments, the OBJECT and a STATUS. The STATUS is Perl scalar; it is 1 if OBJ +is the exact result, 0 if the result was truncted to give OBJ, and undef if it +is unknown whether OBJ is the exact result. + =item CLASS-E_gcd(OBJ1, OBJ2) Returns the greatest common divisor of OBJ1 and OBJ2. @@ -2585,17 +2710,13 @@ You can also look for information at: =over 4 -=item * RT: CPAN's request tracker +=item * GitHub Source Repository -L - -=item * AnnoCPAN: Annotated CPAN documentation +L -L - -=item * CPAN Ratings +=item * RT: CPAN's request tracker -L +L =item * MetaCPAN @@ -2604,24 +2725,6 @@ L - -=item * The Bignum mailing list - -=over 4 - -=item * Post to mailing list - -C - -=item * View mailing list - -L - -=item * Subscribe/Unsubscribe - -L - -=back =back Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/alias.inc =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/alias.inc,v diff -u -p -a -u -p -r1.4 alias.inc --- gnu/usr.bin/perl/cpan/Math-BigInt/t/alias.inc 15 Feb 2023 01:36:19 -0000 1.4 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/alias.inc 22 Jan 2025 00:37:42 -0000 @@ -12,7 +12,7 @@ our $x = $CLASS->new(123); is($x->is_pos(), 1, "$CLASS -> new(123) -> is_pos()"); is($x->is_neg(), 0, "$CLASS -> new(123) -> is_neg()"); is($x->as_int(), 123, "$CLASS -> new(123) -> as_int()"); -is(ref($x->as_int()), 'Math::BigInt', "ref($CLASS -> new(123) -> as_int())"); +isa_ok($x->as_int(), 'Math::BigInt', "$CLASS -> new(123) -> as_int() isa Math::BigInt"); $x->bneg(); is($x->is_pos(), 0, "$CLASS -> new(123) -> bneg() -> is_pos()"); is($x->is_neg(), 1, "$CLASS -> new(123) -> bneg() -> is_neg()"); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/bare_mbr.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/bare_mbr.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/bare_mbr.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/bare_mbr.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,18 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use Test::More tests => 899; # tests in require'd file + +use lib 't'; + +use Math::BigRat lib => 'BareCalc'; + +print "# ", Math::BigRat->config('lib'), "\n"; + +our ($CLASS, $LIB); +$CLASS = "Math::BigRat"; +$LIB = "Math::BigInt::BareCalc"; # backend + +require './t/bigratpm.inc'; # perform same tests as bigratpm.t Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/bfround_numify.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/bfround_numify.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/bfround_numify.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/bfround_numify.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,17 @@ +use strict; +use warnings; + +use Test::More tests => 3; + +use Math::BigFloat; + +my $mbf = 'Math::BigFloat'; + +my $x = $mbf->new('123456.123456'); + +is($x->numify, 123456.123456, 'numify before bfround'); + +$x->bfround(-2); + +is($x->numify, 123456.12, 'numify after bfround'); +is($x->bstr, "123456.12", 'bstr after bfround'); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/big_ap.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/big_ap.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/big_ap.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/big_ap.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,121 @@ +# -*- mode: perl; -*- + +# Test that accuracy() and precision() in BigInt/BigFloat do not disturb +# the rounding force in BigRat. + +use strict; +use warnings; + +use Test::More tests => 17; + +use Math::BigInt; +use Math::BigFloat; +use Math::BigRat; + +my $proper = Math::BigRat -> new('12345678901234567890/2'); +my $proper_inc = Math::BigRat -> new('12345678901234567890/2') -> binc(); +my $proper_dec = Math::BigRat -> new('12345678901234567890/2') -> bdec(); +my $proper_int = Math::BigInt -> new('12345678901234567890'); +my $proper_float = Math::BigFloat -> new('12345678901234567890'); +my $proper2 = Math::BigRat -> new('12345678901234567890'); + +Math::BigInt -> accuracy(3); +Math::BigFloat -> accuracy(5); + +my ($x, $y, $z); + +############################################################################## +# new() + +note "Test new()"; + +$z = Math::BigRat->new("12345678901234567890/2"); +is($z, $proper, q|Math::BigRat->new("12345678901234567890/2")|); + +$z = Math::BigRat->new("1234567890123456789E1"); +is($z, $proper2, q|Math::BigRat->new("1234567890123456789E1")|); + +$z = Math::BigRat->new("12345678901234567890/1E0"); +is($z, $proper2, q|Math::BigRat->new("12345678901234567890/1E0")|); + +$z = Math::BigRat->new("1234567890123456789e1/1"); +is($z, $proper2, q|Math::BigRat->new("1234567890123456789e1/1")|); + +$z = Math::BigRat->new("1234567890123456789e1/1E0"); +is($z, $proper2, q|Math::BigRat->new("1234567890123456789e1/1E0")|); + +$z = Math::BigRat->new($proper_int); +is($z, $proper2, qq|Math::BigRat->new("$proper_int")|); + +$z = Math::BigRat->new($proper_float); +is($z, $proper2, qq|Math::BigRat->new("$proper_float")|); + +############################################################################## +# bdiv + +note "Test bdiv()"; + +$x = Math::BigRat->new("12345678901234567890"); +$y = Math::BigRat->new("2"); +$z = $x->copy->bdiv($y); +is($z, $proper); + +############################################################################## +# bmul + +note "Test bmul()"; + +$x = Math::BigRat->new("$proper"); +$y = Math::BigRat->new("1"); +$z = $x->copy->bmul($y); +is($z, $proper); + +$z = Math::BigRat->new("12345678901234567890/1E0"); +is($z, $proper2); + +$z = Math::BigRat->new($proper_int); +is($z, $proper2); + +$z = Math::BigRat->new($proper_float); +is($z, $proper2); + +############################################################################## +# bdiv + +note "Test bdiv()"; + +$x = Math::BigRat->new("12345678901234567890"); +$y = Math::BigRat->new("2"); +$z = $x->copy->bdiv($y); +is($z, $proper); + +############################################################################## +# bmul + +note "Test bmul()"; + +$x = Math::BigRat->new("$proper"); +$y = Math::BigRat->new("1"); +$z = $x->copy->bmul($y); +is($z, $proper); + +$x = Math::BigRat->new("$proper"); +$y = Math::BigRat->new("2"); +$z = $x->copy->bmul($y); +is($z, $proper2); + +############################################################################## +# binc + +note "Test binc()"; + +$x = $proper->copy()->binc(); +is($x, $proper_inc); + +############################################################################## +# binc + +note "Test bdec()"; + +$x = $proper->copy()->bdec(); +is($x, $proper_dec); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/big_pi_e.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/big_pi_e.t,v diff -u -p -a -u -p -r1.5 big_pi_e.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/big_pi_e.t 15 Feb 2023 01:36:19 -0000 1.5 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/big_pi_e.t 22 Jan 2025 00:37:42 -0000 @@ -13,22 +13,22 @@ use Math::BigFloat; my $pi = Math::BigFloat::bpi(); -is($pi->{_a}, undef, 'A is not defined'); -is($pi->{_p}, undef, 'P is not defined'); +is($pi->{accuracy}, undef, 'A is not defined'); +is($pi->{precision}, undef, 'P is not defined'); $pi = Math::BigFloat->bpi(); -is($pi->{_a}, undef, 'A is not defined'); -is($pi->{_p}, undef, 'P is not defined'); +is($pi->{accuracy}, undef, 'A is not defined'); +is($pi->{precision}, undef, 'P is not defined'); $pi = Math::BigFloat->bpi(10); -is($pi->{_a}, 10, 'A is defined'); -is($pi->{_p}, undef, 'P is not defined'); +is($pi->{accuracy}, 10, 'A is defined'); +is($pi->{precision}, undef, 'P is not defined'); ############################################################################# my $e = Math::BigFloat->new(1)->bexp(); -is($e->{_a}, undef, 'A is not defined'); -is($e->{_p}, undef, 'P is not defined'); +is($e->{accuracy}, undef, 'A is not defined'); +is($e->{precision}, undef, 'P is not defined'); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/bigfltpm.inc =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/bigfltpm.inc,v diff -u -p -a -u -p -r1.8 bigfltpm.inc --- gnu/usr.bin/perl/cpan/Math-BigInt/t/bigfltpm.inc 14 May 2024 19:38:56 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/bigfltpm.inc 22 Jan 2025 00:37:42 -0000 @@ -98,14 +98,14 @@ while () { if (defined $args[2]) { $try .= qq| \$z = $CLASS->new("$args[2]");|; } - $try .= qq| $CLASS\::bgcd(\$x, \$y|; + $try .= qq| $CLASS->bgcd(\$x, \$y|; $try .= qq|, \$z| if defined $args[2]; $try .= qq|);|; } elsif ($f eq "blcm") { if (defined $args[2]) { $try .= qq| \$z = $CLASS->new("$args[2]");|; } - $try .= qq| $CLASS\::blcm(\$x, \$y|; + $try .= qq| $CLASS->blcm(\$x, \$y|; $try .= qq|, \$z| if defined $args[2]; $try .= qq|);|; } elsif ($f eq "bcmp") { @@ -228,23 +228,23 @@ is($CLASS->new($monster)->mantissa(), $x = $CLASS->new(2); $x->bzero(); -is($x->{_a}, undef, qq|\$x = $CLASS->new(2); \$x->bzero(); \$x->{_a}|); -is($x->{_p}, undef, qq|\$x = $CLASS->new(2); \$x->bzero(); \$x->{_p}|); +is($x->{accuracy}, undef, qq|\$x = $CLASS->new(2); \$x->bzero(); \$x->{accuracy}|); +is($x->{precision}, undef, qq|\$x = $CLASS->new(2); \$x->bzero(); \$x->{precision}|); $x = $CLASS->new(2); $x->binf(); -is($x->{_a}, undef, qq|\$x = $CLASS->new(2); \$x->binf(); \$x->{_a}|); -is($x->{_p}, undef, qq|\$x = $CLASS->new(2); \$x->binf(); \$x->{_p}|); +is($x->{accuracy}, undef, qq|\$x = $CLASS->new(2); \$x->binf(); \$x->{accuracy}|); +is($x->{precision}, undef, qq|\$x = $CLASS->new(2); \$x->binf(); \$x->{precision}|); $x = $CLASS->new(2); $x->bone(); -is($x->{_a}, undef, qq|\$x = $CLASS->new(2); \$x->bone(); \$x->{_a}|); -is($x->{_p}, undef, qq|\$x = $CLASS->new(2); \$x->bone(); \$x->{_p}|); +is($x->{accuracy}, undef, qq|\$x = $CLASS->new(2); \$x->bone(); \$x->{accuracy}|); +is($x->{precision}, undef, qq|\$x = $CLASS->new(2); \$x->bone(); \$x->{precision}|); $x = $CLASS->new(2); $x->bnan(); -is($x->{_a}, undef, qq|\$x = $CLASS->new(2); \$x->bnan(); \$x->{_a}|); -is($x->{_p}, undef, qq|\$x = $CLASS->new(2); \$x->bnan(); \$x->{_p}|); +is($x->{accuracy}, undef, qq|\$x = $CLASS->new(2); \$x->bnan(); \$x->{accuracy}|); +is($x->{precision}, undef, qq|\$x = $CLASS->new(2); \$x->bnan(); \$x->{precision}|); ############################################################################### # bone/binf etc as plain calls (Lite failed them) @@ -466,17 +466,17 @@ $y = $CLASS->new("18.2"); # 2 * (2 ** int(18.2)); $x <<= $y; -is($x->copy()->bfround(-9), "602248.763144685", +is($x, 524288, qq|\$x = $CLASS->new("2"); \$y = $CLASS->new("18.2");| . - q| $x <<= $y; $x->copy()->bfround(-9);|); + q| $x <<= $y|); -# 2 * (2 ** 18.2) / (2 ** 18.2) => 2 +# 2 * (2 ** int(18.2)) / (2 ** int(18.2)) => 2 is($x >>= $y, 2, qq|\$x = $CLASS->new("2"); \$y = $CLASS->new("18.2");| . - q| $x <<= $y; $x->copy()->bfround(-9); $x >>= $y|); + q| $x <<= $y; $x >>= $y|); is($x, 2, qq|\$x = $CLASS->new("2"); \$y = $CLASS->new("18.2");| . - q| $x <<= $y; $x->copy()->bfround(-9); $x >>= $y; $x|); + q| $x <<= $y; $x >>= $y; $x|); __DATA__ Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/bigfltrt.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/bigfltrt.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/bigfltrt.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/bigfltrt.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,17 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use lib 't'; + +use Test::More tests => 899; + +use Math::BigRat::Subclass lib => 'Calc'; # test via this Subclass + +our ($CLASS, $LIB); +$CLASS = "Math::BigRat::Subclass"; +$LIB = "Math::BigInt::Calc"; + +# fails still too many tests +require './t/bigratpm.inc'; # all tests here for sharing Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/bigintpm.inc =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/bigintpm.inc,v diff -u -p -a -u -p -r1.8 bigintpm.inc --- gnu/usr.bin/perl/cpan/Math-BigInt/t/bigintpm.inc 14 May 2024 19:38:56 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/bigintpm.inc 22 Jan 2025 00:37:42 -0000 @@ -137,14 +137,14 @@ while () { if (defined $args[2]) { $try .= qq| \$z = $CLASS->new("$args[2]");|; } - $try .= " $CLASS\::bgcd(\$x, \$y"; + $try .= " $CLASS->bgcd(\$x, \$y"; $try .= ", \$z" if defined $args[2]; $try .= ");"; } elsif ($f eq "blcm") { if (defined $args[2]) { $try .= qq| \$z = $CLASS->new("$args[2]");|; } - $try .= " $CLASS\::blcm(\$x, \$y"; + $try .= " $CLASS->blcm(\$x, \$y"; $try .= ", \$z" if defined $args[2]; $try .= ");"; } elsif ($f eq "blsft") { @@ -1451,14 +1451,14 @@ abc:abc:NaN +2:+2:8 +1:+32:4294967296 +1:+48:281474976710656 -+8:-2:NaN ++8:-2:2 # exercise base 10 +12345:4:10:123450000 -1234:0:10:-1234 +1234:0:10:1234 +2:2:10:200 +12:2:10:1200 -+1234:-3:10:NaN ++1234:-3:10:1 1234567890123:12:10:1234567890123000000000000 -3:1:2:-6 -5:1:2:-10 @@ -1470,14 +1470,14 @@ abc:abc:NaN +8:+2:2 +4294967296:+32:1 +281474976710656:+48:1 -+2:-2:NaN ++2:-2:8 # exercise base 10 -1234:0:10:-1234 +1234:0:10:1234 +200:2:10:2 +1234:3:10:1 +1234:2:10:12 -+1234:-3:10:NaN ++1234:-3:10:1234000 310000:4:10:31 12300000:5:10:123 1230000000000:10:10:123 Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/bigrat.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/bigrat.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/bigrat.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/bigrat.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,546 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use Test::More tests => 203; + +# basic testing of Math::BigRat + +use Math::BigRat; +use Math::BigInt; +use Math::BigFloat; + +# shortcuts +my $mbr = 'Math::BigRat'; +my $mbi = 'Math::BigInt'; +my $mbf = 'Math::BigFloat'; + +my ($x, $y, $z); + +$x = Math::BigRat->new(1234); +is($x, 1234, 'value of $x'); +isa_ok($x, 'Math::BigRat'); +ok(!$x->isa('Math::BigInt'), + "An object of class '" . ref($x) . "' isn't a 'Math::BigInt'"); +ok(!$x->isa('Math::BigFloat'), + "An object of class '" . ref($x) . "' isn't a 'Math::BigFloat'"); + +############################################################################## +# new and bnorm() + +foreach my $method (qw/ new bnorm /) { + $x = $mbr->$method(1234); + is($x, 1234, qq|\$x = $mbr->$method(1234)|); + + $x = $mbr->$method("1234/1"); + is($x, 1234, qq|\$x = $mbr->$method("1234/1")|); + + $x = $mbr->$method("1234/2"); + is($x, 617, qq|\$x = $mbr->$method("1234/2")|); + + $x = $mbr->$method("100/1.0"); + is($x, 100, qq|\$x = $mbr->$method("100/1.0")|); + + $x = $mbr->$method("10.0/1.0"); + is($x, 10, qq|\$x = $mbr->$method("10.0/1.0")|); + + $x = $mbr->$method("0.1/10"); + is($x, "1/100", qq|\$x = $mbr->$method("0.1/10")|); + + $x = $mbr->$method("0.1/0.1"); + is($x, "1", qq|\$x = $mbr->$method("0.1/0.1")|); + + $x = $mbr->$method("1e2/10"); + is($x, 10, qq|\$x = $mbr->$method("1e2/10")|); + + $x = $mbr->$method("5/1e2"); + is($x, "1/20", qq|\$x = $mbr->$method("5/1e2")|); + + $x = $mbr->$method("1e2/1e1"); + is($x, 10, qq|\$x = $mbr->$method("1e2/1e1")|); + + $x = $mbr->$method("1 / 3"); + is($x, "1/3", qq|\$x = $mbr->$method("1 / 3")|); + + $x = $mbr->$method("-1 / 3"); + is($x, "-1/3", qq|\$x = $mbr->$method("-1 / 3")|); + + $x = $mbr->$method("NaN"); + is($x, "NaN", qq|\$x = $mbr->$method("NaN")|); + + $x = $mbr->$method("inf"); + is($x, "inf", qq|\$x = $mbr->$method("inf")|); + + $x = $mbr->$method("-inf"); + is($x, "-inf", qq|\$x = $mbr->$method("-inf")|); + + $x = $mbr->$method("1/"); + is($x, "NaN", qq|\$x = $mbr->$method("1/")|); + + $x = $mbr->$method("0x7e"); + is($x, 126, qq|\$x = $mbr->$method("0x7e")|); + + # input ala "1+1/3" isn"t parsed ok yet + $x = $mbr->$method("1+1/3"); + is($x, "NaN", qq|\$x = $mbr->$method("1+1/3")|); + + $x = $mbr->$method("1/1.2"); + is($x, "5/6", qq|\$x = $mbr->$method("1/1.2")|); + + $x = $mbr->$method("1.3/1.2"); + is($x, "13/12", qq|\$x = $mbr->$method("1.3/1.2")|); + + $x = $mbr->$method("1.2/1"); + is($x, "6/5", qq|\$x = $mbr->$method("1.2/1")|); + + ############################################################################ + # other classes as input + + $x = $mbr->$method($mbi->new(1231)); + is($x, "1231", qq|\$x = $mbr->$method($mbi->new(1231))|); + + $x = $mbr->$method($mbf->new(1232)); + is($x, "1232", qq|\$x = $mbr->$method($mbf->new(1232))|); + + $x = $mbr->$method($mbf->new(1232.3)); + is($x, "12323/10", qq|\$x = $mbr->$method($mbf->new(1232.3))|); +} + +my $n = 'numerator'; +my $d = 'denominator'; + +$x = $mbr->new('-0'); +is($x, '0'); +is($x->$n(), '0'); +is($x->$d(), '1'); + +$x = $mbr->new('NaN'); +is($x, 'NaN'); is($x->$n(), 'NaN'); +is($x->$d(), 'NaN'); + +$x = $mbr->new('-NaN'); +is($x, 'NaN'); is($x->$n(), 'NaN'); +is($x->$d(), 'NaN'); + +$x = $mbr->new('-1r4'); +is($x, 'NaN'); is($x->$n(), 'NaN'); +is($x->$d(), 'NaN'); + +$x = $mbr->new('+inf'); +is($x, 'inf'); is($x->$n(), 'inf'); +is($x->$d(), '1'); + +$x = $mbr->new('-inf'); +is($x, '-inf'); +is($x->$n(), '-inf'); +is($x->$d(), '1'); + +$x = $mbr->new('123a4'); +is($x, 'NaN'); +is($x->$n(), 'NaN'); +is($x->$d(), 'NaN'); + +# wrong inputs +$x = $mbr->new('1e2e2'); +is($x, 'NaN'); +is($x->$n(), 'NaN'); +is($x->$d(), 'NaN'); + +$x = $mbr->new('1+2+2'); +is($x, 'NaN'); +is($x->$n(), 'NaN'); +is($x->$d(), 'NaN'); + +# failed due to BigFloat bug +$x = $mbr->new('1.2.2'); +is($x, 'NaN'); +is($x->$n(), 'NaN'); +is($x->$d(), 'NaN'); + +is($mbr->new('123a4'), 'NaN'); +is($mbr->new('123e4'), '1230000'); +is($mbr->new('-NaN'), 'NaN'); +is($mbr->new('NaN'), 'NaN'); +is($mbr->new('+inf'), 'inf'); +is($mbr->new('-inf'), '-inf'); + +############################################################################## +# two Bigints + +is($mbr->new($mbi->new(3), $mbi->new(7))->badd(1), '10/7'); +is($mbr->new($mbi->new(-13), $mbi->new(7)), '-13/7'); +is($mbr->new($mbi->new(13), $mbi->new(-7)), '-13/7'); +is($mbr->new($mbi->new(-13), $mbi->new(-7)), '13/7'); + +############################################################################## +# mixed arguments + +is($mbr->new('3/7')->badd(1), '10/7'); +is($mbr->new('3/10')->badd(1.1), '7/5'); +is($mbr->new('3/7')->badd($mbi->new(1)), '10/7'); +is($mbr->new('3/10')->badd($mbf->new('1.1')), '7/5'); + +is($mbr->new('3/7')->bsub(1), '-4/7'); +is($mbr->new('3/10')->bsub(1.1), '-4/5'); +is($mbr->new('3/7')->bsub($mbi->new(1)), '-4/7'); +is($mbr->new('3/10')->bsub($mbf->new('1.1')), '-4/5'); + +is($mbr->new('3/7')->bmul(1), '3/7'); +is($mbr->new('3/10')->bmul(1.1), '33/100'); +is($mbr->new('3/7')->bmul($mbi->new(1)), '3/7'); +is($mbr->new('3/10')->bmul($mbf->new('1.1')), '33/100'); + +is($mbr->new('3/7')->bdiv(1), '3/7'); +is($mbr->new('3/10')->bdiv(1.1), '3/11'); +is($mbr->new('3/7')->bdiv($mbi->new(1)), '3/7'); +is($mbr->new('3/10')->bdiv($mbf->new('1.1')), '3/11'); + +############################################################################## +$x = $mbr->new('1/4'); +$y = $mbr->new('1/3'); + +is($x + $y, '7/12'); +is($x * $y, '1/12'); +is($x / $y, '3/4'); + +$x = $mbr->new('7/5'); +$x *= '3/2'; +is($x, '21/10'); +$x -= '0.1'; +is($x, '2'); # not 21/10 + +$x = $mbr->new('2/3'); +$y = $mbr->new('3/2'); +is($x > $y, ''); +is($x < $y, 1); +is($x == $y, ''); + +$x = $mbr->new('-2/3'); +$y = $mbr->new('3/2'); +is($x > $y, ''); +is($x < $y, '1'); +is($x == $y, ''); + +$x = $mbr->new('-2/3'); +$y = $mbr->new('-2/3'); +is($x > $y, ''); +is($x < $y, ''); +is($x == $y, '1'); + +$x = $mbr->new('-2/3'); +$y = $mbr->new('-1/3'); +is($x > $y, ''); +is($x < $y, '1'); +is($x == $y, ''); + +$x = $mbr->new('-124'); +$y = $mbr->new('-122'); +is($x->bacmp($y), 1); + +$x = $mbr->new('-124'); +$y = $mbr->new('-122'); +is($x->bcmp($y), -1); + +$x = $mbr->new('3/7'); +$y = $mbr->new('5/7'); +is($x+$y, '8/7'); + +$x = $mbr->new('3/7'); +$y = $mbr->new('5/7'); +is($x*$y, '15/49'); + +$x = $mbr->new('3/5'); +$y = $mbr->new('5/7'); +is($x*$y, '3/7'); + +$x = $mbr->new('3/5'); +$y = $mbr->new('5/7'); +is($x/$y, '21/25'); + +$x = $mbr->new('7/4'); +$y = $mbr->new('1'); +is($x % $y, '3/4'); + +$x = $mbr->new('7/4'); +$y = $mbr->new('5/13'); +is($x % $y, '11/52'); + +$x = $mbr->new('7/4'); +$y = $mbr->new('5/9'); +is($x % $y, '1/12'); + +$x = $mbr->new('-144/9')->bsqrt(); +is($x, 'NaN'); + +$x = $mbr->new('144/9')->bsqrt(); +is($x, '4'); + +$x = $mbr->new('3/4')->bsqrt(); +is($x, + '4330127018922193233818615853764680917357/' . + '5000000000000000000000000000000000000000'); + +############################################################################## +# bpow + +$x = $mbr->new('2/1'); +$z = $x->bpow('3/1'); +is($x, '8'); + +$x = $mbr->new('1/2'); +$z = $x->bpow('3/1'); +is($x, '1/8'); + +$x = $mbr->new('1/3'); +$z = $x->bpow('4/1'); +is($x, '1/81'); + +$x = $mbr->new('2/3'); +$z = $x->bpow('4/1'); +is($x, '16/81'); + +$x = $mbr->new('2/3'); +$z = $x->bpow('5/3'); +is($x, '31797617848703662994667839220546583581/62500000000000000000000000000000000000'); + +############################################################################## +# bfac + +$x = $mbr->new('1'); +$x->bfac(); +is($x, '1'); + +for (my $i = 0; $i < 8; $i++) { + $x = $mbr->new("$i/1")->bfac(); + is($x, $mbi->new($i)->bfac()); +} + +# test for $self->bnan() vs. $x->bnan(); +$x = $mbr->new('-1'); +$x->bfac(); +is($x, 'NaN'); + +############################################################################## +# binc/bdec + +note("binc()"); +$x = $mbr->new('3/2'); +is($x->binc(), '5/2'); + +note("bdec()"); + +$x = $mbr->new('15/6'); +is($x->bdec(), '3/2'); + +############################################################################## +# bfloor + +note("bfloor()"); +$x = $mbr->new('-7/7'); +is($x->$n(), '-1'); +is($x->$d(), '1'); +$x = $mbr->new('-7/7')->bfloor(); +is($x->$n(), '-1'); +is($x->$d(), '1'); + +############################################################################## +# bsstr + +$x = $mbr->new('7/5')->bsstr(); +is($x, '7/5'); +$x = $mbr->new('-7/5')->bsstr(); +is($x, '-7/5'); + +############################################################################## + +note("numify()"); + +my @array = qw/1 2 3 4 5 6 7 8 9/; +$x = $mbr->new('8/8'); +is($array[$x], 2); + +$x = $mbr->new('16/8'); +is($array[$x], 3); + +$x = $mbr->new('17/8'); +is($array[$x], 3); + +$x = $mbr->new('33/8'); +is($array[$x], 5); + +$x = $mbr->new('-33/8'); +is($array[$x], 6); + +$x = $mbr->new('-8/1'); +is($array[$x], 2); # -8 => 2 + +require Math::Complex; + +my $inf = $Math::Complex::Inf; +my $nan = $inf - $inf; + +sub isnumeric { + my $value = shift; + ($value ^ $value) eq "0"; +} + +subtest qq|$mbr -> new("33/8") -> numify()| => sub { + plan tests => 3; + + $x = $mbr -> new("33/8") -> numify(); + is(ref($x), "", '$x is a scalar'); + ok(isnumeric($x), '$x is numeric'); + cmp_ok($x, "==", 4.125, '$x has the right value'); +}; + +subtest qq|$mbr -> new("-33/8") -> numify()| => sub { + plan tests => 3; + + $x = $mbr -> new("-33/8") -> numify(); + is(ref($x), "", '$x is a scalar'); + ok(isnumeric($x), '$x is numeric'); + cmp_ok($x, "==", -4.125, '$x has the right value'); +}; + +subtest qq|$mbr -> new("inf") -> numify()| => sub { + plan tests => 3; + + $x = $mbr -> new("inf") -> numify(); + is(ref($x), "", '$x is a scalar'); + ok(isnumeric($x), '$x is numeric'); + cmp_ok($x, "==", $inf, '$x has the right value'); +}; + +subtest qq|$mbr -> new("-inf") -> numify()| => sub { + plan tests => 3; + + $x = $mbr -> new("-inf") -> numify(); + is(ref($x), "", '$x is a scalar'); + ok(isnumeric($x), '$x is numeric'); + cmp_ok($x, "==", -$inf, '$x has the right value'); +}; + +subtest qq|$mbr -> new("NaN") -> numify()| => sub { + plan tests => 3; + + $x = $mbr -> new("NaN") -> numify(); + is(ref($x), "", '$x is a scalar'); + ok(isnumeric($x), '$x is numeric'); + cmp_ok($x, "!=", $nan, '$x has the right value'); # Note: NaN != NaN +}; + +############################################################################## +# as_hex(), as_bin(), as_oct() + +note("as_hex(), as_bin(), as_oct()"); + +$x = $mbr->new('8/8'); +is($x->as_hex(), '0x1'); +is($x->as_bin(), '0b1'); +is($x->as_oct(), '01'); + +$x = $mbr->new('80/8'); +is($x->as_hex(), '0xa'); +is($x->as_bin(), '0b1010'); +is($x->as_oct(), '012'); + +############################################################################## +# broot(), blog(), bmodpow() and bmodinv() + +note("broot(), blog(), bmodpow(), bmodinv()"); + +$x = $mbr->new(2) ** 32; +$y = $mbr->new(4); +$z = $mbr->new(3); + +is($x->copy()->broot($y), 2 ** 8); +is(ref($x->copy()->broot($y)), $mbr, "\$x is a $mbr"); + +is($x->copy()->bmodpow($y, $z), 1); +is(ref($x->copy()->bmodpow($y, $z)), $mbr, "\$x is a $mbr"); + +$x = $mbr->new(8); +$y = $mbr->new(5033); +$z = $mbr->new(4404); + +is($x->copy()->bmodinv($y), $z); +is(ref($x->copy()->bmodinv($y)), $mbr, "\$x is a $mbr"); + +# square root with exact result +$x = $mbr->new('1.44'); +is($x->copy()->broot(2), '6/5'); +is(ref($x->copy()->broot(2)), $mbr, "\$x is a $mbr"); + +# log with exact result +$x = $mbr->new('256.1'); +is($x->copy()->blog(2), + '8000563442710106079310294693803606983661/1000000000000000000000000000000000000000', + "\$x = $mbr->new('256.1')->blog(2)"); +is(ref($x->copy()->blog(2)), $mbr, "\$x is a $mbr"); + +$x = $mbr->new(144); +is($x->copy()->broot('2'), 12, 'v/144 = 12'); + +$x = $mbr->new(12*12*12); +is($x->copy()->broot('3'), 12, '(12*12*12) ** 1/3 = 12'); + +############################################################################## +# from_hex(), from_bin(), from_oct() + +note("from_hex(), from_bin(), from_oct()"); + +$x = Math::BigRat->from_hex('0x100'); +is($x, '256', 'from_hex'); + +$x = $mbr->from_hex('0x100'); +is($x, '256', 'from_hex'); + +$x = Math::BigRat->from_bin('0b100'); +is($x, '4', 'from_bin'); + +$x = $mbr->from_bin('0b100'); +is($x, '4', 'from_bin'); + +$x = Math::BigRat->from_oct('0100'); +is($x, '64', 'from_oct'); + +$x = $mbr->from_oct('0100'); +is($x, '64', 'from_oct'); + +############################################################################## +# as_float() + +$x = Math::BigRat->new('1/2'); +my $f = $x->as_float(); + +is($x, '1/2', '$x unmodified'); +is($f, '0.5', 'as_float(0.5)'); + +$x = Math::BigRat->new('2/3'); +$f = $x->as_float(5); + +is($x, '2/3', '$x unmodified'); +is($f, '0.66667', 'as_float(2/3, 5)'); + +# Integers should be converted exactly. +$x = Math::BigRat->new("3141592653589793238462643383279502884197169399375106"); +$f = $x->as_float(); + +is($x, "3141592653589793238462643383279502884197169399375106", '$x unmodified'); +is($f, "3141592653589793238462643383279502884197169399375106", + 'as_float(3141592653589793238462643383279502884197169399375106, 5)'); + +############################################################################## +# int() + +$x = Math::BigRat->new('5/2'); +is(int($x), '2', '5/2 converted to integer'); + +$x = Math::BigRat->new('-1/2'); +is(int($x), '0', '-1/2 converted to integer'); + +############################################################################## +# done + +1; Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/bigratpm.inc =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/bigratpm.inc diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/bigratpm.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/bigratpm.inc 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,1226 @@ +#include this file into another test for subclass testing... + +use strict; +use warnings; + +our ($CLASS, $try, $x, $y, $z, $f, @args, $want, $got, $setup, $LIB); + +is($CLASS->config()->{lib}, $LIB); + +$setup = ''; + +while () { + s/#.*$//; # remove comments + s/\s+$//; # remove trailing whitespace + next unless length; # skip empty lines + + if (s/^&//) { + $f = $_; + next; + } + + if (/^\$/) { + $setup = $_; + $setup =~ s/\$/\$${CLASS}::/g; # round_mode, div_scale + #print "\$setup== $setup\n"; + next; + } + + if (m|^(.*?):(/.+)$|) { + $want = $2; + @args = split(/:/, $1, 99); + } else { + @args = split(/:/, $_, 99); + $want = pop(@args); + } + + $try = qq|\$x = $CLASS->new("$args[0]");|; + if ($f eq "bnorm") { + $try .= " \$x;"; + } elsif ($f eq "finf") { + my $a = $args[1] || ''; + $try .= qq| \$x->binf("$a");|; + } elsif ($f eq "fone") { + $try .= qq| \$x->bone("$args[1]");|; + } elsif ($f eq "fstr") { + $try .= " \$x->accuracy($args[1]); \$x->precision($args[2]);"; + $try .= ' $x->bstr();'; + } elsif ($f eq "parts") { + # ->bstr() to see if an object is returned + $try .= ' ($a,$b) = $x->parts(); $a = $a->bstr(); $b = $b->bstr();'; + $try .= ' "$a $b";'; + } elsif ($f eq "numerator") { + # ->bstr() to see if an object is returned + $try .= ' $x->numerator()->bstr();'; + } elsif ($f eq "denominator") { + # ->bstr() to see if an object is returned + $try .= ' $x->denominator()->bstr();'; + } elsif ($f =~ /^(length|numify)$/) { + $try .= " \$x->$f();"; + # some unary ops (can't test the fxxx form, since no AUTOLOAD in BigRat) + } elsif ($f =~ /^f(nan|sstr|neg|floor|ceil|abs)$/) { + $try .= " \$x->b$1();"; + # overloaded functions + } elsif ($f =~ /^(log|exp|sin|cos|atan2|int|neg|abs|sqrt)$/) { + $try .= " \$x = $f(\$x);"; + # some is_xxx test function + } elsif ($f =~ /^is_(zero|pos|neg|negative|positive|odd|even|nan|int)\z/) { + $try .= " \$x->$f();"; + } elsif ($f =~ /^is_(one|inf)$/) { + $try .= @args == 1 ? qq| \$x->$f();| + : qq| \$x->$f("$args[1]");|; + } elsif ($f =~ /^(as_number|as_int)\z/) { + $try .= " \$x->$1();"; + } elsif ($f eq "finc") { + $try .= ' ++$x;'; + } elsif ($f eq "fdec") { + $try .= ' --$x;'; + } elsif ($f eq "digit") { + $try .= " \$x->digit($args[1]);"; + } elsif ($f eq "fround") { + $try .= " $setup; \$x->bround($args[1]);"; + } elsif ($f eq "ffround") { + $try .= " $setup; \$x->bfround($args[1]);"; + } elsif ($f eq "fsqrt") { + $try .= " $setup; \$x->bsqrt();"; + } elsif ($f eq "flog") { + $try .= " $setup; \$x->blog();"; + } elsif ($f eq "ffac") { + $try .= " $setup; \$x->bfac();"; + } else { + $try .= qq| \$y = $CLASS->new("$args[1]");|; + if ($f eq "bcmp") { + $try .= ' $x <=> $y;'; + } elsif ($f eq "bacmp") { + $try .= ' $x->bacmp($y);'; + } elsif ($f eq "bpow") { + $try .= ' $x->bpow($y);'; + } elsif ($f eq "badd") { + $try .= ' $x + $y;'; + } elsif ($f eq "bsub") { + $try .= ' $x - $y;'; + } elsif ($f eq "bmul") { + $try .= ' $x * $y;'; + } elsif ($f eq "bdiv") { + $try .= " $setup; \$x / \$y;"; + } elsif ($f eq "bdiv-list") { + $try .= qq| $setup; join(",", \$x->bdiv(\$y));|; + } elsif ($f eq "brsft") { + $try .= ' $x >> $y;'; + } elsif ($f eq "blsft") { + $try .= ' $x << $y;'; + } elsif ($f eq "bmod") { + $try .= ' $x % $y;'; + } elsif ($f eq "bmodinv") { + $try .= " \$x->bmodinv(\$y);"; + } elsif ($f eq "blog") { + $try .= " \$x->blog(\$y);"; + } else { + $try .= qq| \$z = $CLASS->new("$args[2]");|; + + # Functions with three arguments + if ($f eq "bmodpow") { + $try .= " \$x->bmodpow(\$y, \$z);"; + } else { + warn "Unknown op '$f'"; + } + } + } + # print "# Trying: '$try'\n"; + $got = eval $try; + if ($want =~ m|^/(.*)$|) { + my $pat = $1; + like($got, qr/$pat/, $try); + } else { + if ($want eq "") { + is($got, undef, $try); + } else { + is($got, $want, $try); + #if (ref($got) eq "$CLASS") { + # # float numbers are normalized (for now), so mantissa shouldn't have + # # trailing zeros + # #print $got->_trailing_zeros(), "\n"; + # print "# Has trailing zeros after '$try'\n" + # if !is($got->{_m}->_trailing_zeros(), 0); + #} + } + } # end pattern or string +} # end while + +# check whether $CLASS->new(Math::BigInt->new()) destroys it +# ($y == 12 in this case) +$x = Math::BigInt->new(1200); +$y = $CLASS->new($x); +is($y, 1200, qq|\$x = Math::BigInt->new(1200); \$y = $CLASS->new(\$x); $y|); +is($x, 1200, qq|\$x = Math::BigInt->new(1200); \$y = $CLASS->new(\$x); $x|); + +############################################################################### +# zero, inf, one, nan + +$x = $CLASS->new(2); +$x->bzero(); +is($x->{accuracy}, undef, qq|\$x = $CLASS->new(2); \$x->bzero(); \$x->{accuracy}|); +is($x->{precision}, undef, qq|\$x = $CLASS->new(2); \$x->bzero(); \$x->{precision}|); + +$x = $CLASS->new(2); +$x->binf(); +is($x->{accuracy}, undef, qq|\$x = $CLASS->new(2); \$x->binf(); \$x->{accuracy}|); +is($x->{precision}, undef, qq|\$x = $CLASS->new(2); \$x->binf(); \$x->{precision}|); + +$x = $CLASS->new(2); +$x->bone(); +is($x->{accuracy}, undef, qq|\$x = $CLASS->new(2); \$x->bone(); \$x->{accuracy}|); +is($x->{precision}, undef, qq|\$x = $CLASS->new(2); \$x->bone(); \$x->{precision}|); + +$x = $CLASS->new(2); +$x->bnan(); +is($x->{accuracy}, undef, qq|\$x = $CLASS->new(2); \$x->bnan(); \$x->{accuracy}|); +is($x->{precision}, undef, qq|\$x = $CLASS->new(2); \$x->bnan(); \$x->{precision}|); + +__DATA__ + +&digit +123:2:1 +1234:0:4 +1234:1:3 +1234:2:2 +1234:3:1 +1234:-1:1 +1234:-2:2 +1234:-3:3 +1234:-4:4 +0:0:0 +0:1:0 + +&bmodinv +# format: number:modulus:result +# bmodinv Data errors +abc:abc:NaN +abc:5:NaN +5:abc:NaN +# bmodinv Expected Results from normal use +1:5:1 +3:5:2 +3:-5:-3 +-2:5:2 +8:5033:4404 +1234567891:13:6 +-1234567891:13:7 +324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902 +## bmodinv Error cases / useless use of function +inf:5:NaN +5:inf:NaN +-inf:5:NaN +5:-inf:NaN + +&as_number +144/7:20 +12/1:12 +-12/1:-12 +-12/3:-4 +NaN:NaN ++inf:inf +-inf:-inf + +&as_int +144/7:20 +12/1:12 +-12/1:-12 +-12/3:-4 +NaN:NaN ++inf:inf +-inf:-inf + +&bmodpow +# format: number:exponent:modulus:result +# bmodpow Data errors +abc:abc:abc:NaN +5:abc:abc:NaN +abc:5:abc:NaN +abc:abc:5:NaN +5:5:abc:NaN +5:abc:5:NaN +abc:5:5:NaN +# bmodpow Expected results +0:0:2:1 +1:0:2:1 +0:0:1:0 +8:7:5032:3840 +8:-1:5033:4404 +8:8:-5:-4 +98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518 +# bmodpow Error cases +8:-1:16:NaN +inf:5:13:NaN +5:inf:13:NaN + +&bmod +NaN:1:NaN +1:NaN:NaN +1:1:0 +2:2:0 +12:6:0 +7/4:4/14:1/28 +7/4:4/16:0 +-7/4:4/16:0 +-7/4:-4/16:0 +7/4:-4/16:0 +7/4:4/32:0 +-7/4:4/32:0 +-7/4:-4/32:0 +7/4:-4/32:0 +7/4:4/28:1/28 +-7/4:4/28:3/28 +7/4:-4/28:-3/28 +-7/4:-4/28:-1/28 + +&fsqrt +1:1 +0:0 +NaN:NaN ++inf:inf +-inf:NaN +144:12 +# sqrt(144) / sqrt(4) = 12/2 = 6/1 +144/4:6 +25/16:5/4 +-3:NaN +4/9:2/3 +36/49:6/7 +49/121:7/11 +999966000289/99999820000081:999983/9999991 + +&flog +NaN:NaN +0:-inf +-2:NaN + +&blog +NaN:NaN:NaN +0:NaN:NaN +NaN:0:NaN +NaN:1:NaN +1:NaN:NaN +0:2:-inf +0:-2:NaN +3:-2:NaN + +&finf +1:+:inf +2:-:-inf +3:abc:inf + +&numify +0:0 ++1:1 +1234:1234 +3/4:0.75 +5/2:2.5 +3/2:1.5 +5/4:1.25 + +&fnan +abc:NaN +2:NaN +-2:NaN +0:NaN + +&fone +2:+:1 +-2:-:-1 +-2:+:1 +2:-:-1 +0::1 +-2::1 +abc::1 +2:abc:1 + +&fsstr ++inf:inf +-inf:-inf +abcfsstr:NaN +1:1 +3/1:3 +0.1:1/10 + +&bnorm +1:1 +-0:0 +bnormNaN:NaN ++inf:inf +-inf:-inf +inf/inf:NaN +5/inf:0 +5/-inf:0 +inf/5:inf +-inf/5:-inf +inf/-5:-inf +-inf/-5:inf +123:123 +-123.4567:-1234567/10000 +#1.E3:NaN +.2E-3.:NaN +#1e3e4:NaN +.2E2:20 +inf:inf ++inf:inf +-inf:-inf ++InFiNiTy:inf ++-inf:NaN +abc:NaN + 1 a:NaN +1bcd2:NaN +11111b:NaN ++1z:NaN +-1z:NaN +0:0 ++0:0 ++00:0 ++0_0_0:0 +000000_0000000_00000:0 +-0:0 +-0000:0 ++1:1 ++01:1 ++001:1 ++00000100000:100000 ++00000800/00000010:80 +-00000800/00000010:-80 ++00000800/-00000010:-80 +-00000800/-00000010:80 +123456789:123456789 +-1:-1 +-01:-1 +-001:-1 +-123456789:-123456789 +-00000100000:-100000 +123.456a:NaN +123.456:15432/125 +0.01:1/100 +.002:1/500 ++.2:1/5 +-0.0003:-3/10000 +-.0000000004:-1/2500000000 +123456E2:12345600 +123456E-2:30864/25 +-123456E2:-12345600 +-123456E-2:-30864/25 +1e1:10 +2e-11:1/50000000000 +12/10:6/5 +0.1/0.1:1 +100/0.1:1000 +0.1/10:1/100 +1 / 3:1/3 +1/ 3:1/3 +1 /3:1/3 + +&fneg +fnegNaN:NaN ++inf:-inf +-inf:inf ++0:0 ++1:-1 +-1:1 ++123456789:-123456789 +-123456789:123456789 ++123.456789:-123456789/1000000 +-123456.789:123456789/1000 +123/7:-123/7 +-123/7:123/7 +123/-7:123/7 + +&fabs +fabsNaN:NaN ++inf:inf +-inf:inf ++0:0 ++1:1 +-1:1 ++123456789:123456789 +-123456789:123456789 ++123.456789:123456789/1000000 +-123456.789:123456789/1000 + +&badd +abc:abc:NaN +abc:+0:NaN ++0:abc:NaN ++inf:-inf:NaN +-inf:+inf:NaN ++inf:+inf:inf +-inf:-inf:-inf +baddNaN:+inf:NaN +baddNaN:+inf:NaN ++inf:baddNaN:NaN +-inf:baddNaN:NaN ++0:+0:0 ++1:+0:1 ++0:+1:1 ++1:+1:2 +-1:+0:-1 ++0:-1:-1 +-1:-1:-2 +-1:+1:0 ++1:-1:0 ++9:+1:10 ++99:+1:100 ++999:+1:1000 ++9999:+1:10000 ++99999:+1:100000 ++999999:+1:1000000 ++9999999:+1:10000000 ++99999999:+1:100000000 ++999999999:+1:1000000000 ++9999999999:+1:10000000000 ++99999999999:+1:100000000000 ++10:-1:9 ++100:-1:99 ++1000:-1:999 ++10000:-1:9999 ++100000:-1:99999 ++1000000:-1:999999 ++10000000:-1:9999999 ++100000000:-1:99999999 ++1000000000:-1:999999999 ++10000000000:-1:9999999999 ++123456789:+987654321:1111111110 +-123456789:+987654321:864197532 +-123456789:-987654321:-1111111110 ++123456789:-987654321:-864197532 +1/3:1/3:2/3 +2/3:-1/3:1/3 + +&bsub +abc:abc:NaN +abc:+0:NaN ++0:abc:NaN ++inf:-inf:inf +-inf:+inf:-inf ++inf:+inf:NaN +-inf:-inf:NaN +baddNaN:+inf:NaN +baddNaN:+inf:NaN ++inf:baddNaN:NaN +-inf:baddNaN:NaN ++0:+0:0 ++1:+0:1 ++0:+1:-1 ++1:+1:0 +-1:+0:-1 ++0:-1:1 +-1:-1:0 +-1:+1:-2 ++1:-1:2 ++9:+1:8 ++99:+1:98 ++999:+1:998 ++9999:+1:9998 ++99999:+1:99998 ++999999:+1:999998 ++9999999:+1:9999998 ++99999999:+1:99999998 ++999999999:+1:999999998 ++9999999999:+1:9999999998 ++99999999999:+1:99999999998 ++10:-1:11 ++100:-1:101 ++1000:-1:1001 ++10000:-1:10001 ++100000:-1:100001 ++1000000:-1:1000001 ++10000000:-1:10000001 ++100000000:-1:100000001 ++1000000000:-1:1000000001 ++10000000000:-1:10000000001 ++123456789:+987654321:-864197532 +-123456789:+987654321:-1111111110 +-123456789:-987654321:864197532 ++123456789:-987654321:1111111110 +2/3:1/3:1/3 +7/27:3/54:11/54 +-2/3:+2/3:-4/3 +-2/3:-2/3:0 +0:-123:123 +0:123:-123 + +&bmul +abc:abc:NaN +abc:+0:NaN ++0:abc:NaN ++inf:NaNmul:NaN ++inf:NaNmul:NaN +NaNmul:+inf:NaN +NaNmul:-inf:NaN ++inf:+inf:inf ++inf:-inf:-inf ++inf:-inf:-inf ++inf:+inf:inf ++inf:123.34:inf ++inf:-123.34:-inf +-inf:123.34:-inf +-inf:-123.34:inf +123.34:+inf:inf +-123.34:+inf:-inf +123.34:-inf:-inf +-123.34:-inf:inf ++0:+0:0 ++0:+1:0 ++1:+0:0 ++0:-1:0 +-1:+0:0 ++123456789123456789:+0:0 ++0:+123456789123456789:0 +-1:-1:1 +-1:+1:-1 ++1:-1:-1 ++1:+1:1 ++2:+3:6 +-2:+3:-6 ++2:-3:-6 +-2:-3:6 ++111:+111:12321 ++10101:+10101:102030201 ++1001001:+1001001:1002003002001 ++100010001:+100010001:10002000300020001 ++10000100001:+10000100001:100002000030000200001 ++11111111111:+9:99999999999 ++22222222222:+9:199999999998 ++33333333333:+9:299999999997 ++44444444444:+9:399999999996 ++55555555555:+9:499999999995 ++66666666666:+9:599999999994 ++77777777777:+9:699999999993 ++88888888888:+9:799999999992 ++99999999999:+9:899999999991 +6:120:720 +10:10000:100000 +1/4:1/3:1/12 + +&bdiv-list +0:0:NaN,0 +0:1:0,0 +1:0:inf,1 +-1:0:-inf,-1 +9:4:2,1 +-9:4:-3,3 +9:-4:-3,-3 +-9:-4:2,-1 +11/7:2/3:2,5/21 +-11/7:2/3:-3,3/7 + +&bdiv +$div_scale = 40; $round_mode = "even" +abc:abc:NaN +abc:+1:abc:NaN ++1:abc:NaN +-1:abc:NaN +0:abc:NaN ++0:+0:NaN ++0:+1:0 ++1:+0:inf ++3214:+0:inf ++0:-1:0 +-1:+0:-inf +-3214:+0:-inf ++1:+1:1 +-1:-1:1 ++1:-1:-1 +-1:+1:-1 ++1:+2:1/2 ++2:+1:2 +123:+inf:0 +123:-inf:0 ++10:+5:2 ++100:+4:25 ++1000:+8:125 ++10000:+16:625 ++10000:-16:-625 ++999999999999:+9:111111111111 ++999999999999:+99:10101010101 ++999999999999:+999:1001001001 ++999999999999:+9999:100010001 ++999999999999999:+99999:10000100001 ++1000000000:+9:1000000000/9 ++2000000000:+9:2000000000/9 ++3000000000:+9:1000000000/3 ++4000000000:+9:4000000000/9 ++5000000000:+9:5000000000/9 ++6000000000:+9:2000000000/3 ++7000000000:+9:7000000000/9 ++8000000000:+9:8000000000/9 ++9000000000:+9:1000000000 ++35500000:+113:35500000/113 ++71000000:+226:35500000/113 ++106500000:+339:35500000/113 ++1000000000:+3:1000000000/3 +2:25.024996000799840031993601279744051189762:1000000000000000000000000000000000000000/12512498000399920015996800639872025594881 +123456:1:123456 +1/4:1/3:3/4 +# reset scale for further tests +$div_scale = 40 + +&is_nan +123:0 +abc:1 +NaN:1 +-123:0 + +&is_inf +# without sign argument +abc:0 +NaN:0 ++inf:1 +-inf:1 +-1:0 +0:0 +1:0 +# with sign argument "+" +abc:+:0 +NaN:+:0 ++inf:+:1 +-inf:+:0 +-1:+:0 +0:+:0 +1:+:0 +# with sign argument "-" +abc:-:0 +NaN:-:0 ++inf:-:0 +-inf:-:1 +-1:-:0 +0:-:0 +1:-:0 ++infinity:1 +-infinity:1 + +&is_odd +abc:0 +0:0 +-1:1 +-3:1 +1:1 +3:1 +1000001:1 +1000002:0 ++inf:0 +-inf:0 +123.45:0 +-123.45:0 +2:0 + +&is_int +NaNis_int:0 +0:1 +1:1 +2:1 +-2:1 +-1:1 +-inf:0 ++inf:0 +123.4567:0 +-0.1:0 +-0.002:0 +1/3:0 +3/1:1 + +&is_even +abc:0 +0:1 +-1:0 +-3:0 +1:0 +3:0 +1000001:0 +1000002:1 +2:1 ++inf:0 +-inf:0 +123.456:0 +-123.456:0 +0.01:0 +-0.01:0 +120:1 +1200:1 +-1200:1 + +&is_pos +0:0 +1:1 +-1:0 +-123:0 +NaN:0 +-inf:0 ++inf:1 + +&is_positive +0:0 +1:1 +-1:0 +-123:0 +NaN:0 +-inf:0 ++inf:1 + +&is_neg +0:0 +1:0 +-1:1 +-123:1 +NaN:0 +-inf:1 ++inf:0 + +&is_negative +0:0 +1:0 +-1:1 +-123:1 +NaN:0 +-inf:1 ++inf:0 + +&parts +0:0 1 +1:1 1 +123:123 1 +-123:-123 1 +-1200:-1200 1 +5/7:5 7 +-5/7:-5 7 +NaNparts:NaN NaN ++inf:inf inf +-inf:-inf inf + +&length +123:3 +-123:3 +0:1 +1:1 +12345678901234567890:20 + +&is_zero +NaNzero:0 ++inf:0 +-inf:0 +0:1 +-1:0 +1:0 +0/3:1 +1/3:0 +-0/3:1 +5/inf:1 + +&is_one +# with no sign argument +invalid:0 +NaN:0 ++inf:0 +-inf:0 +-2:0 +-1:0 +0:0 +1:1 +-2:0 +# with sign argument "+" +invalid:+:0 +NaN:+:0 ++inf:+:0 +-inf:+:0 +-2:+:0 +-1:+:0 +0:+:0 +1:+:1 +-2:+:0 +# with sign argument "-" +invalid:-:0 +NaN:-:0 ++inf:-:0 +-inf:-:0 +-2:-:0 +-1:-:1 +0:-:0 +1:-:0 +-2:-:0 +1/3:0 +100/100:1 +0.1/0.1:1 +5/inf:0 + +&ffloor +0:0 +abc:NaN ++inf:inf +-inf:-inf +1:1 +-51:-51 +-51.2:-52 +12.2:12 +3/7:0 +6/7:0 +7/7:1 +8/7:1 +13/7:1 +14/7:2 +15/7:2 +-3/7:-1 +-6/7:-1 +-7/1:-7 +-8/7:-2 +-13/7:-2 +-14/7:-2 +-15/7:-3 + +&fceil +0:0 +abc:NaN ++inf:inf +-inf:-inf +1:1 +-51:-51 +-51.2:-51 +12.2:13 +3/7:1 +6/7:1 +8/7:2 +13/7:2 +14/7:2 +15/7:3 +-3/7:0 +-6/7:0 +-8/7:-1 +-13/7:-1 +-14/7:-2 +-15/7:-2 + +&ffac +NaN:NaN +1:1 +-1:NaN + +&bpow +# +abc:123:NaN +123:abc:NaN +# +-inf:-inf:0 +-inf:-3:0 +-inf:-2:0 +-inf:-3/2:0 +-inf:-1:0 +-inf:-1/2:0 +-inf:0:NaN +-inf:1/2:inf # directed infinity +-inf:1:-inf +-inf:3/2:inf # directed infinity +-inf:2:inf +-inf:3:-inf +-inf:inf:inf # complex infinity +-inf:NaN:NaN +# +-3:-inf:0 +-3:-3:-1/27 +-3:-2:1/9 +-3:-3/2:NaN +-3:-1:-1/3 +-3:-1/2:NaN +-3:0:1 +-3:1/2:NaN +-3:1:-3 +-3:3/2:NaN +-3:2:9 +-3:3:-27 +-3:inf:inf # complex infinity +-3:NaN:NaN +# +-2:-inf:0 +-2:-3:-1/8 +-2:-2:1/4 +-2:-3/2:NaN +-2:-1:-1/2 +-2:-1/2:NaN +-2:0:1 +-2:1/2:NaN +-2:1:-2 +-2:3/2:NaN +-2:2:4 +-2:3:-8 +-2:inf:inf # complex infinity +-2:NaN:NaN +# +-3/2:-inf:0 +-3/2:-3:-8/27 +-3/2:-2:4/9 +-3/2:-3/2:NaN +-3/2:-1:-2/3 +-3/2:-1/2:NaN +-3/2:0:1 +-3/2:1/2:NaN +-3/2:1:-3/2 +-3/2:3/2:NaN +-3/2:2:9/4 +-3/2:3:-27/8 +-3/2:inf:inf # complex infinity +-3/2:NaN:NaN +# +-1:-inf:NaN +-1:-3:-1 +-1:-2:1 +-1:-3/2:NaN +-1:-1:-1 +-1:-1/2:NaN +-1:0:1 +-1:1/2:NaN +-1:1:-1 +-1:3/2:NaN +-1:2:1 +-1:3:-1 +-1:inf:NaN +-1:NaN:NaN +# +-1/2:-inf:inf # complex infinity +-1/2:-3:-8 +-1/2:-2:4 +-1/2:-3/2:NaN +-1/2:-1:-2 +-1/2:-1/2:NaN +-1/2:0:1 +-1/2:1/2:NaN +-1/2:1:-1/2 +-1/2:3/2:NaN +-1/2:2:1/4 +-1/2:3:-1/8 +-1/2:inf:0 +-1/2:NaN:NaN +# +0:-inf:inf # complex infinity +0:-3:inf # complex infinity +0:-2:inf # complex infinity +0:-3/2:inf # complex infinity +0:-1:inf # complex infinity +0:-1/2:inf # complex infinity +0:0:1 +0:1/2:0 +0:1:0 +0:3/2:0 +0:2:0 +0:3:0 +0:inf:0 +0:NaN:NaN +# +1/2:-inf:inf +1/2:-3:8 +1/2:-2:4 +#1/2:-3/2:2.828427124746190097603377448419396157139 +1/2:-1:2 +#1/2:-1/2:1.41421356237309504880168872420969807857 +1/2:0:1 +#1/2:1/2:0.7071067811865475244008443621048490392848 +1/2:1:1/2 +#1/2:3/2:0.3535533905932737622004221810524245196424 +1/2:2:1/4 +1/2:3:1/8 +1/2:inf:0 +1/2:NaN:NaN +# +1:-inf:1 +1:-3:1 +1:-2:1 +1:-3/2:1 +1:-1:1 +1:-1/2:1 +1:0:1 +1:1/2:1 +1:1:1 +1:3/2:1 +1:2:1 +1:3:1 +1:inf:1 +1:NaN:NaN +# +3/2:-inf:0 +3/2:-3:8/27 +3/2:-2:4/9 +#3/2:-3/2:0.5443310539518173551549520166013091982147 +3/2:-1:2/3 +#3/2:-1/2:0.816496580927726032732428024901963797322 +3/2:0:1 +#3/2:1/2:1.224744871391589049098642037352945695983 +3/2:1:3/2 +#3/2:3/2:1.837117307087383573647963056029418543974 +3/2:2:9/4 +3/2:3:27/8 +3/2:inf:inf +3/2:NaN:NaN +# +2:-inf:0 +2:-3:1/8 +2:-2:1/4 +#2:-3/2:0.3535533905932737622004221810524245196424 +2:-1:1/2 +#2:-1/2:0.7071067811865475244008443621048490392848 +2:0:1 +#2:1/2:1.41421356237309504880168872420969807857 +2:1:2 +#2:3/2:2.828427124746190097603377448419396157139 +2:2:4 +2:3:8 +2:inf:inf +2:NaN:NaN +# +3:-inf:0 +3:-3:1/27 +3:-2:1/9 +#3:-3/2:0.1924500897298752548363829268339858185492 +3:-1:1/3 +#3:-1/2:0.5773502691896257645091487805019574556476 +3:0:1 +#3:1/2:1.732050807568877293527446341505872366943 +3:1:3 +#3:3/2:5.196152422706631880582339024517617100828 +3:2:9 +3:3:27 +3:inf:inf +3:NaN:NaN +# +inf:-inf:0 +inf:-3:0 +inf:-2:0 +inf:-3/2:0 +inf:-1:0 +inf:-1/2:0 +inf:0:NaN +inf:1/2:inf +inf:1:inf +inf:3/2:inf +inf:2:inf +inf:3:inf +inf:inf:inf +inf:NaN:NaN +# +NaN:-inf:NaN +NaN:-3:NaN +NaN:-2:NaN +NaN:-3/2:NaN +NaN:-1:NaN +NaN:-1/2:NaN +NaN:0:NaN +NaN:1/2:NaN +NaN:1:NaN +NaN:3/2:NaN +NaN:2:NaN +NaN:3:NaN +NaN:inf:NaN +NaN:NaN:NaN + +&bacmp ++0:-0:0 ++0:+1:-1 +-1:+1:0 ++1:-1:0 +-1:+2:-1 ++2:-1:1 +-123456789:+987654321:-1 ++123456789:-987654321:-1 ++987654321:+123456789:1 +-987654321:+123456789:1 +-123:+4567889:-1 +# NaNs +acmpNaN:123: +123:acmpNaN: +acmpNaN:acmpNaN: +# infinity ++inf:+inf:0 +-inf:-inf:0 ++inf:-inf:0 +-inf:+inf:0 ++inf:123:1 +-inf:123:1 ++inf:-123:1 +-inf:-123:1 ++inf:1/23:1 +-inf:1/23:1 ++inf:-1/23:1 +-inf:-1/23:1 ++inf:12/3:1 +-inf:12/3:1 ++inf:-12/3:1 +-inf:-12/3:1 +123:inf:-1 +-123:inf:-1 +123:-inf:-1 +-123:-inf:-1 +1/23:inf:-1 +-1/23:inf:-1 +1/23:-inf:-1 +-1/23:-inf:-1 +12/3:inf:-1 +-12/3:inf:-1 +12/3:-inf:-1 +-12/3:-inf:-1 +# return undef ++inf:NaN: +NaN:inf: +-inf:NaN: +NaN:-inf: +1/3:2/3:-1 +2/3:1/3:1 +2/3:2/3:0 + +&numerator +NaN:NaN +inf:inf +-inf:-inf +3/7:3 +-3/7:-3 +0:0 +1:1 +5/-3:-5 + +&denominator +NaN:NaN +inf:1 +-inf:1 +3/7:7 +0:1 +1/1:1 +-1/1:1 +-3/7:7 +4/-5:5 + +&finc +3/2:5/2 +-15/6:-3/2 +NaN:NaN +-1/3:2/3 +-2/7:5/7 + +&fdec +15/6:3/2 +-3/2:-5/2 +1/3:-2/3 +2/7:-5/7 +NaN:NaN + +&log +-1:NaN +0:-inf +1:0 +34803:3267955896544848894312057422508991/312500000000000000000000000000000 +-inf:inf +inf:inf +NaN:NaN + +&exp + +&sin + +&cos + +&atan2 + +&int + +&abs + +&sqrt Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/bigratpm.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/bigratpm.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/bigratpm.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/bigratpm.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,14 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use Test::More tests => 899; + +use Math::BigRat lib => 'Calc'; + +our ($CLASS, $LIB); +$CLASS = "Math::BigRat"; +$LIB = "Math::BigInt::Calc"; # backend + +require './t/bigratpm.inc'; # all tests here for sharing Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/bigratup.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/bigratup.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/bigratup.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/bigratup.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,41 @@ +# -*- mode: perl; -*- + +# Test whether $Math::BigInt::upgrade breaks our neck + +use strict; +use warnings; + +use Test::More tests => 5; + +use Math::BigInt upgrade => 'Math::BigRat'; +use Math::BigRat; + +my $rat = 'Math::BigRat'; +my($x, $y, $z); + +############################################################################## +# bceil/bfloor + +$x = $rat->new('49/4'); +is($x->bfloor(), '12', 'floor(49/4)'); + +$x = $rat->new('49/4'); +is($x->bceil(), '13', 'ceil(49/4)'); + +############################################################################## +# bsqrt + +$x = $rat->new('144'); +is($x->bsqrt(), '12', 'bsqrt(144)'); + +$x = $rat->new('144/16'); +is($x->bsqrt(), '3', 'bsqrt(144/16)'); + +$x = $rat->new('1/3'); +is($x->bsqrt(), + '1443375672974064411272871951254893639119/2500000000000000000000000000000000000000', + 'bsqrt(1/3)'); + +# all tests successful + +1; Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/bitwise-mbr.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/bitwise-mbr.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/bitwise-mbr.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/bitwise-mbr.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,42 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use Test::More tests => 2602; + +my @classes = ('Math::BigRat'); + +# We should test all the following operators: +# +# & | ^ << >> &= |= ^= <<= >>= +# +# as well as the corresponding methods +# +# band bior bxor blsft brsft + +for my $class (@classes) { + use_ok($class); + + for my $op (qw( & | ^ )) { + for (my $xscalar = 0 ; $xscalar <= 8 ; $xscalar += 0.5) { + for (my $yscalar = 0 ; $yscalar <= 8 ; $yscalar += 0.5) { + + my $xint = int $xscalar; + my $yint = int $yscalar; + + my $x = $class -> new("$xscalar"); + my $y = $class -> new("$yscalar"); + + my $test = "$x $op $y"; + my $expected = eval "$xscalar $op $yscalar"; + my $got = eval "\$x $op \$y"; + + is($@, '', 'is $@ empty'); + isa_ok($got, $class, $test); + is($got, $expected, + "$x $op $y = $xint $op $yint = $expected"); + } + } + } +} Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/config.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/config.t,v diff -u -p -a -u -p -r1.5 config.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/config.t 15 Feb 2023 01:36:20 -0000 1.5 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/config.t 22 Jan 2025 00:37:42 -0000 @@ -3,148 +3,236 @@ use strict; use warnings; -use Test::More tests => 72; +use Test::More tests => 126; -# test whether Math::BigInt->config() and Math::BigFloat->config() work +# Test Math::BigInt->config(), Math::BigFloat->config(), and +# Math::BigRat->config(). use Math::BigInt lib => 'Calc'; use Math::BigFloat; +use Math::BigRat; my $mbi = 'Math::BigInt'; my $mbf = 'Math::BigFloat'; +my $mbr = 'Math::BigRat'; -my @defaults = - ([ 'lib', 'Math::BigInt::Calc' ], - [ 'lib_version', $Math::BigInt::Calc::VERSION, ], - [ 'upgrade', undef, ], - [ 'div_scale', 40, ], - [ 'precision', undef, ], - [ 'accuracy', undef, ], - [ 'round_mode', 'even', ], - [ 'trap_nan', 0, ], - [ 'trap_inf', 0, ]); +my @classes = ($mbi, $mbf, $mbr); -############################################################################## -# Math::BigInt +# Default configuration. -{ - can_ok($mbi, 'config'); +my %defaults = ( + 'accuracy' => undef, + 'precision' => undef, + 'round_mode' => 'even', + 'div_scale' => 40, + 'trap_inf' => 0, + 'trap_nan' => 0, + 'upgrade' => undef, + 'downgrade' => undef, + 'lib' => 'Math::BigInt::Calc', + 'lib_version' => $Math::BigInt::Calc::VERSION, +); - my @table = @defaults; - unshift @table, ['class', $mbi ]; +############################################################################## +# Test config() as a getter. - # Test getting via the new-style $class->($key): +for my $class (@classes) { - for (my $i = 0 ; $i <= $#table ; ++ $i) { - my $key = $table[$i][0]; - my $val = $table[$i][1]; - is($mbi->config($key), $val, qq|$mbi->config("$key")|); - } + note <<"EOF"; - # Test getting via the old-style $class->()->{$key}, which is still - # supported: +Verify that $class->config("key") works. - my $cfg = $mbi->config(); - is(ref($cfg), 'HASH', 'ref() of output from $mbi->config()'); +EOF - for (my $i = 0 ; $i <= $#table ; ++ $i) { - my $key = $table[$i][0]; - my $val = $table[$i][1]; - is($cfg->{$key}, $val, qq|$mbi->config()->{$key}|); - } + can_ok($class, 'config'); - # can set via hash ref? - $cfg = $mbi->config({ trap_nan => 1 }); - is($cfg->{trap_nan}, 1, 'can set "trap_nan" via hash ref'); + my %table = (%defaults, 'class' => $class); - # reset for later - $mbi->config(trap_nan => 0); -} + # Test getting via the new style $class->config($key). -############################################################################## -# Math::BigFloat + subtest qq|New-style getter $class->config("\$key")| => sub { + plan tests => scalar keys %table; -{ - can_ok($mbf, 'config'); + for my $key (sort keys %table) { + my $val = $table{$key}; + is($class->config($key), $val, qq|$class->config("$key")|); + } + }; - my @table = @defaults; - unshift @table, ['class', $mbf ]; + # Test getting via the old style $class->config()->{$key}, which is still + # supported: - # Test getting via the new-style $class->($key): + my $cfg = $class->config(); + is(ref($cfg), 'HASH', "ref() of output from $class->config()"); - for (my $i = 0 ; $i <= $#table ; ++ $i) { - my $key = $table[$i][0]; - my $val = $table[$i][1]; - is($mbf->config($key), $val, qq|$mbf->config("$key")|); - } + subtest qq|Old-style getter $class->config()->{"\$key"}| => sub { + plan tests => scalar keys %table; - # Test getting via the old-style $class->()->{$key}, which is still - # supported: + for my $key (sort keys %table) { + my $val = $table{$key}; + is($cfg->{$key}, $val, qq|$class->config()->{$key}|); + } + }; - my $cfg = $mbf->config(); - is(ref($cfg), 'HASH', 'ref() of output from $mbf->config()'); + # Can set via hash ref? - for (my $i = 0 ; $i <= $#table ; ++ $i) { - my $key = $table[$i][0]; - my $val = $table[$i][1]; - is($cfg->{$key}, $val, qq|$mbf->config()->{$key}|); - } + $cfg = $class->config({ trap_nan => 1 }); + is($cfg->{trap_nan}, 1, 'can set "trap_nan" to 1 via hash ref'); - # can set via hash ref? - $cfg = $mbf->config({ trap_nan => 1 }); - is($cfg->{trap_nan}, 1, 'can set "trap_nan" via hash ref'); + # Restore for later. - # reset for later - $mbf->config(trap_nan => 0); + $cfg = $class->config({ trap_nan => 0 }); + is($cfg->{trap_nan}, 0, 'can set "trap_nan" to 0 via hash ref'); } ############################################################################## -# test setting values +# Test config() as a setter. + +# Alternative configuration. All values should be different from the default +# configuration. my $test = { - trap_nan => 1, - trap_inf => 1, accuracy => 2, precision => 3, round_mode => 'zero', div_scale => '100', + trap_inf => 1, + trap_nan => 1, upgrade => 'Math::BigInt::SomeClass', downgrade => 'Math::BigInt::SomeClass', }; -my $cfg; +for my $class (@classes) { + + note <<"EOF"; + +Verify that $class->config("key" => value) works and that +it doesn't affect the configuration of other classes. + +EOF + + for my $key (sort keys %$test) { + + # Get the original value for restoring it later. + + my $orig = $class->config($key); + + # Try setting the new value. + + eval { $class->config($key => $test->{$key}); }; + die $@ if $@; + + # Verify that the value was set correctly. + + is($class->config($key), $test->{$key}, + qq|$class->config("$key") set to $test->{$key}|); + + # Verify that setting it in class $class didn't affect other classes. + + for my $other (@classes) { + next if $other eq $class; + + isnt($other->config($key), $class->config($key), + qq|$other->config("$key") isn't affected by setting | . + qq|$class->config("$key")|); + } + + # Restore the value. + + $class->config($key => $orig); -foreach my $key (keys %$test) { + # Verify that the value was restored. - # see if setting in MBI works - eval { $mbi->config($key => $test->{$key}); }; - $cfg = $mbi->config(); - is("$key = $cfg->{$key}", "$key = $test->{$key}", "$key = $test->{$key}"); - $cfg = $mbf->config(); - - # see if setting it in MBI leaves MBF alone - ok(($cfg->{$key} || 0) ne $test->{$key}, - "$key ne \$cfg->{$key}"); - - # see if setting in MBF works - eval { $mbf->config($key => $test->{$key}); }; - $cfg = $mbf->config(); - is("$key = $cfg->{$key}", "$key = $test->{$key}", "$key = $test->{$key}"); + is($class->config($key), $orig, + qq|$class->config("$key") reset to | . + (defined($orig) ? qq|"$orig"| : "undef")); + } } -############################################################################## -# test setting illegal keys (should croak) +# Verify that setting via a hash doesn't modify the hash. + +# In the $test configuration, both accuracy and precision are defined, which +# won't work, so set one of them to undef. + +$test->{accuracy} = undef; + +for my $class (@classes) { + + note <<"EOF"; + +Verify that $class->config({key1 => val1, key2 => val2, ...}) +doesn't modify the hash ref argument. + +EOF + + subtest "Verify that $class->config(\$cfg) doesn't modify \$cfg" => sub { + plan tests => 2 * keys %$test; + + # Make copy of the configuration hash and use it as input to config(). + + my $cfg = { %{ $test } }; + eval { $class -> config($cfg); }; + die $@ if $@; + + # Verify that the configuration hash hasn't been modified. + + for my $key (sort keys %$test) { + ok(exists $cfg->{$key}, qq|existens of \$cfg->{"$key"}|); + is($cfg->{$key}, $test->{$key}, qq|value of \$cfg->{"$key"}|); + } + }; +} + +# Special testing of setting both accuracy and precision simultaneouly with +# config(). This didn't work correctly before. + +for my $class (@classes) { -eval { $mbi->config('some_garbage' => 1); }; -like($@, - qr/ ^ Illegal \s+ key\(s\) \s+ 'some_garbage' \s+ passed \s+ to \s+ - Math::BigInt->config\(\) \s+ at - /x, - 'Passing invalid key to Math::BigInt->config() causes an error.'); - -eval { $mbf->config('some_garbage' => 1); }; -like($@, - qr/ ^ Illegal \s+ key\(s\) \s+ 'some_garbage' \s+ passed \s+ to \s+ - Math::BigFloat->config\(\) \s+ at - /x, - 'Passing invalid key to Math::BigFloat->config() causes an error.'); + note <<"EOF"; + +Verify that $class->config({accuracy => \$a, precision => \$p}) +works as intended. + +EOF + + $class -> config({"accuracy" => 4, "precision" => undef}); + + subtest qq|$class -> config({"accuracy" => 4, "precision" => undef})| + => sub { + plan tests => 2; + + is($class -> config("accuracy"), 4, + qq|$class -> config("accuracy")|); + is($class -> config("precision"), undef, + qq|$class -> config("precision")|); + }; + + $class -> config({"accuracy" => undef, "precision" => 5}); + + subtest qq|$class -> config({"accuracy" => undef, "precision" => 5})| + => sub { + plan tests => 2; + + is($class -> config("accuracy"), undef, + qq|$class -> config("accuracy")|); + is($class -> config("precision"), 5, + qq|$class -> config("precision")|); + }; +} + +# Test getting an invalid key (should croak) + +note <<"EOF"; + +Verify behaviour when getting an invalid key. + +EOF + +for my $class (@classes) { + eval { $class->config('some_garbage' => 1); }; + like($@, + qr/ ^ Illegal \s+ key\(s\) \s+ 'some_garbage' \s+ passed \s+ to \s+ + $class->config\(\) \s+ at + /x, + "Passing invalid key to $class->config() causes an error."); +} Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/downgrade-mbi-mbf.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/downgrade-mbi-mbf.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/downgrade-mbi-mbf.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/downgrade-mbi-mbf.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,775 @@ +# -*- mode: perl; -*- + +# Note that this does not test Math::BigFloat upgrading. + +use strict; +use warnings; + +use Test::More tests => 93; + +use Math::BigInt upgrade => 'Math::BigFloat'; +use Math::BigFloat downgrade => 'Math::BigInt'; + +is(Math::BigFloat->downgrade(), 'Math::BigInt', 'Math::BigFloat->downgrade()'); +is(Math::BigInt->upgrade(), 'Math::BigFloat', 'Math::BigInt->upgrade()'); + +# bug until v1.67: + +subtest 'Math::BigFloat->new("0.2E0")' => sub { + plan tests => 2; + my $x = Math::BigFloat->new("0.2E0"); + is($x, "0.2", 'value of $x'); + is(ref($x), "Math::BigFloat", '$x is a Math::BigFloat'); +}; + +subtest 'Math::BigFloat->new("0.2E1")' => sub { + plan tests => 2; + my $x = Math::BigFloat->new("2"); + is($x, "2", 'value of $x'); + is(ref($x), "Math::BigInt", '$x is downgraded to a Math::BigInt'); +}; + +subtest 'Math::BigFloat->new("0.2E2")' => sub { + plan tests => 2; + my $x = Math::BigFloat->new("20"); + is($x, "20", 'value of $x'); + is(ref($x), "Math::BigInt", '$x is downgraded to a Math::BigInt'); +}; + +# $x is a downgraded to a Math::BigInt, but bpow() and bsqrt() upgrades to +# Math::BigFloat. + +Math::BigFloat -> div_scale(20); # make it a bit faster + +my ($x, $y, $z); +subtest '$x = Math::BigFloat -> new(2);' => sub { + plan tests => 2; + $x = Math::BigFloat -> new(2); # downgrades + is(ref($x), 'Math::BigInt', '$x is downgraded to a Math::BigInt'); + cmp_ok($x, "==", 2, 'value of $x'); +}; + +subtest '$y = Math::BigFloat -> bpow("2", "0.5");' => sub { + plan tests => 2; + $y = Math::BigFloat -> bpow("2", "0.5"); + is(ref($y), 'Math::BigFloat', '$y is a Math::BigFloat'); + cmp_ok($y, "==", "1.4142135623730950488", 'value of $y'); +}; + +subtest '$z = $x -> bsqrt();' => sub { + plan tests => 2; + $z = $x -> bsqrt(); + is(ref($z), 'Math::BigFloat', '$y is a Math::BigFloat'); + cmp_ok($z, "==", "1.4142135623730950488", 'value of $z'); +}; + +# log_2(16) = 4 + +subtest '$x = Math::BigFloat -> new(16); $y = $x -> blog(2);' => sub { + plan tests => 4; + $x = Math::BigFloat -> new(16); + is(ref($x), 'Math::BigInt', '$x is downgraded to a Math::BigInt'); + cmp_ok($x, "==", 16, 'value of $x'); + $y = $x -> blog(2); + is(ref($y), 'Math::BigInt', '$y is downgraded to a Math::BigInt'); + cmp_ok($y, "==", 4, 'value of $y'); +}; + +# log_16(2) = 1/4 + +subtest '$x = Math::BigFloat -> new(2); $y = $x -> blog(16);' => sub { + plan tests => 4; + $x = Math::BigFloat -> new(2); + is(ref($x), 'Math::BigInt', '$x is downgraded to a Math::BigInt'); + cmp_ok($x, "==", 2, 'value of $x'); + $y = $x -> blog(16); + is(ref($y), 'Math::BigFloat', '$y is a Math::BigFloat'); + cmp_ok($y, "==", 0.25, 'value of $y'); +}; + +################################################################################ +# Verify that constructors downgrade when they should. + +note("Enable downgrading, and see if constructors downgrade"); + +note("testing new()"); + +$x = Math::BigFloat -> new("0.5"); +subtest '$x = Math::BigFloat -> new("0.5")' => sub { + plan tests => 2; + cmp_ok($x, "==", 0.5, 'value of $x'); + is(ref $x, "Math::BigFloat", "does not downgrade from Math::BigFloat"); +}; + +$x = Math::BigFloat -> new("4"); +subtest '$x = Math::BigFloat -> new("4")' => sub { + plan tests => 2; + cmp_ok($x, "==", 4, 'value of $x'); + is(ref $x, "Math::BigInt", "downgrades to Math::BigInt"); +}; + +$x = Math::BigFloat -> new("0"); +subtest '$x = Math::BigFloat -> new("0")' => sub { + plan tests => 2; + cmp_ok($x, "==", 0, 'value of $x'); + is(ref $x, "Math::BigInt", "downgrades to Math::BigInt"); +}; + +$x = Math::BigFloat -> new("1"); +subtest '$x = Math::BigFloat -> new("1")' => sub { + plan tests => 2; + cmp_ok($x, "==", 1, 'value of $x'); + is(ref $x, "Math::BigInt", "downgrades to Math::BigInt"); +}; + +$x = Math::BigFloat -> new("Inf"); +subtest '$x = Math::BigFloat -> new("inf")' => sub { + plan tests => 2; + cmp_ok($x, "==", "Inf", 'value of $x'); + is(ref $x, "Math::BigInt", "downgrades to Math::BigInt"); +}; + +$x = Math::BigFloat -> new("NaN"); +subtest '$x = Math::BigFloat -> new("NaN")' => sub { + plan tests => 2; + is($x, "NaN", ); + is(ref $x, "Math::BigInt", "downgrades to Math::BigInt"); +}; + +note("testing bzero()"); + +$x = Math::BigFloat -> bzero(); +subtest '$x = Math::BigFloat -> bzero()' => sub { + plan tests => 2; + cmp_ok($x, '==', 0, 'value of $x'); + is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); +}; + +note("testing bone()"); + +$x = Math::BigFloat -> bone(); +subtest '$x = Math::BigFloat -> bone()' => sub { + plan tests => 2; + cmp_ok($x, '==', 1, 'value of $x'); + is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); +}; + +note("testing binf()"); + +$x = Math::BigFloat -> binf(); +subtest '$x = Math::BigFloat -> binf()' => sub { + plan tests => 2; + cmp_ok($x, '==', 'Inf', 'value of $x'); + is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); +}; + +note("testing bnan()"); + +$x = Math::BigFloat -> bnan(); +subtest '$x = Math::BigFloat -> bnan()' => sub { + plan tests => 2; + is($x, 'NaN', 'value of $x'); + is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); +}; + +note("testing from_dec()"); + +$x = Math::BigFloat -> from_dec('3.14e2'); +subtest '$x = Math::BigFloat -> from_dec("3.14e2")' => sub { + plan tests => 2; + cmp_ok($x, '==', 314, 'value of $x'); + is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); +}; + +note("testing from_hex()"); + +$x = Math::BigFloat -> from_hex('0x1.3ap+8'); +subtest '$x = Math::BigFloat -> from_hex("3.14e2")' => sub { + plan tests => 2; + cmp_ok($x, '==', 314, 'value of $x'); + is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); +}; + +note("testing from_oct()"); + +$x = Math::BigFloat -> from_oct('0o1.164p+8'); +subtest '$x = Math::BigFloat -> from_oct("0o1.164p+8")' => sub { + plan tests => 2; + cmp_ok($x, '==', 314, 'value of $x'); + is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); +}; + +note("testing from_bin()"); + +$x = Math::BigFloat -> from_bin('0b1.0011101p+8'); +subtest '$x = Math::BigFloat -> from_bin("0b1.0011101p+8")' => sub { + plan tests => 2; + cmp_ok($x, '==', 314, 'value of $x'); + is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); +}; + +note("testing from_ieee754()"); + +$x = Math::BigFloat -> from_ieee754("\x43\x9d\x00\x00", "binary32"); +subtest '$x = Math::BigFloat -> from_ieee754("\x43\x9d\x00\x00", "binary32")' => sub { + plan tests => 2; + cmp_ok($x, "==", 314, 'value of $x'); + is(ref $x, "Math::BigInt", 'downgrades to Math::BigInt'); +}; + +note("Disable downgrading, and see if constructors downgrade"); + +Math::BigFloat -> downgrade(undef); + +my $zero = Math::BigFloat -> bzero(); +my $half = Math::BigFloat -> new("0.5"); +my $one = Math::BigFloat -> bone(); +my $four = Math::BigFloat -> new("4"); +my $inf = Math::BigFloat -> binf(); +my $nan = Math::BigFloat -> bnan(); + +is(ref $zero, "Math::BigFloat", "Creating a 0 does not downgrade"); +is(ref $half, "Math::BigFloat", "Creating a 0.5 does not downgrade"); +is(ref $one, "Math::BigFloat", "Creating a 1 does not downgrade"); +is(ref $four, "Math::BigFloat", "Creating a 4 does not downgrade"); +is(ref $inf, "Math::BigFloat", "Creating an Inf does not downgrade"); +is(ref $nan, "Math::BigFloat", "Creating a NaN does not downgrade"); + +################################################################################ +# Verify that other methods downgrade when they should. + +Math::BigFloat -> downgrade("Math::BigInt"); + +note("testing bneg()"); + +$x = $zero -> copy() -> bneg(); +subtest '$x = $zero -> copy() -> bneg();' => sub { + plan tests => 2; + cmp_ok($x, '==', 0, '-(0) = 0'); + is(ref($x), 'Math::BigInt', '-(0) => Math::BigInt'); +}; + +$x = $four -> copy() -> bneg(); +subtest '$x = $four -> copy() -> bneg();' => sub { + plan tests => 2; + cmp_ok($x, '==', -4, '-(4) = -4'); + is(ref($x), 'Math::BigInt', '-(4) => Math::BigInt'); +}; + +$x = $inf -> copy() -> bneg(); +subtest '$x = $inf -> copy() -> bneg();' => sub { + plan tests => 2; + cmp_ok($x, '==', '-inf', '-(Inf) = -Inf'); + is(ref($x), 'Math::BigInt', '-(Inf) => Math::BigInt'); +}; + +$x = $nan -> copy() -> bneg(); +subtest '$x = $nan -> copy() -> bneg();' => sub { + plan tests => 2; + is($x, 'NaN', '-(NaN) = NaN'); + is(ref($x), 'Math::BigInt', '-(NaN) => Math::BigInt'); +}; + +note("testing bnorm()"); + +$x = $zero -> copy() -> bnorm(); +subtest '$x = $zero -> copy() -> bnorm();' => sub { + plan tests => 2; + cmp_ok($x, '==', 0, 'value of $x'); + is(ref($x), 'Math::BigInt', 'bnorm(0) => Math::BigInt'); +}; + +$x = $four -> copy() -> bnorm(); +subtest '$x = $four -> copy() -> bnorm();' => sub { + plan tests => 2; + cmp_ok($x, '==', 4, 'value of $x'); + is(ref($x), 'Math::BigInt', 'bnorm(4) => Math::BigInt'); +}; + +$x = $inf -> copy() -> bnorm(); +subtest '$x = $inf -> copy() -> bnorm();' => sub { + plan tests => 2; + cmp_ok($x, '==', 'inf', 'value of $x'); + is(ref($x), 'Math::BigInt', 'bnorm(Inf) => Math::BigInt'); +}; + +$x = $nan -> copy() -> bnorm(); +subtest '$x = $nan -> copy() -> bnorm();' => sub { + plan tests => 2; + is($x, 'NaN', 'bnorm(NaN)'); + is(ref($x), 'Math::BigInt', 'bnorm(NaN) => Math::BigInt'); +}; + +note("testing binc()"); + +$x = $zero -> copy() -> binc(); +subtest '$x = $zero -> copy() -> binc();' => sub { + plan tests => 2; + cmp_ok($x, '==', 1, 'binc(0)'); + is(ref($x), 'Math::BigInt', 'binc(0) => Math::BigInt'); +}; + +$x = $four -> copy() -> binc(); +subtest '$x = $four -> copy() -> binc();' => sub { + plan tests => 2; + cmp_ok($x, '==', 5, 'binc(4)'); + is(ref($x), 'Math::BigInt', 'binc(4) => Math::BigInt'); +}; + +$x = $inf -> copy() -> binc(); +subtest '$x = $inf -> copy() -> binc();' => sub { + plan tests => 2; + cmp_ok($x, '==', 'inf', 'binc(Inf)'); + is(ref($x), 'Math::BigInt', 'binc(Inf) => Math::BigInt'); +}; + +$x = $nan -> copy() -> binc(); +subtest '$x = $nan -> copy() -> binc();' => sub { + plan tests => 2; + is($x, 'NaN', 'binc(NaN)'); + is(ref($x), 'Math::BigInt', 'binc(NaN) => Math::BigInt'); +}; + +note("testing bdec()"); + +$x = $zero -> copy() -> bdec(); +subtest '$x = $zero -> copy() -> bdec();' => sub { + plan tests => 2; + cmp_ok($x, '==', -1, 'bdec(0)'); + is(ref($x), 'Math::BigInt', 'bdec(0) => Math::BigInt'); +}; + +$x = $four -> copy() -> bdec(); +subtest '$x = $four -> copy() -> bdec();' => sub { + plan tests => 2; + cmp_ok($x, '==', 3, 'bdec(4)'); + is(ref($x), 'Math::BigInt', 'bdec(4) => Math::BigInt'); +}; + +$x = $inf -> copy() -> bdec(); +subtest '$x = $inf -> copy() -> bdec();' => sub { + plan tests => 2; + cmp_ok($x, '==', 'inf', 'bdec(Inf)'); + is(ref($x), 'Math::BigInt', 'bdec(Inf) => Math::BigInt'); +}; + +$x = $nan -> copy() -> bdec(); +subtest '' => sub { + plan tests => 2; + is($x, 'NaN', 'bdec(NaN)'); + is(ref($x), 'Math::BigInt', 'bdec(NaN) => Math::BigInt'); +}; + +note("testing badd()"); + +$x = $half -> copy() -> badd($nan); +subtest '$x = $half -> copy() -> badd($nan);' => sub { + plan tests => 2; + is($x, 'NaN', '0.5 + NaN = NaN'); + is(ref($x), 'Math::BigInt', '0.5 + NaN => Math::BigInt'); +}; + +$x = $half -> copy() -> badd($inf); +subtest '$x = $half -> copy() -> badd($inf);' => sub { + plan tests => 2; + cmp_ok($x, '==', '+Inf', '0.5 + Inf = Inf'); + is(ref($x), 'Math::BigInt', '2.5 + Inf => Math::BigInt'); +}; + +$x = $half -> copy() -> badd($half); +subtest '$x = $half -> copy() -> badd($half);' => sub { + plan tests => 2; + cmp_ok($x, '==', 1, '0.5 + 0.5 = 1'); + is(ref($x), 'Math::BigInt', '0.5 + 0.5 => Math::BigInt'); +}; + +$x = $half -> copy() -> badd($half -> copy() -> bneg()); +subtest '$x = $half -> copy() -> badd($half -> copy() -> bneg());' => sub { + plan tests => 2; + cmp_ok($x, '==', 0, '0.5 + -0.5 = 0'); + is(ref($x), 'Math::BigInt', '0.5 + -0.5 => Math::BigInt'); +}; + +$x = $four -> copy() -> badd($zero); +subtest '$x = $four -> copy() -> badd($zero);' => sub { + plan tests => 2; + cmp_ok($x, '==', 4, '4 + 0 = 4'); + is(ref($x), 'Math::BigInt', '4 + 0 => Math::BigInt'); +}; + +$x = $zero -> copy() -> badd($four); +subtest '$x = $zero -> copy() -> badd($four);' => sub { + plan tests => 2; + cmp_ok($x, '==', 4, '0 + 4 = 4'); + is(ref($x), 'Math::BigInt', '0 + 4 => Math::BigInt'); +}; + +$x = $inf -> copy() -> badd($four); +subtest '$x = $inf -> copy() -> badd($four);' => sub { + plan tests => 2; + cmp_ok($x, '==', '+Inf', 'Inf + 4 = Inf'); + is(ref($x), 'Math::BigInt', 'Inf + 4 => Math::BigInt'); +}; + +$x = $nan -> copy() -> badd($four); +subtest '$x = $nan -> copy() -> badd($four);' => sub { + plan tests => 2; + is($x, 'NaN', 'NaN + 4 = NaN'); + is(ref($x), 'Math::BigInt', 'NaN + 4 => Math::BigInt'); +}; + +note("testing bsub()"); + +$x = $half -> copy() -> bsub($nan); +subtest '$x = $half -> copy() -> bsub($nan);' => sub { + plan tests => 2; + is($x, 'NaN', '0.5 - NaN = NaN'); + is(ref($x), 'Math::BigInt', '0.5 - NaN => Math::BigInt'); +}; + +$x = $half -> copy() -> bsub($inf); +subtest '$x = $half -> copy() -> bsub($inf);' => sub { + plan tests => 2; + cmp_ok($x, '==', '-Inf', '2.5 - Inf = -Inf'); + is(ref($x), 'Math::BigInt', '2.5 - Inf => Math::BigInt'); +}; + +$x = $half -> copy() -> bsub($half); +subtest '$x = $half -> copy() -> bsub($half);' => sub { + plan tests => 2; + cmp_ok($x, '==', 0, '0.5 + 0.5 = 0'); + is(ref($x), 'Math::BigInt', '0.5 - 0.5 => Math::BigInt'); +}; + +$x = $half -> copy() -> bsub($half -> copy() -> bneg()); +subtest '$x = $half -> copy() -> bsub($half -> copy() -> bneg());' => sub { + plan tests => 2; + cmp_ok($x, '==', 1, '0.5 - -0.5 = 1'); + is(ref($x), 'Math::BigInt', '0.5 - -0.5 => Math::BigInt'); +}; + +$x = $four -> copy() -> bsub($zero); +subtest '$x = $four -> copy() -> bsub($zero);' => sub { + plan tests => 2; + cmp_ok($x, '==', 4, '4 - 0 = 4'); + is(ref($x), 'Math::BigInt', '4 - 0 => Math::BigInt'); +}; + +$x = $zero -> copy() -> bsub($four); +subtest '$x = $zero -> copy() -> bsub($four);' => sub { + plan tests => 2; + cmp_ok($x, '==', -4, '0 - 4 = -4'); + is(ref($x), 'Math::BigInt', '0 - 4 => Math::BigInt'); +}; + +$x = $inf -> copy() -> bsub($four); +subtest '$x = $inf -> copy() -> bsub($four);' => sub { + plan tests => 2; + cmp_ok($x, '==', 'Inf', 'Inf - 4 = Inf'); + is(ref($x), 'Math::BigInt', 'Inf - 4 => Math::BigInt'); +}; + +$x = $nan -> copy() -> bsub($four); +subtest '$x = $nan -> copy() -> bsub($four);' => sub { + plan tests => 2; + is($x, 'NaN', 'NaN - 4 = NaN'); + is(ref($x), 'Math::BigInt', 'NaN - 4 => Math::BigInt'); +}; + +note("testing bmul()"); + +$x = $zero -> copy() -> bmul($four); +subtest '$x = $zero -> copy() -> bmul($four);' => sub { + plan tests => 2; + cmp_ok($x, '==', 0, 'bmul(0, 4) = 0'); + is(ref($x), 'Math::BigInt', 'bmul(0, 4) => Math::BigInt'); +}; + +$x = $four -> copy() -> bmul($four); +subtest '$x = $four -> copy() -> bmul($four);' => sub { + plan tests => 2; + cmp_ok($x, '==', 16, 'bmul(4, 4) = 16'); + is(ref($x), 'Math::BigInt', 'bmul(4, 4) => Math::BigInt'); +}; + +$x = $inf -> copy() -> bmul($four); +subtest '$x = $inf -> copy() -> bmul($four);' => sub { + plan tests => 2; + cmp_ok($x, '==', 'inf', 'bmul(Inf, 4) = Inf'); + is(ref($x), 'Math::BigInt', 'bmul(Inf, 4) => Math::BigInt'); +}; + +$x = $nan -> copy() -> bmul($four); +subtest '$x = $nan -> copy() -> bmul($four);' => sub { + plan tests => 2; + is($x, 'NaN', 'bmul(NaN, 4) = NaN'); + is(ref($x), 'Math::BigInt', 'bmul(NaN, 4) => Math::BigInt'); +}; + +$x = $four -> copy() -> bmul('0.5'); +subtest '' => sub { + plan tests => 2; + cmp_ok($x, '==', 2, 'bmul(4, 0.5) = 2'); + is(ref($x), 'Math::BigInt', 'bmul(4, 0.5) => Math::BigInt'); +}; + +note("testing bmuladd()"); + +$x = $zero -> copy() -> bmuladd($four, $four); +subtest '$x = $zero -> copy() -> bmuladd($four, $four);' => sub { + plan tests => 2; + cmp_ok($x, '==', 4, 'bmuladd(0, 4, 4) = 4'); + is(ref($x), 'Math::BigInt', 'bmuladd(0, 4, 4) => Math::BigInt'); +}; + +$x = $four -> copy() -> bmuladd($four, $four); +subtest '$x = $four -> copy() -> bmuladd($four, $four);' => sub { + plan tests => 2; + cmp_ok($x, '==', 20, 'bmuladd(4, 4, 4) = 20'); + is(ref($x), 'Math::BigInt', 'bmuladd(4, 4, 4) => Math::BigInt'); +}; + +$x = $four -> copy() -> bmuladd($four, $inf); +subtest '$x = $four -> copy() -> bmuladd($four, $inf);' => sub { + plan tests => 2; + cmp_ok($x, '==', 'inf', 'bmuladd(4, 4, Inf) = Inf'); + is(ref($x), 'Math::BigInt', 'bmuladd(4, 4, Inf) => Math::BigInt'); +}; + +$x = $inf -> copy() -> bmuladd($four, $four); +subtest '$x = $inf -> copy() -> bmuladd($four, $four);' => sub { + plan tests => 2; + cmp_ok($x, '==', 'inf', 'bmuladd(Inf, 4, 4) = Inf'); + is(ref($x), 'Math::BigInt', 'bmuladd(Inf, 4, 4) => Math::BigInt'); +}; + +$x = $inf -> copy() -> bmuladd($four, $four); +subtest '$x = $inf -> copy() -> bmuladd($four, $four);' => sub { + plan tests => 2; + cmp_ok($x, '==', 'inf', 'bmuladd(Inf, 4, 4) = Inf'); + is(ref($x), 'Math::BigInt', 'bmuladd(Inf, 4, 4) => Math::BigInt'); +}; + +$x = $nan -> copy() -> bmuladd($four, $four); +subtest '$x = $nan -> copy() -> bmuladd($four, $four);' => sub { + plan tests => 2; + is($x, 'NaN', 'bmuladd(NaN, 4, 4) = NaN'); + is(ref($x), 'Math::BigInt', 'bmuladd(NaN, 4, 4) => Math::BigInt'); +}; + +$x = $four -> copy() -> bmuladd("0.5", $four); +subtest '$x = $four -> copy() -> bmuladd("0.5", $four);' => sub { + plan tests => 2; + cmp_ok($x, '==', 6, 'bmuladd(4, 0.5, 4) = 6'); + is(ref($x), 'Math::BigInt', 'bmuladd(4, 0.5, 4) => Math::BigInt'); +}; + +note("testing bdiv()"); + +$x = $zero -> copy() -> bdiv($one); +subtest '$x = $zero -> copy() -> bdiv($one);' => sub { + plan tests => 2; + cmp_ok($x, '==', 0, 'bdiv(0, 1) = 0'); + is(ref($x), 'Math::BigInt', 'bdiv(0, 1) => Math::BigInt'); +}; + +note("testing bmod()"); + +note("testing bmodpow()"); + +note("testing bpow()"); + +note("testing blog()"); + +note("testing bexp()"); + +note("testing bnok()"); + +note("testing bsin()"); + +note("testing bcos()"); + +note("testing batan()"); + +note("testing batan()"); + +note("testing bsqrt()"); + +note("testing broot()"); + +note("testing bfac()"); + +note("testing bdfac()"); + +note("testing btfac()"); + +note("testing bmfac()"); + +note("testing blsft()"); + +note("testing brsft()"); + +note("testing band()"); + +note("testing bior()"); + +note("testing bxor()"); + +note("testing bnot()"); + +note("testing bround()"); + +note("testing Add tests for rounding a non-integer to an integer. Fixme!"); + +$x = $zero -> copy() -> bround(); +subtest '$x = $zero -> copy() -> bround();' => sub { + plan tests => 2; + cmp_ok($x, '==', 0, 'bround(0)'); + is(ref($x), 'Math::BigInt', 'bround(0) => Math::BigInt'); +}; + +$x = $four -> copy() -> bround(); +subtest '$x = $four -> copy() -> bround();' => sub { + plan tests => 2; + cmp_ok($x, '==', 4, 'bround(4)'); + is(ref($x), 'Math::BigInt', 'bround(4) => Math::BigInt'); +}; + +$x = $inf -> copy() -> bround(); +subtest '$x = $inf -> copy() -> bround();' => sub { + plan tests => 2; + cmp_ok($x, '==', 'inf', 'bround(Inf)'); + is(ref($x), 'Math::BigInt', 'bround(Inf) => Math::BigInt'); +}; + +$x = $nan -> copy() -> bround(); +subtest '$x = $nan -> copy() -> bround();' => sub { + plan tests => 2; + is($x, 'NaN', 'bround(NaN)'); + is(ref($x), 'Math::BigInt', 'bround(NaN) => Math::BigInt'); +}; + +note("testing bfround()"); + +note("testing Add tests for rounding a non-integer to an integer. Fixme!"); + +$x = $zero -> copy() -> bfround(); +subtest '$x = $zero -> copy() -> bfround();' => sub { + plan tests => 2; + cmp_ok($x, '==', 0, 'bfround(0)'); + is(ref($x), 'Math::BigInt', 'bfround(0) => Math::BigInt'); +}; + +$x = $four -> copy() -> bfround(); +subtest '$x = $four -> copy() -> bfround();' => sub { + plan tests => 2; + cmp_ok($x, '==', 4, 'bfround(4)'); + is(ref($x), 'Math::BigInt', 'bfround(4) => Math::BigInt'); +}; + +$x = $inf -> copy() -> bfround(); +subtest '$x = $inf -> copy() -> bfround();' => sub { + plan tests => 2; + cmp_ok($x, '==', 'inf', 'bfround(Inf)'); + is(ref($x), 'Math::BigInt', 'bfround(Inf) => Math::BigInt'); +}; + +$x = $nan -> copy() -> bfround(); +subtest '$x = $nan -> copy() -> bfround();' => sub { + plan tests => 2; + is($x, 'NaN', 'bfround(NaN)'); + is(ref($x), 'Math::BigInt', 'bfround(NaN) => Math::BigInt'); +}; + +note("testing bfloor()"); + +$x = $half -> copy() -> bfloor(); +subtest '$x = $half -> copy() -> bfloor();' => sub { + plan tests => 2; + cmp_ok($x, '==', 0, 'bfloor(0)'); + is(ref($x), 'Math::BigInt', 'bfloor(0) => Math::BigInt'); +}; + +$x = $inf -> copy() -> bfloor(); +subtest '$x = $inf -> copy() -> bfloor();' => sub { + plan tests => 2; + cmp_ok($x, '==', 'Inf', 'bfloor(Inf)'); + is(ref($x), 'Math::BigInt', 'bfloor(Inf) => Math::BigInt'); +}; + +$x = $nan -> copy() -> bfloor(); +subtest '$x = $nan -> copy() -> bfloor();' => sub { + plan tests => 2; + is($x, 'NaN', 'bfloor(NaN)'); + is(ref($x), 'Math::BigInt', 'bfloor(NaN) => Math::BigInt'); +}; + +note("testing bceil()"); + +$x = $half -> copy() -> bceil(); +subtest '$x = $half -> copy() -> bceil();' => sub { + plan tests => 2; + cmp_ok($x, '==', 1, 'bceil(0)'); + is(ref($x), 'Math::BigInt', 'bceil(0) => Math::BigInt'); +}; + +$x = $inf -> copy() -> bceil(); +subtest '$x = $inf -> copy() -> bceil();' => sub { + plan tests => 2; + cmp_ok($x, '==', 'Inf', 'bceil(Inf)'); + is(ref($x), 'Math::BigInt', 'bceil(Inf) => Math::BigInt'); +}; + +$x = $nan -> copy() -> bceil(); +subtest '$x = $nan -> copy() -> bceil();' => sub { + plan tests => 2; + is($x, 'NaN', 'bceil(NaN)'); + is(ref($x), 'Math::BigInt', 'bceil(NaN) => Math::BigInt'); +}; + +note("testing bint()"); + +$x = $half -> copy() -> bint(); +subtest '$x = $half -> copy() -> bint();' => sub { + plan tests => 2; + cmp_ok($x, '==', 0, 'bint(0)'); + is(ref($x), 'Math::BigInt', 'bint(0) => Math::BigInt'); +}; + +$x = $inf -> copy() -> bint(); +subtest '$x = $inf -> copy() -> bint();' => sub { + plan tests => 2; + cmp_ok($x, '==', 'Inf', 'bint(Inf)'); + is(ref($x), 'Math::BigInt', 'bint(Inf) => Math::BigInt'); +}; + +$x = $nan -> copy() -> bint(); +subtest '$x = $nan -> copy() -> bint();' => sub { + plan tests => 2; + is($x, 'NaN', 'bint(NaN)'); + is(ref($x), 'Math::BigInt', 'bint(NaN) => Math::BigInt'); +}; + +note("testing bgcd()"); + +note("testing blcm()"); + +note("testing mantissa()"); + +note("testing exponent()"); + +note("testing parts()"); + +note("testing sparts()"); + +note("testing nparts()"); + +note("testing eparts()"); + +note("testing dparts()"); + +note("testing fparts()"); + +note("testing numerator()"); + +note("testing denominator()"); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/downgrade-mbi-mbr.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/downgrade-mbi-mbr.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/downgrade-mbi-mbr.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/downgrade-mbi-mbr.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,429 @@ +# -*- mode: perl; -*- + +# Note that this does not test Math::BigRat upgrading. + +use strict; +use warnings; + +use Test::More tests => 141; + +use Math::BigInt upgrade => 'Math::BigRat'; +use Math::BigRat downgrade => 'Math::BigInt'; + +is(Math::BigRat->downgrade(), 'Math::BigInt', 'Math::BigRat->downgrade()'); +is(Math::BigInt->upgrade(), 'Math::BigRat', 'Math::BigInt->upgrade()'); + +################################################################################ +# Verify that constructors downgrade when they should. + +note("Enable downgrading, and see if constructors downgrade"); + +my $x; + +# new() + +$x = Math::BigRat -> new("0.5"); +cmp_ok($x, "==", 0.5); +is(ref $x, "Math::BigRat", "Creating a 0.5 does not downgrade"); + +$x = Math::BigRat -> new("4"); +cmp_ok($x, "==", 4, 'new("4")'); +is(ref $x, "Math::BigInt", "Creating a 4 downgrades to Math::BigInt"); + +$x = Math::BigRat -> new("0"); +cmp_ok($x, "==", 0, 'new("0")'); +is(ref $x, "Math::BigInt", "Creating a 0 downgrades to Math::BigInt"); + +$x = Math::BigRat -> new("1"); +cmp_ok($x, "==", 1, 'new("1")'); +is(ref $x, "Math::BigInt", "Creating a 1 downgrades to Math::BigInt"); + +$x = Math::BigRat -> new("Inf"); +cmp_ok($x, "==", "Inf", 'new("inf")'); +is(ref $x, "Math::BigInt", "Creating an Inf downgrades to Math::BigInt"); + +$x = Math::BigRat -> new("NaN"); +is($x, "NaN", 'new("NaN")'); +is(ref $x, "Math::BigInt", "Creating a NaN downgrades to Math::BigInt"); + +# bzero() + +$x = Math::BigRat -> bzero(); +cmp_ok($x, "==", 0, "bzero()"); +is(ref $x, "Math::BigInt", "Creating a 0 downgrades to Math::BigInt"); + +# bone() + +$x = Math::BigRat -> bone(); +cmp_ok($x, "==", 1, "bone()"); +is(ref $x, "Math::BigInt", "Creating a 1 downgrades to Math::BigInt"); + +# binf() + +$x = Math::BigRat -> binf(); +cmp_ok($x, "==", "Inf", "binf()"); +is(ref $x, "Math::BigInt", "Creating an Inf downgrades to Math::BigInt"); + +# bnan() + +$x = Math::BigRat -> bnan(); +is($x, "NaN", "bnan()"); +is(ref $x, "Math::BigInt", "Creating a NaN downgrades to Math::BigInt"); + +# from_hex() + +$x = Math::BigRat -> from_hex("13a"); +cmp_ok($x, "==", 314, 'from_hex("13a")'); +is(ref $x, "Math::BigInt", 'from_hex("13a") downgrades to Math::BigInt'); + +# from_oct() + +$x = Math::BigRat -> from_oct("472"); +cmp_ok($x, "==", 314, 'from_oct("472")'); +is(ref $x, "Math::BigInt", 'from_oct("472") downgrades to Math::BigInt'); + +# from_bin() + +$x = Math::BigRat -> from_bin("100111010"); +cmp_ok($x, "==", 314, 'from_bin("100111010")'); +is(ref $x, "Math::BigInt", + 'from_bin("100111010") downgrades to Math::BigInt'); + +note("Disable downgrading, and see if constructors downgrade"); + +Math::BigRat -> downgrade(undef); + +my $half = Math::BigRat -> new("1/2"); +my $four = Math::BigRat -> new("4"); +my $zero = Math::BigRat -> bzero(); +my $inf = Math::BigRat -> binf(); +my $nan = Math::BigRat -> bnan(); + +is(ref $half, "Math::BigRat", "Creating a 0.5 does not downgrade"); +is(ref $four, "Math::BigRat", "Creating a 4 does not downgrade"); +is(ref $zero, "Math::BigRat", "Creating a 0 does not downgrade"); +is(ref $inf, "Math::BigRat", "Creating an Inf does not downgrade"); +is(ref $nan, "Math::BigRat", "Creating a NaN does not downgrade"); + +################################################################################ +# Verify that other methods downgrade when they should. + +Math::BigRat -> downgrade("Math::BigInt"); + +note("bneg()"); + +$x = $zero -> copy() -> bneg(); +cmp_ok($x, "==", 0, "-(0) = 0"); +is(ref($x), "Math::BigInt", "-(0) => Math::BigInt"); + +$x = $four -> copy() -> bneg(); +cmp_ok($x, "==", -4, "-(4) = -4"); +is(ref($x), "Math::BigInt", "-(4) => Math::BigInt"); + +$x = $inf -> copy() -> bneg(); +cmp_ok($x, "==", "-inf", "-(Inf) = -Inf"); +is(ref($x), "Math::BigInt", "-(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bneg(); +is($x, "NaN", "-(NaN) = NaN"); +is(ref($x), "Math::BigInt", "-(NaN) => Math::BigInt"); + +note("bnorm()"); + +$x = $zero -> copy() -> bnorm(); +cmp_ok($x, "==", 0, "bnorm(0)"); +is(ref($x), "Math::BigInt", "bnorm(0) => Math::BigInt"); + +$x = $four -> copy() -> bnorm(); +cmp_ok($x, "==", 4, "bnorm(4)"); +is(ref($x), "Math::BigInt", "bnorm(4) => Math::BigInt"); + +$x = $inf -> copy() -> bnorm(); +cmp_ok($x, "==", "inf", "bnorm(Inf)"); +is(ref($x), "Math::BigInt", "bnorm(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bnorm(); +is($x, "NaN", "bnorm(NaN)"); +is(ref($x), "Math::BigInt", "bnorm(NaN) => Math::BigInt"); + +note("binc()"); + +$x = $zero -> copy() -> binc(); +cmp_ok($x, "==", 1, "binc(0)"); +is(ref($x), "Math::BigInt", "binc(0) => Math::BigInt"); + +$x = $four -> copy() -> binc(); +cmp_ok($x, "==", 5, "binc(4)"); +is(ref($x), "Math::BigInt", "binc(4) => Math::BigInt"); + +$x = $inf -> copy() -> binc(); +cmp_ok($x, "==", "inf", "binc(Inf)"); +is(ref($x), "Math::BigInt", "binc(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> binc(); +is($x, "NaN", "binc(NaN)"); +is(ref($x), "Math::BigInt", "binc(NaN) => Math::BigInt"); + +note("bdec()"); + +$x = $zero -> copy() -> bdec(); +cmp_ok($x, "==", -1, "bdec(0)"); +is(ref($x), "Math::BigInt", "bdec(0) => Math::BigInt"); + +$x = $four -> copy() -> bdec(); +cmp_ok($x, "==", 3, "bdec(4)"); +is(ref($x), "Math::BigInt", "bdec(4) => Math::BigInt"); + +$x = $inf -> copy() -> bdec(); +cmp_ok($x, "==", "inf", "bdec(Inf)"); +is(ref($x), "Math::BigInt", "bdec(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bdec(); +is($x, "NaN", "bdec(NaN)"); +is(ref($x), "Math::BigInt", "bdec(NaN) => Math::BigInt"); + +note("badd()"); + +$x = $half -> copy() -> badd($nan); +is($x, "NaN", "0.5 + NaN = NaN"); +is(ref($x), "Math::BigInt", "0.5 + NaN => Math::BigInt"); + +$x = $half -> copy() -> badd($inf); +cmp_ok($x, "==", "+Inf", "0.5 + Inf = Inf"); +is(ref($x), "Math::BigInt", "2.5 + Inf => Math::BigInt"); + +$x = $half -> copy() -> badd($half); +cmp_ok($x, "==", 1, "0.5 + 0.5 = 1"); +is(ref($x), "Math::BigInt", "0.5 + 0.5 => Math::BigInt"); + +$x = $half -> copy() -> badd($half -> copy() -> bneg()); +cmp_ok($x, "==", 0, "0.5 + -0.5 = 0"); +is(ref($x), "Math::BigInt", "0.5 + -0.5 => Math::BigInt"); + +$x = $four -> copy() -> badd($zero); +cmp_ok($x, "==", 4, "4 + 0 = 4"); +is(ref($x), "Math::BigInt", "4 + 0 => Math::BigInt"); + +$x = $zero -> copy() -> badd($four); +cmp_ok($x, "==", 4, "0 + 4 = 4"); +is(ref($x), "Math::BigInt", "0 + 4 => Math::BigInt"); + +$x = $inf -> copy() -> badd($four); +cmp_ok($x, "==", "+Inf", "Inf + 4 = Inf"); +is(ref($x), "Math::BigInt", "Inf + 4 => Math::BigInt"); + +$x = $nan -> copy() -> badd($four); +is($x, "NaN", "NaN + 4 = NaN"); +is(ref($x), "Math::BigInt", "NaN + 4 => Math::BigInt"); + +note("bsub()"); + +$x = $half -> copy() -> bsub($nan); +is($x, "NaN", "0.5 - NaN = NaN"); +is(ref($x), "Math::BigInt", "0.5 - NaN => Math::BigInt"); + +$x = $half -> copy() -> bsub($inf); +cmp_ok($x, "==", "-Inf", "2.5 - Inf = -Inf"); +is(ref($x), "Math::BigInt", "2.5 - Inf => Math::BigInt"); + +$x = $half -> copy() -> bsub($half); +cmp_ok($x, "==", 0, "0.5 - 0.5 = 0"); +is(ref($x), "Math::BigInt", "0.5 - 0.5 => Math::BigInt"); + +$x = $half -> copy() -> bsub($half -> copy() -> bneg()); +cmp_ok($x, "==", 1, "0.5 - -0.5 = 1"); +is(ref($x), "Math::BigInt", "0.5 - -0.5 => Math::BigInt"); + +$x = $four -> copy() -> bsub($zero); +cmp_ok($x, "==", 4, "4 - 0 = 4"); +is(ref($x), "Math::BigInt", "4 - 0 => Math::BigInt"); + +$x = $zero -> copy() -> bsub($four); +cmp_ok($x, "==", -4, "0 - 4 = -4"); +is(ref($x), "Math::BigInt", "0 - 4 => Math::BigInt"); + +$x = $inf -> copy() -> bsub($four); +cmp_ok($x, "==", "Inf", "Inf - 4 = Inf"); +is(ref($x), "Math::BigInt", "Inf - 4 => Math::BigInt"); + +$x = $nan -> copy() -> bsub($four); +is($x, "NaN", "NaN - 4 = NaN"); +is(ref($x), "Math::BigInt", "NaN - 4 => Math::BigInt"); + +note("bmul()"); + +$x = $zero -> copy() -> bmul($four); +cmp_ok($x, "==", 0, "bmul(0, 4) = 0"); +is(ref($x), "Math::BigInt", "bmul(0, 4) => Math::BigInt"); + +$x = $four -> copy() -> bmul($four); +cmp_ok($x, "==", 16, "bmul(4, 4) = 16"); +is(ref($x), "Math::BigInt", "bmul(4, 4) => Math::BigInt"); + +$x = $inf -> copy() -> bmul($four); +cmp_ok($x, "==", "inf", "bmul(Inf, 4) = Inf"); +is(ref($x), "Math::BigInt", "bmul(Inf, 4) => Math::BigInt"); + +$x = $nan -> copy() -> bmul($four); +is($x, "NaN", "bmul(NaN, 4) = NaN"); +is(ref($x), "Math::BigInt", "bmul(NaN, 4) => Math::BigInt"); + +$x = $four -> copy() -> bmul("0.5"); +cmp_ok($x, "==", 2, "bmul(4, 0.5) = 2"); +is(ref($x), "Math::BigInt", "bmul(4, 0.5) => Math::BigInt"); + +# bmuladd() + +note("bdiv()"); + +note("bmod()"); + +note("bmodpow()"); + +note("bpow()"); + +note("blog()"); + +note("bexp()"); + +note("bnok()"); + +note("bsin()"); + +note("bcos()"); + +note("batan()"); + +note("batan()"); + +note("bsqrt()"); + +note("broot()"); + +note("bfac()"); + +note("bdfac()"); + +note("btfac()"); + +note("bmfac()"); + +note("blsft()"); + +note("brsft()"); + +note("band()"); + +note("bior()"); + +note("bxor()"); + +note("bnot()"); + +note("bround()"); + +# Add tests for rounding a non-integer to an integer. Fixme! + +$x = $zero -> copy() -> bround(); +cmp_ok($x, "==", 0, "bround(0)"); +is(ref($x), "Math::BigInt", "bround(0) => Math::BigInt"); + +$x = $four -> copy() -> bround(); +cmp_ok($x, "==", 4, "bround(4)"); +is(ref($x), "Math::BigInt", "bround(4) => Math::BigInt"); + +$x = $inf -> copy() -> bround(); +cmp_ok($x, "==", "inf", "bround(Inf)"); +is(ref($x), "Math::BigInt", "bround(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bround(); +is($x, "NaN", "bround(NaN)"); +is(ref($x), "Math::BigInt", "bround(NaN) => Math::BigInt"); + +note("bfround()"); + +# Add tests for rounding a non-integer to an integer. Fixme! + +$x = $zero -> copy() -> bfround(); +cmp_ok($x, "==", 0, "bfround(0)"); +is(ref($x), "Math::BigInt", "bfround(0) => Math::BigInt"); + +$x = $four -> copy() -> bfround(); +cmp_ok($x, "==", 4, "bfround(4)"); +is(ref($x), "Math::BigInt", "bfround(4) => Math::BigInt"); + +$x = $inf -> copy() -> bfround(); +cmp_ok($x, "==", "inf", "bfround(Inf)"); +is(ref($x), "Math::BigInt", "bfround(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bfround(); +is($x, "NaN", "bfround(NaN)"); +is(ref($x), "Math::BigInt", "bfround(NaN) => Math::BigInt"); + +note("bfloor()"); + +$x = $half -> copy() -> bfloor(); +cmp_ok($x, "==", 0, "bfloor(0)"); +is(ref($x), "Math::BigInt", "bfloor(0) => Math::BigInt"); + +$x = $inf -> copy() -> bfloor(); +cmp_ok($x, "==", "Inf", "bfloor(Inf)"); +is(ref($x), "Math::BigInt", "bfloor(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bfloor(); +is($x, "NaN", "bfloor(NaN)"); +is(ref($x), "Math::BigInt", "bfloor(NaN) => Math::BigInt"); + +note("bceil()"); + +$x = $half -> copy() -> bceil(); +cmp_ok($x, "==", 1, "bceil(0)"); +is(ref($x), "Math::BigInt", "bceil(0) => Math::BigInt"); + +$x = $inf -> copy() -> bceil(); +cmp_ok($x, "==", "Inf", "bceil(Inf)"); +is(ref($x), "Math::BigInt", "bceil(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bceil(); +is($x, "NaN", "bceil(NaN)"); +is(ref($x), "Math::BigInt", "bceil(NaN) => Math::BigInt"); + +note("bint()"); + +$x = $half -> copy() -> bint(); +cmp_ok($x, "==", 0, "bint(0)"); +is(ref($x), "Math::BigInt", "bint(0) => Math::BigInt"); + +$x = $inf -> copy() -> bint(); +cmp_ok($x, "==", "Inf", "bint(Inf)"); +is(ref($x), "Math::BigInt", "bint(Inf) => Math::BigInt"); + +$x = $nan -> copy() -> bint(); +is($x, "NaN", "bint(NaN)"); +is(ref($x), "Math::BigInt", "bint(NaN) => Math::BigInt"); + +note("bgcd()"); + +note("blcm()"); + +# mantissa() ? + +# exponent() ? + +# parts() ? + +# sparts() + +# nparts() + +# eparts() + +# dparts() + +# fparts() + +# numerator() + +# denominator() + +#require 'upgrade.inc'; # all tests here for sharing Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/downgrade.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/downgrade.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/downgrade.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/downgrade.t 14 May 2024 19:38:56 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,775 +0,0 @@ -# -*- mode: perl; -*- - -# Note that this does not test Math::BigFloat upgrading. - -use strict; -use warnings; - -use Test::More tests => 93; - -use Math::BigInt upgrade => 'Math::BigFloat'; -use Math::BigFloat downgrade => 'Math::BigInt'; - -is(Math::BigFloat->downgrade(), 'Math::BigInt', 'Math::BigFloat->downgrade()'); -is(Math::BigInt->upgrade(), 'Math::BigFloat', 'Math::BigInt->upgrade()'); - -# bug until v1.67: - -subtest 'Math::BigFloat->new("0.2E0")' => sub { - plan tests => 2; - my $x = Math::BigFloat->new("0.2E0"); - is($x, "0.2", 'value of $x'); - is(ref($x), "Math::BigFloat", '$x is a Math::BigFloat'); -}; - -subtest 'Math::BigFloat->new("0.2E1")' => sub { - plan tests => 2; - my $x = Math::BigFloat->new("2"); - is($x, "2", 'value of $x'); - is(ref($x), "Math::BigInt", '$x is downgraded to a Math::BigInt'); -}; - -subtest 'Math::BigFloat->new("0.2E2")' => sub { - plan tests => 2; - my $x = Math::BigFloat->new("20"); - is($x, "20", 'value of $x'); - is(ref($x), "Math::BigInt", '$x is downgraded to a Math::BigInt'); -}; - -# $x is a downgraded to a Math::BigInt, but bpow() and bsqrt() upgrades to -# Math::BigFloat. - -Math::BigFloat -> div_scale(20); # make it a bit faster - -my ($x, $y, $z); -subtest '$x = Math::BigFloat -> new(2);' => sub { - plan tests => 2; - $x = Math::BigFloat -> new(2); # downgrades - is(ref($x), 'Math::BigInt', '$x is downgraded to a Math::BigInt'); - cmp_ok($x, "==", 2, 'value of $x'); -}; - -subtest '$y = Math::BigFloat -> bpow("2", "0.5");' => sub { - plan tests => 2; - $y = Math::BigFloat -> bpow("2", "0.5"); - is(ref($y), 'Math::BigFloat', '$y is a Math::BigFloat'); - cmp_ok($y, "==", "1.4142135623730950488", 'value of $y'); -}; - -subtest '$z = $x -> bsqrt();' => sub { - plan tests => 2; - $z = $x -> bsqrt(); - is(ref($z), 'Math::BigFloat', '$y is a Math::BigFloat'); - cmp_ok($z, "==", "1.4142135623730950488", 'value of $z'); -}; - -# log_2(16) = 4 - -subtest '$x = Math::BigFloat -> new(16); $y = $x -> blog(2);' => sub { - plan tests => 4; - $x = Math::BigFloat -> new(16); - is(ref($x), 'Math::BigInt', '$x is downgraded to a Math::BigInt'); - cmp_ok($x, "==", 16, 'value of $x'); - $y = $x -> blog(2); - is(ref($y), 'Math::BigInt', '$y is downgraded to a Math::BigInt'); - cmp_ok($y, "==", 4, 'value of $y'); -}; - -# log_16(2) = 1/4 - -subtest '$x = Math::BigFloat -> new(2); $y = $x -> blog(16);' => sub { - plan tests => 4; - $x = Math::BigFloat -> new(2); - is(ref($x), 'Math::BigInt', '$x is downgraded to a Math::BigInt'); - cmp_ok($x, "==", 2, 'value of $x'); - $y = $x -> blog(16); - is(ref($y), 'Math::BigFloat', '$y is a Math::BigFloat'); - cmp_ok($y, "==", 0.25, 'value of $y'); -}; - -################################################################################ -# Verify that constructors downgrade when they should. - -note("Enable downgrading, and see if constructors downgrade"); - -note("testing new()"); - -$x = Math::BigFloat -> new("0.5"); -subtest '$x = Math::BigFloat -> new("0.5")' => sub { - plan tests => 2; - cmp_ok($x, "==", 0.5, 'value of $x'); - is(ref $x, "Math::BigFloat", "does not downgrade from Math::BigFloat"); -}; - -$x = Math::BigFloat -> new("4"); -subtest '$x = Math::BigFloat -> new("4")' => sub { - plan tests => 2; - cmp_ok($x, "==", 4, 'value of $x'); - is(ref $x, "Math::BigInt", "downgrades to Math::BigInt"); -}; - -$x = Math::BigFloat -> new("0"); -subtest '$x = Math::BigFloat -> new("0")' => sub { - plan tests => 2; - cmp_ok($x, "==", 0, 'value of $x'); - is(ref $x, "Math::BigInt", "downgrades to Math::BigInt"); -}; - -$x = Math::BigFloat -> new("1"); -subtest '$x = Math::BigFloat -> new("1")' => sub { - plan tests => 2; - cmp_ok($x, "==", 1, 'value of $x'); - is(ref $x, "Math::BigInt", "downgrades to Math::BigInt"); -}; - -$x = Math::BigFloat -> new("Inf"); -subtest '$x = Math::BigFloat -> new("inf")' => sub { - plan tests => 2; - cmp_ok($x, "==", "Inf", 'value of $x'); - is(ref $x, "Math::BigInt", "downgrades to Math::BigInt"); -}; - -$x = Math::BigFloat -> new("NaN"); -subtest '$x = Math::BigFloat -> new("NaN")' => sub { - plan tests => 2; - is($x, "NaN", ); - is(ref $x, "Math::BigInt", "downgrades to Math::BigInt"); -}; - -note("testing bzero()"); - -$x = Math::BigFloat -> bzero(); -subtest '$x = Math::BigFloat -> bzero()' => sub { - plan tests => 2; - cmp_ok($x, '==', 0, 'value of $x'); - is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); -}; - -note("testing bone()"); - -$x = Math::BigFloat -> bone(); -subtest '$x = Math::BigFloat -> bone()' => sub { - plan tests => 2; - cmp_ok($x, '==', 1, 'value of $x'); - is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); -}; - -note("testing binf()"); - -$x = Math::BigFloat -> binf(); -subtest '$x = Math::BigFloat -> binf()' => sub { - plan tests => 2; - cmp_ok($x, '==', 'Inf', 'value of $x'); - is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); -}; - -note("testing bnan()"); - -$x = Math::BigFloat -> bnan(); -subtest '$x = Math::BigFloat -> bnan()' => sub { - plan tests => 2; - is($x, 'NaN', 'value of $x'); - is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); -}; - -note("testing from_dec()"); - -$x = Math::BigFloat -> from_dec('3.14e2'); -subtest '$x = Math::BigFloat -> from_dec("3.14e2")' => sub { - plan tests => 2; - cmp_ok($x, '==', 314, 'value of $x'); - is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); -}; - -note("testing from_hex()"); - -$x = Math::BigFloat -> from_hex('0x1.3ap+8'); -subtest '$x = Math::BigFloat -> from_hex("3.14e2")' => sub { - plan tests => 2; - cmp_ok($x, '==', 314, 'value of $x'); - is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); -}; - -note("testing from_oct()"); - -$x = Math::BigFloat -> from_oct('0o1.164p+8'); -subtest '$x = Math::BigFloat -> from_oct("0o1.164p+8")' => sub { - plan tests => 2; - cmp_ok($x, '==', 314, 'value of $x'); - is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); -}; - -note("testing from_bin()"); - -$x = Math::BigFloat -> from_bin('0b1.0011101p+8'); -subtest '$x = Math::BigFloat -> from_bin("0b1.0011101p+8")' => sub { - plan tests => 2; - cmp_ok($x, '==', 314, 'value of $x'); - is(ref $x, 'Math::BigInt', 'downgrades to Math::BigInt'); -}; - -note("testing from_ieee754()"); - -$x = Math::BigFloat -> from_ieee754("\x43\x9d\x00\x00", "binary32"); -subtest '$x = Math::BigFloat -> from_ieee754("\x43\x9d\x00\x00", "binary32")' => sub { - plan tests => 2; - cmp_ok($x, "==", 314, 'value of $x'); - is(ref $x, "Math::BigInt", 'downgrades to Math::BigInt'); -}; - -note("Disable downgrading, and see if constructors downgrade"); - -Math::BigFloat -> downgrade(undef); - -my $zero = Math::BigFloat -> bzero(); -my $half = Math::BigFloat -> new("0.5"); -my $one = Math::BigFloat -> bone(); -my $four = Math::BigFloat -> new("4"); -my $inf = Math::BigFloat -> binf(); -my $nan = Math::BigFloat -> bnan(); - -is(ref $zero, "Math::BigFloat", "Creating a 0 does not downgrade"); -is(ref $half, "Math::BigFloat", "Creating a 0.5 does not downgrade"); -is(ref $one, "Math::BigFloat", "Creating a 1 does not downgrade"); -is(ref $four, "Math::BigFloat", "Creating a 4 does not downgrade"); -is(ref $inf, "Math::BigFloat", "Creating an Inf does not downgrade"); -is(ref $nan, "Math::BigFloat", "Creating a NaN does not downgrade"); - -################################################################################ -# Verify that other methods downgrade when they should. - -Math::BigFloat -> downgrade("Math::BigInt"); - -note("testing bneg()"); - -$x = $zero -> copy() -> bneg(); -subtest '$x = $zero -> copy() -> bneg();' => sub { - plan tests => 2; - cmp_ok($x, '==', 0, '-(0) = 0'); - is(ref($x), 'Math::BigInt', '-(0) => Math::BigInt'); -}; - -$x = $four -> copy() -> bneg(); -subtest '$x = $four -> copy() -> bneg();' => sub { - plan tests => 2; - cmp_ok($x, '==', -4, '-(4) = -4'); - is(ref($x), 'Math::BigInt', '-(4) => Math::BigInt'); -}; - -$x = $inf -> copy() -> bneg(); -subtest '$x = $inf -> copy() -> bneg();' => sub { - plan tests => 2; - cmp_ok($x, '==', '-inf', '-(Inf) = -Inf'); - is(ref($x), 'Math::BigInt', '-(Inf) => Math::BigInt'); -}; - -$x = $nan -> copy() -> bneg(); -subtest '$x = $nan -> copy() -> bneg();' => sub { - plan tests => 2; - is($x, 'NaN', '-(NaN) = NaN'); - is(ref($x), 'Math::BigInt', '-(NaN) => Math::BigInt'); -}; - -note("testing bnorm()"); - -$x = $zero -> copy() -> bnorm(); -subtest '$x = $zero -> copy() -> bnorm();' => sub { - plan tests => 2; - cmp_ok($x, '==', 0, 'value of $x'); - is(ref($x), 'Math::BigInt', 'bnorm(0) => Math::BigInt'); -}; - -$x = $four -> copy() -> bnorm(); -subtest '$x = $four -> copy() -> bnorm();' => sub { - plan tests => 2; - cmp_ok($x, '==', 4, 'value of $x'); - is(ref($x), 'Math::BigInt', 'bnorm(4) => Math::BigInt'); -}; - -$x = $inf -> copy() -> bnorm(); -subtest '$x = $inf -> copy() -> bnorm();' => sub { - plan tests => 2; - cmp_ok($x, '==', 'inf', 'value of $x'); - is(ref($x), 'Math::BigInt', 'bnorm(Inf) => Math::BigInt'); -}; - -$x = $nan -> copy() -> bnorm(); -subtest '$x = $nan -> copy() -> bnorm();' => sub { - plan tests => 2; - is($x, 'NaN', 'bnorm(NaN)'); - is(ref($x), 'Math::BigInt', 'bnorm(NaN) => Math::BigInt'); -}; - -note("testing binc()"); - -$x = $zero -> copy() -> binc(); -subtest '$x = $zero -> copy() -> binc();' => sub { - plan tests => 2; - cmp_ok($x, '==', 1, 'binc(0)'); - is(ref($x), 'Math::BigInt', 'binc(0) => Math::BigInt'); -}; - -$x = $four -> copy() -> binc(); -subtest '$x = $four -> copy() -> binc();' => sub { - plan tests => 2; - cmp_ok($x, '==', 5, 'binc(4)'); - is(ref($x), 'Math::BigInt', 'binc(4) => Math::BigInt'); -}; - -$x = $inf -> copy() -> binc(); -subtest '$x = $inf -> copy() -> binc();' => sub { - plan tests => 2; - cmp_ok($x, '==', 'inf', 'binc(Inf)'); - is(ref($x), 'Math::BigInt', 'binc(Inf) => Math::BigInt'); -}; - -$x = $nan -> copy() -> binc(); -subtest '$x = $nan -> copy() -> binc();' => sub { - plan tests => 2; - is($x, 'NaN', 'binc(NaN)'); - is(ref($x), 'Math::BigInt', 'binc(NaN) => Math::BigInt'); -}; - -note("testing bdec()"); - -$x = $zero -> copy() -> bdec(); -subtest '$x = $zero -> copy() -> bdec();' => sub { - plan tests => 2; - cmp_ok($x, '==', -1, 'bdec(0)'); - is(ref($x), 'Math::BigInt', 'bdec(0) => Math::BigInt'); -}; - -$x = $four -> copy() -> bdec(); -subtest '$x = $four -> copy() -> bdec();' => sub { - plan tests => 2; - cmp_ok($x, '==', 3, 'bdec(4)'); - is(ref($x), 'Math::BigInt', 'bdec(4) => Math::BigInt'); -}; - -$x = $inf -> copy() -> bdec(); -subtest '$x = $inf -> copy() -> bdec();' => sub { - plan tests => 2; - cmp_ok($x, '==', 'inf', 'bdec(Inf)'); - is(ref($x), 'Math::BigInt', 'bdec(Inf) => Math::BigInt'); -}; - -$x = $nan -> copy() -> bdec(); -subtest '' => sub { - plan tests => 2; - is($x, 'NaN', 'bdec(NaN)'); - is(ref($x), 'Math::BigInt', 'bdec(NaN) => Math::BigInt'); -}; - -note("testing badd()"); - -$x = $half -> copy() -> badd($nan); -subtest '$x = $half -> copy() -> badd($nan);' => sub { - plan tests => 2; - is($x, 'NaN', '0.5 + NaN = NaN'); - is(ref($x), 'Math::BigInt', '0.5 + NaN => Math::BigInt'); -}; - -$x = $half -> copy() -> badd($inf); -subtest '$x = $half -> copy() -> badd($inf);' => sub { - plan tests => 2; - cmp_ok($x, '==', '+Inf', '0.5 + Inf = Inf'); - is(ref($x), 'Math::BigInt', '2.5 + Inf => Math::BigInt'); -}; - -$x = $half -> copy() -> badd($half); -subtest '$x = $half -> copy() -> badd($half);' => sub { - plan tests => 2; - cmp_ok($x, '==', 1, '0.5 + 0.5 = 1'); - is(ref($x), 'Math::BigInt', '0.5 + 0.5 => Math::BigInt'); -}; - -$x = $half -> copy() -> badd($half -> copy() -> bneg()); -subtest '$x = $half -> copy() -> badd($half -> copy() -> bneg());' => sub { - plan tests => 2; - cmp_ok($x, '==', 0, '0.5 + -0.5 = 0'); - is(ref($x), 'Math::BigInt', '0.5 + -0.5 => Math::BigInt'); -}; - -$x = $four -> copy() -> badd($zero); -subtest '$x = $four -> copy() -> badd($zero);' => sub { - plan tests => 2; - cmp_ok($x, '==', 4, '4 + 0 = 4'); - is(ref($x), 'Math::BigInt', '4 + 0 => Math::BigInt'); -}; - -$x = $zero -> copy() -> badd($four); -subtest '$x = $zero -> copy() -> badd($four);' => sub { - plan tests => 2; - cmp_ok($x, '==', 4, '0 + 4 = 4'); - is(ref($x), 'Math::BigInt', '0 + 4 => Math::BigInt'); -}; - -$x = $inf -> copy() -> badd($four); -subtest '$x = $inf -> copy() -> badd($four);' => sub { - plan tests => 2; - cmp_ok($x, '==', '+Inf', 'Inf + 4 = Inf'); - is(ref($x), 'Math::BigInt', 'Inf + 4 => Math::BigInt'); -}; - -$x = $nan -> copy() -> badd($four); -subtest '$x = $nan -> copy() -> badd($four);' => sub { - plan tests => 2; - is($x, 'NaN', 'NaN + 4 = NaN'); - is(ref($x), 'Math::BigInt', 'NaN + 4 => Math::BigInt'); -}; - -note("testing bsub()"); - -$x = $half -> copy() -> bsub($nan); -subtest '$x = $half -> copy() -> bsub($nan);' => sub { - plan tests => 2; - is($x, 'NaN', '0.5 - NaN = NaN'); - is(ref($x), 'Math::BigInt', '0.5 - NaN => Math::BigInt'); -}; - -$x = $half -> copy() -> bsub($inf); -subtest '$x = $half -> copy() -> bsub($inf);' => sub { - plan tests => 2; - cmp_ok($x, '==', '-Inf', '2.5 - Inf = -Inf'); - is(ref($x), 'Math::BigInt', '2.5 - Inf => Math::BigInt'); -}; - -$x = $half -> copy() -> bsub($half); -subtest '$x = $half -> copy() -> bsub($half);' => sub { - plan tests => 2; - cmp_ok($x, '==', 0, '0.5 + 0.5 = 0'); - is(ref($x), 'Math::BigInt', '0.5 - 0.5 => Math::BigInt'); -}; - -$x = $half -> copy() -> bsub($half -> copy() -> bneg()); -subtest '$x = $half -> copy() -> bsub($half -> copy() -> bneg());' => sub { - plan tests => 2; - cmp_ok($x, '==', 1, '0.5 - -0.5 = 1'); - is(ref($x), 'Math::BigInt', '0.5 - -0.5 => Math::BigInt'); -}; - -$x = $four -> copy() -> bsub($zero); -subtest '$x = $four -> copy() -> bsub($zero);' => sub { - plan tests => 2; - cmp_ok($x, '==', 4, '4 - 0 = 4'); - is(ref($x), 'Math::BigInt', '4 - 0 => Math::BigInt'); -}; - -$x = $zero -> copy() -> bsub($four); -subtest '$x = $zero -> copy() -> bsub($four);' => sub { - plan tests => 2; - cmp_ok($x, '==', -4, '0 - 4 = -4'); - is(ref($x), 'Math::BigInt', '0 - 4 => Math::BigInt'); -}; - -$x = $inf -> copy() -> bsub($four); -subtest '$x = $inf -> copy() -> bsub($four);' => sub { - plan tests => 2; - cmp_ok($x, '==', 'Inf', 'Inf - 4 = Inf'); - is(ref($x), 'Math::BigInt', 'Inf - 4 => Math::BigInt'); -}; - -$x = $nan -> copy() -> bsub($four); -subtest '$x = $nan -> copy() -> bsub($four);' => sub { - plan tests => 2; - is($x, 'NaN', 'NaN - 4 = NaN'); - is(ref($x), 'Math::BigInt', 'NaN - 4 => Math::BigInt'); -}; - -note("testing bmul()"); - -$x = $zero -> copy() -> bmul($four); -subtest '$x = $zero -> copy() -> bmul($four);' => sub { - plan tests => 2; - cmp_ok($x, '==', 0, 'bmul(0, 4) = 0'); - is(ref($x), 'Math::BigInt', 'bmul(0, 4) => Math::BigInt'); -}; - -$x = $four -> copy() -> bmul($four); -subtest '$x = $four -> copy() -> bmul($four);' => sub { - plan tests => 2; - cmp_ok($x, '==', 16, 'bmul(4, 4) = 16'); - is(ref($x), 'Math::BigInt', 'bmul(4, 4) => Math::BigInt'); -}; - -$x = $inf -> copy() -> bmul($four); -subtest '$x = $inf -> copy() -> bmul($four);' => sub { - plan tests => 2; - cmp_ok($x, '==', 'inf', 'bmul(Inf, 4) = Inf'); - is(ref($x), 'Math::BigInt', 'bmul(Inf, 4) => Math::BigInt'); -}; - -$x = $nan -> copy() -> bmul($four); -subtest '$x = $nan -> copy() -> bmul($four);' => sub { - plan tests => 2; - is($x, 'NaN', 'bmul(NaN, 4) = NaN'); - is(ref($x), 'Math::BigInt', 'bmul(NaN, 4) => Math::BigInt'); -}; - -$x = $four -> copy() -> bmul('0.5'); -subtest '' => sub { - plan tests => 2; - cmp_ok($x, '==', 2, 'bmul(4, 0.5) = 2'); - is(ref($x), 'Math::BigInt', 'bmul(4, 0.5) => Math::BigInt'); -}; - -note("testing bmuladd()"); - -$x = $zero -> copy() -> bmuladd($four, $four); -subtest '$x = $zero -> copy() -> bmuladd($four, $four);' => sub { - plan tests => 2; - cmp_ok($x, '==', 4, 'bmuladd(0, 4, 4) = 4'); - is(ref($x), 'Math::BigInt', 'bmuladd(0, 4, 4) => Math::BigInt'); -}; - -$x = $four -> copy() -> bmuladd($four, $four); -subtest '$x = $four -> copy() -> bmuladd($four, $four);' => sub { - plan tests => 2; - cmp_ok($x, '==', 20, 'bmuladd(4, 4, 4) = 20'); - is(ref($x), 'Math::BigInt', 'bmuladd(4, 4, 4) => Math::BigInt'); -}; - -$x = $four -> copy() -> bmuladd($four, $inf); -subtest '$x = $four -> copy() -> bmuladd($four, $inf);' => sub { - plan tests => 2; - cmp_ok($x, '==', 'inf', 'bmuladd(4, 4, Inf) = Inf'); - is(ref($x), 'Math::BigInt', 'bmuladd(4, 4, Inf) => Math::BigInt'); -}; - -$x = $inf -> copy() -> bmuladd($four, $four); -subtest '$x = $inf -> copy() -> bmuladd($four, $four);' => sub { - plan tests => 2; - cmp_ok($x, '==', 'inf', 'bmuladd(Inf, 4, 4) = Inf'); - is(ref($x), 'Math::BigInt', 'bmuladd(Inf, 4, 4) => Math::BigInt'); -}; - -$x = $inf -> copy() -> bmuladd($four, $four); -subtest '$x = $inf -> copy() -> bmuladd($four, $four);' => sub { - plan tests => 2; - cmp_ok($x, '==', 'inf', 'bmuladd(Inf, 4, 4) = Inf'); - is(ref($x), 'Math::BigInt', 'bmuladd(Inf, 4, 4) => Math::BigInt'); -}; - -$x = $nan -> copy() -> bmuladd($four, $four); -subtest '$x = $nan -> copy() -> bmuladd($four, $four);' => sub { - plan tests => 2; - is($x, 'NaN', 'bmuladd(NaN, 4, 4) = NaN'); - is(ref($x), 'Math::BigInt', 'bmuladd(NaN, 4, 4) => Math::BigInt'); -}; - -$x = $four -> copy() -> bmuladd("0.5", $four); -subtest '$x = $four -> copy() -> bmuladd("0.5", $four);' => sub { - plan tests => 2; - cmp_ok($x, '==', 6, 'bmuladd(4, 0.5, 4) = 6'); - is(ref($x), 'Math::BigInt', 'bmuladd(4, 0.5, 4) => Math::BigInt'); -}; - -note("testing bdiv()"); - -$x = $zero -> copy() -> bdiv($one); -subtest '$x = $zero -> copy() -> bdiv($one);' => sub { - plan tests => 2; - cmp_ok($x, '==', 0, 'bdiv(0, 1) = 0'); - is(ref($x), 'Math::BigInt', 'bdiv(0, 1) => Math::BigInt'); -}; - -note("testing bmod()"); - -note("testing bmodpow()"); - -note("testing bpow()"); - -note("testing blog()"); - -note("testing bexp()"); - -note("testing bnok()"); - -note("testing bsin()"); - -note("testing bcos()"); - -note("testing batan()"); - -note("testing batan()"); - -note("testing bsqrt()"); - -note("testing broot()"); - -note("testing bfac()"); - -note("testing bdfac()"); - -note("testing btfac()"); - -note("testing bmfac()"); - -note("testing blsft()"); - -note("testing brsft()"); - -note("testing band()"); - -note("testing bior()"); - -note("testing bxor()"); - -note("testing bnot()"); - -note("testing bround()"); - -note("testing Add tests for rounding a non-integer to an integer. Fixme!"); - -$x = $zero -> copy() -> bround(); -subtest '$x = $zero -> copy() -> bround();' => sub { - plan tests => 2; - cmp_ok($x, '==', 0, 'bround(0)'); - is(ref($x), 'Math::BigInt', 'bround(0) => Math::BigInt'); -}; - -$x = $four -> copy() -> bround(); -subtest '$x = $four -> copy() -> bround();' => sub { - plan tests => 2; - cmp_ok($x, '==', 4, 'bround(4)'); - is(ref($x), 'Math::BigInt', 'bround(4) => Math::BigInt'); -}; - -$x = $inf -> copy() -> bround(); -subtest '$x = $inf -> copy() -> bround();' => sub { - plan tests => 2; - cmp_ok($x, '==', 'inf', 'bround(Inf)'); - is(ref($x), 'Math::BigInt', 'bround(Inf) => Math::BigInt'); -}; - -$x = $nan -> copy() -> bround(); -subtest '$x = $nan -> copy() -> bround();' => sub { - plan tests => 2; - is($x, 'NaN', 'bround(NaN)'); - is(ref($x), 'Math::BigInt', 'bround(NaN) => Math::BigInt'); -}; - -note("testing bfround()"); - -note("testing Add tests for rounding a non-integer to an integer. Fixme!"); - -$x = $zero -> copy() -> bfround(); -subtest '$x = $zero -> copy() -> bfround();' => sub { - plan tests => 2; - cmp_ok($x, '==', 0, 'bfround(0)'); - is(ref($x), 'Math::BigInt', 'bfround(0) => Math::BigInt'); -}; - -$x = $four -> copy() -> bfround(); -subtest '$x = $four -> copy() -> bfround();' => sub { - plan tests => 2; - cmp_ok($x, '==', 4, 'bfround(4)'); - is(ref($x), 'Math::BigInt', 'bfround(4) => Math::BigInt'); -}; - -$x = $inf -> copy() -> bfround(); -subtest '$x = $inf -> copy() -> bfround();' => sub { - plan tests => 2; - cmp_ok($x, '==', 'inf', 'bfround(Inf)'); - is(ref($x), 'Math::BigInt', 'bfround(Inf) => Math::BigInt'); -}; - -$x = $nan -> copy() -> bfround(); -subtest '$x = $nan -> copy() -> bfround();' => sub { - plan tests => 2; - is($x, 'NaN', 'bfround(NaN)'); - is(ref($x), 'Math::BigInt', 'bfround(NaN) => Math::BigInt'); -}; - -note("testing bfloor()"); - -$x = $half -> copy() -> bfloor(); -subtest '$x = $half -> copy() -> bfloor();' => sub { - plan tests => 2; - cmp_ok($x, '==', 0, 'bfloor(0)'); - is(ref($x), 'Math::BigInt', 'bfloor(0) => Math::BigInt'); -}; - -$x = $inf -> copy() -> bfloor(); -subtest '$x = $inf -> copy() -> bfloor();' => sub { - plan tests => 2; - cmp_ok($x, '==', 'Inf', 'bfloor(Inf)'); - is(ref($x), 'Math::BigInt', 'bfloor(Inf) => Math::BigInt'); -}; - -$x = $nan -> copy() -> bfloor(); -subtest '$x = $nan -> copy() -> bfloor();' => sub { - plan tests => 2; - is($x, 'NaN', 'bfloor(NaN)'); - is(ref($x), 'Math::BigInt', 'bfloor(NaN) => Math::BigInt'); -}; - -note("testing bceil()"); - -$x = $half -> copy() -> bceil(); -subtest '$x = $half -> copy() -> bceil();' => sub { - plan tests => 2; - cmp_ok($x, '==', 1, 'bceil(0)'); - is(ref($x), 'Math::BigInt', 'bceil(0) => Math::BigInt'); -}; - -$x = $inf -> copy() -> bceil(); -subtest '$x = $inf -> copy() -> bceil();' => sub { - plan tests => 2; - cmp_ok($x, '==', 'Inf', 'bceil(Inf)'); - is(ref($x), 'Math::BigInt', 'bceil(Inf) => Math::BigInt'); -}; - -$x = $nan -> copy() -> bceil(); -subtest '$x = $nan -> copy() -> bceil();' => sub { - plan tests => 2; - is($x, 'NaN', 'bceil(NaN)'); - is(ref($x), 'Math::BigInt', 'bceil(NaN) => Math::BigInt'); -}; - -note("testing bint()"); - -$x = $half -> copy() -> bint(); -subtest '$x = $half -> copy() -> bint();' => sub { - plan tests => 2; - cmp_ok($x, '==', 0, 'bint(0)'); - is(ref($x), 'Math::BigInt', 'bint(0) => Math::BigInt'); -}; - -$x = $inf -> copy() -> bint(); -subtest '$x = $inf -> copy() -> bint();' => sub { - plan tests => 2; - cmp_ok($x, '==', 'Inf', 'bint(Inf)'); - is(ref($x), 'Math::BigInt', 'bint(Inf) => Math::BigInt'); -}; - -$x = $nan -> copy() -> bint(); -subtest '$x = $nan -> copy() -> bint();' => sub { - plan tests => 2; - is($x, 'NaN', 'bint(NaN)'); - is(ref($x), 'Math::BigInt', 'bint(NaN) => Math::BigInt'); -}; - -note("testing bgcd()"); - -note("testing blcm()"); - -note("testing mantissa()"); - -note("testing exponent()"); - -note("testing parts()"); - -note("testing sparts()"); - -note("testing nparts()"); - -note("testing eparts()"); - -note("testing dparts()"); - -note("testing fparts()"); - -note("testing numerator()"); - -note("testing denominator()"); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/hang-mbr.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/hang-mbr.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/hang-mbr.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/hang-mbr.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,20 @@ +# -*- mode: perl; -*- + +# test for bug #34584: hang in exp(1/2) + +use strict; +use warnings; + +use Test::More tests => 1; + +use Math::BigRat; + +my $result = Math::BigRat->new('1/2')->bexp(); + +is("$result", "824360635350064073424325393907081785827/500000000000000000000000000000000000000", + "exp(1/2) worked"); + +############################################################################## +# done + +1; Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/isa.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/isa.t,v diff -u -p -a -u -p -r1.5 isa.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/isa.t 15 Feb 2023 01:36:20 -0000 1.5 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/isa.t 22 Jan 2025 00:37:42 -0000 @@ -4,10 +4,11 @@ use strict; use warnings; use lib 't'; -use Test::More tests => 11; +use Test::More tests => 13; use Math::BigInt::Subclass; use Math::BigFloat::Subclass; +use Math::BigFloat::BareSubclass; use Math::BigInt; use Math::BigFloat; @@ -48,4 +49,11 @@ ok(!Math::BigFloat->new(123)->isa('Math: my $x = Math::BigFloat->new(Math::BigInt::Subclass->new(123)); is(ref($x), 'Math::BigFloat', 'ref($x) = "Math::BigFloat"'); isa_ok($x, 'Math::BigFloat'); +} + +{ + my $x = Math::BigFloat->new(9999.99); + my $y = Math::BigFloat::BareSubclass->new(9999.99); + ok($x == $y, "Math::BigFloat parent == subclass"); + ok($y == $x, "Math::BigFloat subclass == parent"); } Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/mbimbf.inc =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/mbimbf.inc,v diff -u -p -a -u -p -r1.7 mbimbf.inc --- gnu/usr.bin/perl/cpan/Math-BigInt/t/mbimbf.inc 14 May 2024 19:38:56 -0000 1.7 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/mbimbf.inc 22 Jan 2025 00:37:42 -0000 @@ -255,42 +255,42 @@ foreach my $class ($mbi, $mbf) { $x = $class->bzero(); $x->accuracy(5); - is($x->{_a}, 5, qq|\$x = $class->bzero(); \$x->accuracy(5); \$x->{_a}|); + is($x->{accuracy}, 5, qq|\$x = $class->bzero(); \$x->accuracy(5); \$x->{accuracy}|); $x = $class->bzero(); $x->precision(5); - is($x->{_p}, 5, qq|\$x = $class->bzero(); \$x->precision(5); \$x->{_p}|); + is($x->{precision}, 5, qq|\$x = $class->bzero(); \$x->precision(5); \$x->{precision}|); $x = $class->new(0); $x->accuracy(5); - is($x->{_a}, 5, qq|\$x = $class->new(0); \$x->accuracy(5); \$x->{_a}|); + is($x->{accuracy}, 5, qq|\$x = $class->new(0); \$x->accuracy(5); \$x->{accuracy}|); $x = $class->new(0); $x->precision(5); - is($x->{_p}, 5, qq|\$x = $class->new(0); \$x->precision(5); \$x->{_p}|); + is($x->{precision}, 5, qq|\$x = $class->new(0); \$x->precision(5); \$x->{precision}|); $x = $class->bzero(); $x->round(5); - is($x->{_a}, 5, qq|\$x = $class->bzero(); \$x->round(5); \$x->{_a}|); + is($x->{accuracy}, 5, qq|\$x = $class->bzero(); \$x->round(5); \$x->{accuracy}|); $x = $class->bzero(); $x->round(undef, 5); - is($x->{_p}, 5, qq|\$x = $class->bzero(); \$x->round(undef, 5); \$x->{_p}|); + is($x->{precision}, 5, qq|\$x = $class->bzero(); \$x->round(undef, 5); \$x->{precision}|); $x = $class->new(0); $x->round(5); - is($x->{_a}, 5, qq|\$x = $class->new(0); \$x->round(5); \$x->{_a}|); + is($x->{accuracy}, 5, qq|\$x = $class->new(0); \$x->round(5); \$x->{accuracy}|); $x = $class->new(0); $x->round(undef, 5); - is($x->{_p}, 5, qq|\$x = $class->new(0); \$x->round(undef, 5); \$x->{_p}|); + is($x->{precision}, 5, qq|\$x = $class->new(0); \$x->round(undef, 5); \$x->{precision}|); # see if trying to increasing A in bzero() doesn't do something $x = $class->bzero(); - $x->{_a} = 3; + $x->{accuracy} = 3; $x->round(5); - is($x->{_a}, 3, - qq|\$x = $class->bzero(); \$x->{_a} = 3; \$x->round(5); \$x->{_a}|); + is($x->{accuracy}, 3, + qq|\$x = $class->bzero(); \$x->{accuracy} = 3; \$x->round(5); \$x->{accuracy}|); } ############################################################################### @@ -349,8 +349,8 @@ foreach my $class ($mbi, $mbf) { $x = $mbf->new("123.456"); $y = $mbf->new("654.321"); -$x->{_a} = 5; # $x->accuracy(5) would round $x straight away -$y->{_a} = 4; # $y->accuracy(4) would round $x straight away +$x->{accuracy} = 5; # $x->accuracy(5) would round $x straight away +$y->{accuracy} = 4; # $y->accuracy(4) would round $x straight away $z = $x + $y; is($z, "777.8", q|$z = $x + $y|); @@ -373,20 +373,20 @@ is($z, "15241", q|$z = $x * $x|); #is($x, '123.456'); $z = $x->copy(); -$z->{_a} = 2; +$z->{accuracy} = 2; $z = $z / 2; is($z, 62, q|$z = $z / 2|); $x = $mbf->new(123456); -$x->{_a} = 4; +$x->{accuracy} = 4; $z = $x->copy; $z++; is($z, 123500, q|$z++|); $x = $mbi->new(123456); $y = $mbi->new(654321); -$x->{_a} = 5; # $x->accuracy(5) would round $x straight away -$y->{_a} = 4; # $y->accuracy(4) would round $x straight away +$x->{accuracy} = 5; # $x->accuracy(5) would round $x straight away +$y->{accuracy} = 4; # $y->accuracy(4) would round $x straight away $z = $x + $y; is($z, 777800, q|$z = $x + $y|); @@ -409,22 +409,22 @@ $z++; is($z, 123460, q|$z++|); $z = $x->copy(); -$z->{_a} = 2; +$z->{accuracy} = 2; $z = $z / 2; is($z, 62000, q|$z = $z / 2|); $x = $mbi->new(123400); -$x->{_a} = 4; +$x->{accuracy} = 4; is($x->bnot(), -123400, q|$x->bnot()|); # not -1234001 # to be consistent with other methods, babs() and bneg() also support rounding $x = $mbi->new(-123401); -$x->{_a} = 4; +$x->{accuracy} = 4; is($x->babs(), 123400, q|$x->babs()|); $x = $mbi->new(-123401); -$x->{_a} = 4; +$x->{accuracy} = 4; is($x->bneg(), 123400, q|$x->bneg()|); # test bdiv rounding to A and R (bug in v1.48 and maybe earlier versions) @@ -435,27 +435,27 @@ is($x, '123.4', q|$x|); $x = $mbi->new('123456'); $y = $mbi->new('123456'); -$y->{_a} = 6; +$y->{accuracy} = 6; is($x->bdiv($y), 1, q|$x->bdiv($y)|); -is($x->{_a}, 6, q|$x->{_a}|); # carried over +is($x->{accuracy}, 6, q|$x->{accuracy}|); # carried over $x = $mbi->new('123456'); $y = $mbi->new('123456'); -$x->{_a} = 6; +$x->{accuracy} = 6; is($x->bdiv($y), 1, q|$x->bdiv($y)|); -is($x->{_a}, 6, q|$x->{_a}|); # carried over +is($x->{accuracy}, 6, q|$x->{accuracy}|); # carried over $x = $mbi->new('123456'); $y = $mbi->new('223456'); -$y->{_a} = 6; +$y->{accuracy} = 6; is($x->bdiv($y), 0, q|$x->bdiv($y)|); -is($x->{_a}, 6, q|$x->{_a}|); # carried over +is($x->{accuracy}, 6, q|$x->{accuracy}|); # carried over $x = $mbi->new('123456'); $y = $mbi->new('223456'); -$x->{_a} = 6; +$x->{accuracy} = 6; is($x->bdiv($y), 0, q|$x->bdiv($y)|); -is($x->{_a}, 6, q|$x->{_a}|); # carried over +is($x->{accuracy}, 6, q|$x->{accuracy}|); # carried over ############################################################################### # test that bop(0) does the same than bop(undef) @@ -466,7 +466,7 @@ is($x->copy()->bsqrt(0), $x->copy()->bsq is($x->copy->bsqrt(0), '35136.41828644462161665823116758077037159', q|$x->copy->bsqrt(...)|); -is($x->{_a}, undef, q|$x->{_a}|); +is($x->{accuracy}, undef, q|$x->{accuracy}|); # test that bsqrt() modifies $x and does not just return something else # (especially under Math::BigInt::BareCalc) @@ -622,19 +622,19 @@ unlike($warn, qr/^Use of uninitialized v } $x = $mbf->new(10); -$x->{_a} = 4; +$x->{accuracy} = 4; is($x->bdiv(3), '3.333', q|$x->bdiv(3)|); -is($x->{_a}, 4, q|$x->{_a}|); # set's it since no fallback +is($x->{accuracy}, 4, q|$x->{accuracy}|); # set's it since no fallback $x = $mbf->new(10); -$x->{_a} = 4; +$x->{accuracy} = 4; $y = $mbf->new(3); is($x->bdiv($y), '3.333', q|$x->bdiv($y)|); -is($x->{_a}, 4, q|$x->{_a}|); # set's it since no fallback +is($x->{accuracy}, 4, q|$x->{accuracy}|); # set's it since no fallback # rounding to P of x $x = $mbf->new(10); -$x->{_p} = -2; +$x->{precision} = -2; is($x->bdiv(3), '3.33', q|$x->bdiv(3)|); # round in div with requested P @@ -653,22 +653,22 @@ is($x->bdiv(3, undef, -2), '3.33', q|$x- $x = $mbf->new(10); $y = $mbf->new(3); -$y->{_a} = 4; +$y->{accuracy} = 4; is($x->bdiv($y), '3.333', q|$x->bdiv($y) = '3.333'|); -is($x->{_a}, 4, q|$x->{_a} = 4|); -is($y->{_a}, 4, q|$y->{_a} = 4|); # set's it since no fallback -is($x->{_p}, undef, q|$x->{_p} = undef|); -is($y->{_p}, undef, q|$y->{_p} = undef|); +is($x->{accuracy}, 4, q|$x->{accuracy} = 4|); +is($y->{accuracy}, 4, q|$y->{accuracy} = 4|); # set's it since no fallback +is($x->{precision}, undef, q|$x->{precision} = undef|); +is($y->{precision}, undef, q|$y->{precision} = undef|); # rounding to P of y $x = $mbf->new(10); $y = $mbf->new(3); -$y->{_p} = -2; +$y->{precision} = -2; is($x->bdiv($y), '3.33', q|$x->bdiv($y) = '3.33'|); -is($x->{_p}, -2, q|$x->{_p} = -2|); - is($y->{_p}, -2, q|$y->{_p} = -2|); -is($x->{_a}, undef, q|$x->{_a} = undef|); -is($y->{_a}, undef, q|$y->{_a} = undef|); +is($x->{precision}, -2, q|$x->{precision} = -2|); + is($y->{precision}, -2, q|$y->{precision} = -2|); +is($x->{accuracy}, undef, q|$x->{accuracy} = undef|); +is($y->{accuracy}, undef, q|$y->{accuracy} = undef|); ############################################################################### # test whether bround(-n) fails in MBF (undocumented in MBI) @@ -681,91 +681,91 @@ like($@, qr/^bround\(\) needs positive a note("test whether rounding to higher accuracy is no-op"); $x = $mbf->new(1); -$x->{_a} = 4; +$x->{accuracy} = 4; is($x, "1.000", q|$x = "1.000"|); $x->bround(6); # must be no-op -is($x->{_a}, 4, q|$x->{_a} = 4|); +is($x->{accuracy}, 4, q|$x->{accuracy} = 4|); is($x, "1.000", q|$x = "1.000"|); $x = $mbi->new(1230); -$x->{_a} = 3; +$x->{accuracy} = 3; is($x, "1230", q|$x = "1230"|); $x->bround(6); # must be no-op -is($x->{_a}, 3, q|$x->{_a} = 3|); +is($x->{accuracy}, 3, q|$x->{accuracy} = 3|); is($x, "1230", q|$x = "1230"|); -note("bround(n) should set _a"); +note("bround(n) should set accuracy"); $x->bround(2); # smaller works is($x, "1200", q|$x = "1200"|); -is($x->{_a}, 2, q|$x->{_a} = 2|); +is($x->{accuracy}, 2, q|$x->{accuracy} = 2|); # bround(-n) is undocumented and only used by MBF -note("bround(-n) should set _a"); +note("bround(-n) should set accuracy"); $x = $mbi->new(12345); $x->bround(-1); is($x, "12300", q|$x = "12300"|); -is($x->{_a}, 4, q|$x->{_a} = 4|); +is($x->{accuracy}, 4, q|$x->{accuracy} = 4|); -note("bround(-n) should set _a"); +note("bround(-n) should set accuracy"); $x = $mbi->new(12345); $x->bround(-2); is($x, "12000", q|$x = "12000"|); -is($x->{_a}, 3, q|$x->{_a} = 3|); +is($x->{accuracy}, 3, q|$x->{accuracy} = 3|); -note("bround(-n) should set _a"); +note("bround(-n) should set accuracy"); $x = $mbi->new(12345); -$x->{_a} = 5; +$x->{accuracy} = 5; $x->bround(-3); is($x, "10000", q|$x = "10000"|); -is($x->{_a}, 2, q|$x->{_a} = 2|); +is($x->{accuracy}, 2, q|$x->{accuracy} = 2|); -note("bround(-n) should set _a"); +note("bround(-n) should set accuracy"); $x = $mbi->new(12345); -$x->{_a} = 5; +$x->{accuracy} = 5; $x->bround(-4); is($x, "0", q|$x = "0"|); -is($x->{_a}, 1, q|$x->{_a} = 1|); +is($x->{accuracy}, 1, q|$x->{accuracy} = 1|); note("bround(-n) should be no-op if n too big"); $x = $mbi->new(12345); $x->bround(-5); is($x, "0", q|$x = "0"|); # scale to "big" => 0 -is($x->{_a}, 0, q|$x->{_a} = 0|); +is($x->{accuracy}, 0, q|$x->{accuracy} = 0|); note("bround(-n) should be no-op if n too big"); $x = $mbi->new(54321); $x->bround(-5); is($x, "100000", q|$x = "100000"|); # used by MBF to round 0.0054321 at 0.0_6_00000 -is($x->{_a}, 0, q|$x->{_a} = 0|); +is($x->{accuracy}, 0, q|$x->{accuracy} = 0|); note("bround(-n) should be no-op if n too big"); $x = $mbi->new(54321); -$x->{_a} = 5; +$x->{accuracy} = 5; $x->bround(-6); is($x, "100000", q|$x = "100000"|); # no-op -is($x->{_a}, 0, q|$x->{_a} = 0|); +is($x->{accuracy}, 0, q|$x->{accuracy} = 0|); -note("bround(n) should set _a"); +note("bround(n) should set accuracy"); $x = $mbi->new(12345); -$x->{_a} = 5; +$x->{accuracy} = 5; $x->bround(5); # must be no-op is($x, "12345", q|$x = "12345"|); -is($x->{_a}, 5, q|$x->{_a} = 5|); +is($x->{accuracy}, 5, q|$x->{accuracy} = 5|); -note("bround(n) should set _a"); +note("bround(n) should set accuracy"); $x = $mbi->new(12345); -$x->{_a} = 5; +$x->{accuracy} = 5; $x->bround(6); # must be no-op is($x, "12345", q|$x = "12345"|); @@ -791,7 +791,7 @@ note("MBI::bfround should clear A for ne $x = $mbi->new("1234"); $x->accuracy(3); $x->bfround(-2); -is($x->{_a}, undef, q|$x->{_a} = undef|); +is($x->{accuracy}, undef, q|$x->{accuracy} = undef|); note("test that bfround() and bround() work with large numbers"); @@ -816,51 +816,51 @@ is($x, "0.000176118351532229658330398027 note("rounding with already set precision/accuracy"); $x = $mbf->new(1); -$x->{_p} = -5; +$x->{precision} = -5; is($x, "1.00000", q|$x = "1.00000"|); note("further rounding down"); is($x->bfround(-2), "1.00", q|$x->bfround(-2) = "1.00"|); -is($x->{_p}, -2, q|$x->{_p} = -2|); +is($x->{precision}, -2, q|$x->{precision} = -2|); $x = $mbf->new(12345); -$x->{_a} = 5; +$x->{accuracy} = 5; is($x->bround(2), "12000", q|$x->bround(2) = "12000"|); -is($x->{_a}, 2, q|$x->{_a} = 2|); +is($x->{accuracy}, 2, q|$x->{accuracy} = 2|); $x = $mbf->new("1.2345"); -$x->{_a} = 5; +$x->{accuracy} = 5; is($x->bround(2), "1.2", q|$x->bround(2) = "1.2"|); -is($x->{_a}, 2, q|$x->{_a} = 2|); +is($x->{accuracy}, 2, q|$x->{accuracy} = 2|); note("mantissa/exponent format and A/P"); $x = $mbf->new("12345.678"); $x->accuracy(4); is($x, "12350", q|$x = "12350"|); -is($x->{_a}, 4, q|$x->{_a} = 4|); -is($x->{_p}, undef, q|$x->{_p} = undef|); +is($x->{accuracy}, 4, q|$x->{accuracy} = 4|); +is($x->{precision}, undef, q|$x->{precision} = undef|); -#is($x->{_m}->{_a}, undef, q|$x->{_m}->{_a} = undef|); -#is($x->{_e}->{_a}, undef, q|$x->{_e}->{_a} = undef|); -#is($x->{_m}->{_p}, undef, q|$x->{_m}->{_p} = undef|); -#is($x->{_e}->{_p}, undef, q|$x->{_e}->{_p} = undef|); +#is($x->{_m}->{accuracy}, undef, q|$x->{_m}->{accuracy} = undef|); +#is($x->{_e}->{accuracy}, undef, q|$x->{_e}->{accuracy} = undef|); +#is($x->{_m}->{precision}, undef, q|$x->{_m}->{precision} = undef|); +#is($x->{_e}->{precision}, undef, q|$x->{_e}->{precision} = undef|); note("check for no A/P in case of fallback result"); $x = $mbf->new(100) / 3; -is($x->{_a}, undef, q|$x->{_a} = undef|); -is($x->{_p}, undef, q|$x->{_p} = undef|); +is($x->{accuracy}, undef, q|$x->{accuracy} = undef|); +is($x->{precision}, undef, q|$x->{precision} = undef|); note("result & remainder"); $x = $mbf->new(100) / 3; ($x, $y) = $x->bdiv(3); -is($x->{_a}, undef, q|$x->{_a} = undef|); -is($x->{_p}, undef, q|$x->{_p} = undef|); -is($y->{_a}, undef, q|$y->{_a} = undef|); -is($y->{_p}, undef, q|$y->{_p} = undef|); +is($x->{accuracy}, undef, q|$x->{accuracy} = undef|); +is($x->{precision}, undef, q|$x->{precision} = undef|); +is($y->{accuracy}, undef, q|$y->{accuracy} = undef|); +is($y->{precision}, undef, q|$y->{precision} = undef|); ############################################################################### # math with two numbers with different A and P @@ -959,122 +959,122 @@ is($params[0], $x, q|$params[0] = $x|); foreach my $class ($mbi, $mbf) { $x = $class->new(2)->bzero(); - is($x->{_a}, undef, qq|\$x = $class->new(2)->bzero(); \$x->{_a}|); - is($x->{_p}, undef, qq|\$x = $class->new(2)->bzero(); \$x->{_p}|); + is($x->{accuracy}, undef, qq|\$x = $class->new(2)->bzero(); \$x->{accuracy}|); + is($x->{precision}, undef, qq|\$x = $class->new(2)->bzero(); \$x->{precision}|); $x = $class->new(2)->bone(); - is($x->{_a}, undef, qq|\$x = $class->new(2)->bone(); \$x->{_a}|); - is($x->{_p}, undef, qq|\$x = $class->new(2)->bone(); \$x->{_p}|); + is($x->{accuracy}, undef, qq|\$x = $class->new(2)->bone(); \$x->{accuracy}|); + is($x->{precision}, undef, qq|\$x = $class->new(2)->bone(); \$x->{precision}|); $x = $class->new(2)->binf(); - is($x->{_a}, undef, qq|\$x = $class->new(2)->binf(); \$x->{_a}|); - is($x->{_p}, undef, qq|\$x = $class->new(2)->binf(); \$x->{_p}|); + is($x->{accuracy}, undef, qq|\$x = $class->new(2)->binf(); \$x->{accuracy}|); + is($x->{precision}, undef, qq|\$x = $class->new(2)->binf(); \$x->{precision}|); $x = $class->new(2)->bnan(); - is($x->{_a}, undef, qq|\$x = $class->new(2)->bnan(); \$x->{_a}|); - is($x->{_p}, undef, qq|\$x = $class->new(2)->bnan(); \$x->{_p}|); + is($x->{accuracy}, undef, qq|\$x = $class->new(2)->bnan(); \$x->{accuracy}|); + is($x->{precision}, undef, qq|\$x = $class->new(2)->bnan(); \$x->{precision}|); note "Verify that bnan() does not delete/undefine accuracy and precision."; $x = $class->new(2); - $x->{_a} = 1; + $x->{accuracy} = 1; $x->bnan(); - is($x->{_a}, 1, qq|\$x = $class->new(2); \$x->{_a} = 1; \$x->bnan(); \$x->{_a}|); + is($x->{accuracy}, 1, qq|\$x = $class->new(2); \$x->{accuracy} = 1; \$x->bnan(); \$x->{accuracy}|); $x = $class->new(2); - $x->{_p} = 1; + $x->{precision} = 1; $x->bnan(); - is($x->{_p}, 1, qq|\$x = $class->new(2); \$x->{_p} = 1; \$x->bnan(); \$x->{_p}|); + is($x->{precision}, 1, qq|\$x = $class->new(2); \$x->{precision} = 1; \$x->bnan(); \$x->{precision}|); note "Verify that binf() does not delete/undefine accuracy and precision."; $x = $class->new(2); - $x->{_a} = 1; + $x->{accuracy} = 1; $x->binf(); - is($x->{_a}, 1, qq|\$x = $class->new(2); \$x->{_a} = 1; \$x->binf(); \$x->{_a}|); + is($x->{accuracy}, 1, qq|\$x = $class->new(2); \$x->{accuracy} = 1; \$x->binf(); \$x->{accuracy}|); $x = $class->new(2); - $x->{_p} = 1; + $x->{precision} = 1; $x->binf(); - is($x->{_p}, 1, qq|\$x = $class->new(2); \$x->{_p} = 1; \$x->binf(); \$x->{_p}|); + is($x->{precision}, 1, qq|\$x = $class->new(2); \$x->{precision} = 1; \$x->binf(); \$x->{precision}|); note "Verify that accuracy can be set as argument to new()."; $x = $class->new(2, 1); - is($x->{_a}, 1, qq|\$x = $class->new(2, 1); \$x->{_a}|); - is($x->{_p}, undef, qq|\$x = $class->new(2, 1); \$x->{_p}|); + is($x->{accuracy}, 1, qq|\$x = $class->new(2, 1); \$x->{accuracy}|); + is($x->{precision}, undef, qq|\$x = $class->new(2, 1); \$x->{precision}|); note "Verify that precision can be set as argument to new()."; $x = $class->new(2, undef, 1); - is($x->{_a}, undef, qq|\$x = $class->new(2, undef, 1); \$x->{_a}|); - is($x->{_p}, 1, qq|\$x = $class->new(2, undef, 1); \$x->{_p}|); + is($x->{accuracy}, undef, qq|\$x = $class->new(2, undef, 1); \$x->{accuracy}|); + is($x->{precision}, 1, qq|\$x = $class->new(2, undef, 1); \$x->{precision}|); note "Verify that accuracy set with new() is preserved after calling bzero()."; $x = $class->new(2, 1)->bzero(); - is($x->{_a}, 1, qq|\$x = $class->new(2, 1)->bzero(); \$x->{_a}|); - is($x->{_p}, undef, qq|\$x = $class->new(2, 1)->bzero(); \$x->{_p}|); + is($x->{accuracy}, 1, qq|\$x = $class->new(2, 1)->bzero(); \$x->{accuracy}|); + is($x->{precision}, undef, qq|\$x = $class->new(2, 1)->bzero(); \$x->{precision}|); note "Verify that precision set with new() is preserved after calling bzero()."; $x = $class->new(2, undef, 1)->bzero(); - is($x->{_a}, undef, qq|\$x = $class->new(2, undef, 1)->bzero(); \$x->{_a}|); - is($x->{_p}, 1, qq|\$x = $class->new(2, undef, 1)->bzero(); \$x->{_p}|); + is($x->{accuracy}, undef, qq|\$x = $class->new(2, undef, 1)->bzero(); \$x->{accuracy}|); + is($x->{precision}, 1, qq|\$x = $class->new(2, undef, 1)->bzero(); \$x->{precision}|); note "Verify that accuracy set with new() is preserved after calling bone()."; $x = $class->new(2, 1)->bone(); - is($x->{_a}, 1, qq|\$x = $class->new(2, 1)->bone(); \$x->{_a}|); - is($x->{_p}, undef, qq|\$x = $class->new(2, 1)->bone(); \$x->{_p}|); + is($x->{accuracy}, 1, qq|\$x = $class->new(2, 1)->bone(); \$x->{accuracy}|); + is($x->{precision}, undef, qq|\$x = $class->new(2, 1)->bone(); \$x->{precision}|); note "Verify that precision set with new() is preserved after calling bone()."; $x = $class->new(2, undef, 1)->bone(); - is($x->{_a}, undef, qq|\$x = $class->new(2, undef, 1)->bone(); \$x->{_a}|); - is($x->{_p}, 1, qq|\$x = $class->new(2, undef, 1)->bone(); \$x->{_p}|); + is($x->{accuracy}, undef, qq|\$x = $class->new(2, undef, 1)->bone(); \$x->{accuracy}|); + is($x->{precision}, 1, qq|\$x = $class->new(2, undef, 1)->bone(); \$x->{precision}|); note "Verify that accuracy can be set with instance method bone('+')."; $x = $class->new(2); $x->bone('+', 2, undef); - is($x->{_a}, 2, qq|\$x = $class->new(2); \$x->{_a}|); - is($x->{_p}, undef, qq|\$x = $class->new(2); \$x->{_p}|); + is($x->{accuracy}, 2, qq|\$x = $class->new(2); \$x->{accuracy}|); + is($x->{precision}, undef, qq|\$x = $class->new(2); \$x->{precision}|); note "Verify that precision can be set with instance method bone('+')."; $x = $class->new(2); $x->bone('+', undef, 2); - is($x->{_a}, undef, qq|\$x = $class->new(2); \$x->bone('+', undef, 2); \$x->{_a}|); - is($x->{_p}, 2, qq|\$x = $class->new(2); \$x->bone('+', undef, 2); \$x->{_p}|); + is($x->{accuracy}, undef, qq|\$x = $class->new(2); \$x->bone('+', undef, 2); \$x->{accuracy}|); + is($x->{precision}, 2, qq|\$x = $class->new(2); \$x->bone('+', undef, 2); \$x->{precision}|); note "Verify that accuracy can be set with instance method bone('-')."; $x = $class->new(2); $x->bone('-', 2, undef); - is($x->{_a}, 2, qq|\$x = $class->new(2); \$x->bone('-', 2, undef); \$x->{_a}|); - is($x->{_p}, undef, qq|\$x = $class->new(2); \$x->bone('-', 2, undef); \$x->{_p}|); + is($x->{accuracy}, 2, qq|\$x = $class->new(2); \$x->bone('-', 2, undef); \$x->{accuracy}|); + is($x->{precision}, undef, qq|\$x = $class->new(2); \$x->bone('-', 2, undef); \$x->{precision}|); note "Verify that precision can be set with instance method bone('-')."; $x = $class->new(2); $x->bone('-', undef, 2); - is($x->{_a}, undef, qq|\$x = $class->new(2); \$x->bone('-', undef, 2); \$x->{_a}|); - is($x->{_p}, 2, qq|\$x = $class->new(2); \$x->bone('-', undef, 2); \$x->{_p}|); + is($x->{accuracy}, undef, qq|\$x = $class->new(2); \$x->bone('-', undef, 2); \$x->{accuracy}|); + is($x->{precision}, 2, qq|\$x = $class->new(2); \$x->bone('-', undef, 2); \$x->{precision}|); note "Verify that accuracy can be set with instance method bzero()."; $x = $class->new(2); $x->bzero(2, undef); - is($x->{_a}, 2, qq|\$x = $class->new(2);\$x->bzero(2, undef); \$x->{_a}|); - is($x->{_p}, undef, qq|\$x = $class->new(2);\$x->bzero(2, undef); \$x->{_p}|); + is($x->{accuracy}, 2, qq|\$x = $class->new(2);\$x->bzero(2, undef); \$x->{accuracy}|); + is($x->{precision}, undef, qq|\$x = $class->new(2);\$x->bzero(2, undef); \$x->{precision}|); note "Verify that precision can be set with instance method bzero()."; $x = $class->new(2); $x->bzero(undef, 2); - is($x->{_a}, undef, qq|\$x = $class->new(2); \$x->bzero(undef, 2); \$x->{_a}|); - is($x->{_p}, 2, qq|\$x = $class->new(2); \$x->bzero(undef, 2); \$x->{_p}|); + is($x->{accuracy}, undef, qq|\$x = $class->new(2); \$x->bzero(undef, 2); \$x->{accuracy}|); + is($x->{precision}, 2, qq|\$x = $class->new(2); \$x->bzero(undef, 2); \$x->{precision}|); } ############################################################################### @@ -1314,16 +1314,16 @@ while () { # print "Check a=$a p=$p\n"; # print "# Tried: '$try'\n"; if ($a ne '') { - unless (is($x->{_a}, $a, qq|\$x->{_a} == $a|) && - is($x->{_p}, undef, qq|\$x->{_p} is undef|)) + unless (is($x->{accuracy}, $a, qq|\$x->{accuracy} == $a|) && + is($x->{precision}, undef, qq|\$x->{precision} is undef|)) { print "# Check: A = $a and P = undef\n"; print "# Tried: $try\n"; } } if ($p ne '') { - unless (is($x->{_p}, $p, qq|\$x->{_p} == $p|) && - is($x->{_a}, undef, qq|\$x->{_a} is undef|)) + unless (is($x->{precision}, $p, qq|\$x->{precision} == $p|) && + is($x->{accuracy}, undef, qq|\$x->{accuracy} is undef|)) { print "# Check: A = undef and P = $p\n"; print "# Tried: $try\n"; Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/mbimbf.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/mbimbf.t,v diff -u -p -a -u -p -r1.6 mbimbf.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/mbimbf.t 15 Feb 2023 01:36:20 -0000 1.6 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/mbimbf.t 22 Jan 2025 00:37:42 -0000 @@ -7,7 +7,7 @@ use strict; use warnings; use Test::More tests => 712 # tests in require'd file - + 26; # tests in this file + + 52; # tests in this file use Math::BigInt only => 'Calc'; use Math::BigFloat; @@ -58,24 +58,71 @@ foreach my $class (qw/Math::BigInt Math: } foreach my $class (qw/Math::BigInt Math::BigFloat/) { - $class->accuracy(42); + my $x; - # $x gets A of 42, too! - my $x = $class->new(123); + # Accuracy - # really? - is($x->accuracy(), 42, '$x has A of 42'); + # set and check the class accuracy + $class->accuracy(1); + is($class->accuracy(), 1, "$class has A of 1"); - # $x has no A, but the global is still in effect for $x so the return value - # of that operation should be 42, not undef - is($x->accuracy(undef), 42, '$x has A from global'); + # a new instance gets the class accuracy + $x = $class->new(123); + is($x->accuracy(), 1, '$x has A of 1'); - # so $x should still have A = 42 - is($x->accuracy(), 42, '$x has still A of 42'); + # set and check the instance accuracy + $x->accuracy(2); + is($x->accuracy(), 2, '$x has A of 2'); - # reset for further tests + # change the class accuracy + $class->accuracy(3); + is($class->accuracy(), 3, "$class has A of 3"); + + # verify that the instance accuracy hasn't changed + is($x->accuracy(), 2, '$x still has A of 2'); + + # change the instance accuracy + $x->accuracy(undef); + is($x->accuracy(), undef, '$x now has A of undef'); + + # check the class accuracy + is($class->accuracy(), 3, "$class still has A of 3"); + + # change the class accuracy again $class->accuracy(undef); + is($class->accuracy(), undef, "$class now has A of undef"); + + # Precision + + # set and check the class precision + $class->precision(1); + is($class->precision(), 1, "$class has A of 1"); + + # a new instance gets the class precision + $x = $class->new(123); + is($x->precision(), 1, '$x has A of 1'); + + # set and check the instance precision + $x->precision(2); + is($x->precision(), 2, '$x has A of 2'); + + # change the class precision + $class->precision(3); + is($class->precision(), 3, "$class has A of 3"); + + # verify that the instance precision hasn't changed + is($x->precision(), 2, '$x still has A of 2'); + + # change the instance precision + $x->precision(undef); + is($x->precision(), undef, '$x now has A of undef'); + + # check the class precision + is($class->precision(), 3, "$class still has A of 3"); + + # change the class precision again $class->precision(undef); + is($class->precision(), undef, "$class now has A of undef"); } # bug with blog(Math::BigFloat, Math::BigInt) Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/mbr_ali.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/mbr_ali.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/mbr_ali.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/mbr_ali.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,15 @@ +# -*- mode: perl; -*- + +# test that the new alias names work + +use strict; +use warnings; + +use Test::More tests => 6; + +use Math::BigRat; + +our $CLASS; +$CLASS = 'Math::BigRat'; + +require './t/alias.inc'; Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbf0.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbf0.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbf0.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbf0.t 15 Feb 2023 01:36:20 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,15 +0,0 @@ -# -*- mode: perl; -*- - -# check that simple requiring Math::BigFloat and then bzero() works - -use strict; -use warnings; - -use Test::More tests => 1; - -require Math::BigFloat; - -my $x = Math::BigFloat->bzero(); $x++; -is($x, 1, '$x is 1'); - -# all tests done Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbf1.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbf1.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbf1.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbf1.t 15 Feb 2023 01:36:20 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,15 +0,0 @@ -# -*- mode: perl; -*- - -# check that simple requiring Math::BigFloat and then bone() works - -use strict; -use warnings; - -use Test::More tests => 1; - -require Math::BigFloat; - -my $x = Math::BigFloat->bone(); -is($x, 1, '$x is 1'); - -# all tests done Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfa.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfa.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfa.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfa.t 15 Feb 2023 01:36:20 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,15 +0,0 @@ -# -*- mode: perl; -*- - -# check that simple requiring Math::BigFloat and then bnan() works - -use strict; -use warnings; - -use Test::More tests => 1; - -require Math::BigFloat; - -my $x = Math::BigFloat->bnan(1); -is($x, 'NaN', '$x is NaN'); - -# all tests done Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfi.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfi.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfi.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfi.t 15 Feb 2023 01:36:20 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,15 +0,0 @@ -# -*- mode: perl; -*- - -# check that simple requiring Math::BigFloat and then binf() works - -use strict; -use warnings; - -use Test::More tests => 1; - -require Math::BigFloat; - -my $x = Math::BigFloat->binf(); -is($x, 'inf', '$x is inf'); - -# all tests done Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfn.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfn.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfn.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfn.t 15 Feb 2023 01:36:20 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,16 +0,0 @@ -# -*- mode: perl; -*- - -# check that simple requiring Math::BigFloat and then new() works - -use strict; -use warnings; - -use Test::More tests => 1; - -require Math::BigFloat; - -my $x = Math::BigFloat->new(1); -++$x; -is($x, 2, '$x is 2'); - -# all tests done Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfw.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfw.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfw.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/req_mbfw.t 15 Feb 2023 01:36:20 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,29 +0,0 @@ -# -*- mode: perl; -*- - -# check that requiring Math::BigFloat and then calling import() works - -use strict; -use warnings; - -use Test::More tests => 3; - -use lib 't'; - -# normal require that calls import automatically (we thus have MBI afterwards) -require Math::BigFloat; - -my $x = Math::BigFloat->new(1); -++$x; -is($x, 2, '$x is 2'); - -like(Math::BigFloat->config("with"), qr/^Math::BigInt::(Fast)?Calc\z/, - '"with" ignored'); - -# now override -Math::BigFloat->import(with => 'Math::BigInt::Subclass'); - -# the "with" argument is ignored -like(Math::BigFloat->config("with"), qr/^Math::BigInt::(Fast)?Calc\z/, - '"with" ignored'); - -# all tests done Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/require.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/require.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/require.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/require.t 15 Feb 2023 01:36:20 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,17 +0,0 @@ -# -*- mode: perl; -*- - -# check that simple requiring Math::BigInt works - -use strict; -use warnings; - -use Test::More tests => 1; - -require Math::BigInt; - -my $x = Math::BigInt->new(1); -++$x; - -is($x, 2, '$x is 2'); - -# all tests done Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/rt121139.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/rt121139.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/rt121139.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/rt121139.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,16 @@ +# -*- mode: perl; -*- + +# check for cpan rt #121139 + +use strict; +use warnings; +use Test::More tests => 2; +use Math::BigRat; + +my $a = Math::BigRat->new('3/2'); +my $x = Math::BigRat->new('2/3'); +is("$a", "3/2"); + +my $y = $a; +$y = $x * $y; +is("$a", "3/2"); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/sub_mbf.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/sub_mbf.t,v diff -u -p -a -u -p -r1.8 sub_mbf.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/sub_mbf.t 14 May 2024 19:38:56 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/sub_mbf.t 22 Jan 2025 00:37:42 -0000 @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More tests => 3070 # tests in require'd file - + 8; # tests in this file + + 10; # tests in this file use lib 't'; @@ -12,31 +12,35 @@ use Math::BigFloat::Subclass; our ($CLASS, $LIB); $CLASS = "Math::BigFloat::Subclass"; -$LIB = Math::BigFloat->config('lib'); # backend library +$LIB = $CLASS -> config('lib'); # backend library -require './t/bigfltpm.inc'; # perform same tests as bigfltpm +require './t/bigfltpm.inc'; # perform same tests as bigfltpm ############################################################################### # Now do custom tests for Subclass itself -my $ms = $CLASS->new(23); +my $ms = $CLASS -> new(23); is($ms->{_custom}, 1, '$ms has custom attribute \$ms->{_custom}'); # Check that subclass is a Math::BigFloat, but not a Math::Bigint isa_ok($ms, 'Math::BigFloat'); -ok(!$ms->isa('Math::BigInt'), +ok(!$ms -> isa('Math::BigInt'), "An object of class '" . ref($ms) . "' isn't a 'Math::BigInt'"); -use Math::BigFloat; - -my $bf = Math::BigFloat->new(23); # same as other +my $bf = Math::BigFloat -> new(23); # same as other $ms += $bf; is($ms, 46, '$ms is 46'); is($ms->{_custom}, 1, '$ms has custom attribute $ms->{_custom}'); is(ref($ms), $CLASS, "\$ms is not an object of class '$CLASS'"); -cmp_ok(Math::BigFloat::Subclass -> div_scale(), "==", 40, - "Math::BigFloat::Subclass gets 'div_scale' from parent"); +is($CLASS -> accuracy(), undef, + "$CLASS gets 'accuracy' from parent"); + +is($CLASS -> precision(), undef, + "$CLASS gets 'precision' from parent"); + +cmp_ok($CLASS -> div_scale(), "==", 40, + "$CLASS gets 'div_scale' from parent"); -is(Math::BigFloat::Subclass -> round_mode(), "even", - "Math::BigFloat::Subclass gets 'round_mode' from parent"); +is($CLASS -> round_mode(), "even", + "$CLASS gets 'round_mode' from parent"); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/sub_mbi.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/sub_mbi.t,v diff -u -p -a -u -p -r1.8 sub_mbi.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/sub_mbi.t 14 May 2024 19:38:56 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/sub_mbi.t 22 Jan 2025 00:37:42 -0000 @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More tests => 4278 # tests in require'd file - + 7; # tests in this file + + 9; # tests in this file use lib 't'; @@ -12,29 +12,33 @@ use Math::BigInt::Subclass; our ($CLASS, $LIB); $CLASS = "Math::BigInt::Subclass"; -$LIB = "Math::BigInt::Calc"; # backend +$LIB = $CLASS -> config('lib'); # backend library require './t/bigintpm.inc'; # perform same tests as bigintpm ############################################################################### # Now do custom tests for Subclass itself -my $ms = $CLASS->new(23); +my $ms = $CLASS -> new(23); is($ms->{_custom}, 1, '$ms has custom attribute \$ms->{_custom}'); # Check that a subclass is still considered a Math::BigInt isa_ok($ms, 'Math::BigInt'); -use Math::BigInt; - -my $bi = Math::BigInt->new(23); # same as other +my $bi = Math::BigInt -> new(23); # same as other $ms += $bi; is($ms, 46, '$ms is 46'); is($ms->{_custom}, 1, '$ms has custom attribute $ms->{_custom}'); is(ref($ms), $CLASS, "\$ms is not an object of class '$CLASS'"); -cmp_ok(Math::BigInt::Subclass -> div_scale(), "==", 40, - "Math::BigInt::Subclass gets 'div_scale' from parent"); +is($CLASS -> accuracy(), undef, + "$CLASS gets 'accuracy' from parent"); + +is($CLASS -> precision(), undef, + "$CLASS gets 'precision' from parent"); + +cmp_ok($CLASS -> div_scale(), "==", 40, + "$CLASS gets 'div_scale' from parent"); -is(Math::BigInt::Subclass -> round_mode(), "even", - "Math::BigInt::Subclass gets 'round_mode' from parent"); +is($CLASS -> round_mode(), "even", + "$CLASS gets 'round_mode' from parent"); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/sub_mbr.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/sub_mbr.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/sub_mbr.t --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/sub_mbr.t 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,44 @@ +# -*- mode: perl; -*- + +use strict; +use warnings; + +use Test::More tests => 899 # tests in require'd file + + 9; # tests in this file + +use lib 't'; + +use Math::BigRat::Subclass; + +our ($CLASS, $LIB); +$CLASS = "Math::BigRat::Subclass"; +$LIB = $CLASS -> config('lib'); # backend library + +require './t/bigratpm.inc'; + +############################################################################### +# Now do custom tests for Subclass itself + +my $ms = $CLASS -> new(23); +is($ms->{_custom}, 1, '$ms has custom attribute \$ms->{_custom}'); + +# Check that a subclass is still considered a Math::BigRat +isa_ok($ms, 'Math::BigRat'); + +my $bi = Math::BigRat -> new(23); # same as other +$ms += $bi; +is($ms, 46, '$ms is 46'); +is($ms->{_custom}, 1, '$ms has custom attribute $ms->{_custom}'); +is(ref($ms), $CLASS, "\$ms is not an object of class '$CLASS'"); + +is($CLASS -> accuracy(), undef, + "$CLASS gets 'accuracy' from parent"); + +is($CLASS -> precision(), undef, + "$CLASS gets 'precision' from parent"); + +cmp_ok($CLASS -> div_scale(), "==", 40, + "$CLASS gets 'div_scale' from parent"); + +is($CLASS -> round_mode(), "even", + "$CLASS gets 'round_mode' from parent"); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/trap.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/trap.t,v diff -u -p -a -u -p -r1.6 trap.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/trap.t 15 Feb 2023 01:36:20 -0000 1.6 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/trap.t 22 Jan 2025 00:37:42 -0000 @@ -5,64 +5,98 @@ use strict; use warnings; -use Test::More tests => 43; - -use Math::BigInt; -use Math::BigFloat; +use Test::More tests => 90; my $mbi = 'Math::BigInt'; my $mbf = 'Math::BigFloat'; -my ($cfg, $x); +my $mbr = 'Math::BigRat'; + +use_ok($mbi); +use_ok($mbf); +use_ok($mbr); + +my $x; + +foreach my $class ($mbi, $mbf, $mbr) { -foreach my $class ($mbi, $mbf) { - # can do and defaults are okay? - ok($class->can('config'), 'can config()'); + # can do? + can_ok($class, 'config'); + + ########################################################################### + # Default values. + ########################################################################### + + # defaults are okay? is($class->config("trap_nan"), 0, 'trap_nan defaults to 0'); is($class->config("trap_inf"), 0, 'trap_inf defaults to 0'); + ########################################################################### + # Trap NaN. + ########################################################################### + # can set? - $cfg = $class->config( trap_nan => 1 ); - is($cfg->{trap_nan}, 1, 'trap_nan now true'); + $class->config( trap_nan => 1 ); + is($class->config("trap_nan"), 1, qq|$class->config( trap_nan => 1 );|); + + # can reset? + $class->config( trap_nan => 0 ); + is($class->config("trap_nan"), 0, qq|$class->config( trap_nan => 0 );|); + + # can set via hash ref? + $class->config( { trap_nan => 1 } ); + is($class->config("trap_nan"), 1, qq|$class->config( { trap_nan => 1 } );|); + + # 0/0 => NaN + $x = $class->new("0"); + eval { $x->bdiv(0); }; + like($@, qr/^Tried to /, qq|\$x = $class->new("0"); \$x->bdiv(0);|); + + # new() didn't modify $x + is($x, 0, qq|\$x = $class->new("0"); \$x->bdiv(0);|); # also test that new() still works normally - eval ("\$x = \$class->new('42'); \$x->bnan();"); - like($@, qr/^Tried to create/, 'died'); + eval { $x = $class->new('42'); $x->bnan(); }; + like($@, qr/^Tried to /, 'died'); is($x, 42, '$x after new() never modified'); # can reset? - $cfg = $class->config( trap_nan => 0 ); - is($cfg->{trap_nan}, 0, 'trap_nan disabled'); + $class->config( trap_nan => 0 ); + is($class->config("trap_nan"), 0, qq|$class->config( trap_nan => 0 );|); + + ########################################################################### + # Trap inf. + ########################################################################### # can set? - $cfg = $class->config( trap_inf => 1 ); - is($cfg->{trap_inf}, 1, 'trap_inf enabled'); + $class->config( trap_inf => 1 ); + is($class->config("trap_inf"), 1, 'trap_inf enabled'); - eval ("\$x = \$class->new('4711'); \$x->binf();"); - like($@, qr/^Tried to create/, 'died'); + eval { $x = $class->new('4711'); $x->binf(); }; + like($@, qr/^Tried to /, 'died'); is($x, 4711, '$x after new() never modified'); - eval ("\$x = \$class->new('inf');"); - like($@, qr/^Tried to create/, 'died'); + eval { $x = $class->new('inf'); }; + like($@, qr/^Tried to /, 'died'); is($x, 4711, '$x after new() never modified'); - eval ("\$x = \$class->new('-inf');"); - like($@, qr/^Tried to create/, 'died'); + eval { $x = $class->new('-inf'); }; + like($@, qr/^Tried to /, 'died'); is($x, 4711, '$x after new() never modified'); # +$x/0 => +inf - eval ("\$x = \$class->new('4711'); \$x->bdiv(0);"); - like($@, qr/^Tried to create/, 'died'); + eval { $x = $class->new('4711'); $x->bdiv(0); }; + like($@, qr/^Tried to /, 'died'); is($x, 4711, '$x after new() never modified'); # -$x/0 => -inf - eval ("\$x = \$class->new('-0815'); \$x->bdiv(0);"); - like($@, qr/^Tried to create/, 'died'); + eval { $x = $class->new('-0815'); $x->bdiv(0); }; + like($@, qr/^Tried to /, 'died'); is($x, '-815', '$x after new not modified'); - $cfg = $class->config( trap_nan => 1 ); + $class->config( trap_nan => 1 ); # 0/0 => NaN - eval ("\$x = \$class->new('0'); \$x->bdiv(0);"); - like($@, qr/^Tried to create/, 'died'); + eval { $x = $class->new('0'); $x->bdiv(0); }; + like($@, qr/^Tried to /, 'died'); is($x, '0', '$x after new not modified'); } @@ -70,16 +104,40 @@ foreach my $class ($mbi, $mbf) { # Math::BigInt $x = Math::BigInt->new(2); -eval ("\$x = \$mbi->new('0.1');"); +eval { $x = $mbi->new('0.1'); }; is($x, 2, 'never modified since it dies'); -eval ("\$x = \$mbi->new('0a.1');"); + +eval { $x = $mbi->new('0a.1'); }; is($x, 2, 'never modified since it dies'); ############################################################################## # Math::BigFloat $x = Math::BigFloat->new(2); -eval ("\$x = \$mbf->new('0.1a');"); +eval { $x = $mbf->new('0.1a'); }; is($x, 2, 'never modified since it dies'); + +############################################################################## +# BigRat + +Math::BigRat->config(trap_nan => 1, + trap_inf => 1); + +for my $trap (qw/ 0.1a +inf inf -inf /) { + my $x = Math::BigRat->new('7/4'); + + note(""); # this is just for some space in the output + + # In each of the cases below, $x is not modified, because the code dies. + + eval { $x = $mbr->new("$trap"); }; + is($x, "7/4", qq|\$x = $mbr->new("$trap");|); + + eval { $x = $mbr->new("$trap"); }; + is($x, "7/4", qq|\$x = $mbr->new("$trap");|); + + eval { $x = $mbr->new("$trap/7"); }; + is($x, "7/4", qq|\$x = $mbr->new("$trap/7");|); +} # all tests done Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/upgrade.inc =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/upgrade.inc,v diff -u -p -a -u -p -r1.8 upgrade.inc --- gnu/usr.bin/perl/cpan/Math-BigInt/t/upgrade.inc 14 May 2024 19:38:56 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/upgrade.inc 22 Jan 2025 00:37:42 -0000 @@ -600,14 +600,14 @@ abc:abc:NaN +2:+2:8 +1:+32:4294967296 +1:+48:281474976710656 -+8:-2:NaN ++8:-2:2 # exercise base 10 +12345:4:10:123450000 -1234:0:10:-1234 +1234:0:10:1234 +2:2:10:200 +12:2:10:1200 -+1234:-3:10:NaN ++1234:-3:10:1.234 1234567890123:12:10:1234567890123000000000000 &brsft @@ -615,14 +615,14 @@ abc:abc:NaN +8:+2:2 +4294967296:+32:1 +281474976710656:+48:1 -+2:-2:NaN ++2:-2:8 # exercise base 10 -1234:0:10:-1234 +1234:0:10:1234 +200:2:10:2 +1234:3:10:1.234 +1234:2:10:12.34 -+1234:-3:10:NaN ++1234:-3:10:1234000 310000:4:10:31 12300000:5:10:123 1230000000000:10:10:123 @@ -1108,6 +1108,8 @@ abc:0:NaN -7:-4:-8 -7:4:0 -4:7:4 +1:0.5:0 + # equal arguments are treated special, so also do some test with unequal ones 0xFFFF:0xFFFF:0x0xFFFF 0xFFFFFF:0xFFFFFF:0x0xFFFFFF @@ -1140,6 +1142,8 @@ abc:0:NaN -6:-6:-6 -7:4:-3 -4:7:-1 +1:0.5:1 + # equal arguments are treated special, so also do some test with unequal ones 0xFFFF:0xFFFF:0x0xFFFF 0xFFFFFF:0xFFFFFF:0x0xFFFFFF @@ -1189,6 +1193,8 @@ abc:0:NaN -4:7:-5 4:-7:-3 -4:-7:5 +1:0.5:1 + # equal arguments are treated special, so also do some test with unequal ones 0xFFFF:0xFFFF:0 0xFFFFFF:0xFFFFFF:0 @@ -1363,11 +1369,9 @@ abc:12:NaN &broot 144:2:12^ 123:2:11.09053650640941716205160010260993291846^ -# bsqrt always upgrades &bsqrt 145:12.04159457879229548012824103037860805243^ -144:12^ 143:11.95826074310139802112984075619561661399^ 16:4 170:13.03840481040529742916594311485836883306^ Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/upgrade.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/upgrade.t,v diff -u -p -a -u -p -r1.8 upgrade.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/upgrade.t 14 May 2024 19:38:56 -0000 1.8 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/upgrade.t 22 Jan 2025 00:37:42 -0000 @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 2134 # tests in require'd file +use Test::More tests => 2136 # tests in require'd file + 6; # tests in this file use Math::BigInt; Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/upgrade2.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/upgrade2.t,v diff -u -p -a -u -p -r1.3 upgrade2.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/upgrade2.t 14 May 2024 19:38:56 -0000 1.3 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/upgrade2.t 22 Jan 2025 00:37:42 -0000 @@ -5,7 +5,7 @@ use warnings; # Test 2 levels of upgrade classes. This used to cause a segv. -use Test::More tests => 1; +use Test::More tests => 9; use Math::BigInt upgrade => 'Math::BigFloat'; use Math::BigFloat upgrade => 'Math::BigMouse'; @@ -16,3 +16,56 @@ sub Math::BigMouse::bsqrt {}; () = sqrt Math::BigInt->new(2); pass('sqrt on a big int does not segv if there are 2 upgrade levels'); + +# Math::BigRat inherits from Math::BigFloat, which inherits from Math::BigInt. +# Typically, methods call the upgrade version if upgrading is defined and the +# argument is an unknown type. This will call infinite recursion for methods +# that are not implemented in the upgrade class. + +use Math::BigRat; + +Math::BigFloat -> upgrade("Math::BigRat"); +Math::BigFloat -> downgrade(undef); + +Math::BigRat -> upgrade(undef); +Math::BigRat -> downgrade(undef); + +# Input is a scalar. + +note 'Math::BigRat -> babs("2");'; +() = Math::BigRat -> babs("2"); +pass(qq|no 'Deep recursion on subroutine ...'|); + +note 'Math::BigRat -> bsgn("2");'; +() = Math::BigRat -> bsgn("2"); +pass(qq|no 'Deep recursion on subroutine ...'|); + +# Input is a Math::BigInt. + +note 'Math::BigRat -> babs(Math::BigInt -> new("2"));'; +() = Math::BigRat -> babs(Math::BigInt -> new("2")); +pass(qq|no 'Deep recursion on subroutine ...'|); + +note 'Math::BigRat -> bsgn(Math::BigInt -> new("2"));'; +() = Math::BigRat -> bsgn(Math::BigInt -> new("2")); +pass(qq|no 'Deep recursion on subroutine ...'|); + +# Input is a Math::BigFloat. + +note 'Math::BigRat -> babs(Math::BigFloat -> new("2"));'; +() = Math::BigRat -> babs(Math::BigFloat -> new("2")); +pass(qq|no 'Deep recursion on subroutine ...'|); + +note 'Math::BigRat -> bsgn(Math::BigFloat -> new("2"));'; +() = Math::BigRat -> bsgn(Math::BigFloat -> new("2")); +pass(qq|no 'Deep recursion on subroutine ...'|); + +# Input is a Math::BigRat. + +note 'Math::BigRat -> babs(Math::BigRat -> new("2"));'; +() = Math::BigRat -> babs(Math::BigRat -> new("2")); +pass(qq|no 'Deep recursion on subroutine ...'|); + +note 'Math::BigRat -> bsgn(Math::BigRat -> new("2"));'; +() = Math::BigRat -> bsgn(Math::BigRat -> new("2")); +pass(qq|no 'Deep recursion on subroutine ...'|); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib1.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib1.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib1.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib1.t 15 Feb 2023 01:36:20 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,18 +0,0 @@ -# -*- mode: perl; -*- - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent - -use strict; -use warnings; -use lib 't'; - -use Test::More tests => 2; - -use Math::BigFloat lib => 'BareCalc'; # loads "BareCalc" - -is(Math::BigInt->config('lib'), 'Math::BigInt::BareCalc', - "Math::BigInt->config('lib')"); - -is(Math::BigFloat->new(123)->badd(123), 246, - 'Math::BigFloat->new(123)->badd(123)'); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib2.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib2.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib2.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib2.t 15 Feb 2023 01:36:20 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,19 +0,0 @@ -# -*- mode: perl; -*- - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent - -use strict; -use warnings; -use lib 't'; - -use Test::More tests => 2; - -use Math::BigInt; # loads "Calc" -use Math::BigFloat lib => 'BareCalc'; # ignores "BareCalc" - -is(Math::BigInt->config('lib'), 'Math::BigInt::Calc', - "Math::BigInt->config('lib')"); - -is(Math::BigFloat->new(123)->badd(123), 246, - 'Math::BigFloat->new(123)->badd(123)'); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib3.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib3.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib3.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib3.t 15 Feb 2023 01:36:20 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,19 +0,0 @@ -# -*- mode: perl; -*- - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent - -use strict; -use warnings; -use lib 't'; - -use Test::More tests => 2; - -use Math::BigInt lib => 'BareCalc'; # ignores "BareCalc" -use Math::BigFloat; - -is(Math::BigInt->config('lib'), 'Math::BigInt::BareCalc', - "Math::BigInt->config('lib')"); - -is(Math::BigFloat->new(123)->badd(123), 246, - 'Math::BigFloat->new(123)->badd(123)'); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib4.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib4.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib4.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib4.t 15 Feb 2023 01:36:20 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,20 +0,0 @@ -# -*- mode: perl; -*- - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent, except this, since the later overrides -# the former lib statement - -use strict; -use warnings; -use lib 't'; - -use Test::More tests => 2; - -use Math::BigInt lib => 'BareCalc'; # loads "BareCalc" -use Math::BigFloat lib => 'Calc'; # ignores "Calc" - -is(Math::BigInt->config('lib'), 'Math::BigInt::BareCalc', - "Math::BigInt->config('lib')"); - -is(Math::BigFloat->new(123)->badd(123), 246, - 'Math::BigFloat->new(123)->badd(123)'); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib5.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib5.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib5.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib5.t 15 Feb 2023 01:32:40 -0000 1.1.1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,19 +0,0 @@ -# -*- mode: perl; -*- - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent - -use strict; -use warnings; -use lib 't'; - -use Test::More tests => 2; - -use Math::BigFloat lib => 'BareCalc'; # loads "BareCalc" -use Math::BigInt; - -is(Math::BigInt->config('lib'), 'Math::BigInt::BareCalc', - "Math::BigInt->config('lib')"); - -is(Math::BigFloat->new(123)->badd(123), 246, - 'Math::BigFloat->new(123)->badd(123)'); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib6.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib6.t diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib6.t --- gnu/usr.bin/perl/cpan/Math-BigInt/t/use_lib6.t 15 Feb 2023 01:32:40 -0000 1.1.1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,16 +0,0 @@ -# -*- mode: perl; -*- - -# see if using Math::BigInt and Math::BigFloat works together nicely. -# all use_lib*.t should be equivalent - -use strict; -use warnings; -use lib 't'; - -use Test::More tests => 1; - -use Math::BigInt lib => 'BareCalc'; # loads "BareCalc" -eval "use Math::BigFloat only => 'foobar';"; # ignores "foobar" - -is(Math::BigInt->config('lib'), 'Math::BigInt::BareCalc', - "Math::BigInt->config('lib')"); Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigFloat/BareSubclass.pm =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigFloat/BareSubclass.pm diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigFloat/BareSubclass.pm --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigFloat/BareSubclass.pm 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,3 @@ +package Math::BigFloat::BareSubclass; +use base 'Math::BigFloat'; +1; Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigFloat/Subclass.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigFloat/Subclass.pm,v diff -u -p -a -u -p -r1.5 Subclass.pm --- gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigFloat/Subclass.pm 15 Feb 2023 01:36:20 -0000 1.5 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigFloat/Subclass.pm 22 Jan 2025 00:37:42 -0000 @@ -1,49 +1,47 @@ # -*- mode: perl; -*- -# for testing subclassing Math::BigFloat +# test subclassing Math::BigFloat package Math::BigFloat::Subclass; -require 5.006; - use strict; use warnings; -use Exporter; use Math::BigFloat; -our @ISA = qw(Math::BigFloat Exporter); +our @ISA = qw(Math::BigFloat); + +our $VERSION = "0.09"; + +use overload; # inherit overload -our $VERSION = "0.08"; +# Global variables. The values can be specified explicitly or obtained from the +# superclass. -use overload; # inherit overload from BigInt +our $accuracy = undef; # or Math::BigFloat::Subclass -> accuracy(); +our $precision = undef; # or Math::BigFloat::Subclass -> precision(); +our $round_mode = "even"; # or Math::BigFloat::Subclass -> round_mode(); +our $div_scale = 40; # or Math::BigFloat::Subclass -> div_scale(); -# Globals -our $accuracy = undef; -our $precision = undef; -our $round_mode = Math::BigFloat::Subclass -> round_mode(); -our $div_scale = Math::BigFloat::Subclass -> div_scale(); -our $lib = ''; +BEGIN { + *objectify = \&Math::BigInt::objectify; +} + +# We override new() sub new { my $proto = shift; my $class = ref($proto) || $proto; - my $value = shift; - my $a = $accuracy; $a = $_[0] if defined $_[0]; - my $p = $precision; $p = $_[1] if defined $_[1]; - # Store the floating point value - my $self = Math::BigFloat->new($value, $a, $p, $round_mode); + my $self = $class -> SUPER::new(@_); + $self->{'_custom'} = 1; # attribute specific to this subclass bless $self, $class; - $self->{'_custom'} = 1; # make sure this never goes away - return $self; } -BEGIN { - *objectify = \&Math::BigInt::objectify; - # to allow Math::BigFloat::Subclass::bgcd( ... ) style calls - *bgcd = \&Math::BigFloat::bgcd; - *blcm = \&Math::BigFloat::blcm; -} +# Any other methods to override can go here: + +# sub method { +# ... +# } 1; Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigInt/Subclass.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigInt/Subclass.pm,v diff -u -p -a -u -p -r1.5 Subclass.pm --- gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigInt/Subclass.pm 15 Feb 2023 01:36:20 -0000 1.5 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigInt/Subclass.pm 22 Jan 2025 00:37:42 -0000 @@ -1,87 +1,70 @@ # -*- mode: perl; -*- -package Math::BigInt::Subclass; +# test subclassing Math::BigInt -require 5.005_02; +package Math::BigInt::Subclass; use strict; use warnings; -use Exporter; use Math::BigInt; -our @ISA = qw(Math::BigInt Exporter); -our @EXPORT_OK = qw(bgcd objectify); +our @ISA = qw(Math::BigInt); + +our $VERSION = "0.08"; -our $VERSION = "0.07"; +use overload; # inherit overload -use overload; # inherit overload from BigInt +# Global variables. The values can be specified explicitly or obtained from the +# superclass. + +our $accuracy = undef; # or Math::BigInt::Subclass -> accuracy(); +our $precision = undef; # or Math::BigInt::Subclass -> precision(); +our $round_mode = "even"; # or Math::BigInt::Subclass -> round_mode(); +our $div_scale = 40; # or Math::BigInt::Subclass -> div_scale(); + +BEGIN { + *objectify = \&Math::BigInt::objectify; +} -# Globals -our $accuracy = undef; -our $precision = undef; -our $round_mode = Math::BigInt::Subclass -> round_mode(); -our $div_scale = Math::BigInt::Subclass -> div_scale(); -our $lib = ''; +# We override new(). sub new { my $proto = shift; my $class = ref($proto) || $proto; - my $value = shift; - my $a = $accuracy; $a = $_[0] if defined $_[0]; - my $p = $precision; $p = $_[1] if defined $_[1]; - my $self = Math::BigInt->new($value, $a, $p, $round_mode); + my $self = $class -> SUPER::new(@_); + $self->{'_custom'} = 1; # attribute specific to this subclass bless $self, $class; - $self->{'_custom'} = 1; # make sure this never goes away - return $self; -} - -sub bgcd { - Math::BigInt::bgcd(@_); -} - -sub blcm { - Math::BigInt::blcm(@_); } -sub as_int { - Math::BigInt->new($_[0]); -} +# We override import(). This is just for a sample for demonstration. -BEGIN { - *objectify = \&Math::BigInt::objectify; +sub import { + my $self = shift; + my $class = ref($self) || $self; - # these are called by AUTOLOAD from BigFloat, so we need at least these. - # We cheat, of course.. - *bneg = \&Math::BigInt::bneg; - *babs = \&Math::BigInt::babs; - *bnan = \&Math::BigInt::bnan; - *binf = \&Math::BigInt::binf; - *bzero = \&Math::BigInt::bzero; - *bone = \&Math::BigInt::bone; -} + my @a; # unrecognized arguments + while (@_) { + my $param = shift; -sub import { - my $self = shift; + # The parameter "this" takes an option. - my @a; - my $t = 0; - foreach (@_) { - # remove the "lib => foo" parameters and store it - if ($t == 1) { - $lib = $_; - $t = 0; - next; - } - if ($_ eq 'lib') { - $t = 1; + if ($param eq 'something') { + $self -> {$param} = shift; next; } + push @a, $_; } - $self->SUPER::import(@a); # need it for subclasses - $self->export_to_level(1, $self, @a); # need this ? + + $self -> SUPER::import(@a); # need it for subclasses } + +# Any other methods to override can go here: + +# sub method { +# ... +# } 1; Index: gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigRat/Subclass.pm =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigRat/Subclass.pm diff -N gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigRat/Subclass.pm --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/usr.bin/perl/cpan/Math-BigInt/t/Math/BigRat/Subclass.pm 22 Jan 2025 00:37:42 -0000 @@ -0,0 +1,47 @@ +# -*- mode: perl; -*- + +# test subclassing Math::BigRat + +package Math::BigRat::Subclass; + +use strict; +use warnings; + +use Math::BigRat; + +our @ISA = qw(Math::BigRat); + +our $VERSION = '0.04'; + +use overload; # inherit overload + +# Global variables. The values can be specified explicitly or obtained from the +# superclass. + +our $accuracy = undef; # or Math::BigInt::Subclass -> accuracy(); +our $precision = undef; # or Math::BigInt::Subclass -> precision(); +our $round_mode = "even"; # or Math::BigInt::Subclass -> round_mode(); +our $div_scale = 40; # or Math::BigInt::Subclass -> div_scale(); + +BEGIN { + *objectify = \&Math::BigInt::objectify; +} + +# We override new() + +sub new { + my $proto = shift; + my $class = ref($proto) || $proto; + + my $self = $class -> SUPER::new(@_); + $self->{'_custom'} = 1; # attribute specific to this subclass + bless $self, $class; +} + +# Any other methods to override can go here: + +# sub method { +# ... +# } + +1; Index: gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/lib/Math/BigInt/FastCalc.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/lib/Math/BigInt/FastCalc.pm,v diff -u -p -a -u -p -r1.6 FastCalc.pm --- gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/lib/Math/BigInt/FastCalc.pm 14 May 2024 19:38:56 -0000 1.6 +++ gnu/usr.bin/perl/cpan/Math-BigInt-FastCalc/lib/Math/BigInt/FastCalc.pm 22 Jan 2025 00:37:42 -0000 @@ -12,7 +12,7 @@ BEGIN { our @ISA = qw< Math::BigInt::Calc >; } -our $VERSION = '0.5013'; +our $VERSION = '0.5018'; my $MAX_EXP_F; # the maximum possible base 10 exponent with "no integer" my $MAX_EXP_I; # the maximum possible base 10 exponent with "use integer" @@ -183,10 +183,6 @@ L - -=item CPAN Ratings - -L =back Index: gnu/usr.bin/perl/cpan/Math-BigRat/lib/Math/BigRat.pm =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/lib/Math/BigRat.pm diff -N gnu/usr.bin/perl/cpan/Math-BigRat/lib/Math/BigRat.pm --- gnu/usr.bin/perl/cpan/Math-BigRat/lib/Math/BigRat.pm 14 May 2024 19:38:56 -0000 1.7 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,3167 +0,0 @@ -# -# "Tax the rat farms." - Lord Vetinari -# - -# The following hash values are used: -# sign : +,-,NaN,+inf,-inf -# _d : denominator -# _n : numerator (value = _n/_d) -# _a : accuracy -# _p : precision -# You should not look at the innards of a BigRat - use the methods for this. - -package Math::BigRat; - -use 5.006; -use strict; -use warnings; - -use Carp qw< carp croak >; -use Scalar::Util qw< blessed >; - -use Math::BigFloat (); - -our $VERSION = '0.2624'; - -our @ISA = qw(Math::BigFloat); - -our ($accuracy, $precision, $round_mode, $div_scale, - $upgrade, $downgrade, $_trap_nan, $_trap_inf); - -use overload - - # overload key: with_assign - - '+' => sub { $_[0] -> copy() -> badd($_[1]); }, - - '-' => sub { my $c = $_[0] -> copy; - $_[2] ? $c -> bneg() -> badd( $_[1]) - : $c -> bsub($_[1]); }, - - '*' => sub { $_[0] -> copy() -> bmul($_[1]); }, - - '/' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bdiv($_[0]) - : $_[0] -> copy() -> bdiv($_[1]); }, - - '%' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bmod($_[0]) - : $_[0] -> copy() -> bmod($_[1]); }, - - '**' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bpow($_[0]) - : $_[0] -> copy() -> bpow($_[1]); }, - - '<<' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> blsft($_[0]) - : $_[0] -> copy() -> blsft($_[1]); }, - - '>>' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> brsft($_[0]) - : $_[0] -> copy() -> brsft($_[1]); }, - - # overload key: assign - - '+=' => sub { $_[0]->badd($_[1]); }, - - '-=' => sub { $_[0]->bsub($_[1]); }, - - '*=' => sub { $_[0]->bmul($_[1]); }, - - '/=' => sub { scalar $_[0]->bdiv($_[1]); }, - - '%=' => sub { $_[0]->bmod($_[1]); }, - - '**=' => sub { $_[0]->bpow($_[1]); }, - - '<<=' => sub { $_[0]->blsft($_[1]); }, - - '>>=' => sub { $_[0]->brsft($_[1]); }, - -# 'x=' => sub { }, - -# '.=' => sub { }, - - # overload key: num_comparison - - '<' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> blt($_[0]) - : $_[0] -> blt($_[1]); }, - - '<=' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> ble($_[0]) - : $_[0] -> ble($_[1]); }, - - '>' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bgt($_[0]) - : $_[0] -> bgt($_[1]); }, - - '>=' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bge($_[0]) - : $_[0] -> bge($_[1]); }, - - '==' => sub { $_[0] -> beq($_[1]); }, - - '!=' => sub { $_[0] -> bne($_[1]); }, - - # overload key: 3way_comparison - - '<=>' => sub { my $cmp = $_[0] -> bcmp($_[1]); - defined($cmp) && $_[2] ? -$cmp : $cmp; }, - - 'cmp' => sub { $_[2] ? "$_[1]" cmp $_[0] -> bstr() - : $_[0] -> bstr() cmp "$_[1]"; }, - - # overload key: str_comparison - -# 'lt' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bstrlt($_[0]) -# : $_[0] -> bstrlt($_[1]); }, -# -# 'le' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bstrle($_[0]) -# : $_[0] -> bstrle($_[1]); }, -# -# 'gt' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bstrgt($_[0]) -# : $_[0] -> bstrgt($_[1]); }, -# -# 'ge' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bstrge($_[0]) -# : $_[0] -> bstrge($_[1]); }, -# -# 'eq' => sub { $_[0] -> bstreq($_[1]); }, -# -# 'ne' => sub { $_[0] -> bstrne($_[1]); }, - - # overload key: binary - - '&' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> band($_[0]) - : $_[0] -> copy() -> band($_[1]); }, - - '&=' => sub { $_[0] -> band($_[1]); }, - - '|' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bior($_[0]) - : $_[0] -> copy() -> bior($_[1]); }, - - '|=' => sub { $_[0] -> bior($_[1]); }, - - '^' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> bxor($_[0]) - : $_[0] -> copy() -> bxor($_[1]); }, - - '^=' => sub { $_[0] -> bxor($_[1]); }, - -# '&.' => sub { }, - -# '&.=' => sub { }, - -# '|.' => sub { }, - -# '|.=' => sub { }, - -# '^.' => sub { }, - -# '^.=' => sub { }, - - # overload key: unary - - 'neg' => sub { $_[0] -> copy() -> bneg(); }, - -# '!' => sub { }, - - '~' => sub { $_[0] -> copy() -> bnot(); }, - -# '~.' => sub { }, - - # overload key: mutators - - '++' => sub { $_[0] -> binc() }, - - '--' => sub { $_[0] -> bdec() }, - - # overload key: func - - 'atan2' => sub { $_[2] ? ref($_[0]) -> new($_[1]) -> batan2($_[0]) - : $_[0] -> copy() -> batan2($_[1]); }, - - 'cos' => sub { $_[0] -> copy() -> bcos(); }, - - 'sin' => sub { $_[0] -> copy() -> bsin(); }, - - 'exp' => sub { $_[0] -> copy() -> bexp($_[1]); }, - - 'abs' => sub { $_[0] -> copy() -> babs(); }, - - 'log' => sub { $_[0] -> copy() -> blog(); }, - - 'sqrt' => sub { $_[0] -> copy() -> bsqrt(); }, - - 'int' => sub { $_[0] -> copy() -> bint(); }, - - # overload key: conversion - - 'bool' => sub { $_[0] -> is_zero() ? '' : 1; }, - - '""' => sub { $_[0] -> bstr(); }, - - '0+' => sub { $_[0] -> numify(); }, - - '=' => sub { $_[0]->copy(); }, - - ; - -BEGIN { - *objectify = \&Math::BigInt::objectify; # inherit this from BigInt - *AUTOLOAD = \&Math::BigFloat::AUTOLOAD; # can't inherit AUTOLOAD - *as_number = \&as_int; - *is_pos = \&is_positive; - *is_neg = \&is_negative; -} - -############################################################################## -# Global constants and flags. Access these only via the accessor methods! - -$accuracy = $precision = undef; -$round_mode = 'even'; -$div_scale = 40; -$upgrade = undef; -$downgrade = undef; - -# These are internally, and not to be used from the outside at all! - -$_trap_nan = 0; # are NaNs ok? set w/ config() -$_trap_inf = 0; # are infs ok? set w/ config() - -# the math backend library - -my $LIB = 'Math::BigInt::Calc'; - -my $nan = 'NaN'; -#my $class = 'Math::BigRat'; - -sub isa { - return 0 if $_[1] =~ /^Math::Big(Int|Float)/; # we aren't - UNIVERSAL::isa(@_); -} - -############################################################################## - -sub new { - my $proto = shift; - my $protoref = ref $proto; - my $class = $protoref || $proto; - - # Check the way we are called. - - if ($protoref) { - croak("new() is a class method, not an instance method"); - } - - if (@_ < 1) { - #carp("Using new() with no argument is deprecated;", - # " use bzero() or new(0) instead"); - return $class -> bzero(); - } - - if (@_ > 2) { - carp("Superfluous arguments to new() ignored."); - } - - # Get numerator and denominator. If any of the arguments is undefined, - # return zero. - - my ($n, $d) = @_; - - if (@_ == 1 && !defined $n || - @_ == 2 && (!defined $n || !defined $d)) - { - #carp("Use of uninitialized value in new()"); - return $class -> bzero(); - } - - # Initialize a new object. - - my $self = bless {}, $class; - - # One or two input arguments may be given. First handle the numerator $n. - - if (ref($n)) { - $n = Math::BigFloat -> new($n, undef, undef) - unless ($n -> isa('Math::BigRat') || - $n -> isa('Math::BigInt') || - $n -> isa('Math::BigFloat')); - } else { - if (defined $d) { - # If the denominator is defined, the numerator is not a string - # fraction, e.g., "355/113". - $n = Math::BigFloat -> new($n, undef, undef); - } else { - # If the denominator is undefined, the numerator might be a string - # fraction, e.g., "355/113". - if ($n =~ m| ^ \s* (\S+) \s* / \s* (\S+) \s* $ |x) { - $n = Math::BigFloat -> new($1, undef, undef); - $d = Math::BigFloat -> new($2, undef, undef); - } else { - $n = Math::BigFloat -> new($n, undef, undef); - } - } - } - - # At this point $n is an object and $d is either an object or undefined. An - # undefined $d means that $d was not specified by the caller (not that $d - # was specified as an undefined value). - - unless (defined $d) { - #return $n -> copy($n) if $n -> isa('Math::BigRat'); - if ($n -> isa('Math::BigRat')) { - return $downgrade -> new($n) - if defined($downgrade) && $n -> is_int(); - return $class -> copy($n); - } - - if ($n -> is_nan()) { - return $class -> bnan(); - } - - if ($n -> is_inf()) { - return $class -> binf($n -> sign()); - } - - if ($n -> isa('Math::BigInt')) { - $self -> {_n} = $LIB -> _new($n -> copy() -> babs(undef, undef) - -> bstr()); - $self -> {_d} = $LIB -> _one(); - $self -> {sign} = $n -> sign(); - return $downgrade -> new($n) if defined $downgrade; - return $self; - } - - if ($n -> isa('Math::BigFloat')) { - my $m = $n -> mantissa(undef, undef) -> babs(undef, undef); - my $e = $n -> exponent(undef, undef); - $self -> {_n} = $LIB -> _new($m -> bstr()); - $self -> {_d} = $LIB -> _one(); - - if ($e > 0) { - $self -> {_n} = $LIB -> _lsft($self -> {_n}, - $LIB -> _new($e -> bstr()), 10); - } elsif ($e < 0) { - $self -> {_d} = $LIB -> _lsft($self -> {_d}, - $LIB -> _new(-$e -> bstr()), 10); - - my $gcd = $LIB -> _gcd($LIB -> _copy($self -> {_n}), - $self -> {_d}); - if (!$LIB -> _is_one($gcd)) { - $self -> {_n} = $LIB -> _div($self->{_n}, $gcd); - $self -> {_d} = $LIB -> _div($self->{_d}, $gcd); - } - } - - $self -> {sign} = $n -> sign(); - return $downgrade -> new($n, undef, undef) - if defined($downgrade) && $n -> is_int(); - return $self; - } - - die "I don't know how to handle this"; # should never get here - } - - # At the point we know that both $n and $d are defined. We know that $n is - # an object, but $d might still be a scalar. Now handle $d. - - $d = Math::BigFloat -> new($d, undef, undef) - unless ref($d) && ($d -> isa('Math::BigRat') || - $d -> isa('Math::BigInt') || - $d -> isa('Math::BigFloat')); - - # At this point both $n and $d are objects. - - if ($n -> is_nan() || $d -> is_nan()) { - return $class -> bnan(); - } - - # At this point neither $n nor $d is a NaN. - - if ($n -> is_zero()) { - if ($d -> is_zero()) { # 0/0 = NaN - return $class -> bnan(); - } - return $class -> bzero(); - } - - if ($d -> is_zero()) { - return $class -> binf($d -> sign()); - } - - # At this point, neither $n nor $d is a NaN or a zero. - - # Copy them now before manipulating them. - - $n = $n -> copy(); - $d = $d -> copy(); - - if ($d < 0) { # make sure denominator is positive - $n -> bneg(); - $d -> bneg(); - } - - if ($n -> is_inf()) { - return $class -> bnan() if $d -> is_inf(); # Inf/Inf = NaN - return $class -> binf($n -> sign()); - } - - # At this point $n is finite. - - return $class -> bzero() if $d -> is_inf(); - return $class -> binf($d -> sign()) if $d -> is_zero(); - - # At this point both $n and $d are finite and non-zero. - - if ($n < 0) { - $n -> bneg(); - $self -> {sign} = '-'; - } else { - $self -> {sign} = '+'; - } - - if ($n -> isa('Math::BigRat')) { - - if ($d -> isa('Math::BigRat')) { - - # At this point both $n and $d is a Math::BigRat. - - # p r p * s (p / gcd(p, r)) * (s / gcd(s, q)) - # - / - = ----- = --------------------------------- - # q s q * r (q / gcd(s, q)) * (r / gcd(p, r)) - - my $p = $n -> {_n}; - my $q = $n -> {_d}; - my $r = $d -> {_n}; - my $s = $d -> {_d}; - my $gcd_pr = $LIB -> _gcd($LIB -> _copy($p), $r); - my $gcd_sq = $LIB -> _gcd($LIB -> _copy($s), $q); - $self -> {_n} = $LIB -> _mul($LIB -> _div($LIB -> _copy($p), $gcd_pr), - $LIB -> _div($LIB -> _copy($s), $gcd_sq)); - $self -> {_d} = $LIB -> _mul($LIB -> _div($LIB -> _copy($q), $gcd_sq), - $LIB -> _div($LIB -> _copy($r), $gcd_pr)); - - return $downgrade -> new($n->bstr()) - if defined($downgrade) && $self -> is_int(); - return $self; # no need for $self -> bnorm() here - } - - # At this point, $n is a Math::BigRat and $d is a Math::Big(Int|Float). - - my $p = $n -> {_n}; - my $q = $n -> {_d}; - my $m = $d -> mantissa(); - my $e = $d -> exponent(); - - # / p - # | ------------ if e > 0 - # | q * m * 10^e - # | - # p | p - # - / (m * 10^e) = | ----- if e == 0 - # q | q * m - # | - # | p * 10^-e - # | -------- if e < 0 - # \ q * m - - $self -> {_n} = $LIB -> _copy($p); - $self -> {_d} = $LIB -> _mul($LIB -> _copy($q), $m); - if ($e > 0) { - $self -> {_d} = $LIB -> _lsft($self -> {_d}, $e, 10); - } elsif ($e < 0) { - $self -> {_n} = $LIB -> _lsft($self -> {_n}, -$e, 10); - } - - return $self -> bnorm(); - - } else { - - if ($d -> isa('Math::BigRat')) { - - # At this point $n is a Math::Big(Int|Float) and $d is a - # Math::BigRat. - - my $m = $n -> mantissa(); - my $e = $n -> exponent(); - my $p = $d -> {_n}; - my $q = $d -> {_d}; - - # / q * m * 10^e - # | ------------ if e > 0 - # | p - # | - # p | m * q - # (m * 10^e) / - = | ----- if e == 0 - # q | p - # | - # | q * m - # | --------- if e < 0 - # \ p * 10^-e - - $self -> {_n} = $LIB -> _mul($LIB -> _copy($q), $m); - $self -> {_d} = $LIB -> _copy($p); - if ($e > 0) { - $self -> {_n} = $LIB -> _lsft($self -> {_n}, $e, 10); - } elsif ($e < 0) { - $self -> {_d} = $LIB -> _lsft($self -> {_d}, -$e, 10); - } - return $self -> bnorm(); - - } else { - - # At this point $n and $d are both a Math::Big(Int|Float) - - my $m1 = $n -> mantissa(); - my $e1 = $n -> exponent(); - my $m2 = $d -> mantissa(); - my $e2 = $d -> exponent(); - - # / - # | m1 * 10^(e1 - e2) - # | ----------------- if e1 > e2 - # | m2 - # | - # m1 * 10^e1 | m1 - # ---------- = | -- if e1 = e2 - # m2 * 10^e2 | m2 - # | - # | m1 - # | ----------------- if e1 < e2 - # | m2 * 10^(e2 - e1) - # \ - - $self -> {_n} = $LIB -> _new($m1 -> bstr()); - $self -> {_d} = $LIB -> _new($m2 -> bstr()); - my $ediff = $e1 - $e2; - if ($ediff > 0) { - $self -> {_n} = $LIB -> _lsft($self -> {_n}, - $LIB -> _new($ediff -> bstr()), - 10); - } elsif ($ediff < 0) { - $self -> {_d} = $LIB -> _lsft($self -> {_d}, - $LIB -> _new(-$ediff -> bstr()), - 10); - } - - return $self -> bnorm(); - } - } - - return $downgrade -> new($self -> bstr()) - if defined($downgrade) && $self -> is_int(); - return $self; -} - -sub copy { - my $self = shift; - my $selfref = ref $self; - my $class = $selfref || $self; - - # If called as a class method, the object to copy is the next argument. - - $self = shift() unless $selfref; - - my $copy = bless {}, $class; - - $copy->{sign} = $self->{sign}; - $copy->{_d} = $LIB->_copy($self->{_d}); - $copy->{_n} = $LIB->_copy($self->{_n}); - $copy->{_a} = $self->{_a} if defined $self->{_a}; - $copy->{_p} = $self->{_p} if defined $self->{_p}; - - #($copy, $copy->{_a}, $copy->{_p}) - # = $copy->_find_round_parameters(@_); - - return $copy; -} - -sub bnan { - my $self = shift; - my $selfref = ref $self; - my $class = $selfref || $self; - - $self = bless {}, $class unless $selfref; - - if ($_trap_nan) { - croak ("Tried to set a variable to NaN in $class->bnan()"); - } - - return $downgrade -> bnan() if defined $downgrade; - - $self -> {sign} = $nan; - $self -> {_n} = $LIB -> _zero(); - $self -> {_d} = $LIB -> _one(); - - ($self, $self->{_a}, $self->{_p}) - = $self->_find_round_parameters(@_); - - return $self; -} - -sub binf { - my $self = shift; - my $selfref = ref $self; - my $class = $selfref || $self; - - $self = bless {}, $class unless $selfref; - - my $sign = shift(); - $sign = defined($sign) && substr($sign, 0, 1) eq '-' ? '-inf' : '+inf'; - - if ($_trap_inf) { - croak ("Tried to set a variable to +-inf in $class->binf()"); - } - - return $downgrade -> binf($sign) if defined $downgrade; - - $self -> {sign} = $sign; - $self -> {_n} = $LIB -> _zero(); - $self -> {_d} = $LIB -> _one(); - - ($self, $self->{_a}, $self->{_p}) - = $self->_find_round_parameters(@_); - - return $self; -} - -sub bone { - my $self = shift; - my $selfref = ref $self; - my $class = $selfref || $self; - - my $sign = shift(); - $sign = '+' unless defined($sign) && $sign eq '-'; - - return $downgrade -> bone($sign) if defined $downgrade; - - $self = bless {}, $class unless $selfref; - $self -> {sign} = $sign; - $self -> {_n} = $LIB -> _one(); - $self -> {_d} = $LIB -> _one(); - - ($self, $self->{_a}, $self->{_p}) - = $self->_find_round_parameters(@_); - - return $self; -} - -sub bzero { - my $self = shift; - my $selfref = ref $self; - my $class = $selfref || $self; - - return $downgrade -> bzero() if defined $downgrade; - - $self = bless {}, $class unless $selfref; - $self -> {sign} = '+'; - $self -> {_n} = $LIB -> _zero(); - $self -> {_d} = $LIB -> _one(); - - ($self, $self->{_a}, $self->{_p}) - = $self->_find_round_parameters(@_); - - return $self; -} - -############################################################################## - -sub config { - # return (later set?) configuration data as hash ref - my $class = shift() || 'Math::BigRat'; - - if (@_ == 1 && ref($_[0]) ne 'HASH') { - my $cfg = $class->SUPER::config(); - return $cfg->{$_[0]}; - } - - my $cfg = $class->SUPER::config(@_); - - # now we need only to override the ones that are different from our parent - $cfg->{class} = $class; - $cfg->{with} = $LIB; - - $cfg; -} - -############################################################################### -# String conversion methods -############################################################################### - -sub bstr { - my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); - - carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; - - # Inf and NaN - - if ($x->{sign} ne '+' && $x->{sign} ne '-') { - return $x->{sign} unless $x->{sign} eq '+inf'; # -inf, NaN - return 'inf'; # +inf - } - - # Upgrade? - - return $upgrade -> bstr($x, @r) - if defined($upgrade) && !$x -> isa($class); - - # Finite number - - my $s = ''; - $s = $x->{sign} if $x->{sign} ne '+'; # '+3/2' => '3/2' - - my $str = $x->{sign} eq '-' ? '-' : ''; - $str .= $LIB->_str($x->{_n}); - $str .= '/' . $LIB->_str($x->{_d}) unless $LIB -> _is_one($x->{_d}); - return $str; -} - -sub bsstr { - my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); - - carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; - - # Inf and NaN - - if ($x->{sign} ne '+' && $x->{sign} ne '-') { - return $x->{sign} unless $x->{sign} eq '+inf'; # -inf, NaN - return 'inf'; # +inf - } - - # Upgrade? - - return $upgrade -> bsstr($x, @r) - if defined($upgrade) && !$x -> isa($class); - - # Finite number - - my $str = $x->{sign} eq '-' ? '-' : ''; - $str .= $LIB->_str($x->{_n}); - $str .= '/' . $LIB->_str($x->{_d}) unless $LIB -> _is_one($x->{_d}); - return $str; -} - -sub bfstr { - my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); - - carp "Rounding is not supported for ", (caller(0))[3], "()" if @r; - - # Inf and NaN - - if ($x->{sign} ne '+' && $x->{sign} ne '-') { - return $x->{sign} unless $x->{sign} eq '+inf'; # -inf, NaN - return 'inf'; # +inf - } - - # Upgrade? - - return $upgrade -> bfstr($x, @r) - if defined($upgrade) && !$x -> isa($class); - - # Finite number - - my $str = $x->{sign} eq '-' ? '-' : ''; - $str .= $LIB->_str($x->{_n}); - $str .= '/' . $LIB->_str($x->{_d}) unless $LIB -> _is_one($x->{_d}); - return $str; -} - -sub bnorm { - # reduce the number to the shortest form - my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); - - # Both parts must be objects of whatever we are using today. - if (my $c = $LIB->_check($x->{_n})) { - croak("n did not pass the self-check ($c) in bnorm()"); - } - if (my $c = $LIB->_check($x->{_d})) { - croak("d did not pass the self-check ($c) in bnorm()"); - } - - # no normalize for NaN, inf etc. - if ($x->{sign} !~ /^[+-]$/) { - return $downgrade -> new($x) if defined $downgrade; - return $x; - } - - # normalize zeros to 0/1 - if ($LIB->_is_zero($x->{_n})) { - return $downgrade -> bzero() if defined($downgrade); - $x->{sign} = '+'; # never leave a -0 - $x->{_d} = $LIB->_one() unless $LIB->_is_one($x->{_d}); - return $x; - } - - # n/1 - if ($LIB->_is_one($x->{_d})) { - return $downgrade -> new($x) if defined($downgrade); - return $x; # no need to reduce - } - - # Compute the GCD. - my $gcd = $LIB->_gcd($LIB->_copy($x->{_n}), $x->{_d}); - if (!$LIB->_is_one($gcd)) { - $x->{_n} = $LIB->_div($x->{_n}, $gcd); - $x->{_d} = $LIB->_div($x->{_d}, $gcd); - } - - $x; -} - -############################################################################## -# sign manipulation - -sub bneg { - # (BRAT or num_str) return BRAT - # negate number or make a negated number from string - my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); - - return $x if $x->modify('bneg'); - - # for +0 do not negate (to have always normalized +0). Does nothing for 'NaN' - $x->{sign} =~ tr/+-/-+/ - unless ($x->{sign} eq '+' && $LIB->_is_zero($x->{_n})); - - return $downgrade -> new($x) - if defined($downgrade) && $LIB -> _is_one($x->{_d}); - $x; -} - -############################################################################## -# mul/add/div etc - -sub badd { - # add two rational numbers - - # set up parameters - my ($class, $x, $y, @r) = (ref($_[0]), @_); - # objectify is costly, so avoid it - if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { - ($class, $x, $y, @r) = objectify(2, @_); - } - - unless ($x -> is_finite() && $y -> is_finite()) { - if ($x -> is_nan() || $y -> is_nan()) { - return $x -> bnan(@r); - } elsif ($x -> is_inf("+")) { - return $x -> bnan(@r) if $y -> is_inf("-"); - return $x -> binf("+", @r); - } elsif ($x -> is_inf("-")) { - return $x -> bnan(@r) if $y -> is_inf("+"); - return $x -> binf("-", @r); - } elsif ($y -> is_inf("+")) { - return $x -> binf("+", @r); - } elsif ($y -> is_inf("-")) { - return $x -> binf("-", @r); - } - } - - # 1 1 gcd(3, 4) = 1 1*3 + 1*4 7 - # - + - = --------- = -- - # 4 3 4*3 12 - - # we do not compute the gcd() here, but simple do: - # 5 7 5*3 + 7*4 43 - # - + - = --------- = -- - # 4 3 4*3 12 - - # and bnorm() will then take care of the rest - - # 5 * 3 - $x->{_n} = $LIB->_mul($x->{_n}, $y->{_d}); - - # 7 * 4 - my $m = $LIB->_mul($LIB->_copy($y->{_n}), $x->{_d}); - - # 5 * 3 + 7 * 4 - ($x->{_n}, $x->{sign}) = $LIB -> _sadd($x->{_n}, $x->{sign}, $m, $y->{sign}); - - # 4 * 3 - $x->{_d} = $LIB->_mul($x->{_d}, $y->{_d}); - - # normalize result, and possible round - $x->bnorm()->round(@r); -} - -sub bsub { - # subtract two rational numbers - - # set up parameters - my ($class, $x, $y, @r) = (ref($_[0]), @_); - # objectify is costly, so avoid it - if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { - ($class, $x, $y, @r) = objectify(2, @_); - } - - # flip sign of $x, call badd(), then flip sign of result - $x->{sign} =~ tr/+-/-+/ - unless $x->{sign} eq '+' && $x -> is_zero(); # not -0 - $x = $x->badd($y, @r); # does norm and round - $x->{sign} =~ tr/+-/-+/ - unless $x->{sign} eq '+' && $x -> is_zero(); # not -0 - - $x->bnorm(); -} - -sub bmul { - # multiply two rational numbers - - # set up parameters - my ($class, $x, $y, @r) = (ref($_[0]), @_); - # objectify is costly, so avoid it - if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { - ($class, $x, $y, @r) = objectify(2, @_); - } - - return $x->bnan() if $x->{sign} eq 'NaN' || $y->{sign} eq 'NaN'; - - # inf handling - if ($x->{sign} =~ /^[+-]inf$/ || $y->{sign} =~ /^[+-]inf$/) { - return $x->bnan() if $x->is_zero() || $y->is_zero(); - # result will always be +-inf: - # +inf * +/+inf => +inf, -inf * -/-inf => +inf - # +inf * -/-inf => -inf, -inf * +/+inf => -inf - return $x->binf() if ($x->{sign} =~ /^\+/ && $y->{sign} =~ /^\+/); - return $x->binf() if ($x->{sign} =~ /^-/ && $y->{sign} =~ /^-/); - return $x->binf('-'); - } - - # x == 0 # also: or y == 1 or y == -1 - if ($x -> is_zero()) { - $x = $downgrade -> bzero($x) if defined $downgrade; - return wantarray ? ($x, $class->bzero()) : $x; - } - - if ($y -> is_zero()) { - $x = defined($downgrade) ? $downgrade -> bzero($x) : $x -> bzero(); - return wantarray ? ($x, $class->bzero()) : $x; - } - - # According to Knuth, this can be optimized by doing gcd twice (for d - # and n) and reducing in one step. This saves us a bnorm() at the end. - # - # p s p * s (p / gcd(p, r)) * (s / gcd(s, q)) - # - * - = ----- = --------------------------------- - # q r q * r (q / gcd(s, q)) * (r / gcd(p, r)) - - my $gcd_pr = $LIB -> _gcd($LIB -> _copy($x->{_n}), $y->{_d}); - my $gcd_sq = $LIB -> _gcd($LIB -> _copy($y->{_n}), $x->{_d}); - - $x->{_n} = $LIB -> _mul(scalar $LIB -> _div($x->{_n}, $gcd_pr), - scalar $LIB -> _div($LIB -> _copy($y->{_n}), - $gcd_sq)); - $x->{_d} = $LIB -> _mul(scalar $LIB -> _div($x->{_d}, $gcd_sq), - scalar $LIB -> _div($LIB -> _copy($y->{_d}), - $gcd_pr)); - - # compute new sign - $x->{sign} = $x->{sign} eq $y->{sign} ? '+' : '-'; - - $x->bnorm()->round(@r); -} - -sub bdiv { - # (dividend: BRAT or num_str, divisor: BRAT or num_str) return - # (BRAT, BRAT) (quo, rem) or BRAT (only rem) - - # set up parameters - my ($class, $x, $y, @r) = (ref($_[0]), @_); - # objectify is costly, so avoid it - if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { - ($class, $x, $y, @r) = objectify(2, @_); - } - - return $x if $x->modify('bdiv'); - - my $wantarray = wantarray; # call only once - - # At least one argument is NaN. This is handled the same way as in - # Math::BigInt -> bdiv(). See the comments in the code implementing that - # method. - - if ($x -> is_nan() || $y -> is_nan()) { - if ($wantarray) { - return $downgrade -> bnan(), $downgrade -> bnan() - if defined($downgrade); - return $x -> bnan(), $class -> bnan(); - } else { - return $downgrade -> bnan() - if defined($downgrade); - return $x -> bnan(); - } - } - - # Divide by zero and modulo zero. This is handled the same way as in - # Math::BigInt -> bdiv(). See the comments in the code implementing that - # method. - - if ($y -> is_zero()) { - my ($quo, $rem); - if ($wantarray) { - $rem = $x -> copy(); - } - if ($x -> is_zero()) { - $quo = $x -> bnan(); - } else { - $quo = $x -> binf($x -> {sign}); - } - - $quo = $downgrade -> new($quo) - if defined($downgrade) && $quo -> is_int(); - $rem = $downgrade -> new($rem) - if $wantarray && defined($downgrade) && $rem -> is_int(); - return $wantarray ? ($quo, $rem) : $quo; - } - - # Numerator (dividend) is +/-inf. This is handled the same way as in - # Math::BigInt -> bdiv(). See the comments in the code implementing that - # method. - - if ($x -> is_inf()) { - my ($quo, $rem); - $rem = $class -> bnan() if $wantarray; - if ($y -> is_inf()) { - $quo = $x -> bnan(); - } else { - my $sign = $x -> bcmp(0) == $y -> bcmp(0) ? '+' : '-'; - $quo = $x -> binf($sign); - } - - $quo = $downgrade -> new($quo) - if defined($downgrade) && $quo -> is_int(); - $rem = $downgrade -> new($rem) - if $wantarray && defined($downgrade) && $rem -> is_int(); - return $wantarray ? ($quo, $rem) : $quo; - } - - # Denominator (divisor) is +/-inf. This is handled the same way as in - # Math::BigFloat -> bdiv(). See the comments in the code implementing that - # method. - - if ($y -> is_inf()) { - my ($quo, $rem); - if ($wantarray) { - if ($x -> is_zero() || $x -> bcmp(0) == $y -> bcmp(0)) { - $rem = $x -> copy(); - $quo = $x -> bzero(); - } else { - $rem = $class -> binf($y -> {sign}); - $quo = $x -> bone('-'); - } - $quo = $downgrade -> new($quo) - if defined($downgrade) && $quo -> is_int(); - $rem = $downgrade -> new($rem) - if defined($downgrade) && $rem -> is_int(); - return ($quo, $rem); - } else { - if ($y -> is_inf()) { - if ($x -> is_nan() || $x -> is_inf()) { - return $downgrade -> bnan() if defined $downgrade; - return $x -> bnan(); - } else { - return $downgrade -> bzero() if defined $downgrade; - return $x -> bzero(); - } - } - } - } - - # At this point, both the numerator and denominator are finite numbers, and - # the denominator (divisor) is non-zero. - - # x == 0? - if ($x->is_zero()) { - return $wantarray ? ($downgrade -> bzero(), $downgrade -> bzero()) - : $downgrade -> bzero() if defined $downgrade; - return $wantarray ? ($x, $class->bzero()) : $x; - } - - # XXX TODO: list context, upgrade - # According to Knuth, this can be optimized by doing gcd twice (for d and n) - # and reducing in one step. This would save us the bnorm() at the end. - # - # p r p * s (p / gcd(p, r)) * (s / gcd(s, q)) - # - / - = ----- = --------------------------------- - # q s q * r (q / gcd(s, q)) * (r / gcd(p, r)) - - $x->{_n} = $LIB->_mul($x->{_n}, $y->{_d}); - $x->{_d} = $LIB->_mul($x->{_d}, $y->{_n}); - - # compute new sign - $x->{sign} = $x->{sign} eq $y->{sign} ? '+' : '-'; - - $x -> bnorm(); - if (wantarray) { - my $rem = $x -> copy(); - $x = $x -> bfloor(); - $x = $x -> round(@r); - $rem = $rem -> bsub($x -> copy()) -> bmul($y); - $x = $downgrade -> new($x) if defined($downgrade) && $x -> is_int(); - $rem = $downgrade -> new($rem) if defined($downgrade) && $rem -> is_int(); - return $x, $rem; - } else { - return $x -> round(@r); - } -} - -sub bmod { - # compute "remainder" (in Perl way) of $x / $y - - # set up parameters - my ($class, $x, $y, @r) = (ref($_[0]), @_); - # objectify is costly, so avoid it - if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { - ($class, $x, $y, @r) = objectify(2, @_); - } - - return $x if $x->modify('bmod'); - - # At least one argument is NaN. This is handled the same way as in - # Math::BigInt -> bmod(). - - if ($x -> is_nan() || $y -> is_nan()) { - return $x -> bnan(); - } - - # Modulo zero. This is handled the same way as in Math::BigInt -> bmod(). - - if ($y -> is_zero()) { - return $downgrade -> bzero() if defined $downgrade; - return $x; - } - - # Numerator (dividend) is +/-inf. This is handled the same way as in - # Math::BigInt -> bmod(). - - if ($x -> is_inf()) { - return $x -> bnan(); - } - - # Denominator (divisor) is +/-inf. This is handled the same way as in - # Math::BigInt -> bmod(). - - if ($y -> is_inf()) { - if ($x -> is_zero() || $x -> bcmp(0) == $y -> bcmp(0)) { - return $downgrade -> new($x) if defined($downgrade) && $x -> is_int(); - return $x; - } else { - return $downgrade -> binf($y -> sign()) if defined($downgrade); - return $x -> binf($y -> sign()); - } - } - - # At this point, both the numerator and denominator are finite numbers, and - # the denominator (divisor) is non-zero. - - if ($x->is_zero()) { # 0 / 7 = 0, mod 0 - return $downgrade -> bzero() if defined $downgrade; - return $x; - } - - # Compute $x - $y * floor($x/$y). This can probably be optimized by working - # on a lower level. - - $x -> bsub($x -> copy() -> bdiv($y) -> bfloor() -> bmul($y)); - return $x -> round(@r); -} - -############################################################################## -# bdec/binc - -sub bdec { - # decrement value (subtract 1) - my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); - - if ($x->{sign} !~ /^[+-]$/) { # NaN, inf, -inf - return $downgrade -> new($x) if defined $downgrade; - return $x; - } - - if ($x->{sign} eq '-') { - $x->{_n} = $LIB->_add($x->{_n}, $x->{_d}); # -5/2 => -7/2 - } else { - if ($LIB->_acmp($x->{_n}, $x->{_d}) < 0) # n < d? - { - # 1/3 -- => -2/3 - $x->{_n} = $LIB->_sub($LIB->_copy($x->{_d}), $x->{_n}); - $x->{sign} = '-'; - } else { - $x->{_n} = $LIB->_sub($x->{_n}, $x->{_d}); # 5/2 => 3/2 - } - } - $x->bnorm()->round(@r); -} - -sub binc { - # increment value (add 1) - my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); - - if ($x->{sign} !~ /^[+-]$/) { # NaN, inf, -inf - return $downgrade -> new($x) if defined $downgrade; - return $x; - } - - if ($x->{sign} eq '-') { - if ($LIB->_acmp($x->{_n}, $x->{_d}) < 0) { - # -1/3 ++ => 2/3 (overflow at 0) - $x->{_n} = $LIB->_sub($LIB->_copy($x->{_d}), $x->{_n}); - $x->{sign} = '+'; - } else { - $x->{_n} = $LIB->_sub($x->{_n}, $x->{_d}); # -5/2 => -3/2 - } - } else { - $x->{_n} = $LIB->_add($x->{_n}, $x->{_d}); # 5/2 => 7/2 - } - $x->bnorm()->round(@r); -} - -sub binv { - my $x = shift; - my @r = @_; - - return $x if $x->modify('binv'); - - return $x if $x -> is_nan(); - return $x -> bzero() if $x -> is_inf(); - return $x -> binf("+") if $x -> is_zero(); - - ($x -> {_n}, $x -> {_d}) = ($x -> {_d}, $x -> {_n}); - $x -> round(@r); -} - -############################################################################## -# is_foo methods (the rest is inherited) - -sub is_int { - # return true if arg (BRAT or num_str) is an integer - my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); - - return 1 if ($x->{sign} =~ /^[+-]$/) && # NaN and +-inf aren't - $LIB->_is_one($x->{_d}); # x/y && y != 1 => no integer - 0; -} - -sub is_zero { - # return true if arg (BRAT or num_str) is zero - my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); - - return 1 if $x->{sign} eq '+' && $LIB->_is_zero($x->{_n}); - 0; -} - -sub is_one { - # return true if arg (BRAT or num_str) is +1 or -1 if signis given - my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); - - croak "too many arguments for is_one()" if @_ > 2; - my $sign = $_[1] || ''; - $sign = '+' if $sign ne '-'; - return 1 if ($x->{sign} eq $sign && - $LIB->_is_one($x->{_n}) && $LIB->_is_one($x->{_d})); - 0; -} - -sub is_odd { - # return true if arg (BFLOAT or num_str) is odd or false if even - my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); - - return 1 if ($x->{sign} =~ /^[+-]$/) && # NaN & +-inf aren't - ($LIB->_is_one($x->{_d}) && $LIB->_is_odd($x->{_n})); # x/2 is not, but 3/1 - 0; -} - -sub is_even { - # return true if arg (BINT or num_str) is even or false if odd - my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); - - return 0 if $x->{sign} !~ /^[+-]$/; # NaN & +-inf aren't - return 1 if ($LIB->_is_one($x->{_d}) # x/3 is never - && $LIB->_is_even($x->{_n})); # but 4/1 is - 0; -} - -############################################################################## -# parts() and friends - -sub numerator { - my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); - - # NaN, inf, -inf - return Math::BigInt->new($x->{sign}) if ($x->{sign} !~ /^[+-]$/); - - my $n = Math::BigInt->new($LIB->_str($x->{_n})); - $n->{sign} = $x->{sign}; - $n; -} - -sub denominator { - my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); - - # NaN - return Math::BigInt->new($x->{sign}) if $x->{sign} eq 'NaN'; - # inf, -inf - return Math::BigInt->bone() if $x->{sign} !~ /^[+-]$/; - - Math::BigInt->new($LIB->_str($x->{_d})); -} - -sub parts { - my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); - - my $c = 'Math::BigInt'; - - return ($c->bnan(), $c->bnan()) if $x->{sign} eq 'NaN'; - return ($c->binf(), $c->binf()) if $x->{sign} eq '+inf'; - return ($c->binf('-'), $c->binf()) if $x->{sign} eq '-inf'; - - my $n = $c->new($LIB->_str($x->{_n})); - $n->{sign} = $x->{sign}; - my $d = $c->new($LIB->_str($x->{_d})); - ($n, $d); -} - -sub dparts { - my $x = shift; - my $class = ref $x; - - croak("dparts() is an instance method") unless $class; - - if ($x -> is_nan()) { - return $class -> bnan(), $class -> bnan() if wantarray; - return $class -> bnan(); - } - - if ($x -> is_inf()) { - return $class -> binf($x -> sign()), $class -> bzero() if wantarray; - return $class -> binf($x -> sign()); - } - - # 355/113 => 3 + 16/113 - - my ($q, $r) = $LIB -> _div($LIB -> _copy($x -> {_n}), $x -> {_d}); - - my $int = Math::BigRat -> new($x -> {sign} . $LIB -> _str($q)); - return $int unless wantarray; - - my $frc = Math::BigRat -> new($x -> {sign} . $LIB -> _str($r), - $LIB -> _str($x -> {_d})); - - return $int, $frc; -} - -sub fparts { - my $x = shift; - my $class = ref $x; - - croak("fparts() is an instance method") unless $class; - - return ($class -> bnan(), - $class -> bnan()) if $x -> is_nan(); - - my $numer = $x -> copy(); - my $denom = $class -> bzero(); - - $denom -> {_n} = $numer -> {_d}; - $numer -> {_d} = $LIB -> _one(); - - return ($numer, $denom); -} - -sub length { - my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); - - return $nan unless $x->is_int(); - $LIB->_len($x->{_n}); # length(-123/1) => length(123) -} - -sub digit { - my ($class, $x, $n) = ref($_[0]) ? (undef, $_[0], $_[1]) : objectify(1, @_); - - return $nan unless $x->is_int(); - $LIB->_digit($x->{_n}, $n || 0); # digit(-123/1, 2) => digit(123, 2) -} - -############################################################################## -# special calc routines - -sub bceil { - my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); - - if ($x->{sign} !~ /^[+-]$/ || # NaN or inf or - $LIB->_is_one($x->{_d})) # integer - { - return $downgrade -> new($x) if defined $downgrade; - return $x; - } - - $x->{_n} = $LIB->_div($x->{_n}, $x->{_d}); # 22/7 => 3/1 w/ truncate - $x->{_d} = $LIB->_one(); # d => 1 - $x->{_n} = $LIB->_inc($x->{_n}) if $x->{sign} eq '+'; # +22/7 => 4/1 - $x->{sign} = '+' if $x->{sign} eq '-' && $LIB->_is_zero($x->{_n}); # -0 => 0 - return $downgrade -> new($x) if defined $downgrade; - $x; -} - -sub bfloor { - my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); - - if ($x->{sign} !~ /^[+-]$/ || # NaN or inf or - $LIB->_is_one($x->{_d})) # integer - { - return $downgrade -> new($x) if defined $downgrade; - return $x; - } - - $x->{_n} = $LIB->_div($x->{_n}, $x->{_d}); # 22/7 => 3/1 w/ truncate - $x->{_d} = $LIB->_one(); # d => 1 - $x->{_n} = $LIB->_inc($x->{_n}) if $x->{sign} eq '-'; # -22/7 => -4/1 - return $downgrade -> new($x) if defined $downgrade; - $x; -} - -sub bint { - my ($class, $x) = ref($_[0]) ? (ref($_[0]), $_[0]) : objectify(1, @_); - - if ($x->{sign} !~ /^[+-]$/ || # NaN or inf or - $LIB->_is_one($x->{_d})) # integer - { - return $downgrade -> new($x) if defined $downgrade; - return $x; - } - - $x->{_n} = $LIB->_div($x->{_n}, $x->{_d}); # 22/7 => 3/1 w/ truncate - $x->{_d} = $LIB->_one(); # d => 1 - $x->{sign} = '+' if $x->{sign} eq '-' && $LIB -> _is_zero($x->{_n}); - return $downgrade -> new($x) if defined $downgrade; - return $x; -} - -sub bfac { - my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); - - # if $x is not an integer - if (($x->{sign} ne '+') || (!$LIB->_is_one($x->{_d}))) { - return $x->bnan(); - } - - $x->{_n} = $LIB->_fac($x->{_n}); - # since _d is 1, we don't need to reduce/norm the result - $x->round(@r); -} - -sub bpow { - # power ($x ** $y) - - # set up parameters - my ($class, $x, $y, @r) = (ref($_[0]), @_); - - # objectify is costly, so avoid it - if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { - ($class, $x, $y, @r) = objectify(2, @_); - } - - return $x if $x->modify('bpow'); - - # $x and/or $y is a NaN - return $x->bnan() if $x->is_nan() || $y->is_nan(); - - # $x and/or $y is a +/-Inf - if ($x->is_inf("-")) { - return $x->bzero() if $y->is_negative(); - return $x->bnan() if $y->is_zero(); - return $x if $y->is_odd(); - return $x->bneg(); - } elsif ($x->is_inf("+")) { - return $x->bzero() if $y->is_negative(); - return $x->bnan() if $y->is_zero(); - return $x; - } elsif ($y->is_inf("-")) { - return $x->bnan() if $x -> is_one("-"); - return $x->binf("+") if $x > -1 && $x < 1; - return $x->bone() if $x -> is_one("+"); - return $x->bzero(); - } elsif ($y->is_inf("+")) { - return $x->bnan() if $x -> is_one("-"); - return $x->bzero() if $x > -1 && $x < 1; - return $x->bone() if $x -> is_one("+"); - return $x->binf("+"); - } - - if ($x -> is_zero()) { - return $x -> bone() if $y -> is_zero(); - return $x -> binf() if $y -> is_negative(); - return $x; - } - - # We don't support complex numbers, so upgrade or return NaN. - - if ($x -> is_negative() && !$y -> is_int()) { - return $upgrade -> bpow($upgrade -> new($x), $y, @r) - if defined $upgrade; - return $x -> bnan(); - } - - if ($x -> is_one("+") || $y -> is_one()) { - return $x; - } - - if ($x -> is_one("-")) { - return $x if $y -> is_odd(); - return $x -> bneg(); - } - - # (a/b)^-(c/d) = (b/a)^(c/d) - ($x->{_n}, $x->{_d}) = ($x->{_d}, $x->{_n}) if $y->is_negative(); - - unless ($LIB->_is_one($y->{_n})) { - $x->{_n} = $LIB->_pow($x->{_n}, $y->{_n}); - $x->{_d} = $LIB->_pow($x->{_d}, $y->{_n}); - $x->{sign} = '+' if $x->{sign} eq '-' && $LIB->_is_even($y->{_n}); - } - - unless ($LIB->_is_one($y->{_d})) { - return $x->bsqrt(@r) if $LIB->_is_two($y->{_d}); # 1/2 => sqrt - return $x->broot($LIB->_str($y->{_d}), @r); # 1/N => root(N) - } - - return $x->round(@r); -} - -sub blog { - # Return the logarithm of the operand. If a second operand is defined, that - # value is used as the base, otherwise the base is assumed to be Euler's - # constant. - - my ($class, $x, $base, @r); - - # Don't objectify the base, since an undefined base, as in $x->blog() or - # $x->blog(undef) signals that the base is Euler's number. - - if (!ref($_[0]) && $_[0] =~ /^[A-Za-z]|::/) { - # E.g., Math::BigRat->blog(256, 2) - ($class, $x, $base, @r) = - defined $_[2] ? objectify(2, @_) : objectify(1, @_); - } else { - # E.g., Math::BigRat::blog(256, 2) or $x->blog(2) - ($class, $x, $base, @r) = - defined $_[1] ? objectify(2, @_) : objectify(1, @_); - } - - return $x if $x->modify('blog'); - - # Handle all exception cases and all trivial cases. I have used Wolfram Alpha - # (http://www.wolframalpha.com) as the reference for these cases. - - return $x -> bnan() if $x -> is_nan(); - - if (defined $base) { - $base = $class -> new($base) unless ref $base; - if ($base -> is_nan() || $base -> is_one()) { - return $x -> bnan(); - } elsif ($base -> is_inf() || $base -> is_zero()) { - return $x -> bnan() if $x -> is_inf() || $x -> is_zero(); - return $x -> bzero(); - } elsif ($base -> is_negative()) { # -inf < base < 0 - return $x -> bzero() if $x -> is_one(); # x = 1 - return $x -> bone() if $x == $base; # x = base - return $x -> bnan(); # otherwise - } - return $x -> bone() if $x == $base; # 0 < base && 0 < x < inf - } - - # We now know that the base is either undefined or positive and finite. - - if ($x -> is_inf()) { # x = +/-inf - my $sign = defined $base && $base < 1 ? '-' : '+'; - return $x -> binf($sign); - } elsif ($x -> is_neg()) { # -inf < x < 0 - return $x -> bnan(); - } elsif ($x -> is_one()) { # x = 1 - return $x -> bzero(); - } elsif ($x -> is_zero()) { # x = 0 - my $sign = defined $base && $base < 1 ? '+' : '-'; - return $x -> binf($sign); - } - - # Now take care of the cases where $x and/or $base is 1/N. - # - # log(1/N) / log(B) = -log(N)/log(B) - # log(1/N) / log(1/B) = log(N)/log(B) - # log(N) / log(1/B) = -log(N)/log(B) - - my $neg = 0; - if ($x -> numerator() -> is_one()) { - $x -> binv(); - $neg = !$neg; - } - if (defined(blessed($base)) && $base -> isa($class)) { - if ($base -> numerator() -> is_one()) { - $base = $base -> copy() -> binv(); - $neg = !$neg; - } - } - - # disable upgrading and downgrading - - require Math::BigFloat; - my $upg = Math::BigFloat -> upgrade(); - my $dng = Math::BigFloat -> downgrade(); - Math::BigFloat -> upgrade(undef); - Math::BigFloat -> downgrade(undef); - - # At this point we are done handling all exception cases and trivial cases. - - $base = Math::BigFloat -> new($base) if defined $base; - my $xnum = Math::BigFloat -> new($LIB -> _str($x->{_n})); - my $xden = Math::BigFloat -> new($LIB -> _str($x->{_d})); - my $xstr = $xnum -> bdiv($xden) -> blog($base, @r) -> bsstr(); - - # reset upgrading and downgrading - - Math::BigFloat -> upgrade($upg); - Math::BigFloat -> downgrade($dng); - - my $xobj = Math::BigRat -> new($xstr); - $x -> {sign} = $xobj -> {sign}; - $x -> {_n} = $xobj -> {_n}; - $x -> {_d} = $xobj -> {_d}; - - return $neg ? $x -> bneg() : $x; -} - -sub bexp { - # set up parameters - my ($class, $x, $y, @r) = (ref($_[0]), @_); - - # objectify is costly, so avoid it - if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { - ($class, $x, $y, @r) = objectify(1, @_); - } - - return $x->binf(@r) if $x->{sign} eq '+inf'; - return $x->bzero(@r) if $x->{sign} eq '-inf'; - - # we need to limit the accuracy to protect against overflow - my $fallback = 0; - my ($scale, @params); - ($x, @params) = $x->_find_round_parameters(@r); - - # also takes care of the "error in _find_round_parameters?" case - return $x if $x->{sign} eq 'NaN'; - - # no rounding at all, so must use fallback - if (scalar @params == 0) { - # simulate old behaviour - $params[0] = $class->div_scale(); # and round to it as accuracy - $params[1] = undef; # P = undef - $scale = $params[0]+4; # at least four more for proper round - $params[2] = $r[2]; # round mode by caller or undef - $fallback = 1; # to clear a/p afterwards - } else { - # the 4 below is empirical, and there might be cases where it's not enough... - $scale = abs($params[0] || $params[1]) + 4; # take whatever is defined - } - - return $x->bone(@params) if $x->is_zero(); - - # See the comments in Math::BigFloat on how this algorithm works. - # Basically we calculate A and B (where B is faculty(N)) so that A/B = e - - my $x_org = $x->copy(); - if ($scale <= 75) { - # set $x directly from a cached string form - $x->{_n} = - $LIB->_new("90933395208605785401971970164779391644753259799242"); - $x->{_d} = - $LIB->_new("33452526613163807108170062053440751665152000000000"); - $x->{sign} = '+'; - } else { - # compute A and B so that e = A / B. - - # After some terms we end up with this, so we use it as a starting point: - my $A = $LIB->_new("90933395208605785401971970164779391644753259799242"); - my $F = $LIB->_new(42); my $step = 42; - - # Compute how many steps we need to take to get $A and $B sufficiently big - my $steps = Math::BigFloat::_len_to_steps($scale - 4); - # print STDERR "# Doing $steps steps for ", $scale-4, " digits\n"; - while ($step++ <= $steps) { - # calculate $a * $f + 1 - $A = $LIB->_mul($A, $F); - $A = $LIB->_inc($A); - # increment f - $F = $LIB->_inc($F); - } - # compute $B as factorial of $steps (this is faster than doing it manually) - my $B = $LIB->_fac($LIB->_new($steps)); - - # print "A ", $LIB->_str($A), "\nB ", $LIB->_str($B), "\n"; - - $x->{_n} = $A; - $x->{_d} = $B; - $x->{sign} = '+'; - } - - # $x contains now an estimate of e, with some surplus digits, so we can round - if (!$x_org->is_one()) { - # raise $x to the wanted power and round it in one step: - $x->bpow($x_org, @params); - } else { - # else just round the already computed result - delete $x->{_a}; delete $x->{_p}; - # shortcut to not run through _find_round_parameters again - if (defined $params[0]) { - $x->bround($params[0], $params[2]); # then round accordingly - } else { - $x->bfround($params[1], $params[2]); # then round accordingly - } - } - if ($fallback) { - # clear a/p after round, since user did not request it - delete $x->{_a}; delete $x->{_p}; - } - - $x; -} - -sub bnok { - # set up parameters - my ($class, $x, $y, @r) = (ref($_[0]), @_); - - # objectify is costly, so avoid it - if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { - ($class, $x, $y, @r) = objectify(2, @_); - } - - return $x->bnan() if $x->is_nan() || $y->is_nan(); - return $x->bnan() if (($x->is_finite() && !$x->is_int()) || - ($y->is_finite() && !$y->is_int())); - - my $xint = Math::BigInt -> new($x -> bstr()); - my $yint = Math::BigInt -> new($y -> bstr()); - $xint -> bnok($yint); - my $xrat = Math::BigRat -> new($xint); - - $x -> {sign} = $xrat -> {sign}; - $x -> {_n} = $xrat -> {_n}; - $x -> {_d} = $xrat -> {_d}; - - return $x; -} - -sub broot { - # set up parameters - my ($class, $x, $y, @r) = (ref($_[0]), @_); - # objectify is costly, so avoid it - if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { - ($class, $x, $y, @r) = objectify(2, @_); - } - - # Convert $x into a Math::BigFloat. - - my $xd = Math::BigFloat -> new($LIB -> _str($x->{_d})); - my $xflt = Math::BigFloat -> new($LIB -> _str($x->{_n})) -> bdiv($xd); - $xflt -> {sign} = $x -> {sign}; - - # Convert $y into a Math::BigFloat. - - my $yd = Math::BigFloat -> new($LIB -> _str($y->{_d})); - my $yflt = Math::BigFloat -> new($LIB -> _str($y->{_n})) -> bdiv($yd); - $yflt -> {sign} = $y -> {sign}; - - # Compute the root and convert back to a Math::BigRat. - - $xflt -> broot($yflt, @r); - my $xtmp = Math::BigRat -> new($xflt -> bsstr()); - - $x -> {sign} = $xtmp -> {sign}; - $x -> {_n} = $xtmp -> {_n}; - $x -> {_d} = $xtmp -> {_d}; - - return $x; -} - -sub bmodpow { - # set up parameters - my ($class, $x, $y, $m, @r) = (ref($_[0]), @_); - # objectify is costly, so avoid it - if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { - ($class, $x, $y, $m, @r) = objectify(3, @_); - } - - # Convert $x, $y, and $m into Math::BigInt objects. - - my $xint = Math::BigInt -> new($x -> copy() -> bint()); - my $yint = Math::BigInt -> new($y -> copy() -> bint()); - my $mint = Math::BigInt -> new($m -> copy() -> bint()); - - $xint -> bmodpow($yint, $mint, @r); - my $xtmp = Math::BigRat -> new($xint -> bsstr()); - - $x -> {sign} = $xtmp -> {sign}; - $x -> {_n} = $xtmp -> {_n}; - $x -> {_d} = $xtmp -> {_d}; - return $x; -} - -sub bmodinv { - # set up parameters - my ($class, $x, $y, @r) = (ref($_[0]), @_); - # objectify is costly, so avoid it - if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { - ($class, $x, $y, @r) = objectify(2, @_); - } - - # Convert $x and $y into Math::BigInt objects. - - my $xint = Math::BigInt -> new($x -> copy() -> bint()); - my $yint = Math::BigInt -> new($y -> copy() -> bint()); - - $xint -> bmodinv($yint, @r); - my $xtmp = Math::BigRat -> new($xint -> bsstr()); - - $x -> {sign} = $xtmp -> {sign}; - $x -> {_n} = $xtmp -> {_n}; - $x -> {_d} = $xtmp -> {_d}; - return $x; -} - -sub bsqrt { - my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); - - return $x->bnan() if $x->{sign} !~ /^[+]/; # NaN, -inf or < 0 - return $x if $x->{sign} eq '+inf'; # sqrt(inf) == inf - return $x->round(@r) if $x->is_zero() || $x->is_one(); - - my $n = $x -> {_n}; - my $d = $x -> {_d}; - - # Look for an exact solution. For the numerator and the denominator, take - # the square root and square it and see if we got the original value. If we - # did, for both the numerator and the denominator, we have an exact - # solution. - - { - my $nsqrt = $LIB -> _sqrt($LIB -> _copy($n)); - my $n2 = $LIB -> _mul($LIB -> _copy($nsqrt), $nsqrt); - if ($LIB -> _acmp($n, $n2) == 0) { - my $dsqrt = $LIB -> _sqrt($LIB -> _copy($d)); - my $d2 = $LIB -> _mul($LIB -> _copy($dsqrt), $dsqrt); - if ($LIB -> _acmp($d, $d2) == 0) { - $x -> {_n} = $nsqrt; - $x -> {_d} = $dsqrt; - return $x->round(@r); - } - } - } - - local $Math::BigFloat::upgrade = undef; - local $Math::BigFloat::downgrade = undef; - local $Math::BigFloat::precision = undef; - local $Math::BigFloat::accuracy = undef; - local $Math::BigInt::upgrade = undef; - local $Math::BigInt::precision = undef; - local $Math::BigInt::accuracy = undef; - - my $xn = Math::BigFloat -> new($LIB -> _str($n)); - my $xd = Math::BigFloat -> new($LIB -> _str($d)); - - my $xtmp = Math::BigRat -> new($xn -> bdiv($xd) -> bsqrt() -> bsstr()); - - $x -> {sign} = $xtmp -> {sign}; - $x -> {_n} = $xtmp -> {_n}; - $x -> {_d} = $xtmp -> {_d}; - - $x->round(@r); -} - -sub blsft { - my ($class, $x, $y, $b) = objectify(2, @_); - - $b = 2 if !defined $b; - $b = $class -> new($b) unless ref($b) && $b -> isa($class); - - return $x -> bnan() if $x -> is_nan() || $y -> is_nan() || $b -> is_nan(); - - # shift by a negative amount? - return $x -> brsft($y -> copy() -> babs(), $b) if $y -> {sign} =~ /^-/; - - $x -> bmul($b -> bpow($y)); -} - -sub brsft { - my ($class, $x, $y, $b) = objectify(2, @_); - - $b = 2 if !defined $b; - $b = $class -> new($b) unless ref($b) && $b -> isa($class); - - return $x -> bnan() if $x -> is_nan() || $y -> is_nan() || $b -> is_nan(); - - # shift by a negative amount? - return $x -> blsft($y -> copy() -> babs(), $b) if $y -> {sign} =~ /^-/; - - # the following call to bdiv() will return either quotient (scalar context) - # or quotient and remainder (list context). - $x -> bdiv($b -> bpow($y)); -} - -sub band { - my $x = shift; - my $xref = ref($x); - my $class = $xref || $x; - - croak 'band() is an instance method, not a class method' unless $xref; - croak 'Not enough arguments for band()' if @_ < 1; - - my $y = shift; - $y = $class -> new($y) unless ref($y); - - my @r = @_; - - my $xtmp = Math::BigInt -> new($x -> bint()); # to Math::BigInt - $xtmp -> band($y); - $xtmp = $class -> new($xtmp); # back to Math::BigRat - - $x -> {sign} = $xtmp -> {sign}; - $x -> {_n} = $xtmp -> {_n}; - $x -> {_d} = $xtmp -> {_d}; - - return $x -> round(@r); -} - -sub bior { - my $x = shift; - my $xref = ref($x); - my $class = $xref || $x; - - croak 'bior() is an instance method, not a class method' unless $xref; - croak 'Not enough arguments for bior()' if @_ < 1; - - my $y = shift; - $y = $class -> new($y) unless ref($y); - - my @r = @_; - - my $xtmp = Math::BigInt -> new($x -> bint()); # to Math::BigInt - $xtmp -> bior($y); - $xtmp = $class -> new($xtmp); # back to Math::BigRat - - $x -> {sign} = $xtmp -> {sign}; - $x -> {_n} = $xtmp -> {_n}; - $x -> {_d} = $xtmp -> {_d}; - - return $x -> round(@r); -} - -sub bxor { - my $x = shift; - my $xref = ref($x); - my $class = $xref || $x; - - croak 'bxor() is an instance method, not a class method' unless $xref; - croak 'Not enough arguments for bxor()' if @_ < 1; - - my $y = shift; - $y = $class -> new($y) unless ref($y); - - my @r = @_; - - my $xtmp = Math::BigInt -> new($x -> bint()); # to Math::BigInt - $xtmp -> bxor($y); - $xtmp = $class -> new($xtmp); # back to Math::BigRat - - $x -> {sign} = $xtmp -> {sign}; - $x -> {_n} = $xtmp -> {_n}; - $x -> {_d} = $xtmp -> {_d}; - - return $x -> round(@r); -} - -sub bnot { - my $x = shift; - my $xref = ref($x); - my $class = $xref || $x; - - croak 'bnot() is an instance method, not a class method' unless $xref; - - my @r = @_; - - my $xtmp = Math::BigInt -> new($x -> bint()); # to Math::BigInt - $xtmp -> bnot(); - $xtmp = $class -> new($xtmp); # back to Math::BigRat - - $x -> {sign} = $xtmp -> {sign}; - $x -> {_n} = $xtmp -> {_n}; - $x -> {_d} = $xtmp -> {_d}; - - return $x -> round(@r); -} - -############################################################################## -# round - -sub round { - my $x = shift; - return $downgrade -> new($x) if defined($downgrade) && - ($x -> is_int() || $x -> is_inf() || $x -> is_nan()); - $x; -} - -sub bround { - my $x = shift; - return $downgrade -> new($x) if defined($downgrade) && - ($x -> is_int() || $x -> is_inf() || $x -> is_nan()); - $x; -} - -sub bfround { - my $x = shift; - return $downgrade -> new($x) if defined($downgrade) && - ($x -> is_int() || $x -> is_inf() || $x -> is_nan()); - $x; -} - -############################################################################## -# comparing - -sub bcmp { - # compare two signed numbers - - # set up parameters - my ($class, $x, $y) = (ref($_[0]), @_); - - # objectify is costly, so avoid it - if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { - ($class, $x, $y) = objectify(2, @_); - } - - if ($x->{sign} !~ /^[+-]$/ || $y->{sign} !~ /^[+-]$/) { - # $x is NaN and/or $y is NaN - return if $x->{sign} eq $nan || $y->{sign} eq $nan; - # $x and $y are both either +inf or -inf - return 0 if $x->{sign} eq $y->{sign} && $x->{sign} =~ /^[+-]inf$/; - # $x = +inf and $y < +inf - return +1 if $x->{sign} eq '+inf'; - # $x = -inf and $y > -inf - return -1 if $x->{sign} eq '-inf'; - # $x < +inf and $y = +inf - return -1 if $y->{sign} eq '+inf'; - # $x > -inf and $y = -inf - return +1; - } - - # $x >= 0 and $y < 0 - return 1 if $x->{sign} eq '+' && $y->{sign} eq '-'; - # $x < 0 and $y >= 0 - return -1 if $x->{sign} eq '-' && $y->{sign} eq '+'; - - # At this point, we know that $x and $y have the same sign. - - # shortcut - my $xz = $LIB->_is_zero($x->{_n}); - my $yz = $LIB->_is_zero($y->{_n}); - return 0 if $xz && $yz; # 0 <=> 0 - return -1 if $xz && $y->{sign} eq '+'; # 0 <=> +y - return 1 if $yz && $x->{sign} eq '+'; # +x <=> 0 - - my $t = $LIB->_mul($LIB->_copy($x->{_n}), $y->{_d}); - my $u = $LIB->_mul($LIB->_copy($y->{_n}), $x->{_d}); - - my $cmp = $LIB->_acmp($t, $u); # signs are equal - $cmp = -$cmp if $x->{sign} eq '-'; # both are '-' => reverse - $cmp; -} - -sub bacmp { - # compare two numbers (as unsigned) - - # set up parameters - my ($class, $x, $y) = (ref($_[0]), @_); - # objectify is costly, so avoid it - if ((!ref($_[0])) || (ref($_[0]) ne ref($_[1]))) { - ($class, $x, $y) = objectify(2, @_); - } - - if (($x->{sign} !~ /^[+-]$/) || ($y->{sign} !~ /^[+-]$/)) { - # handle +-inf and NaN - return if (($x->{sign} eq $nan) || ($y->{sign} eq $nan)); - return 0 if $x->{sign} =~ /^[+-]inf$/ && $y->{sign} =~ /^[+-]inf$/; - return 1 if $x->{sign} =~ /^[+-]inf$/ && $y->{sign} !~ /^[+-]inf$/; - return -1; - } - - my $t = $LIB->_mul($LIB->_copy($x->{_n}), $y->{_d}); - my $u = $LIB->_mul($LIB->_copy($y->{_n}), $x->{_d}); - $LIB->_acmp($t, $u); # ignore signs -} - -sub beq { - my $self = shift; - my $selfref = ref $self; - #my $class = $selfref || $self; - - croak 'beq() is an instance method, not a class method' unless $selfref; - croak 'Wrong number of arguments for beq()' unless @_ == 1; - - my $cmp = $self -> bcmp(shift); - return defined($cmp) && ! $cmp; -} - -sub bne { - my $self = shift; - my $selfref = ref $self; - #my $class = $selfref || $self; - - croak 'bne() is an instance method, not a class method' unless $selfref; - croak 'Wrong number of arguments for bne()' unless @_ == 1; - - my $cmp = $self -> bcmp(shift); - return defined($cmp) && ! $cmp ? '' : 1; -} - -sub blt { - my $self = shift; - my $selfref = ref $self; - #my $class = $selfref || $self; - - croak 'blt() is an instance method, not a class method' unless $selfref; - croak 'Wrong number of arguments for blt()' unless @_ == 1; - - my $cmp = $self -> bcmp(shift); - return defined($cmp) && $cmp < 0; -} - -sub ble { - my $self = shift; - my $selfref = ref $self; - #my $class = $selfref || $self; - - croak 'ble() is an instance method, not a class method' unless $selfref; - croak 'Wrong number of arguments for ble()' unless @_ == 1; - - my $cmp = $self -> bcmp(shift); - return defined($cmp) && $cmp <= 0; -} - -sub bgt { - my $self = shift; - my $selfref = ref $self; - #my $class = $selfref || $self; - - croak 'bgt() is an instance method, not a class method' unless $selfref; - croak 'Wrong number of arguments for bgt()' unless @_ == 1; - - my $cmp = $self -> bcmp(shift); - return defined($cmp) && $cmp > 0; -} - -sub bge { - my $self = shift; - my $selfref = ref $self; - #my $class = $selfref || $self; - - croak 'bge() is an instance method, not a class method' - unless $selfref; - croak 'Wrong number of arguments for bge()' unless @_ == 1; - - my $cmp = $self -> bcmp(shift); - return defined($cmp) && $cmp >= 0; -} - -############################################################################## -# output conversion - -sub numify { - # convert 17/8 => float (aka 2.125) - my ($self, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); - - # Non-finite number. - - if ($x -> is_nan()) { - require Math::Complex; - my $inf = $Math::Complex::Inf; - return $inf - $inf; - } - - if ($x -> is_inf()) { - require Math::Complex; - my $inf = $Math::Complex::Inf; - return $x -> is_negative() ? -$inf : $inf; - } - - # Finite number. - - my $abs = $LIB->_is_one($x->{_d}) - ? $LIB->_num($x->{_n}) - : Math::BigFloat -> new($LIB->_str($x->{_n})) - -> bdiv($LIB->_str($x->{_d})) - -> bstr(); - return $x->{sign} eq '-' ? 0 - $abs : 0 + $abs; -} - -sub as_int { - my ($class, $x) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); - - return $x -> copy() if $x -> isa("Math::BigInt"); - - # disable upgrading and downgrading - - require Math::BigInt; - my $upg = Math::BigInt -> upgrade(); - my $dng = Math::BigInt -> downgrade(); - Math::BigInt -> upgrade(undef); - Math::BigInt -> downgrade(undef); - - my $y; - if ($x -> is_inf()) { - $y = Math::BigInt -> binf($x->sign()); - } elsif ($x -> is_nan()) { - $y = Math::BigInt -> bnan(); - } else { - my $int = $LIB -> _div($LIB -> _copy($x->{_n}), $x->{_d}); # 22/7 => 3 - $y = Math::BigInt -> new($LIB -> _str($int)); - $y = $y -> bneg() if $x -> is_neg(); - } - - # reset upgrading and downgrading - - Math::BigInt -> upgrade($upg); - Math::BigInt -> downgrade($dng); - - return $y; -} - -sub as_float { - my ($class, $x, @r) = ref($_[0]) ? (ref($_[0]), @_) : objectify(1, @_); - - return $x -> copy() if $x -> isa("Math::BigFloat"); - - # disable upgrading and downgrading - - require Math::BigFloat; - my $upg = Math::BigFloat -> upgrade(); - my $dng = Math::BigFloat -> downgrade(); - Math::BigFloat -> upgrade(undef); - Math::BigFloat -> downgrade(undef); - - my $y; - if ($x -> is_inf()) { - $y = Math::BigFloat -> binf($x->sign()); - } elsif ($x -> is_nan()) { - $y = Math::BigFloat -> bnan(); - } else { - $y = Math::BigFloat -> new($LIB -> _str($x->{_n})); - $y -> {sign} = $x -> {sign}; - unless ($LIB -> _is_one($x->{_d})) { - my $xd = Math::BigFloat -> new($LIB -> _str($x->{_d})); - $y -> bdiv($xd, @r); - } - } - - # reset upgrading and downgrading - - Math::BigFloat -> upgrade($upg); - Math::BigFloat -> downgrade($dng); - - return $y; -} - -sub as_bin { - my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); - - return $x unless $x->is_int(); - - my $s = $x->{sign}; - $s = '' if $s eq '+'; - $s . $LIB->_as_bin($x->{_n}); -} - -sub as_hex { - my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); - - return $x unless $x->is_int(); - - my $s = $x->{sign}; $s = '' if $s eq '+'; - $s . $LIB->_as_hex($x->{_n}); -} - -sub as_oct { - my ($class, $x) = ref($_[0]) ? (undef, $_[0]) : objectify(1, @_); - - return $x unless $x->is_int(); - - my $s = $x->{sign}; $s = '' if $s eq '+'; - $s . $LIB->_as_oct($x->{_n}); -} - -############################################################################## - -sub from_hex { - my $class = shift; - - # The relationship should probably go the otherway, i.e, that new() calls - # from_hex(). Fixme! - my ($x, @r) = @_; - $x =~ s|^\s*(?:0?[Xx]_*)?|0x|; - $class->new($x, @r); -} - -sub from_bin { - my $class = shift; - - # The relationship should probably go the otherway, i.e, that new() calls - # from_bin(). Fixme! - my ($x, @r) = @_; - $x =~ s|^\s*(?:0?[Bb]_*)?|0b|; - $class->new($x, @r); -} - -sub from_oct { - my $class = shift; - - # Why is this different from from_hex() and from_bin()? Fixme! - my @parts; - for my $c (@_) { - push @parts, Math::BigInt->from_oct($c); - } - $class->new (@parts); -} - -############################################################################## -# import - -sub import { - my $class = shift; - my @a; # unrecognized arguments - my $lib_param = ''; - my $lib_value = ''; - - while (@_) { - my $param = shift; - - # Enable overloading of constants. - - if ($param eq ':constant') { - overload::constant - - integer => sub { - $class -> new(shift); - }, - - float => sub { - $class -> new(shift); - }, - - binary => sub { - # E.g., a literal 0377 shall result in an object whose value - # is decimal 255, but new("0377") returns decimal 377. - return $class -> from_oct($_[0]) if $_[0] =~ /^0_*[0-7]/; - $class -> new(shift); - }; - next; - } - - # Upgrading. - - if ($param eq 'upgrade') { - $class -> upgrade(shift); - next; - } - - # Downgrading. - - if ($param eq 'downgrade') { - $class -> downgrade(shift); - next; - } - - # Accuracy. - - if ($param eq 'accuracy') { - $class -> accuracy(shift); - next; - } - - # Precision. - - if ($param eq 'precision') { - $class -> precision(shift); - next; - } - - # Rounding mode. - - if ($param eq 'round_mode') { - $class -> round_mode(shift); - next; - } - - # Backend library. - - if ($param =~ /^(lib|try|only)\z/) { - # alternative library - $lib_param = $param; # "lib", "try", or "only" - $lib_value = shift; - next; - } - - if ($param eq 'with') { - # alternative class for our private parts() - # XXX: no longer supported - # $LIB = shift() || 'Calc'; - # carp "'with' is no longer supported, use 'lib', 'try', or 'only'"; - shift; - next; - } - - # Unrecognized parameter. - - push @a, $param; - } - - require Math::BigInt; - - my @import = ('objectify'); - push @import, $lib_param, $lib_value if $lib_param ne ''; - Math::BigInt -> import(@import); - - # find out which one was actually loaded - $LIB = Math::BigInt -> config("lib"); - - # any non :constant stuff is handled by Exporter (loaded by parent class) - # even if @_ is empty, to give it a chance - $class->SUPER::import(@a); # for subclasses - $class->export_to_level(1, $class, @a); # need this, too -} - -1; - -__END__ - -=pod - -=head1 NAME - -Math::BigRat - arbitrary size rational number math package - -=head1 SYNOPSIS - - use Math::BigRat; - - my $x = Math::BigRat->new('3/7'); $x += '5/9'; - - print $x->bstr(), "\n"; - print $x ** 2, "\n"; - - my $y = Math::BigRat->new('inf'); - print "$y ", ($y->is_inf ? 'is' : 'is not'), " infinity\n"; - - my $z = Math::BigRat->new(144); $z->bsqrt(); - -=head1 DESCRIPTION - -Math::BigRat complements Math::BigInt and Math::BigFloat by providing support -for arbitrary big rational numbers. - -=head2 MATH LIBRARY - -You can change the underlying module that does the low-level -math operations by using: - - use Math::BigRat try => 'GMP'; - -Note: This needs Math::BigInt::GMP installed. - -The following would first try to find Math::BigInt::Foo, then -Math::BigInt::Bar, and when this also fails, revert to Math::BigInt::Calc: - - use Math::BigRat try => 'Foo,Math::BigInt::Bar'; - -If you want to get warned when the fallback occurs, replace "try" with "lib": - - use Math::BigRat lib => 'Foo,Math::BigInt::Bar'; - -If you want the code to die instead, replace "try" with "only": - - use Math::BigRat only => 'Foo,Math::BigInt::Bar'; - -=head1 METHODS - -Any methods not listed here are derived from Math::BigFloat (or -Math::BigInt), so make sure you check these two modules for further -information. - -=over - -=item new() - - $x = Math::BigRat->new('1/3'); - -Create a new Math::BigRat object. Input can come in various forms: - - $x = Math::BigRat->new(123); # scalars - $x = Math::BigRat->new('inf'); # infinity - $x = Math::BigRat->new('123.3'); # float - $x = Math::BigRat->new('1/3'); # simple string - $x = Math::BigRat->new('1 / 3'); # spaced - $x = Math::BigRat->new('1 / 0.1'); # w/ floats - $x = Math::BigRat->new(Math::BigInt->new(3)); # BigInt - $x = Math::BigRat->new(Math::BigFloat->new('3.1')); # BigFloat - $x = Math::BigRat->new(Math::BigInt::Lite->new('2')); # BigLite - - # You can also give D and N as different objects: - $x = Math::BigRat->new( - Math::BigInt->new(-123), - Math::BigInt->new(7), - ); # => -123/7 - -=item numerator() - - $n = $x->numerator(); - -Returns a copy of the numerator (the part above the line) as signed BigInt. - -=item denominator() - - $d = $x->denominator(); - -Returns a copy of the denominator (the part under the line) as positive BigInt. - -=item parts() - - ($n, $d) = $x->parts(); - -Return a list consisting of (signed) numerator and (unsigned) denominator as -BigInts. - -=item dparts() - -Returns the integer part and the fraction part. - -=item fparts() - -Returns the smallest possible numerator and denominator so that the numerator -divided by the denominator gives back the original value. For finite numbers, -both values are integers. Mnemonic: fraction. - -=item numify() - - my $y = $x->numify(); - -Returns the object as a scalar. This will lose some data if the object -cannot be represented by a normal Perl scalar (integer or float), so -use L or L instead. - -This routine is automatically used whenever a scalar is required: - - my $x = Math::BigRat->new('3/1'); - @array = (0, 1, 2, 3); - $y = $array[$x]; # set $y to 3 - -=item as_int() - -=item as_number() - - $x = Math::BigRat->new('13/7'); - print $x->as_int(), "\n"; # '1' - -Returns a copy of the object as BigInt, truncated to an integer. - -C is an alias for C. - -=item as_float() - - $x = Math::BigRat->new('13/7'); - print $x->as_float(), "\n"; # '1' - - $x = Math::BigRat->new('2/3'); - print $x->as_float(5), "\n"; # '0.66667' - -Returns a copy of the object as BigFloat, preserving the -accuracy as wanted, or the default of 40 digits. - -This method was added in v0.22 of Math::BigRat (April 2008). - -=item as_hex() - - $x = Math::BigRat->new('13'); - print $x->as_hex(), "\n"; # '0xd' - -Returns the BigRat as hexadecimal string. Works only for integers. - -=item as_bin() - - $x = Math::BigRat->new('13'); - print $x->as_bin(), "\n"; # '0x1101' - -Returns the BigRat as binary string. Works only for integers. - -=item as_oct() - - $x = Math::BigRat->new('13'); - print $x->as_oct(), "\n"; # '015' - -Returns the BigRat as octal string. Works only for integers. - -=item from_hex() - - my $h = Math::BigRat->from_hex('0x10'); - -Create a BigRat from a hexadecimal number in string form. - -=item from_oct() - - my $o = Math::BigRat->from_oct('020'); - -Create a BigRat from an octal number in string form. - -=item from_bin() - - my $b = Math::BigRat->from_bin('0b10000000'); - -Create a BigRat from an binary number in string form. - -=item bnan() - - $x = Math::BigRat->bnan(); - -Creates a new BigRat object representing NaN (Not A Number). -If used on an object, it will set it to NaN: - - $x->bnan(); - -=item bzero() - - $x = Math::BigRat->bzero(); - -Creates a new BigRat object representing zero. -If used on an object, it will set it to zero: - - $x->bzero(); - -=item binf() - - $x = Math::BigRat->binf($sign); - -Creates a new BigRat object representing infinity. The optional argument is -either '-' or '+', indicating whether you want infinity or minus infinity. -If used on an object, it will set it to infinity: - - $x->binf(); - $x->binf('-'); - -=item bone() - - $x = Math::BigRat->bone($sign); - -Creates a new BigRat object representing one. The optional argument is -either '-' or '+', indicating whether you want one or minus one. -If used on an object, it will set it to one: - - $x->bone(); # +1 - $x->bone('-'); # -1 - -=item length() - - $len = $x->length(); - -Return the length of $x in digits for integer values. - -=item digit() - - print Math::BigRat->new('123/1')->digit(1); # 1 - print Math::BigRat->new('123/1')->digit(-1); # 3 - -Return the N'ths digit from X when X is an integer value. - -=item bnorm() - - $x->bnorm(); - -Reduce the number to the shortest form. This routine is called -automatically whenever it is needed. - -=item bfac() - - $x->bfac(); - -Calculates the factorial of $x. For instance: - - print Math::BigRat->new('3/1')->bfac(), "\n"; # 1*2*3 - print Math::BigRat->new('5/1')->bfac(), "\n"; # 1*2*3*4*5 - -Works currently only for integers. - -=item bround()/round()/bfround() - -Are not yet implemented. - -=item bmod() - - $x->bmod($y); - -Returns $x modulo $y. When $x is finite, and $y is finite and non-zero, the -result is identical to the remainder after floored division (F-division). If, -in addition, both $x and $y are integers, the result is identical to the result -from Perl's % operator. - -=item bmodinv() - - $x->bmodinv($mod); # modular multiplicative inverse - -Returns the multiplicative inverse of C<$x> modulo C<$mod>. If - - $y = $x -> copy() -> bmodinv($mod) - -then C<$y> is the number closest to zero, and with the same sign as C<$mod>, -satisfying - - ($x * $y) % $mod = 1 % $mod - -If C<$x> and C<$y> are non-zero, they must be relative primes, i.e., -C. 'C' is returned when no modular multiplicative -inverse exists. - -=item bmodpow() - - $num->bmodpow($exp,$mod); # modular exponentiation - # ($num**$exp % $mod) - -Returns the value of C<$num> taken to the power C<$exp> in the modulus -C<$mod> using binary exponentiation. C is far superior to -writing - - $num ** $exp % $mod - -because it is much faster - it reduces internal variables into -the modulus whenever possible, so it operates on smaller numbers. - -C also supports negative exponents. - - bmodpow($num, -1, $mod) - -is exactly equivalent to - - bmodinv($num, $mod) - -=item bneg() - - $x->bneg(); - -Used to negate the object in-place. - -=item is_one() - - print "$x is 1\n" if $x->is_one(); - -Return true if $x is exactly one, otherwise false. - -=item is_zero() - - print "$x is 0\n" if $x->is_zero(); - -Return true if $x is exactly zero, otherwise false. - -=item is_pos()/is_positive() - - print "$x is >= 0\n" if $x->is_positive(); - -Return true if $x is positive (greater than or equal to zero), otherwise -false. Please note that '+inf' is also positive, while 'NaN' and '-inf' aren't. - -C is an alias for C. - -=item is_neg()/is_negative() - - print "$x is < 0\n" if $x->is_negative(); - -Return true if $x is negative (smaller than zero), otherwise false. Please -note that '-inf' is also negative, while 'NaN' and '+inf' aren't. - -C is an alias for C. - -=item is_int() - - print "$x is an integer\n" if $x->is_int(); - -Return true if $x has a denominator of 1 (e.g. no fraction parts), otherwise -false. Please note that '-inf', 'inf' and 'NaN' aren't integer. - -=item is_odd() - - print "$x is odd\n" if $x->is_odd(); - -Return true if $x is odd, otherwise false. - -=item is_even() - - print "$x is even\n" if $x->is_even(); - -Return true if $x is even, otherwise false. - -=item bceil() - - $x->bceil(); - -Set $x to the next bigger integer value (e.g. truncate the number to integer -and then increment it by one). - -=item bfloor() - - $x->bfloor(); - -Truncate $x to an integer value. - -=item bint() - - $x->bint(); - -Round $x towards zero. - -=item bsqrt() - - $x->bsqrt(); - -Calculate the square root of $x. - -=item broot() - - $x->broot($n); - -Calculate the N'th root of $x. - -=item badd() - - $x->badd($y); - -Adds $y to $x and returns the result. - -=item bmul() - - $x->bmul($y); - -Multiplies $y to $x and returns the result. - -=item bsub() - - $x->bsub($y); - -Subtracts $y from $x and returns the result. - -=item bdiv() - - $q = $x->bdiv($y); - ($q, $r) = $x->bdiv($y); - -In scalar context, divides $x by $y and returns the result. In list context, -does floored division (F-division), returning an integer $q and a remainder $r -so that $x = $q * $y + $r. The remainer (modulo) is equal to what is returned -by C<< $x->bmod($y) >>. - -=item binv() - - $x->binv(); - -Inverse of $x. - -=item bdec() - - $x->bdec(); - -Decrements $x by 1 and returns the result. - -=item binc() - - $x->binc(); - -Increments $x by 1 and returns the result. - -=item copy() - - my $z = $x->copy(); - -Makes a deep copy of the object. - -Please see the documentation in L for further details. - -=item bstr()/bsstr() - - my $x = Math::BigRat->new('8/4'); - print $x->bstr(), "\n"; # prints 1/2 - print $x->bsstr(), "\n"; # prints 1/2 - -Return a string representing this object. - -=item bcmp() - - $x->bcmp($y); - -Compares $x with $y and takes the sign into account. -Returns -1, 0, 1 or undef. - -=item bacmp() - - $x->bacmp($y); - -Compares $x with $y while ignoring their sign. Returns -1, 0, 1 or undef. - -=item beq() - - $x -> beq($y); - -Returns true if and only if $x is equal to $y, and false otherwise. - -=item bne() - - $x -> bne($y); - -Returns true if and only if $x is not equal to $y, and false otherwise. - -=item blt() - - $x -> blt($y); - -Returns true if and only if $x is equal to $y, and false otherwise. - -=item ble() - - $x -> ble($y); - -Returns true if and only if $x is less than or equal to $y, and false -otherwise. - -=item bgt() - - $x -> bgt($y); - -Returns true if and only if $x is greater than $y, and false otherwise. - -=item bge() - - $x -> bge($y); - -Returns true if and only if $x is greater than or equal to $y, and false -otherwise. - -=item blsft()/brsft() - -Used to shift numbers left/right. - -Please see the documentation in L for further details. - -=item band() - - $x->band($y); # bitwise and - -=item bior() - - $x->bior($y); # bitwise inclusive or - -=item bxor() - - $x->bxor($y); # bitwise exclusive or - -=item bnot() - - $x->bnot(); # bitwise not (two's complement) - -=item bpow() - - $x->bpow($y); - -Compute $x ** $y. - -Please see the documentation in L for further details. - -=item blog() - - $x->blog($base, $accuracy); # logarithm of x to the base $base - -If C<$base> is not defined, Euler's number (e) is used: - - print $x->blog(undef, 100); # log(x) to 100 digits - -=item bexp() - - $x->bexp($accuracy); # calculate e ** X - -Calculates two integers A and B so that A/B is equal to C, where C is -Euler's number. - -This method was added in v0.20 of Math::BigRat (May 2007). - -See also C. - -=item bnok() - - $x->bnok($y); # x over y (binomial coefficient n over k) - -Calculates the binomial coefficient n over k, also called the "choose" -function. The result is equivalent to: - - ( n ) n! - | - | = ------- - ( k ) k!(n-k)! - -This method was added in v0.20 of Math::BigRat (May 2007). - -=item config() - - Math::BigRat->config("trap_nan" => 1); # set - $accu = Math::BigRat->config("accuracy"); # get - -Set or get configuration parameter values. Read-only parameters are marked as -RO. Read-write parameters are marked as RW. The following parameters are -supported. - - Parameter RO/RW Description - Example - ============================================================ - lib RO Name of the math backend library - Math::BigInt::Calc - lib_version RO Version of the math backend library - 0.30 - class RO The class of config you just called - Math::BigRat - version RO version number of the class you used - 0.10 - upgrade RW To which class numbers are upgraded - undef - downgrade RW To which class numbers are downgraded - undef - precision RW Global precision - undef - accuracy RW Global accuracy - undef - round_mode RW Global round mode - even - div_scale RW Fallback accuracy for div, sqrt etc. - 40 - trap_nan RW Trap NaNs - undef - trap_inf RW Trap +inf/-inf - undef - -=back - -=head1 NUMERIC LITERALS - -After C all numeric literals in the given scope -are converted to C objects. This conversion happens at compile -time. Every non-integer is convert to a NaN. - -For example, - - perl -MMath::BigRat=:constant -le 'print 2**150' - -prints the exact value of C<2**150>. Note that without conversion of constants -to objects the expression C<2**150> is calculated using Perl scalars, which -leads to an inaccurate result. - -Please note that strings are not affected, so that - - use Math::BigRat qw/:constant/; - - $x = "1234567890123456789012345678901234567890" - + "123456789123456789"; - -does give you what you expect. You need an explicit Math::BigRat->new() around -at least one of the operands. You should also quote large constants to prevent -loss of precision: - - use Math::BigRat; - - $x = Math::BigRat->new("1234567889123456789123456789123456789"); - -Without the quotes Perl first converts the large number to a floating point -constant at compile time, and then converts the result to a Math::BigRat object -at run time, which results in an inaccurate result. - -=head2 Hexadecimal, octal, and binary floating point literals - -Perl (and this module) accepts hexadecimal, octal, and binary floating point -literals, but use them with care with Perl versions before v5.32.0, because some -versions of Perl silently give the wrong result. Below are some examples of -different ways to write the number decimal 314. - -Hexadecimal floating point literals: - - 0x1.3ap+8 0X1.3AP+8 - 0x1.3ap8 0X1.3AP8 - 0x13a0p-4 0X13A0P-4 - -Octal floating point literals (with "0" prefix): - - 01.164p+8 01.164P+8 - 01.164p8 01.164P8 - 011640p-4 011640P-4 - -Octal floating point literals (with "0o" prefix) (requires v5.34.0): - - 0o1.164p+8 0O1.164P+8 - 0o1.164p8 0O1.164P8 - 0o11640p-4 0O11640P-4 - -Binary floating point literals: - - 0b1.0011101p+8 0B1.0011101P+8 - 0b1.0011101p8 0B1.0011101P8 - 0b10011101000p-2 0B10011101000P-2 - -=head1 BUGS - -Please report any bugs or feature requests to -C, or through the web interface at -L -(requires login). -We will be notified, and then you'll automatically be notified of progress on -your bug as I make changes. - -=head1 SUPPORT - -You can find documentation for this module with the perldoc command. - - perldoc Math::BigRat - -You can also look for information at: - -=over 4 - -=item * GitHub - -L - -=item * RT: CPAN's request tracker - -L - -=item * MetaCPAN - -L - -=item * CPAN Testers Matrix - -L - -=item * CPAN Ratings - -L - -=back - -=head1 LICENSE - -This program is free software; you may redistribute it and/or modify it under -the same terms as Perl itself. - -=head1 SEE ALSO - -L, L and L as well as the backends -L, L, and L. - -=head1 AUTHORS - -=over 4 - -=item * - -Tels L 2001-2009. - -=item * - -Maintained by Peter John Acklam 2011- - -=back - -=cut Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/badd-mbr.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/badd-mbr.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/badd-mbr.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/badd-mbr.t 15 Feb 2023 01:32:35 -0000 1.1.1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,164 +0,0 @@ -# -*- mode: perl; -*- - -use strict; -use warnings; - -use Test::More tests => 173; - -my $class; - -BEGIN { - $class = 'Math::BigRat'; - use_ok($class); -} - -while () { - s/#.*$//; # remove comments - s/\s+$//; # remove trailing whitespace - next unless length; # skip empty lines - - my ($xval, $yval, $zval) = split /:/; - my ($x, $y, $got, @got); - - for my $context_is_scalar (0, 1) { - for my $y_is_scalar (0, 1) { - - my $test = qq|\$x = $class -> new("$xval");|; - - $test .= $y_is_scalar - ? qq| \$y = "$yval";| - : qq| \$y = $class -> new("$yval");|; - - $test .= $context_is_scalar - ? qq| \$got = \$x -> badd(\$y);| - : qq| \@got = \$x -> badd(\$y);|; - - my $desc = "badd() in "; - $desc .= $context_is_scalar ? "scalar context" : "list context"; - $desc .= $y_is_scalar ? " with y as scalar" : " with y as object"; - - subtest $desc, - sub { - plan tests => $context_is_scalar ? 7 : 8; - - eval $test; - is($@, "", "'$test' gives emtpy \$\@"); - - if ($context_is_scalar) { - - # Check output. - - is(ref($got), $class, - "'$test' output arg is a $class"); - - is($got -> bstr(), $zval, - "'$test' output arg has the right value"); - - } else { - - # Check number of output arguments. - - cmp_ok(scalar @got, '==', 1, - "'$test' gives one output arg"); - - # Check output. - - is(ref($got[0]), $class, - "'$test' output arg is a $class"); - - is($got[0] -> bstr(), $zval, - "'$test' output arg has the right value"); - } - - # Check the invocand. - - is(ref($x), $class, - "'$test' invocand is still a $class"); - - is($x -> bstr(), $zval, - "'$test' invocand has the right value"); - - # Check the input argument. - - if ($y_is_scalar) { - - is(ref($y), '', - "'$test' second input arg is still a scalar"); - - is($y, $yval, - "'$test' second input arg is unmodified"); - - } else { - - is(ref($y), $class, - "'$test' second input arg is still a $class"); - - is($y -> bstr(), $yval, - "'$test' second input arg is unmodified"); - } - }; - } - } -} - -__DATA__ - -# x and/or y is NaN - -NaN:NaN:NaN - -NaN:-inf:NaN -NaN:-3:NaN -NaN:0:NaN -NaN:3:NaN -NaN:inf:NaN - --inf:NaN:NaN --3:NaN:NaN -0:NaN:NaN -3:NaN:NaN -inf:NaN:NaN - -# x = inf - -inf:-inf:NaN -inf:-3:inf -inf:-2:inf -inf:-1:inf -inf:0:inf -inf:1:inf -inf:2:inf -inf:3:inf -inf:inf:inf - -# x = -inf - --inf:-inf:-inf --inf:-3:-inf --inf:-2:-inf --inf:-1:-inf --inf:0:-inf --inf:1:-inf --inf:2:-inf --inf:3:-inf --inf:inf:NaN - -# y = inf - --3:inf:inf --2:inf:inf --1:inf:inf -0:inf:inf -1:inf:inf -2:inf:inf -3:inf:inf - -# y = -inf - --3:-inf:-inf --2:-inf:-inf --1:-inf:-inf -0:-inf:-inf -1:-inf:-inf -2:-inf:-inf -3:-inf:-inf Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/big_ap.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/big_ap.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/big_ap.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/big_ap.t 15 Feb 2023 01:36:20 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,121 +0,0 @@ -# -*- mode: perl; -*- - -# Test that accuracy() and precision() in BigInt/BigFloat do not disturb -# the rounding force in BigRat. - -use strict; -use warnings; - -use Test::More tests => 17; - -use Math::BigInt; -use Math::BigFloat; -use Math::BigRat; - -my $proper = Math::BigRat -> new('12345678901234567890/2'); -my $proper_inc = Math::BigRat -> new('12345678901234567890/2') -> binc(); -my $proper_dec = Math::BigRat -> new('12345678901234567890/2') -> bdec(); -my $proper_int = Math::BigInt -> new('12345678901234567890'); -my $proper_float = Math::BigFloat -> new('12345678901234567890'); -my $proper2 = Math::BigRat -> new('12345678901234567890'); - -Math::BigInt -> accuracy(3); -Math::BigFloat -> accuracy(5); - -my ($x, $y, $z); - -############################################################################## -# new() - -note "Test new()"; - -$z = Math::BigRat->new("12345678901234567890/2"); -is($z, $proper, q|Math::BigRat->new("12345678901234567890/2")|); - -$z = Math::BigRat->new("1234567890123456789E1"); -is($z, $proper2, q|Math::BigRat->new("1234567890123456789E1")|); - -$z = Math::BigRat->new("12345678901234567890/1E0"); -is($z, $proper2, q|Math::BigRat->new("12345678901234567890/1E0")|); - -$z = Math::BigRat->new("1234567890123456789e1/1"); -is($z, $proper2, q|Math::BigRat->new("1234567890123456789e1/1")|); - -$z = Math::BigRat->new("1234567890123456789e1/1E0"); -is($z, $proper2, q|Math::BigRat->new("1234567890123456789e1/1E0")|); - -$z = Math::BigRat->new($proper_int); -is($z, $proper2, qq|Math::BigRat->new("$proper_int")|); - -$z = Math::BigRat->new($proper_float); -is($z, $proper2, qq|Math::BigRat->new("$proper_float")|); - -############################################################################## -# bdiv - -note "Test bdiv()"; - -$x = Math::BigRat->new("12345678901234567890"); -$y = Math::BigRat->new("2"); -$z = $x->copy->bdiv($y); -is($z, $proper); - -############################################################################## -# bmul - -note "Test bmul()"; - -$x = Math::BigRat->new("$proper"); -$y = Math::BigRat->new("1"); -$z = $x->copy->bmul($y); -is($z, $proper); - -$z = Math::BigRat->new("12345678901234567890/1E0"); -is($z, $proper2); - -$z = Math::BigRat->new($proper_int); -is($z, $proper2); - -$z = Math::BigRat->new($proper_float); -is($z, $proper2); - -############################################################################## -# bdiv - -note "Test bdiv()"; - -$x = Math::BigRat->new("12345678901234567890"); -$y = Math::BigRat->new("2"); -$z = $x->copy->bdiv($y); -is($z, $proper); - -############################################################################## -# bmul - -note "Test bmul()"; - -$x = Math::BigRat->new("$proper"); -$y = Math::BigRat->new("1"); -$z = $x->copy->bmul($y); -is($z, $proper); - -$x = Math::BigRat->new("$proper"); -$y = Math::BigRat->new("2"); -$z = $x->copy->bmul($y); -is($z, $proper2); - -############################################################################## -# binc - -note "Test binc()"; - -$x = $proper->copy()->binc(); -is($x, $proper_inc); - -############################################################################## -# binc - -note "Test bdec()"; - -$x = $proper->copy()->bdec(); -is($x, $proper_dec); Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/bigfltpm.inc =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/bigfltpm.inc diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/bigfltpm.inc --- gnu/usr.bin/perl/cpan/Math-BigRat/t/bigfltpm.inc 30 Dec 2019 02:13:47 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,1673 +0,0 @@ -#include this file into another test for subclass testing... - -use strict; -use warnings; - -ok ($class->config()->{lib},$CL); - -my $z; - -while () - { - chomp; - $_ =~ s/#.*$//; # remove comments - $_ =~ s/\s+$//; # trailing spaces - next if /^$/; # skip empty lines & comments - if (s/^&//) - { - $f = $_; - } - elsif (/^\$/) - { - $setup = $_; $setup =~ s/\$/\$${class}::/g; # round_mode, div_scale - #print "\$setup== $setup\n"; - } - else - { - if (m|^(.*?):(/.+)$|) - { - $ans = $2; - @args = split(/:/,$1,99); - } - else - { - @args = split(/:/,$_,99); $ans = pop(@args); - } - $try = "\$x = $class->new(\"$args[0]\");"; - if ($f eq "fnorm") - { - $try .= "\$x;"; - } elsif ($f eq "finf") { - $try .= "\$x->finf('$args[1]');"; - } elsif ($f eq "is_inf") { - $try .= "\$x->is_inf('$args[1]');"; - } elsif ($f eq "fone") { - $try .= "\$x->bone('$args[1]');"; - } elsif ($f eq "fstr") { - $try .= "\$x->accuracy($args[1]); \$x->precision($args[2]);"; - $try .= '$x->fstr();'; - } elsif ($f eq "parts") { - # ->bstr() to see if an object is returned - $try .= '($a,$b) = $x->parts(); $a = $a->bstr(); $b = $b->bstr();'; - $try .= '"$a $b";'; - } elsif ($f eq "exponent") { - # ->bstr() to see if an object is returned - $try .= '$x->exponent()->bstr();'; - } elsif ($f eq "mantissa") { - # ->bstr() to see if an object is returned - $try .= '$x->mantissa()->bstr();'; - } elsif ($f =~ /^(numify|length|as_number|as_hex|as_bin)$/) { - $try .= "\$x->$f();"; - # some unary ops (test the fxxx form, since that is done by AUTOLOAD) - } elsif ($f =~ /^f(nan|sstr|neg|floor|ceil|abs)$/) { - $try .= "\$x->f$1();"; - # some is_xxx test function - } elsif ($f =~ /^is_(zero|one|negative|positive|odd|even|nan|int)$/) { - $try .= "\$x->$f();"; - } elsif ($f eq "finc") { - $try .= '++$x;'; - } elsif ($f eq "fdec") { - $try .= '--$x;'; - }elsif ($f eq "fround") { - $try .= "$setup; \$x->fround($args[1]);"; - } elsif ($f eq "ffround") { - $try .= "$setup; \$x->ffround($args[1]);"; - } elsif ($f eq "fsqrt") { - $try .= "$setup; \$x->fsqrt();"; - } elsif ($f eq "ffac") { - $try .= "$setup; \$x->ffac();"; - } elsif ($f eq "flog") { - if (defined $args[1] && $args[1] ne '') - { - $try .= "\$y = $class->new($args[1]);"; - $try .= "$setup; \$x->flog(\$y);"; - } - else - { - $try .= "$setup; \$x->flog();"; - } - } - else - { - $try .= "\$y = $class->new(\"$args[1]\");"; - - if ($f eq "bgcd") - { - if (defined $args[2]) - { - $try .= " \$z = $class->new(\"$args[2]\"); "; - } - $try .= "$class\::bgcd(\$x, \$y"; - $try .= ", \$z" if (defined $args[2]); - $try .= " );"; - } - elsif ($f eq "blcm") - { - if (defined $args[2]) - { - $try .= " \$z = $class->new(\"$args[2]\"); "; - } - $try .= "$class\::blcm(\$x, \$y"; - $try .= ", \$z" if (defined $args[2]); - $try .= " );"; - } elsif ($f eq "fcmp") { - $try .= '$x->fcmp($y);'; - } elsif ($f eq "facmp") { - $try .= '$x->facmp($y);'; - } elsif ($f eq "fpow") { - $try .= '$x ** $y;'; - } elsif ($f eq "bnok") { - $try .= '$x->bnok($y);'; - } elsif ($f eq "froot") { - $try .= "$setup; \$x->froot(\$y);"; - } elsif ($f eq "fadd") { - $try .= '$x + $y;'; - } elsif ($f eq "fsub") { - $try .= '$x - $y;'; - } elsif ($f eq "fmul") { - $try .= '$x * $y;'; - } elsif ($f eq "fdiv") { - $try .= "$setup; \$x / \$y;"; - } elsif ($f eq "fdiv-list") { - $try .= "$setup; join(',',\$x->fdiv(\$y));"; - } elsif ($f eq "frsft") { - $try .= '$x >> $y;'; - } elsif ($f eq "flsft") { - $try .= '$x << $y;'; - } elsif ($f eq "fmod") { - $try .= '$x % $y;'; - } else { warn "Unknown op '$f'"; } - } - # print "# Trying: '$try'\n"; - $ans1 = eval $try; - print "# Error: $@\n" if $@; - if ($ans =~ m|^/(.*)$|) - { - my $pat = $1; - if ($ans1 =~ /$pat/) - { - ok (1,1); - } - else - { - print "# '$try' expected: /$pat/ got: '$ans1'\n" if !ok(1,0); - } - } - else - { - if ($ans eq "") - { - ok_undef ($ans1); - } - else - { - print "# Tried: '$try'\n" if !ok ($ans1, $ans); - if (ref($ans1) eq "$class") - { - # float numbers are normalized (for now), so mantissa shouldn't have - # trailing zeros - #print $ans1->_trailing_zeros(),"\n"; - print "# Has trailing zeros after '$try'\n" - if !ok ($CL->_zeros( $ans1->{_m}), 0); - } - } - } # end pattern or string - } - } # end while - -# check whether $class->new( Math::BigInt->new()) destroys it -# ($y == 12 in this case) -$x = Math::BigInt->new(1200); $y = $class->new($x); -ok ($y,1200); ok ($x,1200); - -############################################################################### -# Really huge, big, ultra-mega-biggy-monster exponents -# Technically, the exponents should not be limited (they are BigInts), but -# practically there are a few places were they are limited to a Perl scalar. -# This is sometimes for speed, sometimes because otherwise the number wouldn't -# fit into your memory (just think of 1e123456789012345678901234567890 + 1!) -# anyway. We don't test everything here, but let's make sure it just basically -# works. - -my $monster = '1e1234567890123456789012345678901234567890'; - -# new and exponent -ok ($class->new($monster)->bsstr(), - '1e+1234567890123456789012345678901234567890'); -ok ($class->new($monster)->exponent(), - '1234567890123456789012345678901234567890'); -# cmp -ok ($class->new($monster) > 0,1); - -# sub/mul -ok ($class->new($monster)->bsub( $monster),0); -ok ($class->new($monster)->bmul(2)->bsstr(), - '2e+1234567890123456789012345678901234567890'); - -# mantissa -$monster = '1234567890123456789012345678901234567890e2'; -ok ($class->new($monster)->mantissa(), - '123456789012345678901234567890123456789'); - -############################################################################### -# zero,inf,one,nan - -$x = $class->new(2); $x->fzero(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); -$x = $class->new(2); $x->finf(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); -$x = $class->new(2); $x->fone(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); -$x = $class->new(2); $x->fnan(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); - -############################################################################### -# bone/binf etc as plain calls (Lite failed them) - -ok ($class->fzero(),0); -ok ($class->fone(),1); -ok ($class->fone('+'),1); -ok ($class->fone('-'),-1); -ok ($class->fnan(),'NaN'); -ok ($class->finf(),'inf'); -ok ($class->finf('+'),'inf'); -ok ($class->finf('-'),'-inf'); -ok ($class->finf('-inf'),'-inf'); - -$class->accuracy(undef); $class->precision(undef); # reset - -############################################################################### -# bug in bsstr()/numify() showed up in after-rounding in bdiv() - -$x = $class->new('0.008'); $y = $class->new(2); -$x->bdiv(3,$y); -ok ($x,'0.0027'); - -############################################################################### -# fsqrt() with set global A/P or A/P enabled on $x, also a test whether fsqrt() -# correctly modifies $x - -$x = $class->new(12); $class->precision(-2); $x->fsqrt(); ok ($x,'3.46'); - -$class->precision(undef); -$x = $class->new(12); $class->precision(0); $x->fsqrt(); ok ($x,'3'); - -$class->precision(-3); $x = $class->new(12); $x->fsqrt(); ok ($x,'3.464'); - -{ - no strict 'refs'; - # A and P set => NaN - ${${class}.'::accuracy'} = 4; $x = $class->new(12); - $x->fsqrt(3); ok ($x,'NaN'); - # supplied arg overrides set global - $class->precision(undef); $x = $class->new(12); $x->fsqrt(3); ok ($x,'3.46'); - $class->accuracy(undef); $class->precision(undef); # reset for further tests -} - -############################################################################# -# can we call objectify (broken until v1.52) - -{ - no strict; - $try = - '@args' . " = $class" . "::objectify(2,$class,4,5);".'join(" ",@args);'; - $ans = eval $try; - ok ($ans,"$class 4 5"); -} - -############################################################################# -# is_one('-') (broken until v1.64) - -ok ($class->new(-1)->is_one(),0); -ok ($class->new(-1)->is_one('-'),1); - -############################################################################# -# bug 1/0.5 leaving 2e-0 instead of 2e0 - -ok ($class->new(1)->fdiv('0.5')->bsstr(),'2e+0'); - -############################################################################### -# [perl #30609] bug with $x -= $x not being 0, but 2*$x - -$x = $class->new(3); $x -= $x; ok ($x, 0); -$x = $class->new(-3); $x -= $x; ok ($x, 0); -$x = $class->new(3); $x += $x; ok ($x, 6); -$x = $class->new(-3); $x += $x; ok ($x, -6); - -$x = $class->new('NaN'); $x -= $x; ok ($x->is_nan(), 1); -$x = $class->new('inf'); $x -= $x; ok ($x->is_nan(), 1); -$x = $class->new('-inf'); $x -= $x; ok ($x->is_nan(), 1); - -$x = $class->new('NaN'); $x += $x; ok ($x->is_nan(), 1); -$x = $class->new('inf'); $x += $x; ok ($x->is_inf(), 1); -$x = $class->new('-inf'); $x += $x; ok ($x->is_inf('-'), 1); - -$x = $class->new('3.14'); $x -= $x; ok ($x, 0); -$x = $class->new('-3.14'); $x -= $x; ok ($x, 0); -$x = $class->new('3.14'); $x += $x; ok ($x, '6.28'); -$x = $class->new('-3.14'); $x += $x; ok ($x, '-6.28'); - -$x = $class->new('3.14'); $x *= $x; ok ($x, '9.8596'); -$x = $class->new('-3.14'); $x *= $x; ok ($x, '9.8596'); -$x = $class->new('3.14'); $x /= $x; ok ($x, '1'); -$x = $class->new('-3.14'); $x /= $x; ok ($x, '1'); -$x = $class->new('3.14'); $x %= $x; ok ($x, '0'); -$x = $class->new('-3.14'); $x %= $x; ok ($x, '0'); - -############################################################################### -# the following two were reported by "kenny" via hotmail.com: - -#perl -MMath::BigFloat -wle 'print Math::BigFloat->new(0)->bpow(".1")' -#Use of uninitialized value in numeric le (<=) at BigFloat.pm line 1851. - -$x = $class->new(0); $y = $class->new('0.1'); -ok ($x ** $y, 0, 'no warnings and zero result'); - -#perl -MMath::BigFloat -lwe 'print Math::BigFloat->new(".222222222222222222222222222222222222222222")->bceil()' -#Use of uninitialized value in numeric le (<=) at BigFloat.pm line 1851. - -$x = $class->new(".222222222222222222222222222222222222222222"); -ok ($x->bceil(), 1, 'no warnings and one as result'); - -############################################################################### -# test **=, <<=, >>= - -# ((2^148)-1)/17 -$x = $class->new(2); $x **= 148; $x++; $x->bdiv(17, 60)->bfloor(); $x->accuracy(undef); -ok ($x,"20988936657440586486151264256610222593863921"); -ok ($x->length(),length "20988936657440586486151264256610222593863921"); - -$x = $class->new('2'); -my $y = $class->new('18'); -ok ($x <<= $y, 2 << 18); -ok ($x, 2 << 18); -ok ($x >>= $y, 2); -ok ($x, 2); - -$x = $class->new('2'); -$y = $class->new('18.2'); -$x <<= $y; # 2 * (2 ** 18.2); - -ok ($x->copy()->bfround(-9), '602248.763144685'); -ok ($x >>= $y, 2); # 2 * (2 ** 18.2) / (2 ** 18.2) => 2 -ok ($x, 2); - -1; # all done - -############################################################################### -# Perl 5.005 does not like ok ($x,undef) - -sub ok_undef - { - my $x = shift; - - ok (1,1) and return if !defined $x; - ok ($x,'undef'); - } - -__DATA__ -&bgcd -inf:12:NaN --inf:12:NaN -12:inf:NaN -12:-inf:NaN -inf:inf:NaN -inf:-inf:NaN --inf:-inf:NaN -abc:abc:NaN -abc:+0:NaN -+0:abc:NaN -+0:+0:0 -+0:+1:1 -+1:+0:1 -+1:+1:1 -+2:+3:1 -+3:+2:1 --3:+2:1 --3:-2:1 --144:-60:12 -144:-60:12 -144:60:12 -100:625:25 -4096:81:1 -1034:804:2 -27:90:56:1 -27:90:54:9 -&blcm -abc:abc:NaN -abc:+0:NaN -+0:abc:NaN -+0:+0:NaN -+1:+0:0 -+0:+1:0 -+27:+90:270 -+1034:+804:415668 -$div_scale = 40; -&bnok -+inf:10:inf -NaN:NaN:NaN -NaN:1:NaN -1:NaN:NaN -1:1:1 -# k > n -1:2:0 -2:3:0 -# k < 0 -1:-2:0 -# 7 over 3 = 35 -7:3:35 -7:6:1 -100:90:17310309456440 -&flog -0::NaN --1::NaN --2::NaN -# base > 0, base != 1 -2:-1:NaN -2:0:NaN -2:1:NaN -# log(1) is always 1, regardless of $base -1::0 -1:1:0 -1:2:0 -2::0.6931471805599453094172321214581765680755 -2.718281828::0.9999999998311266953289851340574956564911 -$div_scale = 20; -2.718281828::0.99999999983112669533 -$div_scale = 15; -123::4.81218435537242 -10::2.30258509299405 -1000::6.90775527898214 -100::4.60517018598809 -2::0.693147180559945 -3.1415::1.14470039286086 -12345::9.42100640177928 -0.001::-6.90775527898214 -# bug until v1.71: -10:10:1 -100:100:1 -# reset for further tests -$div_scale = 40; -1::0 -&frsft -NaNfrsft:2:NaN -0:2:0 -1:1:0.5 -2:1:1 -4:1:2 -123:1:61.5 -32:3:4 -&flsft -NaNflsft:0:NaN -2:1:4 -4:3:32 -5:3:40 -1:2:4 -0:5:0 -&fnorm -1:1 --0:0 -fnormNaN:NaN -+inf:inf --inf:-inf -123:123 --123.4567:-123.4567 -# invalid inputs -1__2:NaN -1E1__2:NaN -11__2E2:NaN -.2E-3.:NaN -1e3e4:NaN -# strange, but valid -.2E2:20 -1.E3:1000 -# some inputs that result in zero -0e0:0 -+0e0:0 -+0e+0:0 --0e+0:0 -0e-0:0 --0e-0:0 -+0e-0:0 -000:0 -00e2:0 -00e02:0 -000e002:0 -000e1230:0 -00e-3:0 -00e+3:0 -00e-03:0 -00e+03:0 --000:0 --00e2:0 --00e02:0 --000e002:0 --000e1230:0 --00e-3:0 --00e+3:0 --00e-03:0 --00e+03:0 -&as_number -0:0 -1:1 -1.2:1 -2.345:2 --2:-2 --123.456:-123 --200:-200 -# test for bug in brsft() not handling cases that return 0 -0.000641:0 -0.0006412:0 -0.00064123:0 -0.000641234:0 -0.0006412345:0 -0.00064123456:0 -0.000641234567:0 -0.0006412345678:0 -0.00064123456789:0 -0.1:0 -0.01:0 -0.001:0 -0.0001:0 -0.00001:0 -0.000001:0 -0.0000001:0 -0.00000001:0 -0.000000001:0 -0.0000000001:0 -0.00000000001:0 -0.12345:0 -0.123456:0 -0.1234567:0 -0.12345678:0 -0.123456789:0 -&finf -1:+:inf -2:-:-inf -3:abc:inf -&as_hex -+inf:inf --inf:-inf -hexNaN:NaN -0:0x0 -5:0x5 --5:-0x5 -&as_bin -+inf:inf --inf:-inf -hexNaN:NaN -0:0b0 -5:0b101 --5:-0b101 -&numify -# uses bsstr() so 5 => 5e+0 to be compatible w/ Perls output -0:0e+1 -+1:1e+0 -1234:1234e+0 -NaN:NaN -+inf:inf --inf:-inf --5:-5e+0 -100:1e+2 --100:-1e+2 -&fnan -abc:NaN -2:NaN --2:NaN -0:NaN -&fone -2:+:1 --2:-:-1 --2:+:1 -2:-:-1 -0::1 --2::1 -abc::1 -2:abc:1 -&fsstr -+inf:inf --inf:-inf -abcfsstr:NaN --abcfsstr:NaN -1234.567:1234567e-3 -123:123e+0 --5:-5e+0 --100:-1e+2 -&fstr -+inf:::inf --inf:::-inf -abcfstr:::NaN -1234.567:9::1234.56700 -1234.567::-6:1234.567000 -12345:5::12345 -0.001234:6::0.00123400 -0.001234::-8:0.00123400 -0:4::0 -0::-4:0.0000 -&fnorm -inf:inf -+inf:inf --inf:-inf -+infinity:NaN -+-inf:NaN -abc:NaN - 1 a:NaN -1bcd2:NaN -11111b:NaN -+1z:NaN --1z:NaN -0e999:0 -0e-999:0 --0e999:0 --0e-999:0 -0:0 -+0:0 -+00:0 -+0_0_0:0 -000000_0000000_00000:0 --0:0 --0000:0 -+1:1 -+01:1 -+001:1 -+00000100000:100000 -123456789:123456789 --1:-1 --01:-1 --001:-1 --123456789:-123456789 --00000100000:-100000 -123.456a:NaN -123.456:123.456 -0.01:0.01 -.002:0.002 -+.2:0.2 --0.0003:-0.0003 --.0000000004:-0.0000000004 -123456E2:12345600 -123456E-2:1234.56 --123456E2:-12345600 --123456E-2:-1234.56 -1e1:10 -2e-11:0.00000000002 -# exercise _split - .02e-1:0.002 - 000001:1 - -00001:-1 - -1:-1 - 000.01:0.01 - -000.0023:-0.0023 - 1.1e1:11 --3e111:-3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 --4e-1111:-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004 -&fpow -NaN:1:NaN -1:NaN:NaN -NaN:-1:NaN --1:NaN:NaN -NaN:-21:NaN --21:NaN:NaN -NaN:21:NaN -21:NaN:NaN -0:0:1 -0:1:0 -0:9:0 -0:-2:inf -2:2:4 -1:2:1 -1:3:1 --1:2:1 --1:3:-1 -123.456:2:15241.383936 -2:-2:0.25 -2:-3:0.125 -128:-2:0.00006103515625 -abc:123.456:NaN -123.456:abc:NaN -+inf:123.45:inf --inf:123.45:-inf -+inf:-123.45:inf --inf:-123.45:-inf --2:2:4 --2:3:-8 --2:4:16 --2:5:-32 --3:2:9 --3:3:-27 --3:4:81 --3:5:-243 -# 2 ** 0.5 == sqrt(2) -# 1.41..7 and not 1.4170 since fallback (bsqrt(9) is '3', not 3.0...0) -2:0.5:1.41421356237309504880168872420969807857 -#2:0.2:1.148698354997035006798626946777927589444 -#6:1.5:14.6969384566990685891837044482353483518 -$div_scale = 20; -#62.5:12.5:26447206647554886213592.3959144 -$div_scale = 40; -&fneg -fnegNaN:NaN -+inf:-inf --inf:inf -+0:0 -+1:-1 --1:1 -+123456789:-123456789 --123456789:123456789 -+123.456789:-123.456789 --123456.789:123456.789 -&fabs -fabsNaN:NaN -+inf:inf --inf:inf -+0:0 -+1:1 --1:1 -+123456789:123456789 --123456789:123456789 -+123.456789:123.456789 --123456.789:123456.789 -&fround -$round_mode = "trunc" -+inf:5:inf --inf:5:-inf -0:5:0 -NaNfround:5:NaN -+10123456789:5:10123000000 --10123456789:5:-10123000000 -+10123456789.123:5:10123000000 --10123456789.123:5:-10123000000 -+10123456789:9:10123456700 --10123456789:9:-10123456700 -+101234500:6:101234000 --101234500:6:-101234000 -$round_mode = "zero" -+20123456789:5:20123000000 --20123456789:5:-20123000000 -+20123456789.123:5:20123000000 --20123456789.123:5:-20123000000 -+20123456789:9:20123456800 --20123456789:9:-20123456800 -+201234500:6:201234000 --201234500:6:-201234000 -$round_mode = "+inf" -+30123456789:5:30123000000 --30123456789:5:-30123000000 -+30123456789.123:5:30123000000 --30123456789.123:5:-30123000000 -+30123456789:9:30123456800 --30123456789:9:-30123456800 -+301234500:6:301235000 --301234500:6:-301234000 -$round_mode = "-inf" -+40123456789:5:40123000000 --40123456789:5:-40123000000 -+40123456789.123:5:40123000000 --40123456789.123:5:-40123000000 -+40123456789:9:40123456800 --40123456789:9:-40123456800 -+401234500:6:401234000 --401234500:6:-401235000 -$round_mode = "odd" -+50123456789:5:50123000000 --50123456789:5:-50123000000 -+50123456789.123:5:50123000000 --50123456789.123:5:-50123000000 -+50123456789:9:50123456800 --50123456789:9:-50123456800 -+501234500:6:501235000 --501234500:6:-501235000 -$round_mode = "even" -+60123456789:5:60123000000 --60123456789:5:-60123000000 -+60123456789:9:60123456800 --60123456789:9:-60123456800 -+601234500:6:601234000 --601234500:6:-601234000 -+60123456789.0123:5:60123000000 --60123456789.0123:5:-60123000000 -$round_mode = "common" -+60123456789:5:60123000000 --60123456789:5:-60123000000 -+60123456789:6:60123500000 --60123456789:6:-60123500000 -+60123456789:9:60123456800 --60123456789:9:-60123456800 -+601234500:6:601235000 --601234500:6:-601235000 -+601234400:6:601234000 --601234400:6:-601234000 -+601234600:6:601235000 --601234600:6:-601235000 -+601234300:6:601234000 -+60123456789.0123:5:60123000000 --60123456789.0123:5:-60123000000 -&ffround -$round_mode = "trunc" -+inf:5:inf --inf:5:-inf -0:5:0 -NaNffround:5:NaN -+1.23:-1:1.2 -+1.234:-1:1.2 -+1.2345:-1:1.2 -+1.23:-2:1.23 -+1.234:-2:1.23 -+1.2345:-2:1.23 -+1.23:-3:1.230 -+1.234:-3:1.234 -+1.2345:-3:1.234 --1.23:-1:-1.2 -+1.27:-1:1.2 --1.27:-1:-1.2 -+1.25:-1:1.2 --1.25:-1:-1.2 -+1.35:-1:1.3 --1.35:-1:-1.3 --0.0061234567890:-1:0.0 --0.0061:-1:0.0 --0.00612:-1:0.0 --0.00612:-2:0.00 --0.006:-1:0.0 --0.006:-2:0.00 --0.0006:-2:0.00 --0.0006:-3:0.000 --0.0065:-3:/-0\.006|-6e-03 --0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 --0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 -0.05:0:0 -0.5:0:0 -0.51:0:0 -0.41:0:0 -$round_mode = "zero" -+2.23:-1:/2.2(?:0{5}\d+)? --2.23:-1:/-2.2(?:0{5}\d+)? -+2.27:-1:/2.(?:3|29{5}\d+) --2.27:-1:/-2.(?:3|29{5}\d+) -+2.25:-1:/2.2(?:0{5}\d+)? --2.25:-1:/-2.2(?:0{5}\d+)? -+2.35:-1:/2.(?:3|29{5}\d+) --2.35:-1:/-2.(?:3|29{5}\d+) --0.0065:-1:0.0 --0.0065:-2:/-0\.01|-1e-02 --0.0065:-3:/-0\.006|-6e-03 --0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 --0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 -0.05:0:0 -0.5:0:0 -0.51:0:1 -0.41:0:0 -$round_mode = "+inf" -+3.23:-1:/3.2(?:0{5}\d+)? --3.23:-1:/-3.2(?:0{5}\d+)? -+3.27:-1:/3.(?:3|29{5}\d+) --3.27:-1:/-3.(?:3|29{5}\d+) -+3.25:-1:/3.(?:3|29{5}\d+) --3.25:-1:/-3.2(?:0{5}\d+)? -+3.35:-1:/3.(?:4|39{5}\d+) --3.35:-1:/-3.(?:3|29{5}\d+) --0.0065:-1:0.0 --0.0065:-2:/-0\.01|-1e-02 --0.0065:-3:/-0\.006|-6e-03 --0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 --0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 -0.05:0:0 -0.5:0:1 -0.51:0:1 -0.41:0:0 -$round_mode = "-inf" -+4.23:-1:/4.2(?:0{5}\d+)? --4.23:-1:/-4.2(?:0{5}\d+)? -+4.27:-1:/4.(?:3|29{5}\d+) --4.27:-1:/-4.(?:3|29{5}\d+) -+4.25:-1:/4.2(?:0{5}\d+)? --4.25:-1:/-4.(?:3|29{5}\d+) -+4.35:-1:/4.(?:3|29{5}\d+) --4.35:-1:/-4.(?:4|39{5}\d+) --0.0065:-1:0.0 --0.0065:-2:/-0\.01|-1e-02 --0.0065:-3:/-0\.007|-7e-03 --0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 --0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 -0.05:0:0 -0.5:0:0 -0.51:0:1 -0.41:0:0 -$round_mode = "odd" -+5.23:-1:/5.2(?:0{5}\d+)? --5.23:-1:/-5.2(?:0{5}\d+)? -+5.27:-1:/5.(?:3|29{5}\d+) --5.27:-1:/-5.(?:3|29{5}\d+) -+5.25:-1:/5.(?:3|29{5}\d+) --5.25:-1:/-5.(?:3|29{5}\d+) -+5.35:-1:/5.(?:3|29{5}\d+) --5.35:-1:/-5.(?:3|29{5}\d+) --0.0065:-1:0.0 --0.0065:-2:/-0\.01|-1e-02 --0.0065:-3:/-0\.007|-7e-03 --0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 --0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 -0.05:0:0 -0.5:0:1 -0.51:0:1 -0.41:0:0 -$round_mode = "even" -+6.23:-1:/6.2(?:0{5}\d+)? --6.23:-1:/-6.2(?:0{5}\d+)? -+6.27:-1:/6.(?:3|29{5}\d+) --6.27:-1:/-6.(?:3|29{5}\d+) -+6.25:-1:/6.(?:2(?:0{5}\d+)?|29{5}\d+) --6.25:-1:/-6.(?:2(?:0{5}\d+)?|29{5}\d+) -+6.35:-1:/6.(?:4|39{5}\d+|29{8}\d+) --6.35:-1:/-6.(?:4|39{5}\d+|29{8}\d+) --0.0065:-1:0.0 --0.0065:-2:/-0\.01|-1e-02 --0.0065:-3:/-0\.006|-7e-03 --0.0065:-4:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 --0.0065:-5:/-0\.006(?:5|49{5}\d+)|-6\.5e-03 -0.05:0:0 -0.5:0:0 -0.51:0:1 -0.41:0:0 -0.01234567:-3:0.012 -0.01234567:-4:0.0123 -0.01234567:-5:0.01235 -0.01234567:-6:0.012346 -0.01234567:-7:0.0123457 -0.01234567:-8:0.01234567 -0.01234567:-9:0.012345670 -0.01234567:-12:0.012345670000 -&fcmp -fcmpNaN:fcmpNaN: -fcmpNaN:+0: -+0:fcmpNaN: -+0:+0:0 --1:+0:-1 -+0:-1:1 -+1:+0:1 -+0:+1:-1 --1:+1:-1 -+1:-1:1 --1:-1:0 -+1:+1:0 --1.1:0:-1 -+0:-1.1:1 -+1.1:+0:1 -+0:+1.1:-1 -+123:+123:0 -+123:+12:1 -+12:+123:-1 --123:-123:0 --123:-12:-1 --12:-123:1 -+123:+124:-1 -+124:+123:1 --123:-124:1 --124:-123:-1 -0:0.01:-1 -0:0.0001:-1 -0:-0.0001:1 -0:-0.1:1 -0.1:0:1 -0.00001:0:1 --0.0001:0:-1 --0.1:0:-1 -0:0.0001234:-1 -0:-0.0001234:1 -0.0001234:0:1 --0.0001234:0:-1 -0.0001:0.0005:-1 -0.0005:0.0001:1 -0.005:0.0001:1 -0.001:0.0005:1 -0.000001:0.0005:-1 -0.00000123:0.0005:-1 -0.00512:0.0001:1 -0.005:0.000112:1 -0.00123:0.0005:1 -1.5:2:-1 -2:1.5:1 -1.54321:234:-1 -234:1.54321:1 -# infinity --inf:5432112345:-1 -+inf:5432112345:1 --inf:-5432112345:-1 -+inf:-5432112345:1 --inf:54321.12345:-1 -+inf:54321.12345:1 --inf:-54321.12345:-1 -+inf:-54321.12345:1 -+inf:+inf:0 --inf:-inf:0 -+inf:-inf:1 --inf:+inf:-1 -# return undef -+inf:NaN: -NaN:inf: --inf:NaN: -NaN:-inf: -&facmp -fcmpNaN:fcmpNaN: -fcmpNaN:+0: -+0:fcmpNaN: -+0:+0:0 --1:+0:1 -+0:-1:-1 -+1:+0:1 -+0:+1:-1 --1:+1:0 -+1:-1:0 --1:-1:0 -+1:+1:0 --1.1:0:1 -+0:-1.1:-1 -+1.1:+0:1 -+0:+1.1:-1 -+123:+123:0 -+123:+12:1 -+12:+123:-1 --123:-123:0 --123:-12:1 --12:-123:-1 -+123:+124:-1 -+124:+123:1 --123:-124:-1 --124:-123:1 -0:0.01:-1 -0:0.0001:-1 -0:-0.0001:-1 -0:-0.1:-1 -0.1:0:1 -0.00001:0:1 --0.0001:0:1 --0.1:0:1 -0:0.0001234:-1 -0:-0.0001234:-1 -0.0001234:0:1 --0.0001234:0:1 -0.0001:0.0005:-1 -0.0005:0.0001:1 -0.005:0.0001:1 -0.001:0.0005:1 -0.000001:0.0005:-1 -0.00000123:0.0005:-1 -0.00512:0.0001:1 -0.005:0.000112:1 -0.00123:0.0005:1 -1.5:2:-1 -2:1.5:1 -1.54321:234:-1 -234:1.54321:1 -# infinity --inf:5432112345:1 -+inf:5432112345:1 --inf:-5432112345:1 -+inf:-5432112345:1 --inf:54321.12345:1 -+inf:54321.12345:1 --inf:-54321.12345:1 -+inf:-54321.12345:1 -+inf:+inf:0 --inf:-inf:0 -+inf:-inf:0 --inf:+inf:0 -5:inf:-1 --1:inf:-1 -5:-inf:-1 --1:-inf:-1 -# return undef -+inf:facmpNaN: -facmpNaN:inf: --inf:facmpNaN: -facmpNaN:-inf: -&fdec -fdecNaN:NaN -+inf:inf --inf:-inf -+0:-1 -+1:0 --1:-2 -1.23:0.23 --1.23:-2.23 -100:99 -101:100 --100:-101 --99:-100 --98:-99 -99:98 -&finc -fincNaN:NaN -+inf:inf --inf:-inf -+0:1 -+1:2 --1:0 -1.23:2.23 --1.23:-0.23 -100:101 --100:-99 --99:-98 --101:-100 -99:100 -&fadd -abc:abc:NaN -abc:+0:NaN -+0:abc:NaN -+inf:-inf:NaN --inf:+inf:NaN -+inf:+inf:inf --inf:-inf:-inf -baddNaN:+inf:NaN -baddNaN:+inf:NaN -+inf:baddNaN:NaN --inf:baddNaN:NaN -+0:+0:0 -+1:+0:1 -+0:+1:1 -+1:+1:2 --1:+0:-1 -+0:-1:-1 --1:-1:-2 --1:+1:0 -+1:-1:0 -+9:+1:10 -+99:+1:100 -+999:+1:1000 -+9999:+1:10000 -+99999:+1:100000 -+999999:+1:1000000 -+9999999:+1:10000000 -+99999999:+1:100000000 -+999999999:+1:1000000000 -+9999999999:+1:10000000000 -+99999999999:+1:100000000000 -+10:-1:9 -+100:-1:99 -+1000:-1:999 -+10000:-1:9999 -+100000:-1:99999 -+1000000:-1:999999 -+10000000:-1:9999999 -+100000000:-1:99999999 -+1000000000:-1:999999999 -+10000000000:-1:9999999999 -+123456789:+987654321:1111111110 --123456789:+987654321:864197532 --123456789:-987654321:-1111111110 -+123456789:-987654321:-864197532 -0.001234:0.0001234:0.0013574 -&fsub -abc:abc:NaN -abc:+0:NaN -+0:abc:NaN -+inf:-inf:inf --inf:+inf:-inf -+inf:+inf:NaN --inf:-inf:NaN -baddNaN:+inf:NaN -baddNaN:+inf:NaN -+inf:baddNaN:NaN --inf:baddNaN:NaN -+0:+0:0 -+1:+0:1 -+0:+1:-1 -+1:+1:0 --1:+0:-1 -+0:-1:1 --1:-1:0 --1:+1:-2 -+1:-1:2 -+9:+1:8 -+99:+1:98 -+999:+1:998 -+9999:+1:9998 -+99999:+1:99998 -+999999:+1:999998 -+9999999:+1:9999998 -+99999999:+1:99999998 -+999999999:+1:999999998 -+9999999999:+1:9999999998 -+99999999999:+1:99999999998 -+10:-1:11 -+100:-1:101 -+1000:-1:1001 -+10000:-1:10001 -+100000:-1:100001 -+1000000:-1:1000001 -+10000000:-1:10000001 -+100000000:-1:100000001 -+1000000000:-1:1000000001 -+10000000000:-1:10000000001 -+123456789:+987654321:-864197532 --123456789:+987654321:-1111111110 --123456789:-987654321:864197532 -+123456789:-987654321:1111111110 -&fmul -abc:abc:NaN -abc:+0:NaN -+0:abc:NaN -+inf:NaNmul:NaN -+inf:NaNmul:NaN -NaNmul:+inf:NaN -NaNmul:-inf:NaN -+inf:+inf:inf -+inf:-inf:-inf -+inf:-inf:-inf -+inf:+inf:inf -+inf:123.34:inf -+inf:-123.34:-inf --inf:123.34:-inf --inf:-123.34:inf -123.34:+inf:inf --123.34:+inf:-inf -123.34:-inf:-inf --123.34:-inf:inf -+0:+0:0 -+0:+1:0 -+1:+0:0 -+0:-1:0 --1:+0:0 -+123456789123456789:+0:0 -+0:+123456789123456789:0 --1:-1:1 --1:+1:-1 -+1:-1:-1 -+1:+1:1 -+2:+3:6 --2:+3:-6 -+2:-3:-6 --2:-3:6 -+111:+111:12321 -+10101:+10101:102030201 -+1001001:+1001001:1002003002001 -+100010001:+100010001:10002000300020001 -+10000100001:+10000100001:100002000030000200001 -+11111111111:+9:99999999999 -+22222222222:+9:199999999998 -+33333333333:+9:299999999997 -+44444444444:+9:399999999996 -+55555555555:+9:499999999995 -+66666666666:+9:599999999994 -+77777777777:+9:699999999993 -+88888888888:+9:799999999992 -+99999999999:+9:899999999991 -6:120:720 -10:10000:100000 -&fdiv-list -0:0:NaN,NaN -0:1:0,0 -9:4:2.25,1 -9:5:1.8,4 -# bug in v1.74 with bdiv in list context, when $y is 1 or -1 -2.1:-1:-2.1,0 -2.1:1:2.1,0 --2.1:-1:2.1,0 --2.1:1:-2.1,0 -&fdiv -$div_scale = 40; $round_mode = 'even' -abc:abc:NaN -abc:+1:abc:NaN -+1:abc:NaN --1:abc:NaN -0:abc:NaN -+0:+0:NaN -+0:+1:0 -+1:+0:inf -+3214:+0:inf -+0:-1:0 --1:+0:-inf --3214:+0:-inf -+1:+1:1 --1:-1:1 -+1:-1:-1 --1:+1:-1 -+1:+2:0.5 -+2:+1:2 -123:+inf:0 -123:-inf:0 -+10:+5:2 -+100:+4:25 -+1000:+8:125 -+10000:+16:625 -+10000:-16:-625 -+999999999999:+9:111111111111 -+999999999999:+99:10101010101 -+999999999999:+999:1001001001 -+999999999999:+9999:100010001 -+999999999999999:+99999:10000100001 -+1000000000:+9:111111111.1111111111111111111111111111111 -+2000000000:+9:222222222.2222222222222222222222222222222 -+3000000000:+9:333333333.3333333333333333333333333333333 -+4000000000:+9:444444444.4444444444444444444444444444444 -+5000000000:+9:555555555.5555555555555555555555555555556 -+6000000000:+9:666666666.6666666666666666666666666666667 -+7000000000:+9:777777777.7777777777777777777777777777778 -+8000000000:+9:888888888.8888888888888888888888888888889 -+9000000000:+9:1000000000 -+35500000:+113:314159.2920353982300884955752212389380531 -+71000000:+226:314159.2920353982300884955752212389380531 -+106500000:+339:314159.2920353982300884955752212389380531 -+1000000000:+3:333333333.3333333333333333333333333333333 -2:25.024996000799840031993601279744051189762:0.07992009269196593320152084692285869265447 -123456:1:123456 -$div_scale = 20 -+1000000000:+9:111111111.11111111111 -+2000000000:+9:222222222.22222222222 -+3000000000:+9:333333333.33333333333 -+4000000000:+9:444444444.44444444444 -+5000000000:+9:555555555.55555555556 -+6000000000:+9:666666666.66666666667 -+7000000000:+9:777777777.77777777778 -+8000000000:+9:888888888.88888888889 -+9000000000:+9:1000000000 -1:10:0.1 -1:100:0.01 -1:1000:0.001 -1:10000:0.0001 -1:504:0.001984126984126984127 -2:1.987654321:1.0062111801179738436 -123456789.123456789123456789123456789:1:123456789.12345678912 -# the next two cases are the "old" behaviour, but are now (>v0.01) different -#+35500000:+113:314159.292035398230088 -#+71000000:+226:314159.292035398230088 -+35500000:+113:314159.29203539823009 -+71000000:+226:314159.29203539823009 -+106500000:+339:314159.29203539823009 -+1000000000:+3:333333333.33333333333 -$div_scale = 1 -# round to accuracy 1 after bdiv -+124:+3:40 -123456789.1234:1:100000000 -# reset scale for further tests -$div_scale = 40 -&fmod -+9:4:1 -+9:5:4 -+9000:56:40 -+56:9000:56 -# inf handling, see table in doc -0:inf:0 -0:-inf:0 -5:inf:5 -5:-inf:5 --5:inf:-5 --5:-inf:-5 -inf:5:0 --inf:5:0 -inf:-5:0 --inf:-5:0 -5:5:0 --5:-5:0 -inf:inf:NaN --inf:-inf:NaN --inf:inf:NaN -inf:-inf:NaN -8:0:8 -inf:0:inf -# exceptions to reminder rule --inf:0:-inf --8:0:-8 -0:0:NaN -abc:abc:NaN -abc:1:abc:NaN -1:abc:NaN -0:0:NaN -0:1:0 -1:0:1 -0:-1:0 --1:0:-1 -1:1:0 --1:-1:0 -1:-1:0 --1:1:0 -1:2:1 -2:1:0 -1000000000:9:1 -2000000000:9:2 -3000000000:9:3 -4000000000:9:4 -5000000000:9:5 -6000000000:9:6 -7000000000:9:7 -8000000000:9:8 -9000000000:9:0 -35500000:113:33 -71000000:226:66 -106500000:339:99 -1000000000:3:1 -10:5:0 -100:4:0 -1000:8:0 -10000:16:0 -999999999999:9:0 -999999999999:99:0 -999999999999:999:0 -999999999999:9999:0 -999999999999999:99999:0 --9:+5:1 -+9:-5:-1 --9:-5:-4 --5:3:1 --2:3:1 -4:3:1 -1:3:1 --5:-3:-2 --2:-3:-2 -4:-3:-2 -1:-3:-2 -4095:4095:0 -100041000510123:3:0 -152403346:12345:4321 -87654321:87654321:0 -# now some floating point tests -123:2.5:0.5 -1230:2.5:0 -123.4:2.5:0.9 -123e1:25:5 --2.1:1:0.9 -2.1:1:0.1 --2.1:-1:-0.1 -2.1:-1:-0.9 --3:1:0 -3:1:0 --3:-1:0 -3:-1:0 -&ffac -Nanfac:NaN --1:NaN -+inf:inf --inf:NaN -0:1 -1:1 -2:2 -3:6 -4:24 -5:120 -6:720 -10:3628800 -11:39916800 -12:479001600 -&froot -# sqrt() -+0:2:0 -+1:2:1 --1:2:NaN -# -$x ** (1/2) => -$y, but not in froot() --123.456:2:NaN -+inf:2:inf --inf:2:NaN -2:2:1.41421356237309504880168872420969807857 --2:2:NaN -4:2:2 -9:2:3 -16:2:4 -100:2:10 -123.456:2:11.11107555549866648462149404118219234119 -15241.38393:2:123.4559999756998444766131352122991626468 -1.44:2:1.2 -12:2:3.464101615137754587054892683011744733886 -0.49:2:0.7 -0.0049:2:0.07 -# invalid ones -1:NaN:NaN --1:NaN:NaN -0:NaN:NaN --inf:NaN:NaN -+inf:NaN:NaN -NaN:0:NaN -NaN:2:NaN -NaN:inf:NaN -NaN:inf:NaN -12:-inf:NaN -12:inf:NaN -+0:0:NaN -+1:0:NaN --1:0:NaN --2:0:NaN --123.45:0:NaN -+inf:0:NaN -12:1:12 --12:1:NaN -8:-1:NaN --8:-1:NaN -# cubic root -8:3:2 --8:3:NaN -# fourths root -16:4:2 -81:4:3 -# see t/bigroot() for more tests -&fsqrt -+0:0 --1:NaN --2:NaN --16:NaN --123.45:NaN -nanfsqrt:NaN -+inf:inf --inf:NaN -1:1 -2:1.41421356237309504880168872420969807857 -4:2 -9:3 -16:4 -100:10 -123.456:11.11107555549866648462149404118219234119 -15241.38393:123.4559999756998444766131352122991626468 -1.44:1.2 -# sqrt(1.44) = 1.2, sqrt(e10) = e5 => 12e4 -1.44E10:120000 -2e10:141421.356237309504880168872420969807857 -144e20:120000000000 -# proved to be an endless loop under 7-9 -12:3.464101615137754587054892683011744733886 -0.49:0.7 -0.0049:0.07 -&is_nan -123:0 -abc:1 -NaN:1 --123:0 -&is_inf -+inf::1 --inf::1 -abc::0 -1::0 -NaN::0 --1::0 -+inf:-:0 -+inf:+:1 --inf:-:1 --inf:+:0 -# it must be exactly /^[+-]inf$/ -+infinity::0 --infinity::0 -&is_odd -abc:0 -0:0 --1:1 --3:1 -1:1 -3:1 -1000001:1 -1000002:0 -+inf:0 --inf:0 -123.45:0 --123.45:0 -2:0 -&is_int -NaNis_int:0 -0:1 -1:1 -2:1 --2:1 --1:1 --inf:0 -+inf:0 -123.4567:0 --0.1:0 --0.002:0 -&is_even -abc:0 -0:1 --1:0 --3:0 -1:0 -3:0 -1000001:0 -1000002:1 -2:1 -+inf:0 --inf:0 -123.456:0 --123.456:0 -0.01:0 --0.01:0 -120:1 -1200:1 --1200:1 -&is_positive -0:0 -1:1 --1:0 --123:0 -NaN:0 --inf:0 -+inf:1 -&is_negative -0:0 -1:0 --1:1 --123:1 -NaN:0 --inf:1 -+inf:0 -&parts -0:0 1 -1:1 0 -123:123 0 --123:-123 0 --1200:-12 2 -NaNparts:NaN NaN -+inf:inf inf --inf:-inf inf -&exponent -0:1 -1:0 -123:0 --123:0 --1200:2 -+inf:inf --inf:inf -NaNexponent:NaN -&mantissa -0:0 -1:1 -123:123 --123:-123 --1200:-12 -+inf:inf --inf:-inf -NaNmantissa:NaN -&length -123:3 --123:3 -0:1 -1:1 -12345678901234567890:20 -&is_zero -NaNzero:0 -+inf:0 --inf:0 -0:1 --1:0 -1:0 -&is_one -NaNone:0 -+inf:0 --inf:0 -0:0 -2:0 -1:1 --1:0 --2:0 -&ffloor -0:0 -abc:NaN -+inf:inf --inf:-inf -1:1 --51:-51 --51.2:-52 -12.2:12 -0.12345:0 -0.123456:0 -0.1234567:0 -0.12345678:0 -0.123456789:0 -&fceil -0:0 -abc:NaN -+inf:inf --inf:-inf -1:1 --51:-51 --51.2:-51 -12.2:13 Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/bigfltrt.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/bigfltrt.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/bigfltrt.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/bigfltrt.t 15 Feb 2023 01:36:20 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,19 +0,0 @@ -# -*- mode: perl; -*- - -use strict; -use warnings; - -use lib 't'; - -use Test::More tests => 1; - -use Math::BigRat::Test lib => 'Calc'; # test via this Subclass - -our ($CLASS, $LIB); -$CLASS = "Math::BigRat::Test"; -$LIB = "Math::BigInt::Calc"; - -pass(); - -# fails still too many tests -#require './t/bigfltpm.inc'; # all tests here for sharing Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/bigrat.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/bigrat.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/bigrat.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/bigrat.t 14 May 2024 19:38:56 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,546 +0,0 @@ -# -*- mode: perl; -*- - -use strict; -use warnings; - -use Test::More tests => 203; - -# basic testing of Math::BigRat - -use Math::BigRat; -use Math::BigInt; -use Math::BigFloat; - -# shortcuts -my $mbr = 'Math::BigRat'; -my $mbi = 'Math::BigInt'; -my $mbf = 'Math::BigFloat'; - -my ($x, $y, $z); - -$x = Math::BigRat->new(1234); -is($x, 1234, 'value of $x'); -isa_ok($x, 'Math::BigRat'); -ok(!$x->isa('Math::BigInt'), - "An object of class '" . ref($x) . "' isn't a 'Math::BigInt'"); -ok(!$x->isa('Math::BigFloat'), - "An object of class '" . ref($x) . "' isn't a 'Math::BigFloat'"); - -############################################################################## -# new and bnorm() - -foreach my $method (qw/ new bnorm /) { - $x = $mbr->$method(1234); - is($x, 1234, qq|\$x = $mbr->$method(1234)|); - - $x = $mbr->$method("1234/1"); - is($x, 1234, qq|\$x = $mbr->$method("1234/1")|); - - $x = $mbr->$method("1234/2"); - is($x, 617, qq|\$x = $mbr->$method("1234/2")|); - - $x = $mbr->$method("100/1.0"); - is($x, 100, qq|\$x = $mbr->$method("100/1.0")|); - - $x = $mbr->$method("10.0/1.0"); - is($x, 10, qq|\$x = $mbr->$method("10.0/1.0")|); - - $x = $mbr->$method("0.1/10"); - is($x, "1/100", qq|\$x = $mbr->$method("0.1/10")|); - - $x = $mbr->$method("0.1/0.1"); - is($x, "1", qq|\$x = $mbr->$method("0.1/0.1")|); - - $x = $mbr->$method("1e2/10"); - is($x, 10, qq|\$x = $mbr->$method("1e2/10")|); - - $x = $mbr->$method("5/1e2"); - is($x, "1/20", qq|\$x = $mbr->$method("5/1e2")|); - - $x = $mbr->$method("1e2/1e1"); - is($x, 10, qq|\$x = $mbr->$method("1e2/1e1")|); - - $x = $mbr->$method("1 / 3"); - is($x, "1/3", qq|\$x = $mbr->$method("1 / 3")|); - - $x = $mbr->$method("-1 / 3"); - is($x, "-1/3", qq|\$x = $mbr->$method("-1 / 3")|); - - $x = $mbr->$method("NaN"); - is($x, "NaN", qq|\$x = $mbr->$method("NaN")|); - - $x = $mbr->$method("inf"); - is($x, "inf", qq|\$x = $mbr->$method("inf")|); - - $x = $mbr->$method("-inf"); - is($x, "-inf", qq|\$x = $mbr->$method("-inf")|); - - $x = $mbr->$method("1/"); - is($x, "NaN", qq|\$x = $mbr->$method("1/")|); - - $x = $mbr->$method("0x7e"); - is($x, 126, qq|\$x = $mbr->$method("0x7e")|); - - # input ala "1+1/3" isn"t parsed ok yet - $x = $mbr->$method("1+1/3"); - is($x, "NaN", qq|\$x = $mbr->$method("1+1/3")|); - - $x = $mbr->$method("1/1.2"); - is($x, "5/6", qq|\$x = $mbr->$method("1/1.2")|); - - $x = $mbr->$method("1.3/1.2"); - is($x, "13/12", qq|\$x = $mbr->$method("1.3/1.2")|); - - $x = $mbr->$method("1.2/1"); - is($x, "6/5", qq|\$x = $mbr->$method("1.2/1")|); - - ############################################################################ - # other classes as input - - $x = $mbr->$method($mbi->new(1231)); - is($x, "1231", qq|\$x = $mbr->$method($mbi->new(1231))|); - - $x = $mbr->$method($mbf->new(1232)); - is($x, "1232", qq|\$x = $mbr->$method($mbf->new(1232))|); - - $x = $mbr->$method($mbf->new(1232.3)); - is($x, "12323/10", qq|\$x = $mbr->$method($mbf->new(1232.3))|); -} - -my $n = 'numerator'; -my $d = 'denominator'; - -$x = $mbr->new('-0'); -is($x, '0'); -is($x->$n(), '0'); -is($x->$d(), '1'); - -$x = $mbr->new('NaN'); -is($x, 'NaN'); is($x->$n(), 'NaN'); -is($x->$d(), 'NaN'); - -$x = $mbr->new('-NaN'); -is($x, 'NaN'); is($x->$n(), 'NaN'); -is($x->$d(), 'NaN'); - -$x = $mbr->new('-1r4'); -is($x, 'NaN'); is($x->$n(), 'NaN'); -is($x->$d(), 'NaN'); - -$x = $mbr->new('+inf'); -is($x, 'inf'); is($x->$n(), 'inf'); -is($x->$d(), '1'); - -$x = $mbr->new('-inf'); -is($x, '-inf'); -is($x->$n(), '-inf'); -is($x->$d(), '1'); - -$x = $mbr->new('123a4'); -is($x, 'NaN'); -is($x->$n(), 'NaN'); -is($x->$d(), 'NaN'); - -# wrong inputs -$x = $mbr->new('1e2e2'); -is($x, 'NaN'); -is($x->$n(), 'NaN'); -is($x->$d(), 'NaN'); - -$x = $mbr->new('1+2+2'); -is($x, 'NaN'); -is($x->$n(), 'NaN'); -is($x->$d(), 'NaN'); - -# failed due to BigFloat bug -$x = $mbr->new('1.2.2'); -is($x, 'NaN'); -is($x->$n(), 'NaN'); -is($x->$d(), 'NaN'); - -is($mbr->new('123a4'), 'NaN'); -is($mbr->new('123e4'), '1230000'); -is($mbr->new('-NaN'), 'NaN'); -is($mbr->new('NaN'), 'NaN'); -is($mbr->new('+inf'), 'inf'); -is($mbr->new('-inf'), '-inf'); - -############################################################################## -# two Bigints - -is($mbr->new($mbi->new(3), $mbi->new(7))->badd(1), '10/7'); -is($mbr->new($mbi->new(-13), $mbi->new(7)), '-13/7'); -is($mbr->new($mbi->new(13), $mbi->new(-7)), '-13/7'); -is($mbr->new($mbi->new(-13), $mbi->new(-7)), '13/7'); - -############################################################################## -# mixed arguments - -is($mbr->new('3/7')->badd(1), '10/7'); -is($mbr->new('3/10')->badd(1.1), '7/5'); -is($mbr->new('3/7')->badd($mbi->new(1)), '10/7'); -is($mbr->new('3/10')->badd($mbf->new('1.1')), '7/5'); - -is($mbr->new('3/7')->bsub(1), '-4/7'); -is($mbr->new('3/10')->bsub(1.1), '-4/5'); -is($mbr->new('3/7')->bsub($mbi->new(1)), '-4/7'); -is($mbr->new('3/10')->bsub($mbf->new('1.1')), '-4/5'); - -is($mbr->new('3/7')->bmul(1), '3/7'); -is($mbr->new('3/10')->bmul(1.1), '33/100'); -is($mbr->new('3/7')->bmul($mbi->new(1)), '3/7'); -is($mbr->new('3/10')->bmul($mbf->new('1.1')), '33/100'); - -is($mbr->new('3/7')->bdiv(1), '3/7'); -is($mbr->new('3/10')->bdiv(1.1), '3/11'); -is($mbr->new('3/7')->bdiv($mbi->new(1)), '3/7'); -is($mbr->new('3/10')->bdiv($mbf->new('1.1')), '3/11'); - -############################################################################## -$x = $mbr->new('1/4'); -$y = $mbr->new('1/3'); - -is($x + $y, '7/12'); -is($x * $y, '1/12'); -is($x / $y, '3/4'); - -$x = $mbr->new('7/5'); -$x *= '3/2'; -is($x, '21/10'); -$x -= '0.1'; -is($x, '2'); # not 21/10 - -$x = $mbr->new('2/3'); -$y = $mbr->new('3/2'); -is($x > $y, ''); -is($x < $y, 1); -is($x == $y, ''); - -$x = $mbr->new('-2/3'); -$y = $mbr->new('3/2'); -is($x > $y, ''); -is($x < $y, '1'); -is($x == $y, ''); - -$x = $mbr->new('-2/3'); -$y = $mbr->new('-2/3'); -is($x > $y, ''); -is($x < $y, ''); -is($x == $y, '1'); - -$x = $mbr->new('-2/3'); -$y = $mbr->new('-1/3'); -is($x > $y, ''); -is($x < $y, '1'); -is($x == $y, ''); - -$x = $mbr->new('-124'); -$y = $mbr->new('-122'); -is($x->bacmp($y), 1); - -$x = $mbr->new('-124'); -$y = $mbr->new('-122'); -is($x->bcmp($y), -1); - -$x = $mbr->new('3/7'); -$y = $mbr->new('5/7'); -is($x+$y, '8/7'); - -$x = $mbr->new('3/7'); -$y = $mbr->new('5/7'); -is($x*$y, '15/49'); - -$x = $mbr->new('3/5'); -$y = $mbr->new('5/7'); -is($x*$y, '3/7'); - -$x = $mbr->new('3/5'); -$y = $mbr->new('5/7'); -is($x/$y, '21/25'); - -$x = $mbr->new('7/4'); -$y = $mbr->new('1'); -is($x % $y, '3/4'); - -$x = $mbr->new('7/4'); -$y = $mbr->new('5/13'); -is($x % $y, '11/52'); - -$x = $mbr->new('7/4'); -$y = $mbr->new('5/9'); -is($x % $y, '1/12'); - -$x = $mbr->new('-144/9')->bsqrt(); -is($x, 'NaN'); - -$x = $mbr->new('144/9')->bsqrt(); -is($x, '4'); - -$x = $mbr->new('3/4')->bsqrt(); -is($x, - '4330127018922193233818615853764680917357/' . - '5000000000000000000000000000000000000000'); - -############################################################################## -# bpow - -$x = $mbr->new('2/1'); -$z = $x->bpow('3/1'); -is($x, '8'); - -$x = $mbr->new('1/2'); -$z = $x->bpow('3/1'); -is($x, '1/8'); - -$x = $mbr->new('1/3'); -$z = $x->bpow('4/1'); -is($x, '1/81'); - -$x = $mbr->new('2/3'); -$z = $x->bpow('4/1'); -is($x, '16/81'); - -$x = $mbr->new('2/3'); -$z = $x->bpow('5/3'); -is($x, '31797617848703662994667839220546583581/62500000000000000000000000000000000000'); - -############################################################################## -# bfac - -$x = $mbr->new('1'); -$x->bfac(); -is($x, '1'); - -for (my $i = 0; $i < 8; $i++) { - $x = $mbr->new("$i/1")->bfac(); - is($x, $mbi->new($i)->bfac()); -} - -# test for $self->bnan() vs. $x->bnan(); -$x = $mbr->new('-1'); -$x->bfac(); -is($x, 'NaN'); - -############################################################################## -# binc/bdec - -note("binc()"); -$x = $mbr->new('3/2'); -is($x->binc(), '5/2'); - -note("bdec()"); - -$x = $mbr->new('15/6'); -is($x->bdec(), '3/2'); - -############################################################################## -# bfloor - -note("bfloor()"); -$x = $mbr->new('-7/7'); -is($x->$n(), '-1'); -is($x->$d(), '1'); -$x = $mbr->new('-7/7')->bfloor(); -is($x->$n(), '-1'); -is($x->$d(), '1'); - -############################################################################## -# bsstr - -$x = $mbr->new('7/5')->bsstr(); -is($x, '7/5'); -$x = $mbr->new('-7/5')->bsstr(); -is($x, '-7/5'); - -############################################################################## - -note("numify()"); - -my @array = qw/1 2 3 4 5 6 7 8 9/; -$x = $mbr->new('8/8'); -is($array[$x], 2); - -$x = $mbr->new('16/8'); -is($array[$x], 3); - -$x = $mbr->new('17/8'); -is($array[$x], 3); - -$x = $mbr->new('33/8'); -is($array[$x], 5); - -$x = $mbr->new('-33/8'); -is($array[$x], 6); - -$x = $mbr->new('-8/1'); -is($array[$x], 2); # -8 => 2 - -require Math::Complex; - -my $inf = $Math::Complex::Inf; -my $nan = $inf - $inf; - -sub isnumeric { - my $value = shift; - ($value ^ $value) eq "0"; -} - -subtest qq|$mbr -> new("33/8") -> numify()| => sub { - plan tests => 3; - - $x = $mbr -> new("33/8") -> numify(); - is(ref($x), "", '$x is a scalar'); - ok(isnumeric($x), '$x is numeric'); - cmp_ok($x, "==", 4.125, '$x has the right value'); -}; - -subtest qq|$mbr -> new("-33/8") -> numify()| => sub { - plan tests => 3; - - $x = $mbr -> new("-33/8") -> numify(); - is(ref($x), "", '$x is a scalar'); - ok(isnumeric($x), '$x is numeric'); - cmp_ok($x, "==", -4.125, '$x has the right value'); -}; - -subtest qq|$mbr -> new("inf") -> numify()| => sub { - plan tests => 3; - - $x = $mbr -> new("inf") -> numify(); - is(ref($x), "", '$x is a scalar'); - ok(isnumeric($x), '$x is numeric'); - cmp_ok($x, "==", $inf, '$x has the right value'); -}; - -subtest qq|$mbr -> new("-inf") -> numify()| => sub { - plan tests => 3; - - $x = $mbr -> new("-inf") -> numify(); - is(ref($x), "", '$x is a scalar'); - ok(isnumeric($x), '$x is numeric'); - cmp_ok($x, "==", -$inf, '$x has the right value'); -}; - -subtest qq|$mbr -> new("NaN") -> numify()| => sub { - plan tests => 3; - - $x = $mbr -> new("NaN") -> numify(); - is(ref($x), "", '$x is a scalar'); - ok(isnumeric($x), '$x is numeric'); - cmp_ok($x, "!=", $nan, '$x has the right value'); # Note: NaN != NaN -}; - -############################################################################## -# as_hex(), as_bin(), as_oct() - -note("as_hex(), as_bin(), as_oct()"); - -$x = $mbr->new('8/8'); -is($x->as_hex(), '0x1'); -is($x->as_bin(), '0b1'); -is($x->as_oct(), '01'); - -$x = $mbr->new('80/8'); -is($x->as_hex(), '0xa'); -is($x->as_bin(), '0b1010'); -is($x->as_oct(), '012'); - -############################################################################## -# broot(), blog(), bmodpow() and bmodinv() - -note("broot(), blog(), bmodpow(), bmodinv()"); - -$x = $mbr->new(2) ** 32; -$y = $mbr->new(4); -$z = $mbr->new(3); - -is($x->copy()->broot($y), 2 ** 8); -is(ref($x->copy()->broot($y)), $mbr, "\$x is a $mbr"); - -is($x->copy()->bmodpow($y, $z), 1); -is(ref($x->copy()->bmodpow($y, $z)), $mbr, "\$x is a $mbr"); - -$x = $mbr->new(8); -$y = $mbr->new(5033); -$z = $mbr->new(4404); - -is($x->copy()->bmodinv($y), $z); -is(ref($x->copy()->bmodinv($y)), $mbr, "\$x is a $mbr"); - -# square root with exact result -$x = $mbr->new('1.44'); -is($x->copy()->broot(2), '6/5'); -is(ref($x->copy()->broot(2)), $mbr, "\$x is a $mbr"); - -# log with exact result -$x = $mbr->new('256.1'); -is($x->copy()->blog(2), - '8000563442710106079310294693803606983661/1000000000000000000000000000000000000000', - "\$x = $mbr->new('256.1')->blog(2)"); -is(ref($x->copy()->blog(2)), $mbr, "\$x is a $mbr"); - -$x = $mbr->new(144); -is($x->copy()->broot('2'), 12, 'v/144 = 12'); - -$x = $mbr->new(12*12*12); -is($x->copy()->broot('3'), 12, '(12*12*12) ** 1/3 = 12'); - -############################################################################## -# from_hex(), from_bin(), from_oct() - -note("from_hex(), from_bin(), from_oct()"); - -$x = Math::BigRat->from_hex('0x100'); -is($x, '256', 'from_hex'); - -$x = $mbr->from_hex('0x100'); -is($x, '256', 'from_hex'); - -$x = Math::BigRat->from_bin('0b100'); -is($x, '4', 'from_bin'); - -$x = $mbr->from_bin('0b100'); -is($x, '4', 'from_bin'); - -$x = Math::BigRat->from_oct('0100'); -is($x, '64', 'from_oct'); - -$x = $mbr->from_oct('0100'); -is($x, '64', 'from_oct'); - -############################################################################## -# as_float() - -$x = Math::BigRat->new('1/2'); -my $f = $x->as_float(); - -is($x, '1/2', '$x unmodified'); -is($f, '0.5', 'as_float(0.5)'); - -$x = Math::BigRat->new('2/3'); -$f = $x->as_float(5); - -is($x, '2/3', '$x unmodified'); -is($f, '0.66667', 'as_float(2/3, 5)'); - -# Integers should be converted exactly. -$x = Math::BigRat->new("3141592653589793238462643383279502884197169399375106"); -$f = $x->as_float(); - -is($x, "3141592653589793238462643383279502884197169399375106", '$x unmodified'); -is($f, "3141592653589793238462643383279502884197169399375106", - 'as_float(3141592653589793238462643383279502884197169399375106, 5)'); - -############################################################################## -# int() - -$x = Math::BigRat->new('5/2'); -is(int($x), '2', '5/2 converted to integer'); - -$x = Math::BigRat->new('-1/2'); -is(int($x), '0', '-1/2 converted to integer'); - -############################################################################## -# done - -1; Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/bigratpm.inc =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/bigratpm.inc diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/bigratpm.inc --- gnu/usr.bin/perl/cpan/Math-BigRat/t/bigratpm.inc 14 May 2024 19:38:56 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,1226 +0,0 @@ -#include this file into another test for subclass testing... - -use strict; -use warnings; - -our ($CLASS, $try, $x, $y, $z, $f, @args, $want, $got, $setup, $LIB); - -is($CLASS->config()->{lib}, $LIB); - -$setup = ''; - -while () { - s/#.*$//; # remove comments - s/\s+$//; # remove trailing whitespace - next unless length; # skip empty lines - - if (s/^&//) { - $f = $_; - next; - } - - if (/^\$/) { - $setup = $_; - $setup =~ s/\$/\$${CLASS}::/g; # round_mode, div_scale - #print "\$setup== $setup\n"; - next; - } - - if (m|^(.*?):(/.+)$|) { - $want = $2; - @args = split(/:/, $1, 99); - } else { - @args = split(/:/, $_, 99); - $want = pop(@args); - } - - $try = qq|\$x = $CLASS->new("$args[0]");|; - if ($f eq "bnorm") { - $try .= " \$x;"; - } elsif ($f eq "finf") { - my $a = $args[1] || ''; - $try .= qq| \$x->binf("$a");|; - } elsif ($f eq "fone") { - $try .= qq| \$x->bone("$args[1]");|; - } elsif ($f eq "fstr") { - $try .= " \$x->accuracy($args[1]); \$x->precision($args[2]);"; - $try .= ' $x->bstr();'; - } elsif ($f eq "parts") { - # ->bstr() to see if an object is returned - $try .= ' ($a,$b) = $x->parts(); $a = $a->bstr(); $b = $b->bstr();'; - $try .= ' "$a $b";'; - } elsif ($f eq "numerator") { - # ->bstr() to see if an object is returned - $try .= ' $x->numerator()->bstr();'; - } elsif ($f eq "denominator") { - # ->bstr() to see if an object is returned - $try .= ' $x->denominator()->bstr();'; - } elsif ($f =~ /^(length|numify)$/) { - $try .= " \$x->$f();"; - # some unary ops (can't test the fxxx form, since no AUTOLOAD in BigRat) - } elsif ($f =~ /^f(nan|sstr|neg|floor|ceil|abs)$/) { - $try .= " \$x->b$1();"; - # overloaded functions - } elsif ($f =~ /^(log|exp|sin|cos|atan2|int|neg|abs|sqrt)$/) { - $try .= " \$x = $f(\$x);"; - # some is_xxx test function - } elsif ($f =~ /^is_(zero|pos|neg|negative|positive|odd|even|nan|int)\z/) { - $try .= " \$x->$f();"; - } elsif ($f =~ /^is_(one|inf)$/) { - $try .= @args == 1 ? qq| \$x->$f();| - : qq| \$x->$f("$args[1]");|; - } elsif ($f =~ /^(as_number|as_int)\z/) { - $try .= " \$x->$1();"; - } elsif ($f eq "finc") { - $try .= ' ++$x;'; - } elsif ($f eq "fdec") { - $try .= ' --$x;'; - } elsif ($f eq "digit") { - $try .= " \$x->digit($args[1]);"; - } elsif ($f eq "fround") { - $try .= " $setup; \$x->bround($args[1]);"; - } elsif ($f eq "ffround") { - $try .= " $setup; \$x->bfround($args[1]);"; - } elsif ($f eq "fsqrt") { - $try .= " $setup; \$x->bsqrt();"; - } elsif ($f eq "flog") { - $try .= " $setup; \$x->blog();"; - } elsif ($f eq "ffac") { - $try .= " $setup; \$x->bfac();"; - } else { - $try .= qq| \$y = $CLASS->new("$args[1]");|; - if ($f eq "bcmp") { - $try .= ' $x <=> $y;'; - } elsif ($f eq "bacmp") { - $try .= ' $x->bacmp($y);'; - } elsif ($f eq "bpow") { - $try .= ' $x->bpow($y);'; - } elsif ($f eq "badd") { - $try .= ' $x + $y;'; - } elsif ($f eq "bsub") { - $try .= ' $x - $y;'; - } elsif ($f eq "bmul") { - $try .= ' $x * $y;'; - } elsif ($f eq "bdiv") { - $try .= " $setup; \$x / \$y;"; - } elsif ($f eq "bdiv-list") { - $try .= qq| $setup; join(",", \$x->bdiv(\$y));|; - } elsif ($f eq "brsft") { - $try .= ' $x >> $y;'; - } elsif ($f eq "blsft") { - $try .= ' $x << $y;'; - } elsif ($f eq "bmod") { - $try .= ' $x % $y;'; - } elsif ($f eq "bmodinv") { - $try .= " \$x->bmodinv(\$y);"; - } elsif ($f eq "blog") { - $try .= " \$x->blog(\$y);"; - } else { - $try .= qq| \$z = $CLASS->new("$args[2]");|; - - # Functions with three arguments - if ($f eq "bmodpow") { - $try .= " \$x->bmodpow(\$y, \$z);"; - } else { - warn "Unknown op '$f'"; - } - } - } - # print "# Trying: '$try'\n"; - $got = eval $try; - if ($want =~ m|^/(.*)$|) { - my $pat = $1; - like($got, qr/$pat/, $try); - } else { - if ($want eq "") { - is($got, undef, $try); - } else { - is($got, $want, $try); - #if (ref($got) eq "$CLASS") { - # # float numbers are normalized (for now), so mantissa shouldn't have - # # trailing zeros - # #print $got->_trailing_zeros(), "\n"; - # print "# Has trailing zeros after '$try'\n" - # if !is($got->{_m}->_trailing_zeros(), 0); - #} - } - } # end pattern or string -} # end while - -# check whether $CLASS->new(Math::BigInt->new()) destroys it -# ($y == 12 in this case) -$x = Math::BigInt->new(1200); -$y = $CLASS->new($x); -is($y, 1200, qq|\$x = Math::BigInt->new(1200); \$y = $CLASS->new(\$x); $y|); -is($x, 1200, qq|\$x = Math::BigInt->new(1200); \$y = $CLASS->new(\$x); $x|); - -############################################################################### -# zero, inf, one, nan - -$x = $CLASS->new(2); -$x->bzero(); -is($x->{_a}, undef, qq|\$x = $CLASS->new(2); \$x->bzero(); \$x->{_a}|); -is($x->{_p}, undef, qq|\$x = $CLASS->new(2); \$x->bzero(); \$x->{_p}|); - -$x = $CLASS->new(2); -$x->binf(); -is($x->{_a}, undef, qq|\$x = $CLASS->new(2); \$x->binf(); \$x->{_a}|); -is($x->{_p}, undef, qq|\$x = $CLASS->new(2); \$x->binf(); \$x->{_p}|); - -$x = $CLASS->new(2); -$x->bone(); -is($x->{_a}, undef, qq|\$x = $CLASS->new(2); \$x->bone(); \$x->{_a}|); -is($x->{_p}, undef, qq|\$x = $CLASS->new(2); \$x->bone(); \$x->{_p}|); - -$x = $CLASS->new(2); -$x->bnan(); -is($x->{_a}, undef, qq|\$x = $CLASS->new(2); \$x->bnan(); \$x->{_a}|); -is($x->{_p}, undef, qq|\$x = $CLASS->new(2); \$x->bnan(); \$x->{_p}|); - -__DATA__ - -&digit -123:2:1 -1234:0:4 -1234:1:3 -1234:2:2 -1234:3:1 -1234:-1:1 -1234:-2:2 -1234:-3:3 -1234:-4:4 -0:0:0 -0:1:0 - -&bmodinv -# format: number:modulus:result -# bmodinv Data errors -abc:abc:NaN -abc:5:NaN -5:abc:NaN -# bmodinv Expected Results from normal use -1:5:1 -3:5:2 -3:-5:-3 --2:5:2 -8:5033:4404 -1234567891:13:6 --1234567891:13:7 -324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902 -## bmodinv Error cases / useless use of function -inf:5:NaN -5:inf:NaN --inf:5:NaN -5:-inf:NaN - -&as_number -144/7:20 -12/1:12 --12/1:-12 --12/3:-4 -NaN:NaN -+inf:inf --inf:-inf - -&as_int -144/7:20 -12/1:12 --12/1:-12 --12/3:-4 -NaN:NaN -+inf:inf --inf:-inf - -&bmodpow -# format: number:exponent:modulus:result -# bmodpow Data errors -abc:abc:abc:NaN -5:abc:abc:NaN -abc:5:abc:NaN -abc:abc:5:NaN -5:5:abc:NaN -5:abc:5:NaN -abc:5:5:NaN -# bmodpow Expected results -0:0:2:1 -1:0:2:1 -0:0:1:0 -8:7:5032:3840 -8:-1:5033:4404 -8:8:-5:-4 -98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518 -# bmodpow Error cases -8:-1:16:NaN -inf:5:13:NaN -5:inf:13:NaN - -&bmod -NaN:1:NaN -1:NaN:NaN -1:1:0 -2:2:0 -12:6:0 -7/4:4/14:1/28 -7/4:4/16:0 --7/4:4/16:0 --7/4:-4/16:0 -7/4:-4/16:0 -7/4:4/32:0 --7/4:4/32:0 --7/4:-4/32:0 -7/4:-4/32:0 -7/4:4/28:1/28 --7/4:4/28:3/28 -7/4:-4/28:-3/28 --7/4:-4/28:-1/28 - -&fsqrt -1:1 -0:0 -NaN:NaN -+inf:inf --inf:NaN -144:12 -# sqrt(144) / sqrt(4) = 12/2 = 6/1 -144/4:6 -25/16:5/4 --3:NaN -4/9:2/3 -36/49:6/7 -49/121:7/11 -999966000289/99999820000081:999983/9999991 - -&flog -NaN:NaN -0:-inf --2:NaN - -&blog -NaN:NaN:NaN -0:NaN:NaN -NaN:0:NaN -NaN:1:NaN -1:NaN:NaN -0:2:-inf -0:-2:NaN -3:-2:NaN - -&finf -1:+:inf -2:-:-inf -3:abc:inf - -&numify -0:0 -+1:1 -1234:1234 -3/4:0.75 -5/2:2.5 -3/2:1.5 -5/4:1.25 - -&fnan -abc:NaN -2:NaN --2:NaN -0:NaN - -&fone -2:+:1 --2:-:-1 --2:+:1 -2:-:-1 -0::1 --2::1 -abc::1 -2:abc:1 - -&fsstr -+inf:inf --inf:-inf -abcfsstr:NaN -1:1 -3/1:3 -0.1:1/10 - -&bnorm -1:1 --0:0 -bnormNaN:NaN -+inf:inf --inf:-inf -inf/inf:NaN -5/inf:0 -5/-inf:0 -inf/5:inf --inf/5:-inf -inf/-5:-inf --inf/-5:inf -123:123 --123.4567:-1234567/10000 -#1.E3:NaN -.2E-3.:NaN -#1e3e4:NaN -.2E2:20 -inf:inf -+inf:inf --inf:-inf -+InFiNiTy:inf -+-inf:NaN -abc:NaN - 1 a:NaN -1bcd2:NaN -11111b:NaN -+1z:NaN --1z:NaN -0:0 -+0:0 -+00:0 -+0_0_0:0 -000000_0000000_00000:0 --0:0 --0000:0 -+1:1 -+01:1 -+001:1 -+00000100000:100000 -+00000800/00000010:80 --00000800/00000010:-80 -+00000800/-00000010:-80 --00000800/-00000010:80 -123456789:123456789 --1:-1 --01:-1 --001:-1 --123456789:-123456789 --00000100000:-100000 -123.456a:NaN -123.456:15432/125 -0.01:1/100 -.002:1/500 -+.2:1/5 --0.0003:-3/10000 --.0000000004:-1/2500000000 -123456E2:12345600 -123456E-2:30864/25 --123456E2:-12345600 --123456E-2:-30864/25 -1e1:10 -2e-11:1/50000000000 -12/10:6/5 -0.1/0.1:1 -100/0.1:1000 -0.1/10:1/100 -1 / 3:1/3 -1/ 3:1/3 -1 /3:1/3 - -&fneg -fnegNaN:NaN -+inf:-inf --inf:inf -+0:0 -+1:-1 --1:1 -+123456789:-123456789 --123456789:123456789 -+123.456789:-123456789/1000000 --123456.789:123456789/1000 -123/7:-123/7 --123/7:123/7 -123/-7:123/7 - -&fabs -fabsNaN:NaN -+inf:inf --inf:inf -+0:0 -+1:1 --1:1 -+123456789:123456789 --123456789:123456789 -+123.456789:123456789/1000000 --123456.789:123456789/1000 - -&badd -abc:abc:NaN -abc:+0:NaN -+0:abc:NaN -+inf:-inf:NaN --inf:+inf:NaN -+inf:+inf:inf --inf:-inf:-inf -baddNaN:+inf:NaN -baddNaN:+inf:NaN -+inf:baddNaN:NaN --inf:baddNaN:NaN -+0:+0:0 -+1:+0:1 -+0:+1:1 -+1:+1:2 --1:+0:-1 -+0:-1:-1 --1:-1:-2 --1:+1:0 -+1:-1:0 -+9:+1:10 -+99:+1:100 -+999:+1:1000 -+9999:+1:10000 -+99999:+1:100000 -+999999:+1:1000000 -+9999999:+1:10000000 -+99999999:+1:100000000 -+999999999:+1:1000000000 -+9999999999:+1:10000000000 -+99999999999:+1:100000000000 -+10:-1:9 -+100:-1:99 -+1000:-1:999 -+10000:-1:9999 -+100000:-1:99999 -+1000000:-1:999999 -+10000000:-1:9999999 -+100000000:-1:99999999 -+1000000000:-1:999999999 -+10000000000:-1:9999999999 -+123456789:+987654321:1111111110 --123456789:+987654321:864197532 --123456789:-987654321:-1111111110 -+123456789:-987654321:-864197532 -1/3:1/3:2/3 -2/3:-1/3:1/3 - -&bsub -abc:abc:NaN -abc:+0:NaN -+0:abc:NaN -+inf:-inf:inf --inf:+inf:-inf -+inf:+inf:NaN --inf:-inf:NaN -baddNaN:+inf:NaN -baddNaN:+inf:NaN -+inf:baddNaN:NaN --inf:baddNaN:NaN -+0:+0:0 -+1:+0:1 -+0:+1:-1 -+1:+1:0 --1:+0:-1 -+0:-1:1 --1:-1:0 --1:+1:-2 -+1:-1:2 -+9:+1:8 -+99:+1:98 -+999:+1:998 -+9999:+1:9998 -+99999:+1:99998 -+999999:+1:999998 -+9999999:+1:9999998 -+99999999:+1:99999998 -+999999999:+1:999999998 -+9999999999:+1:9999999998 -+99999999999:+1:99999999998 -+10:-1:11 -+100:-1:101 -+1000:-1:1001 -+10000:-1:10001 -+100000:-1:100001 -+1000000:-1:1000001 -+10000000:-1:10000001 -+100000000:-1:100000001 -+1000000000:-1:1000000001 -+10000000000:-1:10000000001 -+123456789:+987654321:-864197532 --123456789:+987654321:-1111111110 --123456789:-987654321:864197532 -+123456789:-987654321:1111111110 -2/3:1/3:1/3 -7/27:3/54:11/54 --2/3:+2/3:-4/3 --2/3:-2/3:0 -0:-123:123 -0:123:-123 - -&bmul -abc:abc:NaN -abc:+0:NaN -+0:abc:NaN -+inf:NaNmul:NaN -+inf:NaNmul:NaN -NaNmul:+inf:NaN -NaNmul:-inf:NaN -+inf:+inf:inf -+inf:-inf:-inf -+inf:-inf:-inf -+inf:+inf:inf -+inf:123.34:inf -+inf:-123.34:-inf --inf:123.34:-inf --inf:-123.34:inf -123.34:+inf:inf --123.34:+inf:-inf -123.34:-inf:-inf --123.34:-inf:inf -+0:+0:0 -+0:+1:0 -+1:+0:0 -+0:-1:0 --1:+0:0 -+123456789123456789:+0:0 -+0:+123456789123456789:0 --1:-1:1 --1:+1:-1 -+1:-1:-1 -+1:+1:1 -+2:+3:6 --2:+3:-6 -+2:-3:-6 --2:-3:6 -+111:+111:12321 -+10101:+10101:102030201 -+1001001:+1001001:1002003002001 -+100010001:+100010001:10002000300020001 -+10000100001:+10000100001:100002000030000200001 -+11111111111:+9:99999999999 -+22222222222:+9:199999999998 -+33333333333:+9:299999999997 -+44444444444:+9:399999999996 -+55555555555:+9:499999999995 -+66666666666:+9:599999999994 -+77777777777:+9:699999999993 -+88888888888:+9:799999999992 -+99999999999:+9:899999999991 -6:120:720 -10:10000:100000 -1/4:1/3:1/12 - -&bdiv-list -0:0:NaN,0 -0:1:0,0 -1:0:inf,1 --1:0:-inf,-1 -9:4:2,1 --9:4:-3,3 -9:-4:-3,-3 --9:-4:2,-1 -11/7:2/3:2,5/21 --11/7:2/3:-3,3/7 - -&bdiv -$div_scale = 40; $round_mode = "even" -abc:abc:NaN -abc:+1:abc:NaN -+1:abc:NaN --1:abc:NaN -0:abc:NaN -+0:+0:NaN -+0:+1:0 -+1:+0:inf -+3214:+0:inf -+0:-1:0 --1:+0:-inf --3214:+0:-inf -+1:+1:1 --1:-1:1 -+1:-1:-1 --1:+1:-1 -+1:+2:1/2 -+2:+1:2 -123:+inf:0 -123:-inf:0 -+10:+5:2 -+100:+4:25 -+1000:+8:125 -+10000:+16:625 -+10000:-16:-625 -+999999999999:+9:111111111111 -+999999999999:+99:10101010101 -+999999999999:+999:1001001001 -+999999999999:+9999:100010001 -+999999999999999:+99999:10000100001 -+1000000000:+9:1000000000/9 -+2000000000:+9:2000000000/9 -+3000000000:+9:1000000000/3 -+4000000000:+9:4000000000/9 -+5000000000:+9:5000000000/9 -+6000000000:+9:2000000000/3 -+7000000000:+9:7000000000/9 -+8000000000:+9:8000000000/9 -+9000000000:+9:1000000000 -+35500000:+113:35500000/113 -+71000000:+226:35500000/113 -+106500000:+339:35500000/113 -+1000000000:+3:1000000000/3 -2:25.024996000799840031993601279744051189762:1000000000000000000000000000000000000000/12512498000399920015996800639872025594881 -123456:1:123456 -1/4:1/3:3/4 -# reset scale for further tests -$div_scale = 40 - -&is_nan -123:0 -abc:1 -NaN:1 --123:0 - -&is_inf -# without sign argument -abc:0 -NaN:0 -+inf:1 --inf:1 --1:0 -0:0 -1:0 -# with sign argument "+" -abc:+:0 -NaN:+:0 -+inf:+:1 --inf:+:0 --1:+:0 -0:+:0 -1:+:0 -# with sign argument "-" -abc:-:0 -NaN:-:0 -+inf:-:0 --inf:-:1 --1:-:0 -0:-:0 -1:-:0 -+infinity:1 --infinity:1 - -&is_odd -abc:0 -0:0 --1:1 --3:1 -1:1 -3:1 -1000001:1 -1000002:0 -+inf:0 --inf:0 -123.45:0 --123.45:0 -2:0 - -&is_int -NaNis_int:0 -0:1 -1:1 -2:1 --2:1 --1:1 --inf:0 -+inf:0 -123.4567:0 --0.1:0 --0.002:0 -1/3:0 -3/1:1 - -&is_even -abc:0 -0:1 --1:0 --3:0 -1:0 -3:0 -1000001:0 -1000002:1 -2:1 -+inf:0 --inf:0 -123.456:0 --123.456:0 -0.01:0 --0.01:0 -120:1 -1200:1 --1200:1 - -&is_pos -0:0 -1:1 --1:0 --123:0 -NaN:0 --inf:0 -+inf:1 - -&is_positive -0:0 -1:1 --1:0 --123:0 -NaN:0 --inf:0 -+inf:1 - -&is_neg -0:0 -1:0 --1:1 --123:1 -NaN:0 --inf:1 -+inf:0 - -&is_negative -0:0 -1:0 --1:1 --123:1 -NaN:0 --inf:1 -+inf:0 - -&parts -0:0 1 -1:1 1 -123:123 1 --123:-123 1 --1200:-1200 1 -5/7:5 7 --5/7:-5 7 -NaNparts:NaN NaN -+inf:inf inf --inf:-inf inf - -&length -123:3 --123:3 -0:1 -1:1 -12345678901234567890:20 - -&is_zero -NaNzero:0 -+inf:0 --inf:0 -0:1 --1:0 -1:0 -0/3:1 -1/3:0 --0/3:1 -5/inf:1 - -&is_one -# with no sign argument -invalid:0 -NaN:0 -+inf:0 --inf:0 --2:0 --1:0 -0:0 -1:1 --2:0 -# with sign argument "+" -invalid:+:0 -NaN:+:0 -+inf:+:0 --inf:+:0 --2:+:0 --1:+:0 -0:+:0 -1:+:1 --2:+:0 -# with sign argument "-" -invalid:-:0 -NaN:-:0 -+inf:-:0 --inf:-:0 --2:-:0 --1:-:1 -0:-:0 -1:-:0 --2:-:0 -1/3:0 -100/100:1 -0.1/0.1:1 -5/inf:0 - -&ffloor -0:0 -abc:NaN -+inf:inf --inf:-inf -1:1 --51:-51 --51.2:-52 -12.2:12 -3/7:0 -6/7:0 -7/7:1 -8/7:1 -13/7:1 -14/7:2 -15/7:2 --3/7:-1 --6/7:-1 --7/1:-7 --8/7:-2 --13/7:-2 --14/7:-2 --15/7:-3 - -&fceil -0:0 -abc:NaN -+inf:inf --inf:-inf -1:1 --51:-51 --51.2:-51 -12.2:13 -3/7:1 -6/7:1 -8/7:2 -13/7:2 -14/7:2 -15/7:3 --3/7:0 --6/7:0 --8/7:-1 --13/7:-1 --14/7:-2 --15/7:-2 - -&ffac -NaN:NaN -1:1 --1:NaN - -&bpow -# -abc:123:NaN -123:abc:NaN -# --inf:-inf:0 --inf:-3:0 --inf:-2:0 --inf:-3/2:0 --inf:-1:0 --inf:-1/2:0 --inf:0:NaN --inf:1/2:inf # directed infinity --inf:1:-inf --inf:3/2:inf # directed infinity --inf:2:inf --inf:3:-inf --inf:inf:inf # complex infinity --inf:NaN:NaN -# --3:-inf:0 --3:-3:-1/27 --3:-2:1/9 --3:-3/2:NaN --3:-1:-1/3 --3:-1/2:NaN --3:0:1 --3:1/2:NaN --3:1:-3 --3:3/2:NaN --3:2:9 --3:3:-27 --3:inf:inf # complex infinity --3:NaN:NaN -# --2:-inf:0 --2:-3:-1/8 --2:-2:1/4 --2:-3/2:NaN --2:-1:-1/2 --2:-1/2:NaN --2:0:1 --2:1/2:NaN --2:1:-2 --2:3/2:NaN --2:2:4 --2:3:-8 --2:inf:inf # complex infinity --2:NaN:NaN -# --3/2:-inf:0 --3/2:-3:-8/27 --3/2:-2:4/9 --3/2:-3/2:NaN --3/2:-1:-2/3 --3/2:-1/2:NaN --3/2:0:1 --3/2:1/2:NaN --3/2:1:-3/2 --3/2:3/2:NaN --3/2:2:9/4 --3/2:3:-27/8 --3/2:inf:inf # complex infinity --3/2:NaN:NaN -# --1:-inf:NaN --1:-3:-1 --1:-2:1 --1:-3/2:NaN --1:-1:-1 --1:-1/2:NaN --1:0:1 --1:1/2:NaN --1:1:-1 --1:3/2:NaN --1:2:1 --1:3:-1 --1:inf:NaN --1:NaN:NaN -# --1/2:-inf:inf # complex infinity --1/2:-3:-8 --1/2:-2:4 --1/2:-3/2:NaN --1/2:-1:-2 --1/2:-1/2:NaN --1/2:0:1 --1/2:1/2:NaN --1/2:1:-1/2 --1/2:3/2:NaN --1/2:2:1/4 --1/2:3:-1/8 --1/2:inf:0 --1/2:NaN:NaN -# -0:-inf:inf # complex infinity -0:-3:inf # complex infinity -0:-2:inf # complex infinity -0:-3/2:inf # complex infinity -0:-1:inf # complex infinity -0:-1/2:inf # complex infinity -0:0:1 -0:1/2:0 -0:1:0 -0:3/2:0 -0:2:0 -0:3:0 -0:inf:0 -0:NaN:NaN -# -1/2:-inf:inf -1/2:-3:8 -1/2:-2:4 -#1/2:-3/2:2.828427124746190097603377448419396157139 -1/2:-1:2 -#1/2:-1/2:1.41421356237309504880168872420969807857 -1/2:0:1 -#1/2:1/2:0.7071067811865475244008443621048490392848 -1/2:1:1/2 -#1/2:3/2:0.3535533905932737622004221810524245196424 -1/2:2:1/4 -1/2:3:1/8 -1/2:inf:0 -1/2:NaN:NaN -# -1:-inf:1 -1:-3:1 -1:-2:1 -1:-3/2:1 -1:-1:1 -1:-1/2:1 -1:0:1 -1:1/2:1 -1:1:1 -1:3/2:1 -1:2:1 -1:3:1 -1:inf:1 -1:NaN:NaN -# -3/2:-inf:0 -3/2:-3:8/27 -3/2:-2:4/9 -#3/2:-3/2:0.5443310539518173551549520166013091982147 -3/2:-1:2/3 -#3/2:-1/2:0.816496580927726032732428024901963797322 -3/2:0:1 -#3/2:1/2:1.224744871391589049098642037352945695983 -3/2:1:3/2 -#3/2:3/2:1.837117307087383573647963056029418543974 -3/2:2:9/4 -3/2:3:27/8 -3/2:inf:inf -3/2:NaN:NaN -# -2:-inf:0 -2:-3:1/8 -2:-2:1/4 -#2:-3/2:0.3535533905932737622004221810524245196424 -2:-1:1/2 -#2:-1/2:0.7071067811865475244008443621048490392848 -2:0:1 -#2:1/2:1.41421356237309504880168872420969807857 -2:1:2 -#2:3/2:2.828427124746190097603377448419396157139 -2:2:4 -2:3:8 -2:inf:inf -2:NaN:NaN -# -3:-inf:0 -3:-3:1/27 -3:-2:1/9 -#3:-3/2:0.1924500897298752548363829268339858185492 -3:-1:1/3 -#3:-1/2:0.5773502691896257645091487805019574556476 -3:0:1 -#3:1/2:1.732050807568877293527446341505872366943 -3:1:3 -#3:3/2:5.196152422706631880582339024517617100828 -3:2:9 -3:3:27 -3:inf:inf -3:NaN:NaN -# -inf:-inf:0 -inf:-3:0 -inf:-2:0 -inf:-3/2:0 -inf:-1:0 -inf:-1/2:0 -inf:0:NaN -inf:1/2:inf -inf:1:inf -inf:3/2:inf -inf:2:inf -inf:3:inf -inf:inf:inf -inf:NaN:NaN -# -NaN:-inf:NaN -NaN:-3:NaN -NaN:-2:NaN -NaN:-3/2:NaN -NaN:-1:NaN -NaN:-1/2:NaN -NaN:0:NaN -NaN:1/2:NaN -NaN:1:NaN -NaN:3/2:NaN -NaN:2:NaN -NaN:3:NaN -NaN:inf:NaN -NaN:NaN:NaN - -&bacmp -+0:-0:0 -+0:+1:-1 --1:+1:0 -+1:-1:0 --1:+2:-1 -+2:-1:1 --123456789:+987654321:-1 -+123456789:-987654321:-1 -+987654321:+123456789:1 --987654321:+123456789:1 --123:+4567889:-1 -# NaNs -acmpNaN:123: -123:acmpNaN: -acmpNaN:acmpNaN: -# infinity -+inf:+inf:0 --inf:-inf:0 -+inf:-inf:0 --inf:+inf:0 -+inf:123:1 --inf:123:1 -+inf:-123:1 --inf:-123:1 -+inf:1/23:1 --inf:1/23:1 -+inf:-1/23:1 --inf:-1/23:1 -+inf:12/3:1 --inf:12/3:1 -+inf:-12/3:1 --inf:-12/3:1 -123:inf:-1 --123:inf:-1 -123:-inf:-1 --123:-inf:-1 -1/23:inf:-1 --1/23:inf:-1 -1/23:-inf:-1 --1/23:-inf:-1 -12/3:inf:-1 --12/3:inf:-1 -12/3:-inf:-1 --12/3:-inf:-1 -# return undef -+inf:NaN: -NaN:inf: --inf:NaN: -NaN:-inf: -1/3:2/3:-1 -2/3:1/3:1 -2/3:2/3:0 - -&numerator -NaN:NaN -inf:inf --inf:-inf -3/7:3 --3/7:-3 -0:0 -1:1 -5/-3:-5 - -&denominator -NaN:NaN -inf:1 --inf:1 -3/7:7 -0:1 -1/1:1 --1/1:1 --3/7:7 -4/-5:5 - -&finc -3/2:5/2 --15/6:-3/2 -NaN:NaN --1/3:2/3 --2/7:5/7 - -&fdec -15/6:3/2 --3/2:-5/2 -1/3:-2/3 -2/7:-5/7 -NaN:NaN - -&log --1:NaN -0:-inf -1:0 -34803:3267955896544848894312057422508991/312500000000000000000000000000000 --inf:inf -inf:inf -NaN:NaN - -&exp - -&sin - -&cos - -&atan2 - -&int - -&abs - -&sqrt Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/bigratpm.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/bigratpm.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/bigratpm.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/bigratpm.t 15 Feb 2023 01:36:20 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,14 +0,0 @@ -# -*- mode: perl; -*- - -use strict; -use warnings; - -use Test::More tests => 899; - -use Math::BigRat lib => 'Calc'; - -our ($CLASS, $LIB); -$CLASS = "Math::BigRat"; -$LIB = "Math::BigInt::Calc"; # backend - -require './t/bigratpm.inc'; # all tests here for sharing Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/bigratup.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/bigratup.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/bigratup.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/bigratup.t 15 Feb 2023 01:36:20 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,41 +0,0 @@ -# -*- mode: perl; -*- - -# Test whether $Math::BigInt::upgrade breaks our neck - -use strict; -use warnings; - -use Test::More tests => 5; - -use Math::BigInt upgrade => 'Math::BigRat'; -use Math::BigRat; - -my $rat = 'Math::BigRat'; -my($x, $y, $z); - -############################################################################## -# bceil/bfloor - -$x = $rat->new('49/4'); -is($x->bfloor(), '12', 'floor(49/4)'); - -$x = $rat->new('49/4'); -is($x->bceil(), '13', 'ceil(49/4)'); - -############################################################################## -# bsqrt - -$x = $rat->new('144'); -is($x->bsqrt(), '12', 'bsqrt(144)'); - -$x = $rat->new('144/16'); -is($x->bsqrt(), '3', 'bsqrt(144/16)'); - -$x = $rat->new('1/3'); -is($x->bsqrt(), - '1443375672974064411272871951254893639119/2500000000000000000000000000000000000000', - 'bsqrt(1/3)'); - -# all tests successful - -1; Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/binv-mbr.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/binv-mbr.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/binv-mbr.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/binv-mbr.t 15 Feb 2023 01:32:35 -0000 1.1.1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,89 +0,0 @@ -# -*- mode: perl; -*- - -use strict; -use warnings; - -use Test::More tests => 21; - -use Scalar::Util qw< refaddr >; - -my $class; - -BEGIN { - $class = 'Math::BigRat'; - use_ok($class); -} - -while () { - s/#.*$//; # remove comments - s/\s+$//; # remove trailing whitespace - next unless length; # skip empty lines - - my ($xval, $yval) = split /:/; - my ($x, $got, @got); - - for my $context_is_scalar (0, 1) { - - my $test = qq|\$x = $class -> new("$xval");|; - - $test .= $context_is_scalar - ? qq| \$got = \$x -> binv();| - : qq| \@got = \$x -> binv();|; - - my $desc = "binv() in "; - $desc .= $context_is_scalar ? "scalar context" : "list context"; - - subtest $desc, - sub { - plan tests => $context_is_scalar ? 4 : 5; - - eval $test; - is($@, "", "'$test' gives emtpy \$\@"); - - if ($context_is_scalar) { - - # Check output. - - is(ref($got), $class, - "'$test' output arg is a $class"); - - is($x -> bstr(), $yval, - "'$test' output arg has the right value"); - - is(refaddr($got), refaddr($x), - "'$test' output arg is the invocand"); - - } else { - - # Check number of output arguments. - - cmp_ok(scalar(@got), '==', 1, - "'$test' gives one output arg"); - - # Check output. - - is(ref($got[0]), $class, - "'$test' output arg is a $class"); - - is($got[0] -> bstr(), $yval, - "'$test' output arg has the right value"); - - is(refaddr($got[0]), refaddr($x), - "'$test' output arg is the invocand"); - } - }; - } -} - -__DATA__ - -NaN:NaN -inf:0 -5:1/5 -2:1/2 -1:1 -0:inf --1:-1 --2:-1/2 --5:-1/5 --inf:0 Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/bitwise.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/bitwise.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/bitwise.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/bitwise.t 15 Feb 2023 01:36:20 -0000 1.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,42 +0,0 @@ -# -*- mode: perl; -*- - -use strict; -use warnings; - -use Test::More tests => 2602; - -my @classes = ('Math::BigRat'); - -# We should test all the following operators: -# -# & | ^ << >> &= |= ^= <<= >>= -# -# as well as the corresponding methods -# -# band bior bxor blsft brsft - -for my $class (@classes) { - use_ok($class); - - for my $op (qw( & | ^ )) { - for (my $xscalar = 0 ; $xscalar <= 8 ; $xscalar += 0.5) { - for (my $yscalar = 0 ; $yscalar <= 8 ; $yscalar += 0.5) { - - my $xint = int $xscalar; - my $yint = int $yscalar; - - my $x = $class -> new("$xscalar"); - my $y = $class -> new("$yscalar"); - - my $test = "$x $op $y"; - my $expected = eval "$xscalar $op $yscalar"; - my $got = eval "\$x $op \$y"; - - is($@, '', 'is $@ empty'); - isa_ok($got, $class, $test); - is($got, $expected, - "$x $op $y = $xint $op $yint = $expected"); - } - } - } -} Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/bnok-mbr.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/bnok-mbr.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/bnok-mbr.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/bnok-mbr.t 15 Feb 2023 01:32:35 -0000 1.1.1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,1451 +0,0 @@ -# -*- mode: perl; -*- - -use strict; -use warnings; - -use Test::More tests => 4957; - -my $class; - -BEGIN { - $class = 'Math::BigRat'; - use_ok($class); -} - -while () { - s/#.*$//; # remove comments - s/\s+$//; # remove trailing whitespace - next unless length; # skip empty lines - - my ($nval, $kval, $nokval) = split /:/; - my ($n, $k, $got, @got); - - for my $context_is_scalar (0, 1) { - for my $k_is_scalar (0, 1) { - - my $test = qq|\$n = $class -> new("$nval");|; - - $test .= $k_is_scalar - ? qq| \$k = "$kval";| - : qq| \$k = $class -> new("$kval");|; - - $test .= $context_is_scalar - ? qq| \$got = \$n -> bnok(\$k);| - : qq| \@got = \$n -> bnok(\$k);|; - - my $desc = "bnok() in "; - $desc .= $context_is_scalar ? "scalar context" : "list context"; - $desc .= $k_is_scalar ? " with k as scalar" : " with k as object"; - - subtest $desc, - sub { - plan tests => $context_is_scalar ? 7 : 8; - - eval $test; - is($@, "", "'$test' gives emtpy \$\@"); - - if ($context_is_scalar) { - - # Check output. - - is(ref($got), $class, - "'$test' output arg is a $class"); - - is($got -> bstr(), $nokval, - "'$test' output arg has the right value"); - - } else { - - # Check number of output arguments. - - cmp_ok(scalar @got, '==', 1, - "'$test' gives one output arg"); - - # Check output. - - is(ref($got[0]), $class, - "'$test' output arg is a $class"); - - is($got[0] -> bstr(), $nokval, - "'$test' output arg has the right value"); - } - - # Check the invocand. - - is(ref($n), $class, - "'$test' invocand is still a $class"); - - is($n -> bstr(), $nokval, - "'$test' invocand has the right value"); - - # Check the input argument. - - if ($k_is_scalar) { - - is(ref($k), '', - "'$test' second input arg is still a scalar"); - - is($k, $kval, - "'$test' second input arg is unmodified"); - - } else { - - is(ref($k), $class, - "'$test' second input arg is still a $class"); - - is($k -> bstr(), $kval, - "'$test' second input arg is unmodified"); - } - }; - } - } -} - -__DATA__ - -# n and/or k is NaN - -NaN:NaN:NaN -NaN:0:NaN -NaN:3:NaN -3:NaN:NaN -NaN:-3:NaN --3:NaN:NaN - -# n = inf - -inf:-inf:NaN -inf:-3:0 -inf:-2:0 -inf:-1:0 -inf:0:1 -inf:1:inf -inf:2:inf -inf:3:inf -inf:inf:NaN - -# n = -inf - --inf:-inf:NaN --inf:-3:0 --inf:-2:0 --inf:-1:0 --inf:0:1 --inf:1:-inf --inf:2:inf --inf:3:-inf --inf:inf:NaN - -# k = inf - --3:inf:NaN --2:inf:NaN --1:inf:NaN -0:inf:NaN -1:inf:NaN -2:inf:NaN -3:inf:NaN - -# k = -inf - --3:-inf:NaN --2:-inf:NaN --1:-inf:NaN -0:-inf:NaN -1:-inf:NaN -2:-inf:NaN -3:-inf:NaN - -# n = -15, k = n - 15 ... n + 15 - --15:-30:-77558760 --15:-29:40116600 --15:-28:-20058300 --15:-27:9657700 --15:-26:-4457400 --15:-25:1961256 --15:-24:-817190 --15:-23:319770 --15:-22:-116280 --15:-21:38760 --15:-20:-11628 --15:-19:3060 --15:-18:-680 --15:-17:120 --15:-16:-15 --15:-15:1 --15:-14:0 --15:-13:0 --15:-12:0 --15:-11:0 --15:-10:0 --15:-9:0 --15:-8:0 --15:-7:0 --15:-6:0 --15:-5:0 --15:-4:0 --15:-3:0 --15:-2:0 --15:-1:0 --15:0:1 --15:1:-15 --15:2:120 --15:3:-680 --15:4:3060 --15:5:-11628 --15:6:38760 --15:7:-116280 --15:8:319770 --15:9:-817190 --15:10:1961256 --15:11:-4457400 --15:12:9657700 --15:13:-20058300 --15:14:40116600 --15:15:-77558760 - -# n = -14, k = n - 15 ... n + 15 - --14:-29:-37442160 --14:-28:20058300 --14:-27:-10400600 --14:-26:5200300 --14:-25:-2496144 --14:-24:1144066 --14:-23:-497420 --14:-22:203490 --14:-21:-77520 --14:-20:27132 --14:-19:-8568 --14:-18:2380 --14:-17:-560 --14:-16:105 --14:-15:-14 --14:-14:1 --14:-13:0 --14:-12:0 --14:-11:0 --14:-10:0 --14:-9:0 --14:-8:0 --14:-7:0 --14:-6:0 --14:-5:0 --14:-4:0 --14:-3:0 --14:-2:0 --14:-1:0 --14:0:1 --14:1:-14 --14:2:105 --14:3:-560 --14:4:2380 --14:5:-8568 --14:6:27132 --14:7:-77520 --14:8:203490 --14:9:-497420 --14:10:1144066 --14:11:-2496144 --14:12:5200300 --14:13:-10400600 --14:14:20058300 --14:15:-37442160 - -# n = -13, k = n - 15 ... n + 15 - --13:-28:-17383860 --13:-27:9657700 --13:-26:-5200300 --13:-25:2704156 --13:-24:-1352078 --13:-23:646646 --13:-22:-293930 --13:-21:125970 --13:-20:-50388 --13:-19:18564 --13:-18:-6188 --13:-17:1820 --13:-16:-455 --13:-15:91 --13:-14:-13 --13:-13:1 --13:-12:0 --13:-11:0 --13:-10:0 --13:-9:0 --13:-8:0 --13:-7:0 --13:-6:0 --13:-5:0 --13:-4:0 --13:-3:0 --13:-2:0 --13:-1:0 --13:0:1 --13:1:-13 --13:2:91 --13:3:-455 --13:4:1820 --13:5:-6188 --13:6:18564 --13:7:-50388 --13:8:125970 --13:9:-293930 --13:10:646646 --13:11:-1352078 --13:12:2704156 --13:13:-5200300 --13:14:9657700 --13:15:-17383860 - -# n = -12, k = n - 15 ... n + 15 - --12:-27:-7726160 --12:-26:4457400 --12:-25:-2496144 --12:-24:1352078 --12:-23:-705432 --12:-22:352716 --12:-21:-167960 --12:-20:75582 --12:-19:-31824 --12:-18:12376 --12:-17:-4368 --12:-16:1365 --12:-15:-364 --12:-14:78 --12:-13:-12 --12:-12:1 --12:-11:0 --12:-10:0 --12:-9:0 --12:-8:0 --12:-7:0 --12:-6:0 --12:-5:0 --12:-4:0 --12:-3:0 --12:-2:0 --12:-1:0 --12:0:1 --12:1:-12 --12:2:78 --12:3:-364 --12:4:1365 --12:5:-4368 --12:6:12376 --12:7:-31824 --12:8:75582 --12:9:-167960 --12:10:352716 --12:11:-705432 --12:12:1352078 --12:13:-2496144 --12:14:4457400 --12:15:-7726160 - -# n = -11, k = n - 15 ... n + 15 - --11:-26:-3268760 --11:-25:1961256 --11:-24:-1144066 --11:-23:646646 --11:-22:-352716 --11:-21:184756 --11:-20:-92378 --11:-19:43758 --11:-18:-19448 --11:-17:8008 --11:-16:-3003 --11:-15:1001 --11:-14:-286 --11:-13:66 --11:-12:-11 --11:-11:1 --11:-10:0 --11:-9:0 --11:-8:0 --11:-7:0 --11:-6:0 --11:-5:0 --11:-4:0 --11:-3:0 --11:-2:0 --11:-1:0 --11:0:1 --11:1:-11 --11:2:66 --11:3:-286 --11:4:1001 --11:5:-3003 --11:6:8008 --11:7:-19448 --11:8:43758 --11:9:-92378 --11:10:184756 --11:11:-352716 --11:12:646646 --11:13:-1144066 --11:14:1961256 --11:15:-3268760 - -# n = -10, k = n - 15 ... n + 15 - --10:-25:-1307504 --10:-24:817190 --10:-23:-497420 --10:-22:293930 --10:-21:-167960 --10:-20:92378 --10:-19:-48620 --10:-18:24310 --10:-17:-11440 --10:-16:5005 --10:-15:-2002 --10:-14:715 --10:-13:-220 --10:-12:55 --10:-11:-10 --10:-10:1 --10:-9:0 --10:-8:0 --10:-7:0 --10:-6:0 --10:-5:0 --10:-4:0 --10:-3:0 --10:-2:0 --10:-1:0 --10:0:1 --10:1:-10 --10:2:55 --10:3:-220 --10:4:715 --10:5:-2002 --10:6:5005 --10:7:-11440 --10:8:24310 --10:9:-48620 --10:10:92378 --10:11:-167960 --10:12:293930 --10:13:-497420 --10:14:817190 --10:15:-1307504 - -# n = -9, k = n - 15 ... n + 15 - --9:-24:-490314 --9:-23:319770 --9:-22:-203490 --9:-21:125970 --9:-20:-75582 --9:-19:43758 --9:-18:-24310 --9:-17:12870 --9:-16:-6435 --9:-15:3003 --9:-14:-1287 --9:-13:495 --9:-12:-165 --9:-11:45 --9:-10:-9 --9:-9:1 --9:-8:0 --9:-7:0 --9:-6:0 --9:-5:0 --9:-4:0 --9:-3:0 --9:-2:0 --9:-1:0 --9:0:1 --9:1:-9 --9:2:45 --9:3:-165 --9:4:495 --9:5:-1287 --9:6:3003 --9:7:-6435 --9:8:12870 --9:9:-24310 --9:10:43758 --9:11:-75582 --9:12:125970 --9:13:-203490 --9:14:319770 --9:15:-490314 - -# n = -8, k = n - 15 ... n + 15 - --8:-23:-170544 --8:-22:116280 --8:-21:-77520 --8:-20:50388 --8:-19:-31824 --8:-18:19448 --8:-17:-11440 --8:-16:6435 --8:-15:-3432 --8:-14:1716 --8:-13:-792 --8:-12:330 --8:-11:-120 --8:-10:36 --8:-9:-8 --8:-8:1 --8:-7:0 --8:-6:0 --8:-5:0 --8:-4:0 --8:-3:0 --8:-2:0 --8:-1:0 --8:0:1 --8:1:-8 --8:2:36 --8:3:-120 --8:4:330 --8:5:-792 --8:6:1716 --8:7:-3432 --8:8:6435 --8:9:-11440 --8:10:19448 --8:11:-31824 --8:12:50388 --8:13:-77520 --8:14:116280 --8:15:-170544 - -# n = -7, k = n - 15 ... n + 15 - --7:-22:-54264 --7:-21:38760 --7:-20:-27132 --7:-19:18564 --7:-18:-12376 --7:-17:8008 --7:-16:-5005 --7:-15:3003 --7:-14:-1716 --7:-13:924 --7:-12:-462 --7:-11:210 --7:-10:-84 --7:-9:28 --7:-8:-7 --7:-7:1 --7:-6:0 --7:-5:0 --7:-4:0 --7:-3:0 --7:-2:0 --7:-1:0 --7:0:1 --7:1:-7 --7:2:28 --7:3:-84 --7:4:210 --7:5:-462 --7:6:924 --7:7:-1716 --7:8:3003 --7:9:-5005 --7:10:8008 --7:11:-12376 --7:12:18564 --7:13:-27132 --7:14:38760 --7:15:-54264 - -# n = -6, k = n - 15 ... n + 15 - --6:-21:-15504 --6:-20:11628 --6:-19:-8568 --6:-18:6188 --6:-17:-4368 --6:-16:3003 --6:-15:-2002 --6:-14:1287 --6:-13:-792 --6:-12:462 --6:-11:-252 --6:-10:126 --6:-9:-56 --6:-8:21 --6:-7:-6 --6:-6:1 --6:-5:0 --6:-4:0 --6:-3:0 --6:-2:0 --6:-1:0 --6:0:1 --6:1:-6 --6:2:21 --6:3:-56 --6:4:126 --6:5:-252 --6:6:462 --6:7:-792 --6:8:1287 --6:9:-2002 --6:10:3003 --6:11:-4368 --6:12:6188 --6:13:-8568 --6:14:11628 --6:15:-15504 - -# n = -5, k = n - 15 ... n + 15 - --5:-20:-3876 --5:-19:3060 --5:-18:-2380 --5:-17:1820 --5:-16:-1365 --5:-15:1001 --5:-14:-715 --5:-13:495 --5:-12:-330 --5:-11:210 --5:-10:-126 --5:-9:70 --5:-8:-35 --5:-7:15 --5:-6:-5 --5:-5:1 --5:-4:0 --5:-3:0 --5:-2:0 --5:-1:0 --5:0:1 --5:1:-5 --5:2:15 --5:3:-35 --5:4:70 --5:5:-126 --5:6:210 --5:7:-330 --5:8:495 --5:9:-715 --5:10:1001 --5:11:-1365 --5:12:1820 --5:13:-2380 --5:14:3060 --5:15:-3876 - -# n = -4, k = n - 15 ... n + 15 - --4:-19:-816 --4:-18:680 --4:-17:-560 --4:-16:455 --4:-15:-364 --4:-14:286 --4:-13:-220 --4:-12:165 --4:-11:-120 --4:-10:84 --4:-9:-56 --4:-8:35 --4:-7:-20 --4:-6:10 --4:-5:-4 --4:-4:1 --4:-3:0 --4:-2:0 --4:-1:0 --4:0:1 --4:1:-4 --4:2:10 --4:3:-20 --4:4:35 --4:5:-56 --4:6:84 --4:7:-120 --4:8:165 --4:9:-220 --4:10:286 --4:11:-364 --4:12:455 --4:13:-560 --4:14:680 --4:15:-816 - -# n = -3, k = n - 15 ... n + 15 - --3:-18:-136 --3:-17:120 --3:-16:-105 --3:-15:91 --3:-14:-78 --3:-13:66 --3:-12:-55 --3:-11:45 --3:-10:-36 --3:-9:28 --3:-8:-21 --3:-7:15 --3:-6:-10 --3:-5:6 --3:-4:-3 --3:-3:1 --3:-2:0 --3:-1:0 --3:0:1 --3:1:-3 --3:2:6 --3:3:-10 --3:4:15 --3:5:-21 --3:6:28 --3:7:-36 --3:8:45 --3:9:-55 --3:10:66 --3:11:-78 --3:12:91 --3:13:-105 --3:14:120 --3:15:-136 - -# n = -2, k = n - 15 ... n + 15 - --2:-17:-16 --2:-16:15 --2:-15:-14 --2:-14:13 --2:-13:-12 --2:-12:11 --2:-11:-10 --2:-10:9 --2:-9:-8 --2:-8:7 --2:-7:-6 --2:-6:5 --2:-5:-4 --2:-4:3 --2:-3:-2 --2:-2:1 --2:-1:0 --2:0:1 --2:1:-2 --2:2:3 --2:3:-4 --2:4:5 --2:5:-6 --2:6:7 --2:7:-8 --2:8:9 --2:9:-10 --2:10:11 --2:11:-12 --2:12:13 --2:13:-14 --2:14:15 --2:15:-16 - -# n = -1, k = n - 15 ... n + 15 - --1:-16:-1 --1:-15:1 --1:-14:-1 --1:-13:1 --1:-12:-1 --1:-11:1 --1:-10:-1 --1:-9:1 --1:-8:-1 --1:-7:1 --1:-6:-1 --1:-5:1 --1:-4:-1 --1:-3:1 --1:-2:-1 --1:-1:1 --1:0:1 --1:1:-1 --1:2:1 --1:3:-1 --1:4:1 --1:5:-1 --1:6:1 --1:7:-1 --1:8:1 --1:9:-1 --1:10:1 --1:11:-1 --1:12:1 --1:13:-1 --1:14:1 --1:15:-1 - -# n = 0, k = n - 15 ... n + 15 - -0:-15:0 -0:-14:0 -0:-13:0 -0:-12:0 -0:-11:0 -0:-10:0 -0:-9:0 -0:-8:0 -0:-7:0 -0:-6:0 -0:-5:0 -0:-4:0 -0:-3:0 -0:-2:0 -0:-1:0 -0:0:1 -0:1:0 -0:2:0 -0:3:0 -0:4:0 -0:5:0 -0:6:0 -0:7:0 -0:8:0 -0:9:0 -0:10:0 -0:11:0 -0:12:0 -0:13:0 -0:14:0 -0:15:0 - -# n = 1, k = n - 15 ... n + 15 - -1:-15:0 -1:-14:0 -1:-13:0 -1:-12:0 -1:-11:0 -1:-10:0 -1:-9:0 -1:-8:0 -1:-7:0 -1:-6:0 -1:-5:0 -1:-4:0 -1:-3:0 -1:-2:0 -1:-1:0 -1:0:1 -1:1:1 -1:2:0 -1:3:0 -1:4:0 -1:5:0 -1:6:0 -1:7:0 -1:8:0 -1:9:0 -1:10:0 -1:11:0 -1:12:0 -1:13:0 -1:14:0 -1:15:0 -1:16:0 - -# n = 2, k = n - 15 ... n + 15 - -2:-15:0 -2:-14:0 -2:-13:0 -2:-12:0 -2:-11:0 -2:-10:0 -2:-9:0 -2:-8:0 -2:-7:0 -2:-6:0 -2:-5:0 -2:-4:0 -2:-3:0 -2:-2:0 -2:-1:0 -2:0:1 -2:1:2 -2:2:1 -2:3:0 -2:4:0 -2:5:0 -2:6:0 -2:7:0 -2:8:0 -2:9:0 -2:10:0 -2:11:0 -2:12:0 -2:13:0 -2:14:0 -2:15:0 -2:16:0 -2:17:0 - -# n = 3, k = n - 15 ... n + 15 - -3:-15:0 -3:-14:0 -3:-13:0 -3:-12:0 -3:-11:0 -3:-10:0 -3:-9:0 -3:-8:0 -3:-7:0 -3:-6:0 -3:-5:0 -3:-4:0 -3:-3:0 -3:-2:0 -3:-1:0 -3:0:1 -3:1:3 -3:2:3 -3:3:1 -3:4:0 -3:5:0 -3:6:0 -3:7:0 -3:8:0 -3:9:0 -3:10:0 -3:11:0 -3:12:0 -3:13:0 -3:14:0 -3:15:0 -3:16:0 -3:17:0 -3:18:0 - -# n = 4, k = n - 15 ... n + 15 - -4:-15:0 -4:-14:0 -4:-13:0 -4:-12:0 -4:-11:0 -4:-10:0 -4:-9:0 -4:-8:0 -4:-7:0 -4:-6:0 -4:-5:0 -4:-4:0 -4:-3:0 -4:-2:0 -4:-1:0 -4:0:1 -4:1:4 -4:2:6 -4:3:4 -4:4:1 -4:5:0 -4:6:0 -4:7:0 -4:8:0 -4:9:0 -4:10:0 -4:11:0 -4:12:0 -4:13:0 -4:14:0 -4:15:0 -4:16:0 -4:17:0 -4:18:0 -4:19:0 - -# n = 5, k = n - 15 ... n + 15 - -5:-15:0 -5:-14:0 -5:-13:0 -5:-12:0 -5:-11:0 -5:-10:0 -5:-9:0 -5:-8:0 -5:-7:0 -5:-6:0 -5:-5:0 -5:-4:0 -5:-3:0 -5:-2:0 -5:-1:0 -5:0:1 -5:1:5 -5:2:10 -5:3:10 -5:4:5 -5:5:1 -5:6:0 -5:7:0 -5:8:0 -5:9:0 -5:10:0 -5:11:0 -5:12:0 -5:13:0 -5:14:0 -5:15:0 -5:16:0 -5:17:0 -5:18:0 -5:19:0 -5:20:0 - -# n = 6, k = n - 15 ... n + 15 - -6:-15:0 -6:-14:0 -6:-13:0 -6:-12:0 -6:-11:0 -6:-10:0 -6:-9:0 -6:-8:0 -6:-7:0 -6:-6:0 -6:-5:0 -6:-4:0 -6:-3:0 -6:-2:0 -6:-1:0 -6:0:1 -6:1:6 -6:2:15 -6:3:20 -6:4:15 -6:5:6 -6:6:1 -6:7:0 -6:8:0 -6:9:0 -6:10:0 -6:11:0 -6:12:0 -6:13:0 -6:14:0 -6:15:0 -6:16:0 -6:17:0 -6:18:0 -6:19:0 -6:20:0 -6:21:0 - -# n = 7, k = n - 15 ... n + 15 - -7:-15:0 -7:-14:0 -7:-13:0 -7:-12:0 -7:-11:0 -7:-10:0 -7:-9:0 -7:-8:0 -7:-7:0 -7:-6:0 -7:-5:0 -7:-4:0 -7:-3:0 -7:-2:0 -7:-1:0 -7:0:1 -7:1:7 -7:2:21 -7:3:35 -7:4:35 -7:5:21 -7:6:7 -7:7:1 -7:8:0 -7:9:0 -7:10:0 -7:11:0 -7:12:0 -7:13:0 -7:14:0 -7:15:0 -7:16:0 -7:17:0 -7:18:0 -7:19:0 -7:20:0 -7:21:0 -7:22:0 - -# n = 8, k = n - 15 ... n + 15 - -8:-15:0 -8:-14:0 -8:-13:0 -8:-12:0 -8:-11:0 -8:-10:0 -8:-9:0 -8:-8:0 -8:-7:0 -8:-6:0 -8:-5:0 -8:-4:0 -8:-3:0 -8:-2:0 -8:-1:0 -8:0:1 -8:1:8 -8:2:28 -8:3:56 -8:4:70 -8:5:56 -8:6:28 -8:7:8 -8:8:1 -8:9:0 -8:10:0 -8:11:0 -8:12:0 -8:13:0 -8:14:0 -8:15:0 -8:16:0 -8:17:0 -8:18:0 -8:19:0 -8:20:0 -8:21:0 -8:22:0 -8:23:0 - -# n = 9, k = n - 15 ... n + 15 - -9:-15:0 -9:-14:0 -9:-13:0 -9:-12:0 -9:-11:0 -9:-10:0 -9:-9:0 -9:-8:0 -9:-7:0 -9:-6:0 -9:-5:0 -9:-4:0 -9:-3:0 -9:-2:0 -9:-1:0 -9:0:1 -9:1:9 -9:2:36 -9:3:84 -9:4:126 -9:5:126 -9:6:84 -9:7:36 -9:8:9 -9:9:1 -9:10:0 -9:11:0 -9:12:0 -9:13:0 -9:14:0 -9:15:0 -9:16:0 -9:17:0 -9:18:0 -9:19:0 -9:20:0 -9:21:0 -9:22:0 -9:23:0 -9:24:0 - -# n = 10, k = n - 15 ... n + 15 - -10:-15:0 -10:-14:0 -10:-13:0 -10:-12:0 -10:-11:0 -10:-10:0 -10:-9:0 -10:-8:0 -10:-7:0 -10:-6:0 -10:-5:0 -10:-4:0 -10:-3:0 -10:-2:0 -10:-1:0 -10:0:1 -10:1:10 -10:2:45 -10:3:120 -10:4:210 -10:5:252 -10:6:210 -10:7:120 -10:8:45 -10:9:10 -10:10:1 -10:11:0 -10:12:0 -10:13:0 -10:14:0 -10:15:0 -10:16:0 -10:17:0 -10:18:0 -10:19:0 -10:20:0 -10:21:0 -10:22:0 -10:23:0 -10:24:0 -10:25:0 - -# n = 11, k = n - 15 ... n + 15 - -11:-15:0 -11:-14:0 -11:-13:0 -11:-12:0 -11:-11:0 -11:-10:0 -11:-9:0 -11:-8:0 -11:-7:0 -11:-6:0 -11:-5:0 -11:-4:0 -11:-3:0 -11:-2:0 -11:-1:0 -11:0:1 -11:1:11 -11:2:55 -11:3:165 -11:4:330 -11:5:462 -11:6:462 -11:7:330 -11:8:165 -11:9:55 -11:10:11 -11:11:1 -11:12:0 -11:13:0 -11:14:0 -11:15:0 -11:16:0 -11:17:0 -11:18:0 -11:19:0 -11:20:0 -11:21:0 -11:22:0 -11:23:0 -11:24:0 -11:25:0 -11:26:0 - -# n = 12, k = n - 15 ... n + 15 - -12:-15:0 -12:-14:0 -12:-13:0 -12:-12:0 -12:-11:0 -12:-10:0 -12:-9:0 -12:-8:0 -12:-7:0 -12:-6:0 -12:-5:0 -12:-4:0 -12:-3:0 -12:-2:0 -12:-1:0 -12:0:1 -12:1:12 -12:2:66 -12:3:220 -12:4:495 -12:5:792 -12:6:924 -12:7:792 -12:8:495 -12:9:220 -12:10:66 -12:11:12 -12:12:1 -12:13:0 -12:14:0 -12:15:0 -12:16:0 -12:17:0 -12:18:0 -12:19:0 -12:20:0 -12:21:0 -12:22:0 -12:23:0 -12:24:0 -12:25:0 -12:26:0 -12:27:0 - -# n = 13, k = n - 15 ... n + 15 - -13:-15:0 -13:-14:0 -13:-13:0 -13:-12:0 -13:-11:0 -13:-10:0 -13:-9:0 -13:-8:0 -13:-7:0 -13:-6:0 -13:-5:0 -13:-4:0 -13:-3:0 -13:-2:0 -13:-1:0 -13:0:1 -13:1:13 -13:2:78 -13:3:286 -13:4:715 -13:5:1287 -13:6:1716 -13:7:1716 -13:8:1287 -13:9:715 -13:10:286 -13:11:78 -13:12:13 -13:13:1 -13:14:0 -13:15:0 -13:16:0 -13:17:0 -13:18:0 -13:19:0 -13:20:0 -13:21:0 -13:22:0 -13:23:0 -13:24:0 -13:25:0 -13:26:0 -13:27:0 -13:28:0 - -# n = 14, k = n - 15 ... n + 15 - -14:-15:0 -14:-14:0 -14:-13:0 -14:-12:0 -14:-11:0 -14:-10:0 -14:-9:0 -14:-8:0 -14:-7:0 -14:-6:0 -14:-5:0 -14:-4:0 -14:-3:0 -14:-2:0 -14:-1:0 -14:0:1 -14:1:14 -14:2:91 -14:3:364 -14:4:1001 -14:5:2002 -14:6:3003 -14:7:3432 -14:8:3003 -14:9:2002 -14:10:1001 -14:11:364 -14:12:91 -14:13:14 -14:14:1 -14:15:0 -14:16:0 -14:17:0 -14:18:0 -14:19:0 -14:20:0 -14:21:0 -14:22:0 -14:23:0 -14:24:0 -14:25:0 -14:26:0 -14:27:0 -14:28:0 -14:29:0 - -# n = 15, k = n - 15 ... n + 15 - -15:-15:0 -15:-14:0 -15:-13:0 -15:-12:0 -15:-11:0 -15:-10:0 -15:-9:0 -15:-8:0 -15:-7:0 -15:-6:0 -15:-5:0 -15:-4:0 -15:-3:0 -15:-2:0 -15:-1:0 -15:0:1 -15:1:15 -15:2:105 -15:3:455 -15:4:1365 -15:5:3003 -15:6:5005 -15:7:6435 -15:8:6435 -15:9:5005 -15:10:3003 -15:11:1365 -15:12:455 -15:13:105 -15:14:15 -15:15:1 -15:16:0 -15:17:0 -15:18:0 -15:19:0 -15:20:0 -15:21:0 -15:22:0 -15:23:0 -15:24:0 -15:25:0 -15:26:0 -15:27:0 -15:28:0 -15:29:0 -15:30:0 Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/const-mbr.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/const-mbr.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/const-mbr.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/const-mbr.t 15 Feb 2023 01:32:35 -0000 1.1.1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,319 +0,0 @@ -# -*- mode: perl; -*- - -# Binary, octal, and hexadecimal floating point literals were introduced in -# v5.22.0. -# -# - It wasn't until v5.28.0 that binary, octal, and hexadecimal floating point -# literals were converted to the correct value on perls compiled with quadmath -# support. -# -# - It wasn't until v5.32.0 that binary and octal floating point literals worked -# correctly with constant overloading. Before v5.32.0, it seems like the -# second character is always silently converted to an "x", so, e.g., "0b1.1p8" -# is passed to the overload::constant subroutine as "0x1.1p8", and "01.1p+8" -# is passed as "0x.1p+8". -# -# - Octal floating point literals using the "0o" prefix were introduced in -# v5.34.0. - -# Note that all numeric literals that should not be overloaded must be quoted. - -use strict; -use warnings; - -use Test::More tests => "171"; - -use Math::BigRat ":constant"; - -my $class = "Math::BigRat"; -my $x; - -################################################################################ -# The following tests should be identical for Math::BigInt, Math::BigFloat and -# Math::BigRat. - -# These are handled by "binary". - -$x = 0xff; -is($x, "255", "hexadecimal integer literal 0xff"); -is(ref($x), $class, "value is a $class"); - -SKIP: { - # Hexadecimal literals using the "0X" prefix require v5.14.0. - skip "perl v5.14.0 required for hexadecimal integer literals" - . " with '0X' prefix", "2" if $] < "5.014"; - - $x = eval "0XFF"; - is($x, "255", "hexadecimal integer literal 0XFF"); - is(ref($x), $class, "value is a $class"); -} - -$x = 0377; -is($x, "255", "octal integer literal 0377"); -is(ref($x), $class, "value is a $class"); - -SKIP: { - # Octal literals using the "0o" prefix requires v5.34.0. - skip "perl v5.34.0 required for octal floating point literals" - . " with '0o' prefix", "4" if $] < "5.034"; - - for my $str (qw/ 0o377 0O377 /) { - $x = eval $str; - is($x, "255", "octal integer literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -$x = 0b11111111; -is($x, "255", "binary integer literal 0b11111111"); -is(ref($x), $class, "value is a $class"); - -SKIP: { - # Binary literals using the "0B" prefix require v5.14.0. - skip "perl v5.14.0 required for binary integer literals" - . " with '0B' prefix", "2" if $] < "5.014"; - - $x = eval "0B11111111"; - is($x, "255", "binary integer literal 0B11111111"); - is(ref($x), $class, "value is a $class"); -} - -# These are handled by "float". - -$x = 999999999999999999999999999999999999999999999999999999999999999999999999; -is($x, - "999999999999999999999999999999999999999999999999999999999999999999999999", - "decimal integer literal " . ("9" x 72)); -is(ref($x), $class, "value is a $class"); - -$x = 1e72 - 1; -is($x, - "999999999999999999999999999999999999999999999999999999999999999999999999", - "literal 1e72 - 1"); -is(ref($x), $class, "value is a $class"); - -# These are handled by "float". - -SKIP: { - # Hexadecimal floating point literals require v5.28.0. - skip "perl v5.28.0 required for hexadecimal floating point literals", - "6" * "2" + "2" * "2" if $] < "5.028"; - - for my $str (qw/ 0x1.3ap+8 0X1.3AP+8 - 0x1.3ap8 0X1.3AP8 - 0x13a0p-4 0X13A0P-4 /) - { - $x = eval $str; - is($x, "314", "hexadecimal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } - - for my $str (qw/ 0x0.0p+8 0X0.0P+8 /) - { - $x = eval $str; - is($x, "0", "hexadecimal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -SKIP: { - # Octal floating point literals using the "0o" prefix require v5.34.0. - skip "perl v5.34.0 required for octal floating point literals" - . " with '0o' prefix", "6" * "2" + "6" * "2" if $] < "5.034"; - - for my $str (qw/ 0o1.164p+8 0O1.164P+8 - 0o1.164p8 0O1.164P8 - 0o11640p-4 0O11640P-4 /) - { - $x = eval $str; - is($x, "314", "octal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } - - for my $str (qw/ 0o0.0p+8 0O0.0P+8 - 0o0.0p8 0O0.0P8 - 0o0.0p-8 0O0.0P-8 /) - { - $x = eval $str; - is($x, "0", "octal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -SKIP: { - # Octal floating point literals using the "0" prefix require v5.32.0. - skip "perl v5.32.0 required for octal floating point literals", - "6" * "2" + "6" * "2" if $] < "5.032"; - - for my $str (qw/ 01.164p+8 01.164P+8 - 01.164p8 01.164P8 - 011640p-4 011640P-4 /) - { - $x = eval $str; - is($x, "314", "octal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } - - for my $str (qw/ 00.0p+8 00.0P+8 - 00.0p8 00.0P8 - 00.0p-8 00.0P-8 /) - { - $x = eval $str; - is($x, "0", "octal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -SKIP: { - # Binary floating point literals require v5.32.0. - skip "perl v5.32.0 required for binary floating point literals", - "6" * "2" + "6" * "2" if $] < "5.032"; - - for my $str (qw/ 0b1.0011101p+8 0B1.0011101P+8 - 0b1.0011101p8 0B1.0011101P8 - 0b10011101000p-2 0B10011101000P-2 /) - { - $x = eval $str; - is($x, "314", "binary floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } - - for my $str (qw/ 0b0p+8 0B0P+8 - 0b0p8 0B0P8 - 0b0p-8 0B0P-8 - /) - { - $x = eval $str; - is($x, "0", "binary floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -# These are handled by "integer". - -$x = 314; -is($x, "314", "integer literal 314"); -is(ref($x), $class, "value is a $class"); - -$x = 0; -is($x, "0", "integer literal 0"); -is(ref($x), $class, "value is a $class"); - -$x = 2 ** 255; -is($x, - "578960446186580977117854925043439539266" - . "34992332820282019728792003956564819968", - "2 ** 255"); -is(ref($x), $class, "value is a $class"); - -# These are handled by "binary". - -{ - no warnings "portable"; # protect against "non-portable" warnings - - # hexadecimal constant - $x = 0x123456789012345678901234567890; - is($x, - "94522879687365475552814062743484560", - "hexadecimal constant 0x123456789012345678901234567890"); - is(ref($x), $class, "value is a $class"); - - # octal constant - $x = 012345676543210123456765432101234567654321; - is($x, - "1736132869400711976876385488263403729", - "octal constant 012345676543210123456765432101234567654321"); - is(ref($x), $class, "value is a $class"); - - # binary constant - $x = 0b01010100011001010110110001110011010010010110000101101101; - is($x, - "23755414508757357", - "binary constant 0b0101010001100101011011000111" - . "0011010010010110000101101101"); - is(ref($x), $class, "value is a $class"); -} - -################################################################################ -# The following tests are unique to $class. - -# These are handled by "float". - -$x = 0.999999999999999999999999999999999999999999999999999999999999999999999999; -is($x, - "999999999999999999999999999999999999999999999999999999999999999999999999" . - "/1000000000000000000000000000000000000000000000000000000000000000000000000", - "decimal floating point literal 0." . ("9" x 72)); -is(ref($x), $class, "value is a $class"); - -$x = 1e72 - 0.1; -is($x, - "9999999999999999999999999999999999999999999999999999999999999999999999999" - . "/10", - "literal 1e72 - 0.1"); -is(ref($x), $class, "value is a $class"); - -# These are handled by "float". - -SKIP: { - # Hexadecimal floating point literals require v5.28.0. - skip "perl v5.28.0 required for hexadecimal floating point literals", - "6" * "2" if $] < "5.028"; - - for my $str (qw/ 0x1.92p+1 0X1.92P+1 - 0x1.92p1 0X1.92P1 - 0x19.2p-3 0X19.2P-3 /) - { - $x = eval $str; - is($x, "201/64", "hexadecimal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -SKIP: { - # Octal floating point literals using the "0o" prefix require v5.34.0. - skip "perl v5.34.0 required for octal floating point literals" - . " with '0o' prefix", "6" * "2" if $] < "5.034"; - - for my $str (qw/ 0o1.444p+1 0O1.444P+1 - 0o1.444p1 0O1.444P1 - 0o14.44p-2 0O14.44P-2 /) - { - $x = eval $str; - is($x, "201/64", "octal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -SKIP: { - # Octal floating point literals using the "0" prefix require v5.32.0. - skip "perl v5.32.0 required for octal floating point literals", - "6" * "2" if $] < "5.032"; - - for my $str (qw/ 01.444p+1 01.444P+1 - 01.444p1 01.444P1 - 014.44p-2 014.44P-2 /) - { - $x = eval $str; - is($x, "201/64", "octal floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -SKIP: { - # Binary floating point literals require v5.32.0. - skip "perl v5.32.0 required for binary floating point literals", - "6" * "2" if $] < "5.032"; - - for my $str (qw/ 0b1.1001001p+1 0B1.1001001P+1 - 0b1.1001001p1 0B1.1001001P1 - 0b110.01001p-1 0B110.01001P-1 /) - { - $x = eval $str; - is($x, "201/64", "binary floating point literal $str"); - is(ref($x), $class, "value is a $class"); - } -} - -is(1.0 / 3.0, "1/3", - "1.0 / 3.0 = 1/3"); Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/downgrade.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/downgrade.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/downgrade.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/downgrade.t 14 May 2024 19:36:35 -0000 1.1.1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,430 +0,0 @@ -# -*- mode: perl; -*- - -# Note that this does not test Math::BigRat upgrading. - -use strict; -use warnings; - -use Test::More tests => 141; - -use Math::BigInt upgrade => 'Math::BigRat'; -use Math::BigRat downgrade => 'Math::BigInt'; - -is(Math::BigRat->downgrade(), 'Math::BigInt', 'Math::BigRat->downgrade()'); -is(Math::BigInt->upgrade(), 'Math::BigRat', 'Math::BigInt->upgrade()'); - - -################################################################################ -# Verify that constructors downgrade when they should. - -note("Enable downgrading, and see if constructors downgrade"); - -my $x; - -# new() - -$x = Math::BigRat -> new("0.5"); -cmp_ok($x, "==", 0.5); -is(ref $x, "Math::BigRat", "Creating a 0.5 does not downgrade"); - -$x = Math::BigRat -> new("4"); -cmp_ok($x, "==", 4, 'new("4")'); -is(ref $x, "Math::BigInt", "Creating a 4 downgrades to Math::BigInt"); - -$x = Math::BigRat -> new("0"); -cmp_ok($x, "==", 0, 'new("0")'); -is(ref $x, "Math::BigInt", "Creating a 0 downgrades to Math::BigInt"); - -$x = Math::BigRat -> new("1"); -cmp_ok($x, "==", 1, 'new("1")'); -is(ref $x, "Math::BigInt", "Creating a 1 downgrades to Math::BigInt"); - -$x = Math::BigRat -> new("Inf"); -cmp_ok($x, "==", "Inf", 'new("inf")'); -is(ref $x, "Math::BigInt", "Creating an Inf downgrades to Math::BigInt"); - -$x = Math::BigRat -> new("NaN"); -is($x, "NaN", 'new("NaN")'); -is(ref $x, "Math::BigInt", "Creating a NaN downgrades to Math::BigInt"); - -# bzero() - -$x = Math::BigRat -> bzero(); -cmp_ok($x, "==", 0, "bzero()"); -is(ref $x, "Math::BigInt", "Creating a 0 downgrades to Math::BigInt"); - -# bone() - -$x = Math::BigRat -> bone(); -cmp_ok($x, "==", 1, "bone()"); -is(ref $x, "Math::BigInt", "Creating a 1 downgrades to Math::BigInt"); - -# binf() - -$x = Math::BigRat -> binf(); -cmp_ok($x, "==", "Inf", "binf()"); -is(ref $x, "Math::BigInt", "Creating an Inf downgrades to Math::BigInt"); - -# bnan() - -$x = Math::BigRat -> bnan(); -is($x, "NaN", "bnan()"); -is(ref $x, "Math::BigInt", "Creating a NaN downgrades to Math::BigInt"); - -# from_hex() - -$x = Math::BigRat -> from_hex("13a"); -cmp_ok($x, "==", 314, 'from_hex("13a")'); -is(ref $x, "Math::BigInt", 'from_hex("13a") downgrades to Math::BigInt'); - -# from_oct() - -$x = Math::BigRat -> from_oct("472"); -cmp_ok($x, "==", 314, 'from_oct("472")'); -is(ref $x, "Math::BigInt", 'from_oct("472") downgrades to Math::BigInt'); - -# from_bin() - -$x = Math::BigRat -> from_bin("100111010"); -cmp_ok($x, "==", 314, 'from_bin("100111010")'); -is(ref $x, "Math::BigInt", - 'from_bin("100111010") downgrades to Math::BigInt'); - -note("Disable downgrading, and see if constructors downgrade"); - -Math::BigRat -> downgrade(undef); - -my $half = Math::BigRat -> new("1/2"); -my $four = Math::BigRat -> new("4"); -my $zero = Math::BigRat -> bzero(); -my $inf = Math::BigRat -> binf(); -my $nan = Math::BigRat -> bnan(); - -is(ref $half, "Math::BigRat", "Creating a 0.5 does not downgrade"); -is(ref $four, "Math::BigRat", "Creating a 4 does not downgrade"); -is(ref $zero, "Math::BigRat", "Creating a 0 does not downgrade"); -is(ref $inf, "Math::BigRat", "Creating an Inf does not downgrade"); -is(ref $nan, "Math::BigRat", "Creating a NaN does not downgrade"); - -################################################################################ -# Verify that other methods downgrade when they should. - -Math::BigRat -> downgrade("Math::BigInt"); - -note("bneg()"); - -$x = $zero -> copy() -> bneg(); -cmp_ok($x, "==", 0, "-(0) = 0"); -is(ref($x), "Math::BigInt", "-(0) => Math::BigInt"); - -$x = $four -> copy() -> bneg(); -cmp_ok($x, "==", -4, "-(4) = -4"); -is(ref($x), "Math::BigInt", "-(4) => Math::BigInt"); - -$x = $inf -> copy() -> bneg(); -cmp_ok($x, "==", "-inf", "-(Inf) = -Inf"); -is(ref($x), "Math::BigInt", "-(Inf) => Math::BigInt"); - -$x = $nan -> copy() -> bneg(); -is($x, "NaN", "-(NaN) = NaN"); -is(ref($x), "Math::BigInt", "-(NaN) => Math::BigInt"); - -note("bnorm()"); - -$x = $zero -> copy() -> bnorm(); -cmp_ok($x, "==", 0, "bnorm(0)"); -is(ref($x), "Math::BigInt", "bnorm(0) => Math::BigInt"); - -$x = $four -> copy() -> bnorm(); -cmp_ok($x, "==", 4, "bnorm(4)"); -is(ref($x), "Math::BigInt", "bnorm(4) => Math::BigInt"); - -$x = $inf -> copy() -> bnorm(); -cmp_ok($x, "==", "inf", "bnorm(Inf)"); -is(ref($x), "Math::BigInt", "bnorm(Inf) => Math::BigInt"); - -$x = $nan -> copy() -> bnorm(); -is($x, "NaN", "bnorm(NaN)"); -is(ref($x), "Math::BigInt", "bnorm(NaN) => Math::BigInt"); - -note("binc()"); - -$x = $zero -> copy() -> binc(); -cmp_ok($x, "==", 1, "binc(0)"); -is(ref($x), "Math::BigInt", "binc(0) => Math::BigInt"); - -$x = $four -> copy() -> binc(); -cmp_ok($x, "==", 5, "binc(4)"); -is(ref($x), "Math::BigInt", "binc(4) => Math::BigInt"); - -$x = $inf -> copy() -> binc(); -cmp_ok($x, "==", "inf", "binc(Inf)"); -is(ref($x), "Math::BigInt", "binc(Inf) => Math::BigInt"); - -$x = $nan -> copy() -> binc(); -is($x, "NaN", "binc(NaN)"); -is(ref($x), "Math::BigInt", "binc(NaN) => Math::BigInt"); - -note("bdec()"); - -$x = $zero -> copy() -> bdec(); -cmp_ok($x, "==", -1, "bdec(0)"); -is(ref($x), "Math::BigInt", "bdec(0) => Math::BigInt"); - -$x = $four -> copy() -> bdec(); -cmp_ok($x, "==", 3, "bdec(4)"); -is(ref($x), "Math::BigInt", "bdec(4) => Math::BigInt"); - -$x = $inf -> copy() -> bdec(); -cmp_ok($x, "==", "inf", "bdec(Inf)"); -is(ref($x), "Math::BigInt", "bdec(Inf) => Math::BigInt"); - -$x = $nan -> copy() -> bdec(); -is($x, "NaN", "bdec(NaN)"); -is(ref($x), "Math::BigInt", "bdec(NaN) => Math::BigInt"); - -note("badd()"); - -$x = $half -> copy() -> badd($nan); -is($x, "NaN", "0.5 + NaN = NaN"); -is(ref($x), "Math::BigInt", "0.5 + NaN => Math::BigInt"); - -$x = $half -> copy() -> badd($inf); -cmp_ok($x, "==", "+Inf", "0.5 + Inf = Inf"); -is(ref($x), "Math::BigInt", "2.5 + Inf => Math::BigInt"); - -$x = $half -> copy() -> badd($half); -cmp_ok($x, "==", 1, "0.5 + 0.5 = 1"); -is(ref($x), "Math::BigInt", "0.5 + 0.5 => Math::BigInt"); - -$x = $half -> copy() -> badd($half -> copy() -> bneg()); -cmp_ok($x, "==", 0, "0.5 + -0.5 = 0"); -is(ref($x), "Math::BigInt", "0.5 + -0.5 => Math::BigInt"); - -$x = $four -> copy() -> badd($zero); -cmp_ok($x, "==", 4, "4 + 0 = 4"); -is(ref($x), "Math::BigInt", "4 + 0 => Math::BigInt"); - -$x = $zero -> copy() -> badd($four); -cmp_ok($x, "==", 4, "0 + 4 = 4"); -is(ref($x), "Math::BigInt", "0 + 4 => Math::BigInt"); - -$x = $inf -> copy() -> badd($four); -cmp_ok($x, "==", "+Inf", "Inf + 4 = Inf"); -is(ref($x), "Math::BigInt", "Inf + 4 => Math::BigInt"); - -$x = $nan -> copy() -> badd($four); -is($x, "NaN", "NaN + 4 = NaN"); -is(ref($x), "Math::BigInt", "NaN + 4 => Math::BigInt"); - -note("bsub()"); - -$x = $half -> copy() -> bsub($nan); -is($x, "NaN", "0.5 - NaN = NaN"); -is(ref($x), "Math::BigInt", "0.5 - NaN => Math::BigInt"); - -$x = $half -> copy() -> bsub($inf); -cmp_ok($x, "==", "-Inf", "2.5 - Inf = -Inf"); -is(ref($x), "Math::BigInt", "2.5 - Inf => Math::BigInt"); - -$x = $half -> copy() -> bsub($half); -cmp_ok($x, "==", 0, "0.5 - 0.5 = 0"); -is(ref($x), "Math::BigInt", "0.5 - 0.5 => Math::BigInt"); - -$x = $half -> copy() -> bsub($half -> copy() -> bneg()); -cmp_ok($x, "==", 1, "0.5 - -0.5 = 1"); -is(ref($x), "Math::BigInt", "0.5 - -0.5 => Math::BigInt"); - -$x = $four -> copy() -> bsub($zero); -cmp_ok($x, "==", 4, "4 - 0 = 4"); -is(ref($x), "Math::BigInt", "4 - 0 => Math::BigInt"); - -$x = $zero -> copy() -> bsub($four); -cmp_ok($x, "==", -4, "0 - 4 = -4"); -is(ref($x), "Math::BigInt", "0 - 4 => Math::BigInt"); - -$x = $inf -> copy() -> bsub($four); -cmp_ok($x, "==", "Inf", "Inf - 4 = Inf"); -is(ref($x), "Math::BigInt", "Inf - 4 => Math::BigInt"); - -$x = $nan -> copy() -> bsub($four); -is($x, "NaN", "NaN - 4 = NaN"); -is(ref($x), "Math::BigInt", "NaN - 4 => Math::BigInt"); - -note("bmul()"); - -$x = $zero -> copy() -> bmul($four); -cmp_ok($x, "==", 0, "bmul(0, 4) = 0"); -is(ref($x), "Math::BigInt", "bmul(0, 4) => Math::BigInt"); - -$x = $four -> copy() -> bmul($four); -cmp_ok($x, "==", 16, "bmul(4, 4) = 16"); -is(ref($x), "Math::BigInt", "bmul(4, 4) => Math::BigInt"); - -$x = $inf -> copy() -> bmul($four); -cmp_ok($x, "==", "inf", "bmul(Inf, 4) = Inf"); -is(ref($x), "Math::BigInt", "bmul(Inf, 4) => Math::BigInt"); - -$x = $nan -> copy() -> bmul($four); -is($x, "NaN", "bmul(NaN, 4) = NaN"); -is(ref($x), "Math::BigInt", "bmul(NaN, 4) => Math::BigInt"); - -$x = $four -> copy() -> bmul("0.5"); -cmp_ok($x, "==", 2, "bmul(4, 0.5) = 2"); -is(ref($x), "Math::BigInt", "bmul(4, 0.5) => Math::BigInt"); - -# bmuladd() - -note("bdiv()"); - -note("bmod()"); - -note("bmodpow()"); - -note("bpow()"); - -note("blog()"); - -note("bexp()"); - -note("bnok()"); - -note("bsin()"); - -note("bcos()"); - -note("batan()"); - -note("batan()"); - -note("bsqrt()"); - -note("broot()"); - -note("bfac()"); - -note("bdfac()"); - -note("btfac()"); - -note("bmfac()"); - -note("blsft()"); - -note("brsft()"); - -note("band()"); - -note("bior()"); - -note("bxor()"); - -note("bnot()"); - -note("bround()"); - -# Add tests for rounding a non-integer to an integer. Fixme! - -$x = $zero -> copy() -> bround(); -cmp_ok($x, "==", 0, "bround(0)"); -is(ref($x), "Math::BigInt", "bround(0) => Math::BigInt"); - -$x = $four -> copy() -> bround(); -cmp_ok($x, "==", 4, "bround(4)"); -is(ref($x), "Math::BigInt", "bround(4) => Math::BigInt"); - -$x = $inf -> copy() -> bround(); -cmp_ok($x, "==", "inf", "bround(Inf)"); -is(ref($x), "Math::BigInt", "bround(Inf) => Math::BigInt"); - -$x = $nan -> copy() -> bround(); -is($x, "NaN", "bround(NaN)"); -is(ref($x), "Math::BigInt", "bround(NaN) => Math::BigInt"); - -note("bfround()"); - -# Add tests for rounding a non-integer to an integer. Fixme! - -$x = $zero -> copy() -> bfround(); -cmp_ok($x, "==", 0, "bfround(0)"); -is(ref($x), "Math::BigInt", "bfround(0) => Math::BigInt"); - -$x = $four -> copy() -> bfround(); -cmp_ok($x, "==", 4, "bfround(4)"); -is(ref($x), "Math::BigInt", "bfround(4) => Math::BigInt"); - -$x = $inf -> copy() -> bfround(); -cmp_ok($x, "==", "inf", "bfround(Inf)"); -is(ref($x), "Math::BigInt", "bfround(Inf) => Math::BigInt"); - -$x = $nan -> copy() -> bfround(); -is($x, "NaN", "bfround(NaN)"); -is(ref($x), "Math::BigInt", "bfround(NaN) => Math::BigInt"); - -note("bfloor()"); - -$x = $half -> copy() -> bfloor(); -cmp_ok($x, "==", 0, "bfloor(0)"); -is(ref($x), "Math::BigInt", "bfloor(0) => Math::BigInt"); - -$x = $inf -> copy() -> bfloor(); -cmp_ok($x, "==", "Inf", "bfloor(Inf)"); -is(ref($x), "Math::BigInt", "bfloor(Inf) => Math::BigInt"); - -$x = $nan -> copy() -> bfloor(); -is($x, "NaN", "bfloor(NaN)"); -is(ref($x), "Math::BigInt", "bfloor(NaN) => Math::BigInt"); - -note("bceil()"); - -$x = $half -> copy() -> bceil(); -cmp_ok($x, "==", 1, "bceil(0)"); -is(ref($x), "Math::BigInt", "bceil(0) => Math::BigInt"); - -$x = $inf -> copy() -> bceil(); -cmp_ok($x, "==", "Inf", "bceil(Inf)"); -is(ref($x), "Math::BigInt", "bceil(Inf) => Math::BigInt"); - -$x = $nan -> copy() -> bceil(); -is($x, "NaN", "bceil(NaN)"); -is(ref($x), "Math::BigInt", "bceil(NaN) => Math::BigInt"); - -note("bint()"); - -$x = $half -> copy() -> bint(); -cmp_ok($x, "==", 0, "bint(0)"); -is(ref($x), "Math::BigInt", "bint(0) => Math::BigInt"); - -$x = $inf -> copy() -> bint(); -cmp_ok($x, "==", "Inf", "bint(Inf)"); -is(ref($x), "Math::BigInt", "bint(Inf) => Math::BigInt"); - -$x = $nan -> copy() -> bint(); -is($x, "NaN", "bint(NaN)"); -is(ref($x), "Math::BigInt", "bint(NaN) => Math::BigInt"); - -note("bgcd()"); - -note("blcm()"); - -# mantissa() ? - -# exponent() ? - -# parts() ? - -# sparts() - -# nparts() - -# eparts() - -# dparts() - -# fparts() - -# numerator() - -# denominator() - -#require 'upgrade.inc'; # all tests here for sharing Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/dparts-mbr.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/dparts-mbr.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/dparts-mbr.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/dparts-mbr.t 15 Feb 2023 01:32:35 -0000 1.1.1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,67 +0,0 @@ -# -*- mode: perl; -*- - -use strict; -use warnings; - -use Test::More tests => 17; - -my $class; - -BEGIN { - $class = 'Math::BigRat'; - use_ok($class); -} - -while () { - s/#.*$//; # remove comments - s/\s+$//; # remove trailing whitespace - next unless length; # skip empty lines - - my ($x_str, $int_str, $frc_str) = split /:/; - my $test; - - $test = qq|\$x = $class -> new("$x_str");| - . qq| (\$i, \$f) = \$x -> dparts();|; - - subtest $test => sub { - plan tests => 5; - - my $x = $class -> new($x_str); - my ($int_got, $frc_got) = $x -> dparts(); - - is(ref($int_got), $class, "class of integer part"); - is(ref($frc_got), $class, "class of fraction part"); - - is($int_got, $int_str, "value of integer part"); - is($frc_got, $frc_str, "value of fraction part"); - is($x, $x_str, "input is unmodified"); - }; - - $test = qq|\$x = $class -> new("$x_str");| - . qq| \$i = \$x -> dparts();|; - - subtest $test => sub { - plan tests => 3, - - my $x = $class -> new($x_str); - my $int_got = $x -> dparts(); - - isa_ok($int_got, $class); - - is($int_got, $int_str, "value of integer part"); - is($x, $x_str, "input is unmodified"); - }; -} - -__DATA__ - -NaN:NaN:NaN - -inf:inf:0 --inf:-inf:0 - --9/4:-2:-1/4 --1:-1:0 -0:0:0 -1:1:0 -9/4:2:1/4 Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/fparts-mbr.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/fparts-mbr.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/fparts-mbr.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/fparts-mbr.t 15 Feb 2023 01:32:35 -0000 1.1.1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,97 +0,0 @@ -# -*- mode: perl; -*- - -# test fparts(), numerator(), denominator() - -use strict; -use warnings; - -use Test::More tests => 43; - -my $class; - -BEGIN { - $class = 'Math::BigRat'; - use_ok($class); -} - -while () { - s/#.*$//; # remove comments - s/\s+$//; # remove trailing whitespace - next unless length; # skip empty lines - - my ($x_str, $n_str, $d_str) = split /:/; - my $test; - - # test fparts() - - $test = qq|\$x = $class -> new("$x_str");| - . qq| (\$n, \$d) = \$x -> fparts();|; - - subtest $test => sub { - plan tests => 5; - - my $x = $class -> new($x_str); - my ($n, $d) = $x -> fparts(); - - is(ref($n), $class, "class of numerator"); - is(ref($d), $class, "class of denominator"); - - is($n, $n_str, "value of numerator"); - is($d, $d_str, "value of denominator"); - is($x, $x_str, "input is unmodified"); - }; - - # test numerator() - - $test = qq|\$x = $class -> new("$x_str");| - . qq| \$n = \$x -> numerator();|; - - subtest $test => sub { - plan tests => 3; - - my $x = $class -> new($x_str); - my $n = $x -> numerator(); - - is(ref($n), "Math::BigInt", "class of numerator"); - - is($n, $n_str, "value of numerator"); - is($x, $x_str, "input is unmodified"); - }; - - # test denominator() - - $test = qq|\$x = $class -> new("$x_str");| - . qq| \$d = \$x -> denominator();|; - - subtest $test => sub { - plan tests => 3; - - my $x = $class -> new($x_str); - my $d = $x -> denominator(); - - is(ref($d), "Math::BigInt", "class of denominator"); - - is($d, $d_str, "value of denominator"); - is($x, $x_str, "input is unmodified"); - }; -} - -__DATA__ - -NaN:NaN:NaN - -inf:inf:1 --inf:-inf:1 - --30:-30:1 --3:-3:1 --1:-1:1 -0:0:1 -1:1:1 -3:3:1 -30:30:1 - --31400:-31400:1 --157/50:-157:50 -157/50:157:50 -31400:31400:1 Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/hang.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/hang.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/hang.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/hang.t 15 Feb 2023 01:36:20 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,20 +0,0 @@ -# -*- mode: perl; -*- - -# test for bug #34584: hang in exp(1/2) - -use strict; -use warnings; - -use Test::More tests => 1; - -use Math::BigRat; - -my $result = Math::BigRat->new('1/2')->bexp(); - -is("$result", "824360635350064073424325393907081785827/500000000000000000000000000000000000000", - "exp(1/2) worked"); - -############################################################################## -# done - -1; Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/new-mbr.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/new-mbr.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/new-mbr.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/new-mbr.t 15 Feb 2023 01:32:35 -0000 1.1.1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,68 +0,0 @@ -# -*- mode: perl; -*- - -use strict; -use warnings; - -use Test::More tests => 8; - -my $class; - -BEGIN { $class = 'Math::BigRat'; } -BEGIN { use_ok($class); } - -use Scalar::Util qw< refaddr >; - -# CPAN RT #132712. - -my $q1 = $class -> new("-1/2"); -my ($n, $d) = $q1 -> parts(); - -my $n_orig = $n -> copy(); -my $d_orig = $d -> copy(); -my $q2 = $class -> new($n, $d); - -cmp_ok($n, "==", $n_orig, - "The value of the numerator hasn't changed"); -cmp_ok($d, "==", $d_orig, - "The value of the denominator hasn't changed"); - -isnt(refaddr($n), refaddr($n_orig), - "The addresses of the numerators have changed"); -isnt(refaddr($d), refaddr($d_orig), - "The addresses of the denominators have changed"); - -# new() - -{ - my $x = $class -> new(); - subtest qq|\$x = $class -> new();|, => sub { - plan tests => 2; - - is(ref($x), $class, "output arg is a $class"); - is($x, "0", 'output arg has the right value'); - }; -} - -# new("") - -{ - my $x = $class -> new(""); - subtest qq|\$x = $class -> new("");|, => sub { - plan tests => 2; - - is(ref($x), $class, "output arg is a $class"); - is($x, "NaN", 'output arg has the right value'); - }; -} - -# new(undef) - -{ - my $x = $class -> new(undef); - subtest qq|\$x = $class -> new(undef);|, => sub { - plan tests => 2; - - is(ref($x), $class, "output arg is a $class"); - is($x, "0", 'output arg has the right value'); - }; -} Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/requirer.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/requirer.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/requirer.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/requirer.t 15 Feb 2023 01:36:20 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,18 +0,0 @@ -# -*- mode: perl; -*- - -# check that simple requiring BigRat works - -use strict; -use warnings; - -use Test::More tests => 1; - -my ($x); - -require Math::BigRat; -$x = Math::BigRat->new(1); -++$x; - -is($x, 2, '$x got successfully modified'); - -# all tests done Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/rt121139.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/rt121139.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/rt121139.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/rt121139.t 15 Feb 2023 01:32:35 -0000 1.1.1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,16 +0,0 @@ -# -*- mode: perl; -*- - -# check for cpan rt #121139 - -use strict; -use warnings; -use Test::More tests => 2; -use Math::BigRat; - -my $a = Math::BigRat->new('3/2'); -my $x = Math::BigRat->new('2/3'); -is("$a", "3/2"); - -my $y = $a; -$y = $x * $y; -is("$a", "3/2"); Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/trap.t =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/trap.t diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/trap.t --- gnu/usr.bin/perl/cpan/Math-BigRat/t/trap.t 15 Feb 2023 01:36:20 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,105 +0,0 @@ -# -*- mode: perl; -*- - -# test that config( trap_nan => 1, trap_inf => 1) really works/dies - -use strict; -use warnings; - -use Test::More tests => 29; - -use Math::BigRat; - -my $mbr = 'Math::BigRat'; -my $x; - -foreach my $class ($mbr) { - - # can do? - can_ok($class, 'config'); - - ########################################################################### - # Default values. - ########################################################################### - - # defaults are okay? - is($class->config("trap_nan"), 0, qq|$class->config("trap_nan")|); - is($class->config("trap_inf"), 0, qq|$class->config("trap_inf")|); - - ########################################################################### - # Trap NaN. - ########################################################################### - - # can set? - $class->config( trap_nan => 1 ); - is($class->config("trap_nan"), 1, q|$class->config("trap_nan")|); - - # can reset? - $class->config( trap_nan => 0 ); - is($class->config("trap_nan"), 0, qq|$class->config("trap_nan")|); - - # can set via hash ref? - $class->config( { trap_nan => 1 } ); - is($class->config("trap_nan"), 1, q|$class->config("trap_nan")|); - - # also test that new() still works normally - eval { $x = $class->new("42"); $x->bnan(); }; - like($@, qr/^Tried to set/, qq|\$x = $class->new("42"); \$x->bnan();|); - # after new() never modified - is($x, 42, qq|\$x = $class->new("42"); \$x->bnan();|); - - # 0/0 => NaN - eval { $x = $class->new("0"); $x->bdiv(0); }; - like($@, qr/^Tried to set/, qq|\$x = $class->new("0"); \$x->bdiv(0);|); - # after new() never modified - is($x, 0, qq|\$x = $class->new("0"); \$x->bdiv(0);|); - - ########################################################################### - # Trap inf. - ########################################################################### - - # can set? - $class->config( trap_inf => 1 ); - is($class->config("trap_inf"), 1, qq|$class->config("trap_inf")|); - - eval { $x = $class->new("4711"); $x->binf(); }; - like($@, qr/^Tried to set/, qq|\$x = $class->new("4711"); \$x->binf();|); - # after new() never modified - is($x, 4711, qq|\$x = $class->new("4711"); \$x->binf();|); - - # +$x/0 => +inf - eval { $x = $class->new("4711"); $x->bdiv(0); }; - like($@, qr/^Tried to set/, qq|\$x =\$class->new("4711"); \$x->bdiv(0);|); - # after new() never modified - is($x, 4711, qq|\$x =\$class->new("4711"); \$x->bdiv(0);|); - - # -$x/0 => -inf - eval { $x = $class->new("-0815"); $x->bdiv(0); }; - like($@, qr/^Tried to set/, qq|\$x = $class->new("-0815"); \$x->bdiv(0);|); - # after new() never modified - is($x, -815, qq|\$x = $class->new("-0815"); \$x->bdiv(0);|); -} - -############################################################################## -# BigRat - -Math::BigRat->config(trap_nan => 1, - trap_inf => 1); - -for my $trap (qw/ 0.1a +inf inf -inf /) { - my $x = Math::BigRat->new('7/4'); - - note(""); # this is just for some space in the output - - # In each of the cases below, $x is not modified, because the code dies. - - eval { $x = $mbr->new("$trap"); }; - is($x, "7/4", qq|\$x = $mbr->new("$trap");|); - - eval { $x = $mbr->new("$trap"); }; - is($x, "7/4", qq|\$x = $mbr->new("$trap");|); - - eval { $x = $mbr->new("$trap/7"); }; - is($x, "7/4", qq|\$x = $mbr->new("$trap/7");|); -} - -# all tests done Index: gnu/usr.bin/perl/cpan/Math-BigRat/t/Math/BigRat/Test.pm =================================================================== RCS file: gnu/usr.bin/perl/cpan/Math-BigRat/t/Math/BigRat/Test.pm diff -N gnu/usr.bin/perl/cpan/Math-BigRat/t/Math/BigRat/Test.pm --- gnu/usr.bin/perl/cpan/Math-BigRat/t/Math/BigRat/Test.pm 30 Dec 2019 02:13:47 -0000 1.5 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,116 +0,0 @@ -package Math::BigRat::Test; - -require 5.006; -use strict; -use warnings; - -use Exporter; -use Math::BigRat; -use Math::BigFloat; - -our @ISA = qw(Math::BigRat Exporter); -our $VERSION = '0.04'; - -use overload; # inherit overload from BigRat - -# Globals -our $accuracy = undef; -our $precision = undef; -our $round_mode = 'even'; -our $div_scale = 40; - -my $class = 'Math::BigRat::Test'; - -#sub new { -# my $proto = shift; -# my $class = ref($proto) || $proto; -# -# my $value = shift; -# my $a = $accuracy; $a = $_[0] if defined $_[0]; -# my $p = $precision; $p = $_[1] if defined $_[1]; -# # Store the floating point value -# my $self = Math::BigFloat->new($value, $a, $p, $round_mode); -# bless $self, $class; -# $self->{'_custom'} = 1; # make sure this never goes away -# return $self; -#} - -BEGIN { - *fstr = \&bstr; - *fsstr = \&bsstr; - *objectify = \&Math::BigInt::objectify; - *AUTOLOAD = \&Math::BigRat::AUTOLOAD; - no strict 'refs'; - foreach my $method (qw/div acmp floor ceil root sqrt log fac modpow modinv/) { - *{'b' . $method} = \&{'Math::BigRat::b' . $method}; - } -} - -sub fround { - my ($x, $a) = @_; - - #print "$a $accuracy $precision $round_mode\n"; - Math::BigFloat->round_mode($round_mode); - Math::BigFloat->accuracy($a || $accuracy); - Math::BigFloat->precision(undef); - my $y = Math::BigFloat->new($x->bsstr(), undef, undef); - $class->new($y->fround($a)); -} - -sub ffround { - my ($x, $p) = @_; - - Math::BigFloat->round_mode($round_mode); - Math::BigFloat->accuracy(undef); - Math::BigFloat->precision($p || $precision); - my $y = Math::BigFloat->new($x->bsstr(), undef, undef); - $class->new($y->ffround($p)); -} - -sub bstr { - # calculate a BigFloat compatible string output - my ($x) = @_; - - $x = $class->new($x) unless ref $x; - - if ($x->{sign} !~ /^[+-]$/) { # inf, NaN etc - my $s = $x->{sign}; - $s =~ s/^\+//; # +inf => inf - return $s; - } - - my $s = ''; - $s = $x->{sign} if $x->{sign} ne '+'; # +3 vs 3 - - # print " bstr \$x ", $accuracy || $x->{_a} || 'notset', " ", $precision || $x->{_p} || 'notset', "\n"; - return $s.$x->{_n} if $x->{_d}->is_one(); - my $output = Math::BigFloat->new($x->{_n})->bdiv($x->{_d}); - local $Math::BigFloat::accuracy = $accuracy || $x->{_a}; - local $Math::BigFloat::precision = $precision || $x->{_p}; - $s.$output->bstr(); -} - -sub numify { - $_[0]->bsstr(); -} - -sub bsstr { - # calculate a BigFloat compatible string output - my ($x) = @_; - - $x = $class->new($x) unless ref $x; - - if ($x->{sign} !~ /^[+-]$/) { # inf, NaN etc - my $s = $x->{sign}; - $s =~ s/^\+//; # +inf => inf - return $s; - } - - my $s = ''; - $s = $x->{sign} if $x->{sign} ne '+'; # +3 vs 3 - - my $output = Math::BigFloat->new($x->{_n})->bdiv($x->{_d}); - return $s.$output->bsstr(); -} - -1; Index: gnu/usr.bin/perl/cpan/Module-Metadata/lib/Module/Metadata.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Module-Metadata/lib/Module/Metadata.pm,v diff -u -p -a -u -p -r1.5 Metadata.pm --- gnu/usr.bin/perl/cpan/Module-Metadata/lib/Module/Metadata.pm 1 Mar 2021 23:19:48 -0000 1.5 +++ gnu/usr.bin/perl/cpan/Module-Metadata/lib/Module/Metadata.pm 22 Jan 2025 00:37:42 -0000 @@ -1,6 +1,6 @@ # -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*- # vim:ts=8:sw=2:et:sta:sts=2:tw=78 -package Module::Metadata; # git description: v1.000036-4-g435a294 +package Module::Metadata; # git description: v1.000037-8-g92dec6c # ABSTRACT: Gather package and POD information from perl module files # Adapted from Perl-licensed code originally distributed with @@ -14,7 +14,7 @@ sub __clean_eval { eval $_[0] } use strict; use warnings; -our $VERSION = '1.000037'; +our $VERSION = '1.000038'; use Carp qw/croak/; use File::Spec; @@ -74,11 +74,22 @@ my $PKG_REGEXP = qr{ # match a packag \s+ # whitespace ($PKG_NAME_REGEXP) # a package name \s* # optional whitespace - ($V_NUM_REGEXP)? # optional version number - \s* # optional whitesapce + ($V_NUM_REGEXP)? # optional version number + \s* # optional whitespace [;\{] # semicolon line terminator or block start (since 5.16) }x; +my $CLASS_REGEXP = qr{ # match a class declaration (core since 5.38) + ^[\s\{;]* # intro chars on a line + class # the word 'class' + \s+ # whitespace + ($PKG_NAME_REGEXP) # a package name + \s* # optional whitespace + ($V_NUM_REGEXP)? # optional version number + \s* # optional whitespace + [;\{] # semicolon line terminator or block start +}x; + my $VARNAME_REGEXP = qr{ # match fully-qualified VERSION name ([\$*]) # sigil - $ or * ( @@ -607,7 +618,7 @@ sub _parse_fh { ? $self->_parse_version_expression( $line ) : (); - if ( $line =~ /$PKG_REGEXP/o ) { + if ( $line =~ /$PKG_REGEXP/o or $line =~ /$CLASS_REGEXP/ ) { $package = $1; my $version = $2; push( @packages, $package ) unless grep( $package eq $_, @packages ); @@ -850,7 +861,7 @@ Module::Metadata - Gather package and PO =head1 VERSION -version 1.000037 +version 1.000038 =head1 SYNOPSIS @@ -1082,7 +1093,7 @@ assistance from David Golden (xdg) =item * -Tomas Doran +Graham Knop =item * @@ -1116,75 +1127,71 @@ Olivier Mengué =item * -Graham Knop - -=item * - -tokuhirom +Tomas Doran =item * -Tatsuhiko Miyagawa +Christian Walde =item * -Christian Walde +Craig A. Berry =item * -Leon Timmermans +Tatsuhiko Miyagawa =item * -Peter Rabbitson +tokuhirom =item * -Steve Hay +Chris 'BinGOs' Williams =item * -Jerry D. Hedden +David Mitchell =item * -Craig A. Berry +David Steinbrunner =item * -Craig A. Berry +Edward Zborowski =item * -David Mitchell +Gareth Harper =item * -David Steinbrunner +James Raspass =item * -Edward Zborowski +Jerry D. Hedden =item * -Gareth Harper +Josh Jore =item * -James Raspass +Kent Fredric =item * -Chris 'BinGOs' Williams +Leon Timmermans =item * -Josh Jore +Peter Rabbitson =item * -Kent Fredric +Steve Hay =back Index: gnu/usr.bin/perl/cpan/Module-Metadata/t/extract-package.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Module-Metadata/t/extract-package.t,v diff -u -p -a -u -p -r1.3 extract-package.t --- gnu/usr.bin/perl/cpan/Module-Metadata/t/extract-package.t 30 Dec 2019 02:13:47 -0000 1.3 +++ gnu/usr.bin/perl/cpan/Module-Metadata/t/extract-package.t 22 Jan 2025 00:37:42 -0000 @@ -127,6 +127,21 @@ $VERSION = '999'; $::VERSION = 0.01; --- }, +{ + name => 'class NAME::SUBNAME', + package => [ 'Simple::Edward' ], + code => <<'---', +class Simple::Edward; +--- +}, +{ + name => 'class NAME::SUBNAME', + package => [ 'main', 'Simple::Edward' ], + code => <<'---', +our $foo = 1; +class Simple::Edward; +--- +}, ); my $test_num = 0; Index: gnu/usr.bin/perl/cpan/Module-Metadata/t/extract-version.t =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Module-Metadata/t/extract-version.t,v diff -u -p -a -u -p -r1.3 extract-version.t --- gnu/usr.bin/perl/cpan/Module-Metadata/t/extract-version.t 30 Dec 2019 02:13:47 -0000 1.3 +++ gnu/usr.bin/perl/cpan/Module-Metadata/t/extract-version.t 22 Jan 2025 00:37:42 -0000 @@ -355,6 +355,38 @@ our $VERSION = '1.23_00_00'; all_versions => { Simple => 'v1.2_3' }, }, { + name => 'class NAME VERSION', + code => <<'---', + class Simple 1.23; +--- + vers => '1.23', + all_versions => { Simple => '1.23' }, +}, +{ + name => 'class NAME VERSION', + code => <<'---', + class Simple 1.23_01; +--- + vers => '1.23_01', + all_versions => { Simple => '1.23_01' }, +}, +{ + name => 'class NAME VERSION', + code => <<'---', + class Simple v1.2.3; +--- + vers => 'v1.2.3', + all_versions => { Simple => 'v1.2.3' }, +}, +{ + name => 'class NAME VERSION', + code => <<'---', + class Simple v1.2_3; +--- + vers => 'v1.2_3', + all_versions => { Simple => 'v1.2_3' }, +}, +{ name => 'trailing crud', code => <<'---', package Simple; @@ -435,6 +467,46 @@ package Simple v1.2.3_4 { all_versions => { Simple => 'v1.2.3_4' }, }, { + name => 'class NAME BLOCK, undef $VERSION', + code => <<'---', +class Simple { + our $VERSION; +} +--- + vers => $undef, + all_versions => {}, +}, +{ + name => 'class NAME BLOCK, with $VERSION', + code => <<'---', +class Simple { + our $VERSION = '1.23'; +} +--- + vers => '1.23', + all_versions => { Simple => '1.23' }, +}, +{ + name => 'class NAME VERSION BLOCK (1)', + code => <<'---', +class Simple 1.23 { + 1; +} +--- + vers => '1.23', + all_versions => { Simple => '1.23' }, +}, +{ + name => 'class NAME VERSION BLOCK (2)', + code => <<'---', +class Simple v1.2.3_4 { + 1; +} +--- + vers => 'v1.2.3_4', + all_versions => { Simple => 'v1.2.3_4' }, +}, +{ name => 'set from separately-initialised variable, two lines', code => <<'---', package Simple; @@ -619,6 +691,7 @@ my $tmpdir = GeneratePackage::tmpdir(); # iterate through @modules foreach my $test_case (@modules) { + note ''; note '-------'; note $test_case->{name}; my $code = $test_case->{code}; Index: gnu/usr.bin/perl/cpan/Pod-Checker/lib/Pod/Checker.pm =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Pod-Checker/lib/Pod/Checker.pm,v diff -u -p -a -u -p -r1.1.1.4 Checker.pm --- gnu/usr.bin/perl/cpan/Pod-Checker/lib/Pod/Checker.pm 14 May 2024 19:36:32 -0000 1.1.1.4 +++ gnu/usr.bin/perl/cpan/Pod-Checker/lib/Pod/Checker.pm 22 Jan 2025 00:37:42 -0000 @@ -10,7 +10,7 @@ package Pod::Checker; use strict; use warnings; -our $VERSION = '1.75'; ## Current version of this package +our $VERSION = '1.77'; ## Current version of this package =head1 NAME Index: gnu/usr.bin/perl/cpan/Pod-Checker/scripts/podchecker.PL =================================================================== RCS file: /home/afresh1/OpenBSD-perl/OP/cvs/src/gnu/usr.bin/perl/cpan/Pod-Checker/scripts/podchecker.PL,v diff -u -p -a -u -p -r1.1.1.3 podchecker.PL --- gnu/usr.bin/perl/cpan/Pod-Checker/scripts/podchecker.PL 15 Feb 2023 01:32:43 -0000 1.1.1.3 +++ gnu/usr.bin/perl/cpan/Pod-Checker/scripts/podchecker.PL 22 Jan 2025 00:37:42 -0000 @@ -68,6 +68,10 @@ Print a brief help message and exit. Print the manual page and exit. +=item B<-quiet> + +Do not print a success message. + =item B<-warnings> B<-nowarnings> Turn on/off printing of warnings. Repeating B<-warnings> increases the @@ -133,7 +137,7 @@ use Getopt::Long; my %options; ## Parse options -GetOptions(\%options, qw(help man warnings+ nowarnings)) || pod2usage(2); +GetOptions(\%options, qw(help man quiet warnings+ nowarnings)) || pod2usage(2); pod2usage(1) if ($options{help}); pod2usage(-verbose => 2) if ($options{man}); @@ -173,7 +177,7 @@ for my $podfile (@ARGV) { print STDERR "$podfile does not contain any pod commands.\n"; } else { - print STDERR "$podfile pod syntax OK.\n"; + print "$podfile pod syntax OK.\n" unless $options{quiet}; } } exit $status; Index: gnu/usr.bin/perl/cpan/Pod-Perldoc/corpus/no-head.pod =================================================================== RCS file: gnu/usr.bin/perl/cpan/Pod-Perldoc/corpus/no-head.pod diff -N gnu/usr.bin/perl/cpan/Pod-Perldoc/corpus/no-head.pod --- gnu/usr.bin/perl/cpan/Pod-Perldoc/corpus/no-head.pod 25 Mar 2013 20:08:03 -0000 1.1.1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,5 +0,0 @@ -=pod - -This is a line of text - -=cut Index: gnu/usr.bin/perl/cpan/Pod-Perldoc/corpus/perlfunc.pod =================================================================== RCS file: gnu/usr.bin/perl/cpan/Pod-Perldoc/corpus/perlfunc.pod diff -N gnu/usr.bin/perl/cpan/Pod-Perldoc/corpus/perlfunc.pod --- gnu/usr.bin/perl/cpan/Pod-Perldoc/corpus/perlfunc.pod 25 Mar 2013 20:08:06 -0000 1.1.1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,8298 +0,0 @@ -=head1 NAME -X - -perlfunc - Perl builtin functions - -=head1 DESCRIPTION - -The functions in this section can serve as terms in an expression. -They fall into two major categories: list operators and named unary -operators. These differ in their precedence relationship with a -following comma. (See the precedence table in L.) List -operators take more than one argument, while unary operators can never -take more than one argument. Thus, a comma terminates the argument of -a unary operator, but merely separates the arguments of a list -operator. A unary operator generally provides scalar context to its -argument, while a list operator may provide either scalar or list -contexts for its arguments. If it does both, scalar arguments -come first and list argument follow, and there can only ever -be one such list argument. For instance, splice() has three scalar -arguments followed by a list, whereas gethostbyname() has four scalar -arguments. - -In the syntax descriptions that follow, list operators that expect a -list (and provide list context for elements of the list) are shown -with LIST as an argument. Such a list may consist of any combination -of scalar arguments or list values; the list values will be included -in the list as if each individual element were interpolated at that -point in the list, forming a longer single-dimensional list value. -Commas should separate literal elements of the LIST. - -Any function in the list below may be used either with or without -parentheses around its arguments. (The syntax descriptions omit the -parentheses.) If you use parentheses, the simple but occasionally -surprising rule is this: It I like a function, therefore it I a -function, and precedence doesn't matter. Otherwise it's a list -operator or unary operator, and precedence does matter. Whitespace -between the function and left parenthesis doesn't count, so sometimes -you need to be careful: - - print 1+2+4; # Prints 7. - print(1+2) + 4; # Prints 3. - print (1+2)+4; # Also prints 3! - print +(1+2)+4; # Prints 7. - print ((1+2)+4); # Prints 7. - -If you run Perl with the B<-w> switch it can warn you about this. For -example, the third line above produces: - - print (...) interpreted as function at - line 1. - Useless use of integer addition in void context at - line 1. - -A few functions take no arguments at all, and therefore work as neither -unary nor list operators. These include such functions as C